mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 18:13:05 +02:00
move some stuff out of Avatar::simulate()
call it explicity in AvatarManager::updateOtherAvatars()
This commit is contained in:
parent
b8afc87ad9
commit
69a7b1ef76
4 changed files with 42 additions and 15 deletions
|
@ -188,25 +188,35 @@ AABox Avatar::getBounds() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Avatar::animateScaleChanges(float deltaTime) {
|
void Avatar::animateScaleChanges(float deltaTime) {
|
||||||
float currentScale = getUniformScale();
|
if (_isAnimatingScale) {
|
||||||
auto desiredScale = getDomainLimitedScale();
|
float currentScale = getUniformScale();
|
||||||
if (currentScale != desiredScale) {
|
float desiredScale = getDomainLimitedScale();
|
||||||
|
|
||||||
// use exponential decay toward the domain limit clamped scale
|
// use exponential decay toward the domain limit clamped scale
|
||||||
const float SCALE_ANIMATION_TIMESCALE = 0.5f;
|
const float SCALE_ANIMATION_TIMESCALE = 0.5f;
|
||||||
float blendFactor = glm::clamp(deltaTime / SCALE_ANIMATION_TIMESCALE, 0.0f, 1.0f);
|
float blendFactor = glm::clamp(deltaTime / SCALE_ANIMATION_TIMESCALE, 0.0f, 1.0f);
|
||||||
float animatedScale = (1.0f - blendFactor) * currentScale + blendFactor * desiredScale;
|
float animatedScale = (1.0f - blendFactor) * currentScale + blendFactor * desiredScale;
|
||||||
|
|
||||||
// snap to the end when we get close enough
|
// snap to the end when we get close enough
|
||||||
const float MIN_RELATIVE_SCALE_ERROR = 0.03f;
|
const float MIN_RELATIVE_ERROR = 0.03f;
|
||||||
if (fabsf(desiredScale - currentScale) / desiredScale < MIN_RELATIVE_SCALE_ERROR) {
|
float relativeError = fabsf(desiredScale - currentScale) / desiredScale;
|
||||||
|
if (relativeError < MIN_RELATIVE_ERROR) {
|
||||||
animatedScale = desiredScale;
|
animatedScale = desiredScale;
|
||||||
|
_isAnimatingScale = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
setScale(glm::vec3(animatedScale)); // avatar scale is uniform
|
setScale(glm::vec3(animatedScale)); // avatar scale is uniform
|
||||||
|
|
||||||
|
// TODO: rebuilding the shape constantly is somehwat expensive.
|
||||||
|
// We should only rebuild after significant change.
|
||||||
rebuildCollisionShape();
|
rebuildCollisionShape();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Avatar::setTargetScale(float targetScale) {
|
||||||
|
AvatarData::setTargetScale(targetScale);
|
||||||
|
_isAnimatingScale = true;
|
||||||
|
}
|
||||||
|
|
||||||
void Avatar::updateAvatarEntities() {
|
void Avatar::updateAvatarEntities() {
|
||||||
PerformanceTimer perfTimer("attachments");
|
PerformanceTimer perfTimer("attachments");
|
||||||
// - if queueEditEntityMessage sees clientOnly flag it does _myAvatar->updateAvatarEntity()
|
// - if queueEditEntityMessage sees clientOnly flag it does _myAvatar->updateAvatarEntity()
|
||||||
|
@ -311,12 +321,6 @@ bool Avatar::shouldDie() const {
|
||||||
void Avatar::simulate(float deltaTime, bool inView) {
|
void Avatar::simulate(float deltaTime, bool inView) {
|
||||||
PROFILE_RANGE(simulation, "simulate");
|
PROFILE_RANGE(simulation, "simulate");
|
||||||
PerformanceTimer perfTimer("simulate");
|
PerformanceTimer perfTimer("simulate");
|
||||||
|
|
||||||
if (!isDead() && !_motionState) {
|
|
||||||
DependencyManager::get<AvatarManager>()->addAvatarToSimulation(this);
|
|
||||||
}
|
|
||||||
animateScaleChanges(deltaTime);
|
|
||||||
|
|
||||||
{
|
{
|
||||||
PROFILE_RANGE(simulation, "updateJoints");
|
PROFILE_RANGE(simulation, "updateJoints");
|
||||||
uint64_t start = usecTimestampNow();
|
uint64_t start = usecTimestampNow();
|
||||||
|
|
|
@ -181,6 +181,8 @@ public:
|
||||||
void setLastRenderUpdateTime(uint64_t time) { _lastRenderUpdateTime = time; }
|
void setLastRenderUpdateTime(uint64_t time) { _lastRenderUpdateTime = time; }
|
||||||
|
|
||||||
bool shouldDie() const;
|
bool shouldDie() const;
|
||||||
|
void animateScaleChanges(float deltaTime);
|
||||||
|
void setTargetScale(float targetScale) override;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
||||||
|
@ -231,8 +233,6 @@ protected:
|
||||||
// protected methods...
|
// protected methods...
|
||||||
bool isLookingAtMe(AvatarSharedPointer avatar) const;
|
bool isLookingAtMe(AvatarSharedPointer avatar) const;
|
||||||
|
|
||||||
virtual void animateScaleChanges(float deltaTime);
|
|
||||||
|
|
||||||
glm::vec3 getBodyRightDirection() const { return getOrientation() * IDENTITY_RIGHT; }
|
glm::vec3 getBodyRightDirection() const { return getOrientation() * IDENTITY_RIGHT; }
|
||||||
glm::vec3 getBodyUpDirection() const { return getOrientation() * IDENTITY_UP; }
|
glm::vec3 getBodyUpDirection() const { return getOrientation() * IDENTITY_UP; }
|
||||||
glm::vec3 getBodyFrontDirection() const { return getOrientation() * IDENTITY_FRONT; }
|
glm::vec3 getBodyFrontDirection() const { return getOrientation() * IDENTITY_FRONT; }
|
||||||
|
@ -269,6 +269,7 @@ private:
|
||||||
bool _initialized;
|
bool _initialized;
|
||||||
bool _isLookAtTarget { false };
|
bool _isLookAtTarget { false };
|
||||||
bool _inScene { false };
|
bool _inScene { false };
|
||||||
|
bool _isAnimatingScale { false };
|
||||||
|
|
||||||
float getBoundingRadius() const;
|
float getBoundingRadius() const;
|
||||||
|
|
||||||
|
|
|
@ -175,6 +175,9 @@ void AvatarManager::updateOtherAvatars(float deltaTime) {
|
||||||
removeAvatar(avatar->getID());
|
removeAvatar(avatar->getID());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (avatar->isDead()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// priority = weighted linear combination of:
|
// priority = weighted linear combination of:
|
||||||
// (a) apparentSize
|
// (a) apparentSize
|
||||||
|
@ -205,7 +208,24 @@ void AvatarManager::updateOtherAvatars(float deltaTime) {
|
||||||
while (!sortedAvatars.empty()) {
|
while (!sortedAvatars.empty()) {
|
||||||
const AvatarPriority& sortData = sortedAvatars.top();
|
const AvatarPriority& sortData = sortedAvatars.top();
|
||||||
const auto& avatar = std::static_pointer_cast<Avatar>(sortData.avatar);
|
const auto& avatar = std::static_pointer_cast<Avatar>(sortData.avatar);
|
||||||
|
|
||||||
|
// for ALL avatars...
|
||||||
avatar->ensureInScene(avatar);
|
avatar->ensureInScene(avatar);
|
||||||
|
if (!avatar->getMotionState()) {
|
||||||
|
ShapeInfo shapeInfo;
|
||||||
|
avatar->computeShapeInfo(shapeInfo);
|
||||||
|
btCollisionShape* shape = const_cast<btCollisionShape*>(ObjectMotionState::getShapeManager()->getShape(shapeInfo));
|
||||||
|
if (shape) {
|
||||||
|
// don't add to the simulation now, instead put it on a list to be added later
|
||||||
|
AvatarMotionState* motionState = new AvatarMotionState(avatar.get(), shape);
|
||||||
|
avatar->setMotionState(motionState);
|
||||||
|
_motionStatesToAddToPhysics.insert(motionState);
|
||||||
|
_motionStatesThatMightUpdate.insert(motionState);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
avatar->animateScaleChanges(deltaTime);
|
||||||
|
|
||||||
|
// for avatars in view...
|
||||||
const bool inView = sortData.priority > 0.5f * OUT_OF_VIEW_PENALTY;
|
const bool inView = sortData.priority > 0.5f * OUT_OF_VIEW_PENALTY;
|
||||||
avatar->simulate(deltaTime, inView);
|
avatar->simulate(deltaTime, inView);
|
||||||
if (expiry > usecTimestampNow()) {
|
if (expiry > usecTimestampNow()) {
|
||||||
|
@ -429,6 +449,7 @@ void AvatarManager::handleCollisionEvents(const CollisionEvents& collisionEvents
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
void AvatarManager::addAvatarToSimulation(Avatar* avatar) {
|
void AvatarManager::addAvatarToSimulation(Avatar* avatar) {
|
||||||
assert(!avatar->getMotionState());
|
assert(!avatar->getMotionState());
|
||||||
|
|
||||||
|
@ -443,6 +464,7 @@ void AvatarManager::addAvatarToSimulation(Avatar* avatar) {
|
||||||
_motionStatesThatMightUpdate.insert(motionState);
|
_motionStatesThatMightUpdate.insert(motionState);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
void AvatarManager::updateAvatarRenderStatus(bool shouldRenderAvatars) {
|
void AvatarManager::updateAvatarRenderStatus(bool shouldRenderAvatars) {
|
||||||
if (DependencyManager::get<SceneScriptingInterface>()->shouldRenderAvatars()) {
|
if (DependencyManager::get<SceneScriptingInterface>()->shouldRenderAvatars()) {
|
||||||
|
|
|
@ -69,7 +69,7 @@ public:
|
||||||
void handleOutgoingChanges(const VectorOfMotionStates& motionStates);
|
void handleOutgoingChanges(const VectorOfMotionStates& motionStates);
|
||||||
void handleCollisionEvents(const CollisionEvents& collisionEvents);
|
void handleCollisionEvents(const CollisionEvents& collisionEvents);
|
||||||
|
|
||||||
void addAvatarToSimulation(Avatar* avatar);
|
//void addAvatarToSimulation(Avatar* avatar);
|
||||||
|
|
||||||
Q_INVOKABLE RayToAvatarIntersectionResult findRayIntersection(const PickRay& ray,
|
Q_INVOKABLE RayToAvatarIntersectionResult findRayIntersection(const PickRay& ray,
|
||||||
const QScriptValue& avatarIdsToInclude = QScriptValue(),
|
const QScriptValue& avatarIdsToInclude = QScriptValue(),
|
||||||
|
|
Loading…
Reference in a new issue