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

View file

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

View file

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