From ed670ff48ec316b9494fc2a8868ace0629991296 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Fri, 29 Aug 2014 20:19:24 -0700 Subject: [PATCH] fix bug with animations randomly not working --- libraries/entities/src/ModelEntityItem.cpp | 51 +++++++++++++--------- libraries/entities/src/todo.txt | 33 ++++++++++---- 2 files changed, 55 insertions(+), 29 deletions(-) diff --git a/libraries/entities/src/ModelEntityItem.cpp b/libraries/entities/src/ModelEntityItem.cpp index 1eeb64c756..0879fac10f 100644 --- a/libraries/entities/src/ModelEntityItem.cpp +++ b/libraries/entities/src/ModelEntityItem.cpp @@ -21,20 +21,18 @@ EntityItem* ModelEntityItem::factory(const EntityItemID& entityID, const EntityI return new ModelEntityItem(entityID, properties); } -// our non-pure virtual subclass for now... ModelEntityItem::ModelEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) : EntityItem(entityItemID, properties) { _type = EntityTypes::Model; setProperties(properties, true); _animationFrameIndex = 0.0f; + _lastAnimated = usecTimestampNow(); + _jointMappingCompleted = false; } EntityItemProperties ModelEntityItem::getProperties() const { - //qDebug() << "ModelEntityItem::getProperties()... <<<<<<<<<<<<<<<< <<<<<<<<<<<<<<<<<<<<<<<<<"; - EntityItemProperties properties = EntityItem::getProperties(); // get the properties from our base class - properties._color = getXColor(); properties._modelURL = getModelURL(); properties._animationURL = getAnimationURL(); @@ -50,9 +48,6 @@ EntityItemProperties ModelEntityItem::getProperties() const { properties._animationFPSChanged = false; properties._glowLevel = getGlowLevel(); properties._glowLevelChanged = false; - - //qDebug() << "ModelEntityItem::getProperties() getModelURL()=" << getModelURL(); - return properties; } @@ -496,14 +491,24 @@ void ModelEntityItem::mapJoints(const QStringList& modelJointNames) { QVector ModelEntityItem::getAnimationFrame() { bool wantDebug = false; + if (wantDebug) { + qDebug() << "ModelEntityItem::getAnimationFrame()...."; + } QVector frameData; if (hasAnimation() && _jointMappingCompleted) { Animation* myAnimation = getAnimation(_animationURL); QVector frames = myAnimation->getFrames(); int frameCount = frames.size(); + if (wantDebug) { + qDebug() << " (hasAnimation() && _jointMappingCompleted)"; + qDebug() << " myAnimation=" << myAnimation; + qDebug() << " frameCount=" << frameCount; + qDebug() << " _animationFrameIndex=" << _animationFrameIndex; + } + if (frameCount > 0) { - int animationFrameIndex = (int)glm::floor(_animationFrameIndex) % frameCount; + int animationFrameIndex = (int)(glm::floor(_animationFrameIndex)) % frameCount; if (animationFrameIndex < 0 || animationFrameIndex > frameCount) { if (wantDebug) { @@ -516,9 +521,8 @@ QVector ModelEntityItem::getAnimationFrame() { animationFrameIndex = 0; } - //qDebug() << "ModelEntityItem::getAnimationFrame().... _animationFrameIndex=" << _animationFrameIndex << "frameCount=" << frameCount << "animationFrameIndex=" << animationFrameIndex; - QVector rotations = frames[animationFrameIndex].rotations; + frameData.resize(_jointMapping.size()); for (int j = 0; j < _jointMapping.size(); j++) { int rotationIndex = _jointMapping[j]; @@ -552,32 +556,37 @@ EntityItem::SimulationState ModelEntityItem::getSimulationState() const { } void ModelEntityItem::update(const quint64& updateTime) { + const bool wantDebugging = true; + //_lastUpdated = updateTime; - //setShouldBeDeleted(getShouldBeDeleted()); EntityItem::update(updateTime); // let our base class handle it's updates... quint64 now = updateTime; //usecTimestampNow(); - //qDebug() << "ModelEntityItem::update() getAnimationIsPlaying()="<< getAnimationIsPlaying(); - // only advance the frame index if we're playing if (getAnimationIsPlaying()) { - float deltaTime = (float)(now - _lastAnimated) / (float)USECS_PER_SECOND; - - const bool wantDebugging = false; if (wantDebugging) { - qDebug() << "EntityItem::update() now=" << now; - qDebug() << " updateTime=" << updateTime; - qDebug() << " _lastAnimated=" << _lastAnimated; - qDebug() << " deltaTime=" << deltaTime; + qDebug() << "ModelEntityItem::update()"; + qDebug() << " ID="<< getEntityItemID(); + qDebug() << " usecTimestampNow()=" << usecTimestampNow(); + qDebug() << " now=" << now; + qDebug() << " updateTime=" << updateTime; + qDebug() << " _lastAnimated=" << _lastAnimated; } + + float deltaTime = (float)(now - _lastAnimated) / (float)USECS_PER_SECOND; + + if (wantDebugging) { + qDebug() << " deltaTime=" << deltaTime; + } + _lastAnimated = now; _animationFrameIndex += deltaTime * _animationFPS; if (wantDebugging) { - qDebug() << " _animationFrameIndex=" << _animationFrameIndex; + qDebug() << "_animationFrameIndex=" << _animationFrameIndex; } } else { diff --git a/libraries/entities/src/todo.txt b/libraries/entities/src/todo.txt index 9e7cd36052..66ceec98d1 100644 --- a/libraries/entities/src/todo.txt +++ b/libraries/entities/src/todo.txt @@ -5,8 +5,6 @@ 3) Make sure LOD logic honors the LOD settings for entities in "spanners/parent" cells. - 4) test animation again... - 7) some jutter with moving entities -- I think this might only happen with lots of models in an element or in view this may be related to issue 13 below @@ -14,21 +12,29 @@ 8) Look into why non-changed octree cells are being resent when editing an entity -- this is probably because we're marking the trees as dirty -- but we probably can not send entitys that haven't changed - 9) Verify pruning logic... - The old code used the update loop to handle pruning elements from the tree - do we need this? - 10) What happens if the edit properties don't fit in a single message MTU??? - 11) quickly do some edits... then change domains... watch the entities continue to exist in new domain and move around. - -- verify this happens in old code, if so... move to "nice to have" - 12) Double check operators for these problems: MovingEntitiesOperator has these issues: - does the same pruning/reallocating issue as the old UpdateEntityOperator - doesn't used clamped boxes for best fit tests... so could be problematic + -- crash on shutdown while animating... + Thread 0 Crashed:: Dispatch queue: com.apple.main-thread + 0 io.highfidelity.Interface 0x000000010cf99a6a EntityTree::updateChangingEntities(unsigned long long, QSet&) + 202 + 1 io.highfidelity.Interface 0x000000010cf998a6 EntityTree::update() + 70 + 2 io.highfidelity.Interface 0x000000010cb64a3e EntityTreeRenderer::update() + 62 + 3 io.highfidelity.Interface 0x000000010c9eb6ec Application::update(float) + 796 + 4 io.highfidelity.Interface 0x000000010c9f5e26 Application::idle() + 550 + 5 io.highfidelity.Interface 0x000000010c99f567 Application::qt_static_metacall(QObject*, QMetaObject::Call, int, void**) + 1655 + 6 QtCore 0x0000000112474a30 QMetaObject::activate(QObject*, int, int, void**) + 2640 + 7 QtCore 0x000000011246d5c1 QObject::event(QEvent*) + 49 + + // NICE TO HAVE: + -- if animation is stopped, changing frame doesn't update the simulation + why is _entityItems a pointer? why not just make it a member of EntityTreeElement.... @@ -91,6 +97,11 @@ 9 libsystem_pthread.dylib 0x00007fff8bb9672a _pthread_start + 137 10 libsystem_pthread.dylib 0x00007fff8bb9afc9 thread_start + 13 + + 11) quickly do some edits... then change domains... watch the entities continue to exist in new domain and move around. + -- verify this happens in old code, if so... move to "nice to have" + + =============== @@ -213,6 +224,12 @@ // was not actually the best fit. it's not clear how this happened, but we can protect // against it in the update operator if it does happen again. This made update operator more robust. // SOLVED -- 48) server and client definitley not adding entities to proper update lists on load... only on change... +// SOLVED -- 49) test animation again... +// FIXED -- This looks like it was all related to members not being initialized... +// FIXED -- animations don't appear on all viewers +// FIXED -- animations are on different frames -- the data suggest they are the same frame number from a simulation perspective +// SOLVED -- 50) Verify pruning logic... + ---------------- properties -----------------