mirror of
https://github.com/JulianGro/overte.git
synced 2025-07-04 08:09:49 +02:00
initialize the _lastAnimated time when the modelEntityRenderer is instantiated, this fixes the sync between interface and the server
This commit is contained in:
parent
522dc3dfb1
commit
d607ca0914
4 changed files with 190 additions and 110 deletions
|
@ -63,13 +63,17 @@ bool ModelEntityWrapper::isModelLoaded() const {
|
||||||
EntityItemPointer RenderableModelEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) {
|
EntityItemPointer RenderableModelEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) {
|
||||||
EntityItemPointer entity(new RenderableModelEntityItem(entityID, properties.getDimensionsInitialized()),
|
EntityItemPointer entity(new RenderableModelEntityItem(entityID, properties.getDimensionsInitialized()),
|
||||||
[](EntityItem* ptr) { ptr->deleteLater(); });
|
[](EntityItem* ptr) { ptr->deleteLater(); });
|
||||||
|
|
||||||
entity->setProperties(properties);
|
entity->setProperties(properties);
|
||||||
|
|
||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
RenderableModelEntityItem::RenderableModelEntityItem(const EntityItemID& entityItemID, bool dimensionsInitialized) :
|
RenderableModelEntityItem::RenderableModelEntityItem(const EntityItemID& entityItemID, bool dimensionsInitialized) :
|
||||||
ModelEntityWrapper(entityItemID),
|
ModelEntityWrapper(entityItemID),
|
||||||
_dimensionsInitialized(dimensionsInitialized) {
|
_dimensionsInitialized(dimensionsInitialized) {
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RenderableModelEntityItem::~RenderableModelEntityItem() { }
|
RenderableModelEntityItem::~RenderableModelEntityItem() { }
|
||||||
|
@ -987,29 +991,17 @@ void ModelEntityRenderer::animate(const TypedEntityPointer& entity) {
|
||||||
}
|
}
|
||||||
|
|
||||||
//get entity model anim props
|
//get entity model anim props
|
||||||
bool isLooping = entity->getAnimationLoop();
|
|
||||||
int firstFrame = entity->getAnimationFirstFrame();
|
|
||||||
int lastFrame = entity->getAnimationLastFrame();
|
|
||||||
bool isHolding = entity->getAnimationHold();
|
|
||||||
int updatedFrameCount = lastFrame - firstFrame + 1;
|
|
||||||
|
|
||||||
//get the updated frame from the ModelEntity
|
int updatedFrameCount = entity->getAnimationLastFrame() - entity->getAnimationFirstFrame() + 1;
|
||||||
auto modelAnimProperties = entity->getAnimationProperties();
|
|
||||||
|
|
||||||
|
|
||||||
//_currentFrame = modelAnimProperties.getCurrentFrame();
|
if ((entity->getAnimationFirstFrame() < 0) && (entity->getAnimationFirstFrame() > entity->getAnimationLastFrame())){// && (lastFrame <= frameCount)) {
|
||||||
|
//we don't increment currentframe if the first frame is < zero or > than last frame.
|
||||||
//tempbool = modelAnimProperties.getRunning();
|
//return;
|
||||||
//qCDebug(entitiesrenderer) << "is playing is: " << tempbool;
|
|
||||||
|
|
||||||
qCDebug(entitiesrenderer) << "the client frame count is the following " << _currentFrame;
|
|
||||||
|
|
||||||
if ((firstFrame >= 0) && (firstFrame < lastFrame) && (lastFrame <= frameCount)) {
|
|
||||||
//length of animation in now determined by first and last frame
|
|
||||||
updatedFrameCount = (lastFrame - firstFrame + 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (!_lastAnimated) {
|
if (!_lastAnimated) {
|
||||||
_lastAnimated = usecTimestampNow();
|
_lastAnimated = usecTimestampNow();
|
||||||
return;
|
return;
|
||||||
|
@ -1022,45 +1014,37 @@ void ModelEntityRenderer::animate(const TypedEntityPointer& entity) {
|
||||||
auto interval = now - _lastAnimated;
|
auto interval = now - _lastAnimated;
|
||||||
_lastAnimated = now;
|
_lastAnimated = now;
|
||||||
|
|
||||||
float oldCurrentFrame = _currentFrame;
|
|
||||||
float deltaTime = (float)interval / (float)USECS_PER_SECOND;
|
|
||||||
_currentFrame += (deltaTime * _renderAnimationProperties.getFPS());
|
|
||||||
|
|
||||||
//here we implement the looping animation property
|
//here we implement the looping animation property
|
||||||
//if we have played through the animation once then we hold on the last frame
|
//if we have played through the animation once then we hold on the last frame
|
||||||
|
if (!(entity->getAnimationHold()) && entity->getAnimationIsPlaying()) {
|
||||||
if( isLooping || (_currentFrame < _renderAnimationProperties.getLastFrame() ) ){
|
|
||||||
//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;
|
float deltaTime = (float)interval / (float)USECS_PER_SECOND;
|
||||||
_currentFrame += (deltaTime * _renderAnimationProperties.getFPS());
|
_currentFrame += (deltaTime * entity->getAnimationFPS());
|
||||||
while ((_currentFrame - _renderAnimationProperties.getFirstFrame()) > updatedFrameCount) {
|
if (_currentFrame > entity->getAnimationLastFrame()) {
|
||||||
_currentFrame -= updatedFrameCount;
|
if (entity->getAnimationLoop()) {
|
||||||
|
while ((_currentFrame - entity->getAnimationFirstFrame()) > (updatedFrameCount - 1)) {
|
||||||
|
_currentFrame -= (updatedFrameCount - 1);
|
||||||
}
|
}
|
||||||
|
}else{
|
||||||
|
_currentFrame = entity->getAnimationLastFrame();
|
||||||
}
|
}
|
||||||
else {
|
}else if (_currentFrame < entity->getAnimationFirstFrame()) {
|
||||||
//use old currentFrame
|
if (entity->getAnimationFirstFrame() < 0) {
|
||||||
_currentFrame = oldCurrentFrame;
|
_currentFrame = 0;
|
||||||
}
|
|
||||||
}else {
|
}else {
|
||||||
//make current frame the endanim frame
|
_currentFrame = entity->getAnimationFirstFrame();
|
||||||
_currentFrame = _renderAnimationProperties.getLastFrame();
|
|
||||||
}
|
}
|
||||||
//save the last place that we rendered ourselves.
|
}
|
||||||
//entity->setAnimationCurrentFrame(_currentFrame);
|
}
|
||||||
|
qCDebug(entitiesrenderer) << "_currentFrame " << _currentFrame;
|
||||||
|
|
||||||
|
|
||||||
{
|
{
|
||||||
//where are we in the currently defined animation segment?
|
//where are we in the currently defined animation segment?
|
||||||
// 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;
|
|
||||||
int animationCurrentFrame = (int)(glm::floor(_currentFrame));
|
int animationCurrentFrame = (int)(glm::floor(_currentFrame));
|
||||||
|
//in the case where the last frame is greater than the framecount then clamp
|
||||||
|
//it to the end of the animation until it loops around.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (animationCurrentFrame < 0 || animationCurrentFrame > frameCount) {
|
if (animationCurrentFrame < 0 || animationCurrentFrame > frameCount) {
|
||||||
animationCurrentFrame = 0;
|
animationCurrentFrame = 0;
|
||||||
|
@ -1382,23 +1366,65 @@ void ModelEntityRenderer::doRenderUpdateSynchronousTyped(const ScenePointer& sce
|
||||||
// make a copy of the animation properites
|
// make a copy of the animation properites
|
||||||
auto newAnimationProperties = entity->getAnimationProperties();
|
auto newAnimationProperties = entity->getAnimationProperties();
|
||||||
if (newAnimationProperties != _renderAnimationProperties) {
|
if (newAnimationProperties != _renderAnimationProperties) {
|
||||||
qCDebug(entitiesrenderer) << "this is where the change is currently handled in the rendering code";
|
|
||||||
qCDebug(entitiesrenderer) << "getting the currently playing frame from the modelentityitem update" << newAnimationProperties.getCurrentFrame();
|
|
||||||
withWriteLock([&] {
|
withWriteLock([&] {
|
||||||
if ( (newAnimationProperties.getCurrentFrame() != _renderAnimationProperties.getCurrentFrame()) || (newAnimationProperties.getFirstFrame() != _renderAnimationProperties.getFirstFrame()) || (newAnimationProperties.getLastFrame() != _renderAnimationProperties.getLastFrame()) || (newAnimationProperties.getRunning() && !_renderAnimationProperties.getRunning())) {
|
if ((newAnimationProperties.getFirstFrame() != _renderAnimationProperties.getFirstFrame()) || (newAnimationProperties.getLastFrame() != _renderAnimationProperties.getLastFrame()) || (newAnimationProperties.getRunning() && !_renderAnimationProperties.getRunning())) {
|
||||||
if (!(newAnimationProperties.getCurrentFrame() > newAnimationProperties.getLastFrame()) && !(newAnimationProperties.getCurrentFrame() < newAnimationProperties.getFirstFrame())) {
|
if (_currentFrame < 0) {
|
||||||
|
qCDebug(entitiesrenderer) << "point A before assign" << _currentFrame;
|
||||||
_currentFrame = newAnimationProperties.getCurrentFrame();// +((float)newAnimationProperties.getCurrentlyPlayingFrame() / (float)USECS_PER_SECOND)*(newAnimationProperties.getFPS());
|
_currentFrame = newAnimationProperties.getCurrentFrame();// +((float)newAnimationProperties.getCurrentlyPlayingFrame() / (float)USECS_PER_SECOND)*(newAnimationProperties.getFPS());
|
||||||
_endAnim = _currentFrame + ( newAnimationProperties.getLastFrame() - newAnimationProperties.getFirstFrame() );
|
qCDebug(entitiesrenderer) << "point A after assign" << _currentFrame;
|
||||||
_lastAnimated = 0;
|
qCDebug(entitiesrenderer) << "current " <<newAnimationProperties.getCurrentFrame()<< " first "<< newAnimationProperties.getFirstFrame()<< " last " << newAnimationProperties.getLastFrame() <<" running "<< newAnimationProperties.getRunning();
|
||||||
}
|
qCDebug(entitiesrenderer) << "The previous current Frame " << newAnimationProperties.getCurrentFrame() << " or " << _renderAnimationProperties.getCurrentFrame();
|
||||||
}else if ( _renderAnimationProperties.getLoop() && !newAnimationProperties.getLoop()) {
|
qCDebug(entitiesrenderer) << "last animated before resume animating" << _lastAnimated;
|
||||||
//int currentframe_mod_length = (int)(_currentFrame - (int)(glm::floor(newAnimationProperties.getCurrentFrame()))) % ((int)(glm::floor(newAnimationProperties.getLastFrame())) - (int)(glm::floor(newAnimationProperties.getFirstFrame())) + 1);
|
//_lastAnimated = usecTimestampNow();
|
||||||
//_endAnim = _currentFrame + ((int)(newAnimationProperties.getLastFrame()) - (int)(newAnimationProperties.getFirstFrame())) - (float)currentframe_mod_length;
|
//qCDebug(entitiesrenderer) << "last animated" << _lastAnimated;
|
||||||
|
//tempbool = true;
|
||||||
|
}else {
|
||||||
|
_currentFrame = newAnimationProperties.getFirstFrame();
|
||||||
|
_lastAnimated = usecTimestampNow();
|
||||||
|
qCDebug(entitiesrenderer) << "point A.2 reset start";
|
||||||
}
|
}
|
||||||
|
}else if ( !_renderAnimationProperties.getLoop() && newAnimationProperties.getLoop()) {
|
||||||
|
//_currentFrame = newAnimationProperties.getCurrentFrame();
|
||||||
|
qCDebug(entitiesrenderer) << "turn on loop " << _currentFrame;
|
||||||
|
}else if (_renderAnimationProperties.getLoop() && !newAnimationProperties.getLoop()) {
|
||||||
|
//_currentFrame = newAnimationProperties.getCurrentFrame();
|
||||||
|
qCDebug(entitiesrenderer) << "turn off loop " << _currentFrame;
|
||||||
|
}else if (_renderAnimationProperties.getHold() != newAnimationProperties.getHold()) {
|
||||||
|
//_currentFrame = newAnimationProperties.getCurrentFrame();
|
||||||
|
qCDebug(entitiesrenderer) << "get hold " << _currentFrame;
|
||||||
|
//_lastAnimated = 0;
|
||||||
|
}else if (_renderAnimationProperties.getCurrentFrame() != newAnimationProperties.getCurrentFrame()){
|
||||||
_currentFrame = newAnimationProperties.getCurrentFrame();
|
_currentFrame = newAnimationProperties.getCurrentFrame();
|
||||||
qCDebug(entitiesrenderer) << "renderable update to current frame " << _currentFrame;
|
//_lastAnimated = usecTimestampNow();
|
||||||
_renderAnimationProperties = newAnimationProperties;
|
qCDebug(entitiesrenderer) << "point C " << _currentFrame;
|
||||||
|
}else {
|
||||||
|
//do nothing
|
||||||
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
_renderAnimationProperties = entity->getAnimationProperties();
|
||||||
|
} else {
|
||||||
|
//if first frame is less than zero then don't do anything.
|
||||||
|
if (!(entity->getAnimationFirstFrame() < 0)) {
|
||||||
|
// if the current frame is less than zero, this is from the initialization.
|
||||||
|
if (_currentFrame < 0) {
|
||||||
|
qCDebug(entitiesrenderer) << "point D property current frame " << entity->getName() << newAnimationProperties.getCurrentFrame();
|
||||||
|
if ((newAnimationProperties.getCurrentFrame() < newAnimationProperties.getLastFrame()) && (newAnimationProperties.getCurrentFrame() > newAnimationProperties.getFirstFrame())) {
|
||||||
|
|
||||||
|
_currentFrame = newAnimationProperties.getCurrentFrame();
|
||||||
|
qCDebug(entitiesrenderer) << "point D.1 " << _currentFrame;
|
||||||
|
qCDebug(entitiesrenderer) << "last animated " << _lastAnimated;
|
||||||
|
_lastAnimated = usecTimestampNow();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
_currentFrame = newAnimationProperties.getFirstFrame();
|
||||||
|
qCDebug(entitiesrenderer) << "point D.2 " << _currentFrame;
|
||||||
|
_lastAnimated = usecTimestampNow();
|
||||||
|
qCDebug(entitiesrenderer) << entity->getName() << "last animated " << _lastAnimated;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//angus
|
//angus
|
||||||
|
@ -1410,9 +1436,12 @@ void ModelEntityRenderer::doRenderUpdateSynchronousTyped(const ScenePointer& sce
|
||||||
if (!jointsMapped()) {
|
if (!jointsMapped()) {
|
||||||
mapJoints(entity, model->getJointNames());
|
mapJoints(entity, model->getJointNames());
|
||||||
}
|
}
|
||||||
|
if (!(entity->getAnimationFirstFrame() < 0) && !(entity->getAnimationFirstFrame() > entity->getAnimationLastFrame())) {
|
||||||
animate(entity);
|
animate(entity);
|
||||||
|
}
|
||||||
emit requestRenderUpdate();
|
emit requestRenderUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModelEntityRenderer::flagForCollisionGeometryUpdate() {
|
void ModelEntityRenderer::flagForCollisionGeometryUpdate() {
|
||||||
|
|
|
@ -133,7 +133,10 @@ class ModelEntityRenderer : public TypedEntityRenderer<RenderableModelEntityItem
|
||||||
friend class EntityRenderer;
|
friend class EntityRenderer;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ModelEntityRenderer(const EntityItemPointer& entity) : Parent(entity) { }
|
ModelEntityRenderer(const EntityItemPointer& entity) : Parent(entity) {
|
||||||
|
_lastAnimated = usecTimestampNow();
|
||||||
|
qCDebug(entitiesrenderer) << "set the last animated here" << _lastAnimated;
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void removeFromScene(const ScenePointer& scene, Transaction& transaction) override;
|
virtual void removeFromScene(const ScenePointer& scene, Transaction& transaction) override;
|
||||||
|
@ -184,7 +187,7 @@ private:
|
||||||
bool _shouldHighlight { false };
|
bool _shouldHighlight { false };
|
||||||
bool _animating { false };
|
bool _animating { false };
|
||||||
uint64_t _lastAnimated { 0 };
|
uint64_t _lastAnimated { 0 };
|
||||||
float _currentFrame { 0 };
|
float _currentFrame { -1 };
|
||||||
float _endAnim{ 0 };
|
float _endAnim{ 0 };
|
||||||
bool tempbool{ false };
|
bool tempbool{ false };
|
||||||
quint64 _currentlyPlayingFrame{ 0 };
|
quint64 _currentlyPlayingFrame{ 0 };
|
||||||
|
|
|
@ -197,33 +197,67 @@ void ModelEntityItem::update(const quint64& now) {
|
||||||
auto currentAnimationProperties = this->getAnimationProperties();
|
auto currentAnimationProperties = this->getAnimationProperties();
|
||||||
|
|
||||||
if (_previousAnimationProperties != currentAnimationProperties) {
|
if (_previousAnimationProperties != currentAnimationProperties) {
|
||||||
qCDebug(entities) << "this is where the _currentFrame change is handled in the ModelEntityItem.cpp code";
|
//qCDebug(entities) << "properties changed in modelentity code" << _currentFrame;
|
||||||
withWriteLock([&] {
|
withWriteLock([&] {
|
||||||
_previousAnimationProperties = currentAnimationProperties;
|
|
||||||
if ( (currentAnimationProperties.getFirstFrame() != _previousAnimationProperties.getFirstFrame()) || (currentAnimationProperties.getLastFrame() != _previousAnimationProperties.getLastFrame()) || (currentAnimationProperties.getRunning() && !_previousAnimationProperties.getRunning())) {
|
if ( (currentAnimationProperties.getFirstFrame() != _previousAnimationProperties.getFirstFrame()) || (currentAnimationProperties.getLastFrame() != _previousAnimationProperties.getLastFrame()) || (currentAnimationProperties.getRunning() && !_previousAnimationProperties.getRunning())) {
|
||||||
// if (!(currentAnimationProperties.getCurrentFrame() > currentAnimationProperties.getLastFrame()) && !(currentAnimationProperties.getCurrentFrame() < currentAnimationProperties.getFirstFrame())) {
|
_lastAnimated = usecTimestampNow();
|
||||||
// _currentlyPlayingFrame = currentAnimationProperties.getCurrentFrame();
|
_currentFrame = currentAnimationProperties.getFirstFrame();
|
||||||
//_endAnim = _currentlyPlayingFrame + ( currentAnimationProperties.getLastFrame() - currentAnimationProperties.getFirstFrame() );
|
qCDebug(entities) << "point 2 " << _currentFrame;
|
||||||
//_lastAnimated = 0;
|
|
||||||
// }
|
|
||||||
qCDebug(entities) << "this is where the _currentFrame change is handled in the ModelEntityItem.cpp code, current frame is: \n\n" << currentAnimationProperties.getCurrentFrame();
|
|
||||||
setAnimationCurrentFrame(currentAnimationProperties.getFirstFrame());
|
setAnimationCurrentFrame(currentAnimationProperties.getFirstFrame());
|
||||||
}
|
}else if (currentAnimationProperties.getHold() && !_previousAnimationProperties.getHold()) {
|
||||||
else {
|
//_lastAnimated = 0;
|
||||||
//else if ( _previousAnimationProperties.getLoop() && !currentAnimationProperties.getLoop()) {
|
//_currentFrame = currentAnimationProperties.getCurrentFrame();
|
||||||
// int currentframe_mod_length = (int)(_currentlyPlayingFrame - (int)(glm::floor(currentAnimationProperties.getCurrentFrame()))) % ((int)(glm::floor(currentAnimationProperties.getLastFrame())) - (int)(glm::floor(currentAnimationProperties.getFirstFrame())) + 1);
|
qCDebug(entities) << "hold is pressed" << _currentFrame;
|
||||||
//_endAnim = _currentlyPlayingFrame + ((int)(currentAnimationProperties.getLastFrame()) - (int)(currentAnimationProperties.getFirstFrame())) - (float)currentframe_mod_length;
|
}else if (!currentAnimationProperties.getHold() && _previousAnimationProperties.getHold()) {
|
||||||
//}
|
//_lastAnimated = 0;
|
||||||
setAnimationCurrentFrame(currentAnimationProperties.getCurrentFrame());
|
//_currentFrame = currentAnimationProperties.getCurrentFrame();
|
||||||
|
qCDebug(entities) << "hold is unpressed" << _currentFrame;
|
||||||
|
}else if (!currentAnimationProperties.getLoop() && _previousAnimationProperties.getLoop()) {
|
||||||
|
//_lastAnimated = 0;
|
||||||
|
qCDebug(entities) << "loop is unpressed" << _currentFrame;
|
||||||
|
}else if (currentAnimationProperties.getLoop() && !_previousAnimationProperties.getLoop()) {
|
||||||
|
//_lastAnimated = 0;
|
||||||
|
qCDebug(entities) << "loop is pressed" << _currentFrame;
|
||||||
|
}else if(currentAnimationProperties.getCurrentFrame() != _previousAnimationProperties.getCurrentFrame()){
|
||||||
|
_currentFrame = currentAnimationProperties.getCurrentFrame();
|
||||||
|
// if (_currentFrame < currentAnimationProperties.getFirstFrame()) {
|
||||||
|
// _currentFrame = currentAnimationProperties.getFirstFrame();
|
||||||
|
// }
|
||||||
|
// current frame greater than lastframe is dealt with in updateframe.
|
||||||
|
//_lastAnimated = usecTimestampNow();
|
||||||
|
qCDebug(entities) << "point 3 " << _currentFrame;
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
_previousAnimationProperties = this->getAnimationProperties();
|
||||||
|
//qCDebug(entities) << "point 4 " << _currentFrame;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
qCDebug(entities) << "this is where the _currentFrame change is handled in the ModelEntityItem.cpp code, current frame is: " << currentAnimationProperties.getCurrentFrame();
|
//if the first frame is less than zero that is an error, so don't do anything.
|
||||||
|
if (!(getAnimationFirstFrame() < 0)) {
|
||||||
|
//if the current frame is less than zero then we are restarting the server.
|
||||||
|
if (_currentFrame < 0) {
|
||||||
|
qCDebug(entities) << "point 3.5 " << _currentFrame;
|
||||||
|
//_previousAnimationProperties = currentAnimationProperties;
|
||||||
|
if ((currentAnimationProperties.getCurrentFrame() < currentAnimationProperties.getLastFrame()) && (currentAnimationProperties.getCurrentFrame() > currentAnimationProperties.getFirstFrame())) {
|
||||||
|
_currentFrame = currentAnimationProperties.getCurrentFrame();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
_currentFrame = currentAnimationProperties.getFirstFrame();
|
||||||
|
setAnimationCurrentFrame(_currentFrame);
|
||||||
|
_lastAnimated = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
//_previousAnimationProperties = currentAnimationProperties;
|
//_previousAnimationProperties = currentAnimationProperties;
|
||||||
|
if (isAnimatingSomething()) {
|
||||||
|
if (!(getAnimationFirstFrame() < 0) && !(getAnimationFirstFrame() > getAnimationLastFrame()) ) {
|
||||||
updateFrameCount();
|
updateFrameCount();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -252,9 +286,6 @@ void ModelEntityItem::updateFrameCount() {
|
||||||
auto interval = now - _lastAnimated;
|
auto interval = now - _lastAnimated;
|
||||||
_lastAnimated = now;
|
_lastAnimated = now;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//here we implement the looping animation property
|
//here we implement the looping animation property
|
||||||
//get entity anim props
|
//get entity anim props
|
||||||
|
|
||||||
|
@ -264,27 +295,36 @@ void ModelEntityItem::updateFrameCount() {
|
||||||
bool isHolding = getAnimationHold();
|
bool isHolding = getAnimationHold();
|
||||||
int updatedFrameCount = lastFrame - firstFrame + 1;
|
int updatedFrameCount = lastFrame - firstFrame + 1;
|
||||||
|
|
||||||
if (isLooping || (_currentFrame < _previousAnimationProperties.getLastFrame())) {
|
|
||||||
//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.
|
//qCDebug(entities) << "point 5 " << _currentFrame;
|
||||||
if (!isHolding && getAnimationIsPlaying() && !(_previousAnimationProperties.getCurrentFrame() > _previousAnimationProperties.getLastFrame()) && !(_previousAnimationProperties.getCurrentFrame() < _previousAnimationProperties.getFirstFrame())) {
|
|
||||||
|
if (!isHolding && getAnimationIsPlaying()) {
|
||||||
float deltaTime = (float)interval / (float)USECS_PER_SECOND;
|
float deltaTime = (float)interval / (float)USECS_PER_SECOND;
|
||||||
_currentFrame += (deltaTime * _previousAnimationProperties.getFPS());
|
_currentFrame += (deltaTime * getAnimationFPS());
|
||||||
while ((_currentFrame - _previousAnimationProperties.getFirstFrame()) > updatedFrameCount) {
|
if (_currentFrame > getAnimationLastFrame()) {
|
||||||
_currentFrame -= updatedFrameCount;
|
if (isLooping) {
|
||||||
|
while ((_currentFrame - getAnimationFirstFrame()) > (updatedFrameCount - 1)) {
|
||||||
|
_currentFrame -= (updatedFrameCount - 1);
|
||||||
}
|
}
|
||||||
qCDebug(entities) << "the frame is now 1 " << _currentFrame;
|
|
||||||
// setAnimationCurrentlyPlayingFrame(_currentlyPlayingFrame);
|
|
||||||
setAnimationCurrentFrame(_currentFrame);
|
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
} else {
|
|
||||||
_currentFrame = getAnimationLastFrame();
|
_currentFrame = getAnimationLastFrame();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (_currentFrame < getAnimationFirstFrame()) {
|
||||||
|
if (getAnimationFirstFrame() < 0) {
|
||||||
|
_currentFrame = 0;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
_currentFrame = getAnimationFirstFrame();
|
||||||
|
}
|
||||||
|
}
|
||||||
setAnimationCurrentFrame(_currentFrame);
|
setAnimationCurrentFrame(_currentFrame);
|
||||||
qCDebug(entities) << "the frame is now 2 " << _currentFrame;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//qCDebug(entities) << "_currentFrame is " << _currentFrame;
|
||||||
}
|
}
|
||||||
|
|
||||||
//angus
|
//angus
|
||||||
|
@ -706,6 +746,13 @@ float ModelEntityItem::getAnimationCurrentFrame() const {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float ModelEntityItem::getAnimationFPS() const {
|
||||||
|
return resultWithReadLock<float>([&] {
|
||||||
|
return _animationProperties.getFPS();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//angus change
|
//angus change
|
||||||
bool ModelEntityItem::isAnimatingSomething() const {
|
bool ModelEntityItem::isAnimatingSomething() const {
|
||||||
return resultWithReadLock<bool>([&] {
|
return resultWithReadLock<bool>([&] {
|
||||||
|
|
|
@ -108,6 +108,7 @@ public:
|
||||||
|
|
||||||
bool getAnimationIsPlaying() const;
|
bool getAnimationIsPlaying() const;
|
||||||
float getAnimationCurrentFrame() const;
|
float getAnimationCurrentFrame() const;
|
||||||
|
float getAnimationFPS() const;
|
||||||
bool isAnimatingSomething() const;
|
bool isAnimatingSomething() const;
|
||||||
|
|
||||||
quint64 getCurrentlyPlayingFrame() const;
|
quint64 getCurrentlyPlayingFrame() const;
|
||||||
|
@ -178,7 +179,7 @@ private:
|
||||||
AnimationPropertyGroup _previousAnimationProperties;
|
AnimationPropertyGroup _previousAnimationProperties;
|
||||||
bool _propTestFlag{ true };
|
bool _propTestFlag{ true };
|
||||||
bool _propTestFlag2{ true };
|
bool _propTestFlag2{ true };
|
||||||
float _currentFrame{ 0 };
|
float _currentFrame{ -1 };
|
||||||
//angus
|
//angus
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue