properly delete departing avatars

This commit is contained in:
Andrew Meadows 2015-12-10 18:09:58 -08:00
parent e9f52b1211
commit 33634cdaa1
5 changed files with 37 additions and 24 deletions

View file

@ -150,11 +150,12 @@ float Avatar::getLODDistance() const {
void Avatar::animateScaleChanges(float deltaTime) { void Avatar::animateScaleChanges(float deltaTime) {
float currentScale = getUniformScale(); float currentScale = getUniformScale();
if (currentScale != _targetScale) { if (currentScale != _targetScale) {
const float SCALE_ANIMATION_TIMESCALE = 1.0f; const float SCALE_ANIMATION_TIMESCALE = 0.5f;
float blendFactor = deltaTime / SCALE_ANIMATION_TIMESCALE; float scaleVelocity = (_targetScale - currentScale) / SCALE_ANIMATION_TIMESCALE;
float animatedScale = (1.0f - blendFactor) * currentScale + blendFactor * _targetScale; float animatedScale = currentScale + deltaTime * scaleVelocity;
const float CLOSE_ENOUGH = 0.05f; const float MIN_SCALE_SPEED = 0.3f;
if (fabsf(animatedScale - _targetScale) / _targetScale < CLOSE_ENOUGH) { if (fabsf(scaleVelocity) < MIN_SCALE_SPEED) {
// close enough
animatedScale = _targetScale; animatedScale = _targetScale;
} }
setScale(glm::vec3(animatedScale)); // avatar scale is uniform setScale(glm::vec3(animatedScale)); // avatar scale is uniform
@ -165,6 +166,9 @@ void Avatar::animateScaleChanges(float deltaTime) {
void Avatar::simulate(float deltaTime) { void Avatar::simulate(float deltaTime) {
PerformanceTimer perfTimer("simulate"); PerformanceTimer perfTimer("simulate");
if (!isDead() && !_motionState) {
DependencyManager::get<AvatarManager>()->updateAvatarPhysicsShape(this);
}
animateScaleChanges(deltaTime); animateScaleChanges(deltaTime);
// update the billboard render flag // update the billboard render flag
@ -1107,13 +1111,14 @@ void Avatar::computeShapeInfo(ShapeInfo& shapeInfo) {
shapeInfo.setOffset(uniformScale * _skeletonModel.getBoundingCapsuleOffset()); shapeInfo.setOffset(uniformScale * _skeletonModel.getBoundingCapsuleOffset());
} }
void Avatar::setMotionState(AvatarMotionState* motionState) {
_motionState = motionState;
}
// virtual // virtual
void Avatar::rebuildCollisionShape() { void Avatar::rebuildCollisionShape() {
if (_motionState) { if (_motionState) {
_motionState->addDirtyFlags(Simulation::DIRTY_SHAPE); _motionState->addDirtyFlags(Simulation::DIRTY_SHAPE);
} else {
// adebug TODO: move most of updateAvatarPhysicsShape() to here
DependencyManager::get<AvatarManager>()->updateAvatarPhysicsShape(this);
} }
} }

View file

@ -157,7 +157,6 @@ public:
virtual void computeShapeInfo(ShapeInfo& shapeInfo); virtual void computeShapeInfo(ShapeInfo& shapeInfo);
void setMotionState(AvatarMotionState* motionState) { _motionState = motionState; }
AvatarMotionState* getMotionState() { return _motionState; } AvatarMotionState* getMotionState() { return _motionState; }
virtual void setPosition(const glm::vec3& position) override; virtual void setPosition(const glm::vec3& position) override;
@ -172,6 +171,10 @@ public slots:
glm::quat getRightPalmRotation(); glm::quat getRightPalmRotation();
protected: protected:
friend class AvatarManager;
void setMotionState(AvatarMotionState* motionState);
SkeletonModel _skeletonModel; SkeletonModel _skeletonModel;
glm::vec3 _skeletonOffset; glm::vec3 _skeletonOffset;
QVector<Model*> _attachmentModels; QVector<Model*> _attachmentModels;

View file

@ -261,6 +261,7 @@ void AvatarManager::removeAvatar(const QUuid& sessionUUID) {
void AvatarManager::handleRemovedAvatar(const AvatarSharedPointer& removedAvatar) { void AvatarManager::handleRemovedAvatar(const AvatarSharedPointer& removedAvatar) {
AvatarHashMap::handleRemovedAvatar(removedAvatar); AvatarHashMap::handleRemovedAvatar(removedAvatar);
removedAvatar->die();
removeAvatarMotionState(removedAvatar); removeAvatarMotionState(removedAvatar);
_avatarFades.push_back(removedAvatar); _avatarFades.push_back(removedAvatar);
} }
@ -375,7 +376,6 @@ void AvatarManager::handleCollisionEvents(const CollisionEvents& collisionEvents
} }
void AvatarManager::updateAvatarPhysicsShape(Avatar* avatar) { void AvatarManager::updateAvatarPhysicsShape(Avatar* avatar) {
// adebug TODO: move most of this logic to MyAvatar class
assert(!avatar->getMotionState()); assert(!avatar->getMotionState());
ShapeInfo shapeInfo; ShapeInfo shapeInfo;

View file

@ -342,6 +342,9 @@ public:
glm::vec3 getClientGlobalPosition() { return _globalPosition; } glm::vec3 getClientGlobalPosition() { return _globalPosition; }
void die() { _isDead = true; }
bool isDead() const { return _isDead; }
public slots: public slots:
void sendAvatarDataPacket(); void sendAvatarDataPacket();
void sendIdentityPacket(); void sendIdentityPacket();
@ -413,6 +416,8 @@ protected:
// updates about one avatar to another. // updates about one avatar to another.
glm::vec3 _globalPosition; glm::vec3 _globalPosition;
bool _isDead { false };
private: private:
friend void avatarStateFromFrame(const QByteArray& frameData, AvatarData* _avatar); friend void avatarStateFromFrame(const QByteArray& frameData, AvatarData* _avatar);
static QUrl _defaultFullAvatarModelUrl; static QUrl _defaultFullAvatarModelUrl;