mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-16 17:20:12 +02:00
everything now works with an atomic start time property. but now I will get rid of this and use current frame instead
This commit is contained in:
parent
1e5d099b06
commit
fdf5139a74
6 changed files with 70 additions and 38 deletions
|
@ -997,7 +997,7 @@ void ModelEntityRenderer::animate(const TypedEntityPointer& entity) {
|
|||
auto modelAnimProperties = entity->getAnimationProperties();
|
||||
|
||||
|
||||
//_currentFrame = modelAnimProperties.getCurrentlyPlayingFrame();
|
||||
//_currentFrame = modelAnimProperties.getCurrentFrame();
|
||||
|
||||
//tempbool = modelAnimProperties.getRunning();
|
||||
//qCDebug(entitiesrenderer) << "is playing is: " << tempbool;
|
||||
|
@ -1016,26 +1016,44 @@ void ModelEntityRenderer::animate(const TypedEntityPointer& entity) {
|
|||
}
|
||||
|
||||
auto now = usecTimestampNow();
|
||||
auto interval = now - _lastAnimated;
|
||||
|
||||
//find out how long it has been since this animation started.
|
||||
auto interval = now - _currentlyPlayingFrame;
|
||||
//auto interval = now - _lastAnimated;
|
||||
_lastAnimated = now;
|
||||
|
||||
|
||||
//new global start time code
|
||||
float nowTime = (float)interval / (float)USECS_PER_SECOND;
|
||||
float oldCurrentFrame = _currentFrame;
|
||||
_currentFrame = _renderAnimationProperties.getCurrentFrame() + (nowTime * _renderAnimationProperties.getFPS());
|
||||
|
||||
|
||||
//here we implement the looping animation property
|
||||
//if we have played through the animation once then we hold on the last frame
|
||||
|
||||
if( isLooping || ( _currentFrame < _endAnim ) ){
|
||||
if( isLooping || (_currentFrame < _endAnim ) ){
|
||||
//else advance the current frame.
|
||||
//if hold or not playing don't advance the current frame.
|
||||
//also if the animFrame is outside of first or last frame then don't advance the motion.
|
||||
if (!isHolding && entity->getAnimationIsPlaying() && !( _renderAnimationProperties.getCurrentFrame() > _renderAnimationProperties.getLastFrame() ) && !( _renderAnimationProperties.getCurrentFrame() < _renderAnimationProperties.getFirstFrame() ) ) {
|
||||
float deltaTime = (float)interval / (float)USECS_PER_SECOND;
|
||||
_currentlyPlayingFrame += (deltaTime * _renderAnimationProperties.getFPS());
|
||||
//float deltaTime = (float)interval / (float)USECS_PER_SECOND;
|
||||
//_currentlyPlayingFrame += (deltaTime * _renderAnimationProperties.getFPS());
|
||||
//do nothing
|
||||
}
|
||||
else {
|
||||
//use old currentFrame
|
||||
_currentFrame = oldCurrentFrame;
|
||||
}
|
||||
}
|
||||
else {
|
||||
//make current frame the endanim frame
|
||||
_currentFrame = _endAnim;
|
||||
}
|
||||
|
||||
{
|
||||
//where are we in the currently defined animation segment?
|
||||
int animationCurrentFrame = (int)(glm::floor(_currentlyPlayingFrame - firstFrame)) % updatedFrameCount;
|
||||
int animationCurrentFrame = (int)(glm::floor(_currentFrame - firstFrame)) % updatedFrameCount;
|
||||
//this gives us the absolute frame value to use by adding the first frame value.
|
||||
animationCurrentFrame += firstFrame;
|
||||
|
||||
|
@ -1369,7 +1387,7 @@ void ModelEntityRenderer::doRenderUpdateSynchronousTyped(const ScenePointer& sce
|
|||
withWriteLock([&] {
|
||||
if ( (newAnimationProperties.getCurrentFrame() != _renderAnimationProperties.getCurrentFrame()) || (newAnimationProperties.getFirstFrame() != _renderAnimationProperties.getFirstFrame()) || (newAnimationProperties.getLastFrame() != _renderAnimationProperties.getLastFrame()) || (newAnimationProperties.getRunning() && !_renderAnimationProperties.getRunning())) {
|
||||
if (!(newAnimationProperties.getCurrentFrame() > newAnimationProperties.getLastFrame()) && !(newAnimationProperties.getCurrentFrame() < newAnimationProperties.getFirstFrame())) {
|
||||
_currentFrame = newAnimationProperties.getCurrentFrame();
|
||||
_currentFrame = newAnimationProperties.getCurrentFrame();// +((float)newAnimationProperties.getCurrentlyPlayingFrame() / (float)USECS_PER_SECOND)*(newAnimationProperties.getFPS());
|
||||
_endAnim = _currentFrame + ( newAnimationProperties.getLastFrame() - newAnimationProperties.getFirstFrame() );
|
||||
_lastAnimated = 0;
|
||||
}
|
||||
|
@ -1378,6 +1396,7 @@ void ModelEntityRenderer::doRenderUpdateSynchronousTyped(const ScenePointer& sce
|
|||
_endAnim = _currentFrame + ((int)(newAnimationProperties.getLastFrame()) - (int)(newAnimationProperties.getFirstFrame())) - (float)currentframe_mod_length;
|
||||
}
|
||||
_currentlyPlayingFrame = newAnimationProperties.getCurrentlyPlayingFrame();
|
||||
qCDebug(entitiesrenderer) << "renderable update to currently playing frame " << _currentlyPlayingFrame;
|
||||
_renderAnimationProperties = newAnimationProperties;
|
||||
});
|
||||
}
|
||||
|
|
|
@ -187,7 +187,7 @@ private:
|
|||
float _currentFrame { 0 };
|
||||
float _endAnim{ 0 };
|
||||
bool tempbool{ false };
|
||||
float _currentlyPlayingFrame{ 0 };
|
||||
quint64 _currentlyPlayingFrame{ 0 };
|
||||
};
|
||||
|
||||
} } // namespace
|
||||
|
|
|
@ -75,7 +75,7 @@ void AnimationPropertyGroup::copyFromScriptValue(const QScriptValue& object, boo
|
|||
COPY_GROUP_PROPERTY_FROM_QSCRIPTVALUE(animation, hold, bool, setHold);
|
||||
|
||||
//angus added
|
||||
COPY_GROUP_PROPERTY_FROM_QSCRIPTVALUE(animation, currentlyPlayingFrame, float, setCurrentlyPlayingFrame);
|
||||
COPY_GROUP_PROPERTY_FROM_QSCRIPTVALUE(animation, currentlyPlayingFrame, quint64, setCurrentlyPlayingFrame);
|
||||
|
||||
// legacy property support
|
||||
COPY_PROPERTY_FROM_QSCRIPTVALUE_GETTER(animationFPS, float, setFPS, getFPS);
|
||||
|
@ -109,7 +109,7 @@ void AnimationPropertyGroup::setFromOldAnimationSettings(const QString& value) {
|
|||
bool loop = getLoop();
|
||||
bool hold = getHold();
|
||||
bool allowTranslation = getAllowTranslation();
|
||||
float currentlyPlayingFrame = getCurrentlyPlayingFrame();
|
||||
quint64 currentlyPlayingFrame = getCurrentlyPlayingFrame();
|
||||
|
||||
QJsonDocument settingsAsJson = QJsonDocument::fromJson(value.toUtf8());
|
||||
QJsonObject settingsAsJsonObject = settingsAsJson.object();
|
||||
|
@ -149,7 +149,7 @@ void AnimationPropertyGroup::setFromOldAnimationSettings(const QString& value) {
|
|||
}
|
||||
|
||||
if (settingsMap.contains("currentlyPlayingFrame")) {
|
||||
currentlyPlayingFrame = settingsMap["currentlyPlayingFrame"].toFloat();
|
||||
currentlyPlayingFrame = settingsMap["currentlyPlayingFrame"].toULongLong();
|
||||
}
|
||||
|
||||
setAllowTranslation(allowTranslation);
|
||||
|
@ -232,7 +232,7 @@ bool AnimationPropertyGroup::decodeFromEditPacket(EntityPropertyFlags& propertyF
|
|||
READ_ENTITY_PROPERTY(PROP_ANIMATION_FIRST_FRAME, float, setFirstFrame);
|
||||
READ_ENTITY_PROPERTY(PROP_ANIMATION_LAST_FRAME, float, setLastFrame);
|
||||
READ_ENTITY_PROPERTY(PROP_ANIMATION_HOLD, bool, setHold);
|
||||
READ_ENTITY_PROPERTY(PROP_ANIMATION_CURRENTLY_PLAYING_FRAME, float, setCurrentlyPlayingFrame);
|
||||
READ_ENTITY_PROPERTY(PROP_ANIMATION_CURRENTLY_PLAYING_FRAME, quint64, setCurrentlyPlayingFrame);
|
||||
|
||||
DECODE_GROUP_PROPERTY_HAS_CHANGED(PROP_ANIMATION_URL, URL);
|
||||
DECODE_GROUP_PROPERTY_HAS_CHANGED(PROP_ANIMATION_FPS, FPS);
|
||||
|
@ -367,6 +367,6 @@ int AnimationPropertyGroup::readEntitySubclassDataFromBuffer(const unsigned char
|
|||
READ_ENTITY_PROPERTY(PROP_ANIMATION_FIRST_FRAME, float, setFirstFrame);
|
||||
READ_ENTITY_PROPERTY(PROP_ANIMATION_LAST_FRAME, float, setLastFrame);
|
||||
READ_ENTITY_PROPERTY(PROP_ANIMATION_HOLD, bool, setHold);
|
||||
READ_ENTITY_PROPERTY(PROP_ANIMATION_CURRENTLY_PLAYING_FRAME, float, setCurrentlyPlayingFrame);
|
||||
READ_ENTITY_PROPERTY(PROP_ANIMATION_CURRENTLY_PLAYING_FRAME, quint64, setCurrentlyPlayingFrame);
|
||||
return bytesRead;
|
||||
}
|
||||
|
|
|
@ -86,7 +86,7 @@ public:
|
|||
DEFINE_PROPERTY(PROP_ANIMATION_LAST_FRAME, LastFrame, lastFrame, float, MAXIMUM_POSSIBLE_FRAME); // was animationSettings.lastFrame
|
||||
DEFINE_PROPERTY(PROP_ANIMATION_HOLD, Hold, hold, bool, false); // was animationSettings.hold
|
||||
DEFINE_PROPERTY(PROP_ANIMATION_ALLOW_TRANSLATION, AllowTranslation, allowTranslation, bool, true);
|
||||
DEFINE_PROPERTY(PROP_ANIMATION_CURRENTLY_PLAYING_FRAME, CurrentlyPlayingFrame, currentlyPlayingFrame, float, 0.0f);
|
||||
DEFINE_PROPERTY(PROP_ANIMATION_CURRENTLY_PLAYING_FRAME, CurrentlyPlayingFrame, currentlyPlayingFrame, quint64, 0);
|
||||
|
||||
protected:
|
||||
friend bool operator==(const AnimationPropertyGroup& a, const AnimationPropertyGroup& b);
|
||||
|
|
|
@ -200,19 +200,23 @@ void ModelEntityItem::update(const quint64& now) {
|
|||
qCDebug(entities) << "this is where the _currentFrame change is handled in the ModelEntityItem.cpp code";
|
||||
withWriteLock([&] {
|
||||
if ( (currentAnimationProperties.getCurrentFrame() != _previousAnimationProperties.getCurrentFrame()) || (currentAnimationProperties.getFirstFrame() != _previousAnimationProperties.getFirstFrame()) || (currentAnimationProperties.getLastFrame() != _previousAnimationProperties.getLastFrame()) || (currentAnimationProperties.getRunning() && !_previousAnimationProperties.getRunning())) {
|
||||
if (!(currentAnimationProperties.getCurrentFrame() > currentAnimationProperties.getLastFrame()) && !(currentAnimationProperties.getCurrentFrame() < currentAnimationProperties.getFirstFrame())) {
|
||||
_currentlyPlayingFrame = currentAnimationProperties.getCurrentFrame();
|
||||
_endAnim = _currentlyPlayingFrame + ( currentAnimationProperties.getLastFrame() - currentAnimationProperties.getFirstFrame() );
|
||||
_lastAnimated = 0;
|
||||
}
|
||||
}else if ( _previousAnimationProperties.getLoop() && !currentAnimationProperties.getLoop()) {
|
||||
int currentframe_mod_length = (int)(_currentlyPlayingFrame - (int)(glm::floor(currentAnimationProperties.getCurrentFrame()))) % ((int)(glm::floor(currentAnimationProperties.getLastFrame())) - (int)(glm::floor(currentAnimationProperties.getFirstFrame())) + 1);
|
||||
_endAnim = _currentlyPlayingFrame + ((int)(currentAnimationProperties.getLastFrame()) - (int)(currentAnimationProperties.getFirstFrame())) - (float)currentframe_mod_length;
|
||||
// if (!(currentAnimationProperties.getCurrentFrame() > currentAnimationProperties.getLastFrame()) && !(currentAnimationProperties.getCurrentFrame() < currentAnimationProperties.getFirstFrame())) {
|
||||
// _currentlyPlayingFrame = currentAnimationProperties.getCurrentFrame();
|
||||
//_endAnim = _currentlyPlayingFrame + ( currentAnimationProperties.getLastFrame() - currentAnimationProperties.getFirstFrame() );
|
||||
//_lastAnimated = 0;
|
||||
// }
|
||||
setAnimationCurrentlyPlayingFrame(usecTimestampNow());
|
||||
}
|
||||
//_previousAnimationProperties = currentAnimationProperties;
|
||||
//else if ( _previousAnimationProperties.getLoop() && !currentAnimationProperties.getLoop()) {
|
||||
// int currentframe_mod_length = (int)(_currentlyPlayingFrame - (int)(glm::floor(currentAnimationProperties.getCurrentFrame()))) % ((int)(glm::floor(currentAnimationProperties.getLastFrame())) - (int)(glm::floor(currentAnimationProperties.getFirstFrame())) + 1);
|
||||
//_endAnim = _currentlyPlayingFrame + ((int)(currentAnimationProperties.getLastFrame()) - (int)(currentAnimationProperties.getFirstFrame())) - (float)currentframe_mod_length;
|
||||
//}
|
||||
_previousAnimationProperties = currentAnimationProperties;
|
||||
});
|
||||
|
||||
qCDebug(entities) << "this is where the _currentFrame change is handled in the ModelEntityItem.cpp code, currently playing frame is: " << currentAnimationProperties.getCurrentlyPlayingFrame();
|
||||
}
|
||||
_previousAnimationProperties = currentAnimationProperties;
|
||||
//_previousAnimationProperties = currentAnimationProperties;
|
||||
updateFrameCount();
|
||||
|
||||
}
|
||||
|
@ -229,36 +233,45 @@ bool ModelEntityItem::needsToCallUpdate() const {
|
|||
|
||||
void ModelEntityItem::updateFrameCount() {
|
||||
|
||||
|
||||
|
||||
if (!_lastAnimated) {
|
||||
_lastAnimated = usecTimestampNow();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
auto now = usecTimestampNow();
|
||||
auto interval = now - _lastAnimated;
|
||||
_lastAnimated = now;
|
||||
|
||||
//this is now getting the time since the server started the animation.
|
||||
//auto interval = now - _currentlyPlayingFrame;
|
||||
//auto interval = now - _lastAnimated;
|
||||
//_lastAnimated = now;
|
||||
|
||||
|
||||
|
||||
|
||||
//here we implement the looping animation property
|
||||
//get entity anim props
|
||||
|
||||
bool isLooping = getAnimationLoop();
|
||||
int firstFrame = getAnimationFirstFrame();
|
||||
int lastFrame = getAnimationLastFrame();
|
||||
bool isHolding = getAnimationHold();
|
||||
|
||||
if (isLooping || (_currentlyPlayingFrame < _endAnim)) {
|
||||
//if (isLooping || (_currentFrame < _endAnim)) {
|
||||
//else advance the current frame.
|
||||
//if hold or not playing don't advance the current frame.
|
||||
//also if the animFrame is outside of first or last frame then don't advance the motion.
|
||||
if (!isHolding && getAnimationIsPlaying() && !(_previousAnimationProperties.getCurrentFrame() > _previousAnimationProperties.getLastFrame()) && !(_previousAnimationProperties.getCurrentFrame() < _previousAnimationProperties.getFirstFrame())) {
|
||||
float deltaTime = (float)interval / (float)USECS_PER_SECOND;
|
||||
_currentlyPlayingFrame += (deltaTime * _previousAnimationProperties.getFPS());
|
||||
qCDebug(entities) << "the frame is now " << _currentlyPlayingFrame;
|
||||
setAnimationCurrentlyPlayingFrame(_currentlyPlayingFrame);
|
||||
// float deltaTime = (float)interval / (float)USECS_PER_SECOND;
|
||||
// _currentlyPlayingFrame += (deltaTime * _previousAnimationProperties.getFPS());
|
||||
// qCDebug(entities) << "the frame is now " << _currentlyPlayingFrame;
|
||||
// setAnimationCurrentlyPlayingFrame(_currentlyPlayingFrame);
|
||||
setAnimationCurrentlyPlayingFrame(now);
|
||||
}
|
||||
|
||||
}
|
||||
//}
|
||||
|
||||
}
|
||||
|
||||
//angus
|
||||
|
@ -612,7 +625,7 @@ void ModelEntityItem::setAnimationCurrentFrame(float value) {
|
|||
});
|
||||
}
|
||||
|
||||
void ModelEntityItem::setAnimationCurrentlyPlayingFrame(float value) {
|
||||
void ModelEntityItem::setAnimationCurrentlyPlayingFrame(quint64 value) {
|
||||
_dirtyFlags |= Simulation::DIRTY_UPDATEABLE;
|
||||
withWriteLock([&] {
|
||||
_animationProperties.setCurrentlyPlayingFrame(value);
|
||||
|
@ -689,7 +702,7 @@ bool ModelEntityItem::isAnimatingSomething() const {
|
|||
});
|
||||
}
|
||||
|
||||
float ModelEntityItem::getCurrentlyPlayingFrame() const {
|
||||
quint64 ModelEntityItem::getCurrentlyPlayingFrame() const {
|
||||
return resultWithReadLock<float>([&] {
|
||||
return _currentlyPlayingFrame;
|
||||
});
|
||||
|
|
|
@ -87,7 +87,7 @@ public:
|
|||
void setAnimationURL(const QString& url);
|
||||
|
||||
void setAnimationCurrentFrame(float value);
|
||||
void setAnimationCurrentlyPlayingFrame(float value);
|
||||
void setAnimationCurrentlyPlayingFrame(quint64 value);
|
||||
void setAnimationIsPlaying(bool value);
|
||||
void setAnimationFPS(float value);
|
||||
|
||||
|
@ -110,7 +110,7 @@ public:
|
|||
float getAnimationCurrentFrame() const;
|
||||
bool isAnimatingSomething() const;
|
||||
|
||||
float getCurrentlyPlayingFrame() const;
|
||||
quint64 getCurrentlyPlayingFrame() const;
|
||||
int getLastKnownCurrentFrame() const;
|
||||
|
||||
static const QString DEFAULT_TEXTURES;
|
||||
|
@ -172,7 +172,7 @@ protected:
|
|||
|
||||
private:
|
||||
//angus
|
||||
float _currentlyPlayingFrame{ -1 };
|
||||
quint64 _currentlyPlayingFrame{ 0 };
|
||||
float _endAnim{ 0 };
|
||||
uint64_t _lastAnimated{ 0 };
|
||||
AnimationPropertyGroup _previousAnimationProperties;
|
||||
|
|
Loading…
Reference in a new issue