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) {
float currentScale = getUniformScale();
if (currentScale != _targetScale) {
const float SCALE_ANIMATION_TIMESCALE = 1.0f;
float blendFactor = deltaTime / SCALE_ANIMATION_TIMESCALE;
float animatedScale = (1.0f - blendFactor) * currentScale + blendFactor * _targetScale;
const float CLOSE_ENOUGH = 0.05f;
if (fabsf(animatedScale - _targetScale) / _targetScale < CLOSE_ENOUGH) {
const float SCALE_ANIMATION_TIMESCALE = 0.5f;
float scaleVelocity = (_targetScale - currentScale) / SCALE_ANIMATION_TIMESCALE;
float animatedScale = currentScale + deltaTime * scaleVelocity;
const float MIN_SCALE_SPEED = 0.3f;
if (fabsf(scaleVelocity) < MIN_SCALE_SPEED) {
// close enough
animatedScale = _targetScale;
}
setScale(glm::vec3(animatedScale)); // avatar scale is uniform
@ -165,6 +166,9 @@ void Avatar::animateScaleChanges(float deltaTime) {
void Avatar::simulate(float deltaTime) {
PerformanceTimer perfTimer("simulate");
if (!isDead() && !_motionState) {
DependencyManager::get<AvatarManager>()->updateAvatarPhysicsShape(this);
}
animateScaleChanges(deltaTime);
// update the billboard render flag
@ -1107,13 +1111,14 @@ void Avatar::computeShapeInfo(ShapeInfo& shapeInfo) {
shapeInfo.setOffset(uniformScale * _skeletonModel.getBoundingCapsuleOffset());
}
void Avatar::setMotionState(AvatarMotionState* motionState) {
_motionState = motionState;
}
// virtual
void Avatar::rebuildCollisionShape() {
if (_motionState) {
_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);
void setMotionState(AvatarMotionState* motionState) { _motionState = motionState; }
AvatarMotionState* getMotionState() { return _motionState; }
virtual void setPosition(const glm::vec3& position) override;
@ -172,6 +171,10 @@ public slots:
glm::quat getRightPalmRotation();
protected:
friend class AvatarManager;
void setMotionState(AvatarMotionState* motionState);
SkeletonModel _skeletonModel;
glm::vec3 _skeletonOffset;
QVector<Model*> _attachmentModels;

View file

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

View file

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