mirror of
https://github.com/overte-org/overte.git
synced 2025-08-07 13:50:35 +02:00
properly delete departing avatars
This commit is contained in:
parent
e9f52b1211
commit
33634cdaa1
5 changed files with 37 additions and 24 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue