move code from Avatar to OtherAvatar

This commit is contained in:
Andrew Meadows 2018-08-15 15:07:15 -07:00
parent 1c87d7b109
commit 99aafb1f95
4 changed files with 30 additions and 28 deletions

View file

@ -71,3 +71,21 @@ void OtherAvatar::updateSpaceProxy(workload::Transaction& transaction) const {
transaction.update(_spaceIndex, sphere);
}
}
int OtherAvatar::parseDataFromBuffer(const QByteArray& buffer) {
int32_t bytesRead = Avatar::parseDataFromBuffer(buffer);
if (_moving && _physicsCallback) {
_physicsCallback(Simulation::DIRTY_POSITION);
}
return bytesRead;
}
void OtherAvatar::rebuildCollisionShape() {
if (_physicsCallback) {
_physicsCallback(Simulation::DIRTY_SHAPE | Simulation::DIRTY_MASS);
}
}
void OtherAvatar::setPhysicsCallback(AvatarPhysicsCallback cb) {
_physicsCallback = cb;
}

View file

@ -1,6 +1,6 @@
//
// Created by Bradley Austin Davis on 2017/04/27
// Copyright 2013-2017 High Fidelity, Inc.
// Created by amantly 2018.06.26
// Copyright 2018 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
@ -18,6 +18,8 @@
#include "ui/overlays/Overlays.h"
#include "ui/overlays/Sphere3DOverlay.h"
using AvatarPhysicsCallback = std::function<void(uint32_t)>;
class OtherAvatar : public Avatar {
public:
explicit OtherAvatar(QThread* thread);
@ -32,9 +34,16 @@ public:
int32_t getSpaceIndex() const { return _spaceIndex; }
void updateSpaceProxy(workload::Transaction& transaction) const;
int parseDataFromBuffer(const QByteArray& buffer) override;
void setPhysicsCallback(AvatarPhysicsCallback cb);
bool isInPhysicsSimulation() const { return _physicsCallback != nullptr; }
void rebuildCollisionShape() override;
protected:
std::shared_ptr<Sphere3DOverlay> _otherAvatarOrbMeshPlaceholder { nullptr };
OverlayID _otherAvatarOrbMeshPlaceholderID { UNKNOWN_OVERLAY_ID };
AvatarPhysicsCallback _physicsCallback { nullptr };
int32_t _spaceIndex { -1 };
};

View file

@ -1483,9 +1483,6 @@ int Avatar::parseDataFromBuffer(const QByteArray& buffer) {
const float MOVE_DISTANCE_THRESHOLD = 0.001f;
_moving = glm::distance(oldPosition, getWorldPosition()) > MOVE_DISTANCE_THRESHOLD;
if (_moving) {
addPhysicsFlags(Simulation::DIRTY_POSITION);
}
if (_moving || _hasNewJointData) {
locationChanged();
}
@ -1627,20 +1624,6 @@ float Avatar::computeMass() {
return _density * TWO_PI * radius * radius * (glm::length(end - start) + 2.0f * radius / 3.0f);
}
void Avatar::rebuildCollisionShape() {
addPhysicsFlags(Simulation::DIRTY_SHAPE | Simulation::DIRTY_MASS);
}
void Avatar::setPhysicsCallback(AvatarPhysicsCallback cb) {
_physicsCallback = cb;
}
void Avatar::addPhysicsFlags(uint32_t flags) {
if (_physicsCallback) {
_physicsCallback(flags);
}
}
// thread-safe
glm::vec3 Avatar::getLeftPalmPosition() const {
return _leftPalmPositionCache.get();

View file

@ -50,8 +50,6 @@ enum ScreenTintLayer {
class Texture;
using AvatarPhysicsCallback = std::function<void(uint32_t)>;
class Avatar : public AvatarData, public scriptable::ModelProvider {
Q_OBJECT
@ -244,7 +242,7 @@ public:
// (otherwise floating point error will cause problems at large positions).
void applyPositionDelta(const glm::vec3& delta);
virtual void rebuildCollisionShape();
virtual void rebuildCollisionShape() = 0;
virtual void computeShapeInfo(ShapeInfo& shapeInfo);
void getCapsule(glm::vec3& start, glm::vec3& end, float& radius);
@ -332,10 +330,6 @@ public:
render::ItemID getRenderItemID() { return _renderItemID; }
bool isMoving() const { return _moving; }
void setPhysicsCallback(AvatarPhysicsCallback cb);
void addPhysicsFlags(uint32_t flags);
bool isInPhysicsSimulation() const { return _physicsCallback != nullptr; }
void fadeIn(render::ScenePointer scene);
void fadeOut(render::ScenePointer scene, KillAvatarReason reason);
bool isFading() const { return _isFading; }
@ -530,8 +524,6 @@ protected:
int _voiceSphereID;
AvatarPhysicsCallback _physicsCallback { nullptr };
float _displayNameTargetAlpha { 1.0f };
float _displayNameAlpha { 1.0f };