cleanup after removing spaghetti

This commit is contained in:
Andrew Meadows 2018-08-15 15:20:54 -07:00
parent 99aafb1f95
commit 3ecabb6583
3 changed files with 14 additions and 12 deletions

View file

@ -247,7 +247,7 @@ void AvatarManager::updateOtherAvatars(float deltaTime) {
if (shape) { if (shape) {
AvatarMotionState* motionState = new AvatarMotionState(avatar, shape); AvatarMotionState* motionState = new AvatarMotionState(avatar, shape);
motionState->setMass(avatar->computeMass()); motionState->setMass(avatar->computeMass());
avatar->setPhysicsCallback([=] (uint32_t flags) { motionState->addDirtyFlags(flags); }); avatar->setMotionState(motionState);
_motionStates.insert(avatar.get(), motionState); _motionStates.insert(avatar.get(), motionState);
_motionStatesToAddToPhysics.insert(motionState); _motionStatesToAddToPhysics.insert(motionState);
} }
@ -406,7 +406,7 @@ void AvatarManager::handleRemovedAvatar(const AvatarSharedPointer& removedAvatar
AvatarHashMap::handleRemovedAvatar(avatar, removalReason); AvatarHashMap::handleRemovedAvatar(avatar, removalReason);
// remove from physics // remove from physics
avatar->setPhysicsCallback(nullptr); avatar->setMotionState(nullptr);
AvatarMotionStateMap::iterator itr = _motionStates.find(avatar.get()); AvatarMotionStateMap::iterator itr = _motionStates.find(avatar.get());
if (itr != _motionStates.end()) { if (itr != _motionStates.end()) {
AvatarMotionState* motionState = *itr; AvatarMotionState* motionState = *itr;

View file

@ -9,6 +9,8 @@
#include "OtherAvatar.h" #include "OtherAvatar.h"
#include "Application.h" #include "Application.h"
#include "AvatarMotionState.h"
OtherAvatar::OtherAvatar(QThread* thread) : Avatar(thread) { OtherAvatar::OtherAvatar(QThread* thread) : Avatar(thread) {
// give the pointer to our head to inherited _headData variable from AvatarData // give the pointer to our head to inherited _headData variable from AvatarData
_headData = new Head(this); _headData = new Head(this);
@ -74,18 +76,18 @@ void OtherAvatar::updateSpaceProxy(workload::Transaction& transaction) const {
int OtherAvatar::parseDataFromBuffer(const QByteArray& buffer) { int OtherAvatar::parseDataFromBuffer(const QByteArray& buffer) {
int32_t bytesRead = Avatar::parseDataFromBuffer(buffer); int32_t bytesRead = Avatar::parseDataFromBuffer(buffer);
if (_moving && _physicsCallback) { if (_moving && _motionState) {
_physicsCallback(Simulation::DIRTY_POSITION); _motionState->addDirtyFlags(Simulation::DIRTY_POSITION);
} }
return bytesRead; return bytesRead;
} }
void OtherAvatar::rebuildCollisionShape() { void OtherAvatar::rebuildCollisionShape() {
if (_physicsCallback) { if (_motionState) {
_physicsCallback(Simulation::DIRTY_SHAPE | Simulation::DIRTY_MASS); _motionState->addDirtyFlags(Simulation::DIRTY_SHAPE | Simulation::DIRTY_MASS);
} }
} }
void OtherAvatar::setPhysicsCallback(AvatarPhysicsCallback cb) { void OtherAvatar::setMotionState(AvatarMotionState* motionState) {
_physicsCallback = cb; _motionState = motionState;
} }

View file

@ -18,7 +18,7 @@
#include "ui/overlays/Overlays.h" #include "ui/overlays/Overlays.h"
#include "ui/overlays/Sphere3DOverlay.h" #include "ui/overlays/Sphere3DOverlay.h"
using AvatarPhysicsCallback = std::function<void(uint32_t)>; class AvatarMotionState;
class OtherAvatar : public Avatar { class OtherAvatar : public Avatar {
public: public:
@ -36,14 +36,14 @@ public:
int parseDataFromBuffer(const QByteArray& buffer) override; int parseDataFromBuffer(const QByteArray& buffer) override;
void setPhysicsCallback(AvatarPhysicsCallback cb); void setMotionState(AvatarMotionState* motionState);
bool isInPhysicsSimulation() const { return _physicsCallback != nullptr; } bool isInPhysicsSimulation() const { return _motionState != nullptr; }
void rebuildCollisionShape() override; void rebuildCollisionShape() override;
protected: protected:
std::shared_ptr<Sphere3DOverlay> _otherAvatarOrbMeshPlaceholder { nullptr }; std::shared_ptr<Sphere3DOverlay> _otherAvatarOrbMeshPlaceholder { nullptr };
OverlayID _otherAvatarOrbMeshPlaceholderID { UNKNOWN_OVERLAY_ID }; OverlayID _otherAvatarOrbMeshPlaceholderID { UNKNOWN_OVERLAY_ID };
AvatarPhysicsCallback _physicsCallback { nullptr }; AvatarMotionState* _motionState { nullptr };
int32_t _spaceIndex { -1 }; int32_t _spaceIndex { -1 };
}; };