From f618a2adfa3375a1d3d6dc62df5679df96056394 Mon Sep 17 00:00:00 2001 From: Brad Hefta-Gaub Date: Fri, 2 Oct 2015 17:06:32 -0700 Subject: [PATCH] gak - get streaming working again --- libraries/animation/src/AnimationLoop.cpp | 13 ++--- libraries/animation/src/AnimationLoop.h | 1 - .../entities/src/AnimationPropertyGroup.cpp | 47 +++++++++++-------- .../entities/src/EntityItemProperties.cpp | 1 + libraries/entities/src/ModelEntityItem.cpp | 22 +++++++-- 5 files changed, 51 insertions(+), 33 deletions(-) diff --git a/libraries/animation/src/AnimationLoop.cpp b/libraries/animation/src/AnimationLoop.cpp index 6062d71f9c..cd360a79a7 100644 --- a/libraries/animation/src/AnimationLoop.cpp +++ b/libraries/animation/src/AnimationLoop.cpp @@ -24,8 +24,7 @@ AnimationLoop::AnimationLoop() : _running(false), _frameIndex(0.0f), _maxFrameIndexHint(MAXIMUM_POSSIBLE_FRAME), - _resetOnRunning(false), - _firstRun(true) + _resetOnRunning(false) { } @@ -38,8 +37,7 @@ AnimationLoop::AnimationLoop(const AnimationDetails& animationDetails) : _lastFrame(animationDetails.lastFrame), _running(animationDetails.running), _frameIndex(animationDetails.frameIndex), - _resetOnRunning(false), - _firstRun(true) + _resetOnRunning(false) { } @@ -53,8 +51,7 @@ AnimationLoop::AnimationLoop(float fps, bool loop, bool hold, bool startAutomati _lastFrame(lastFrame), _running(running), _frameIndex(frameIndex), - _resetOnRunning(false), - _firstRun(true) + _resetOnRunning(false) { } @@ -94,10 +91,10 @@ void AnimationLoop::setRunning(bool running) { _running = running; // If we just set running to true, then also reset the frame to the first frame - if (running && (_resetOnRunning || _firstRun)) { + if (running && (_resetOnRunning)) { // move back to the beginning + qDebug() << "resetting _frameIndex:" << _frameIndex << "to _firstFrame:" << _firstFrame; _frameIndex = _firstFrame; - _firstRun = false; } } } diff --git a/libraries/animation/src/AnimationLoop.h b/libraries/animation/src/AnimationLoop.h index eb58774223..6c3df659dc 100644 --- a/libraries/animation/src/AnimationLoop.h +++ b/libraries/animation/src/AnimationLoop.h @@ -70,7 +70,6 @@ private: float _frameIndex; float _maxFrameIndexHint; bool _resetOnRunning; - bool _firstRun; }; #endif // hifi_AnimationLoop_h diff --git a/libraries/entities/src/AnimationPropertyGroup.cpp b/libraries/entities/src/AnimationPropertyGroup.cpp index 47733c205d..653cf4c4f8 100644 --- a/libraries/entities/src/AnimationPropertyGroup.cpp +++ b/libraries/entities/src/AnimationPropertyGroup.cpp @@ -100,7 +100,8 @@ void AnimationPropertyGroup::copyFromScriptValue(const QScriptValue& object, boo void AnimationPropertyGroup::setFromOldAnimationSettings(const QString& value) { - qDebug() << "AnimationPropertyGroup::setFromOldAnimationSettings() value:" << value; + qDebug() << "AnimationPropertyGroup::setFromOldAnimationSettings() url:" << getURL() << "value:" << value; + // the animations setting is a JSON string that may contain various animation settings. // if it includes fps, frameIndex, or running, those values will be parsed out and // will over ride the regular animation settings @@ -125,37 +126,37 @@ void AnimationPropertyGroup::setFromOldAnimationSettings(const QString& value) { if (settingsMap.contains("frameIndex")) { frameIndex = settingsMap["frameIndex"].toFloat(); - qDebug() << "AnimationPropertyGroup::setFromOldAnimationSettings() had frameIndex"; + qDebug() << "AnimationPropertyGroup::setFromOldAnimationSettings() had frameIndex:" << frameIndex; } if (settingsMap.contains("running")) { running = settingsMap["running"].toBool(); - qDebug() << "AnimationPropertyGroup::setFromOldAnimationSettings() had running"; + qDebug() << "AnimationPropertyGroup::setFromOldAnimationSettings() had running:" << running; } if (settingsMap.contains("firstFrame")) { frameIndex = settingsMap["firstFrame"].toFloat(); - qDebug() << "AnimationPropertyGroup::setFromOldAnimationSettings() had firstFrame"; + qDebug() << "AnimationPropertyGroup::setFromOldAnimationSettings() had firstFrame:" << firstFrame; } if (settingsMap.contains("lastFrame")) { frameIndex = settingsMap["lastFrame"].toFloat(); - qDebug() << "AnimationPropertyGroup::setFromOldAnimationSettings() had lastFrame"; + qDebug() << "AnimationPropertyGroup::setFromOldAnimationSettings() had lastFrame:" << lastFrame; } if (settingsMap.contains("loop")) { running = settingsMap["loop"].toBool(); - qDebug() << "AnimationPropertyGroup::setFromOldAnimationSettings() had loop"; + qDebug() << "AnimationPropertyGroup::setFromOldAnimationSettings() had loop:" << loop; } if (settingsMap.contains("hold")) { running = settingsMap["hold"].toBool(); - qDebug() << "AnimationPropertyGroup::setFromOldAnimationSettings() had hold"; + qDebug() << "AnimationPropertyGroup::setFromOldAnimationSettings() had hold:" << hold; } if (settingsMap.contains("startAutomatically")) { running = settingsMap["startAutomatically"].toBool(); - qDebug() << "AnimationPropertyGroup::setFromOldAnimationSettings() had startAutomatically"; + qDebug() << "AnimationPropertyGroup::setFromOldAnimationSettings() had startAutomatically:" << startAutomatically; } if (_animationLoop) { @@ -182,7 +183,9 @@ void AnimationPropertyGroup::setFromOldAnimationSettings(const QString& value) { void AnimationPropertyGroup::debugDump() const { qDebug() << " AnimationPropertyGroup: ---------------------------------------------"; - qDebug() << " URL:" << getURL() << " has changed:" << urlChanged(); + qDebug() << " url:" << getURL() << " has changed:" << urlChanged(); + qDebug() << " fps:" << getFPS() << " has changed:" << fpsChanged(); + qDebug() << "frameIndex:" << getFrameIndex() << " has changed:" << frameIndexChanged(); } bool AnimationPropertyGroup::appendToEditPacket(OctreePacketData* packetData, @@ -377,15 +380,6 @@ void AnimationPropertyGroup::appendSubclassData(OctreePacketData* packetData, En APPEND_ENTITY_PROPERTY(PROP_ANIMATION_URL, getURL()); if (_animationLoop) { - APPEND_ENTITY_PROPERTY(PROP_ANIMATION_FPS, getFPS()); - APPEND_ENTITY_PROPERTY(PROP_ANIMATION_FRAME_INDEX, getFrameIndex()); - APPEND_ENTITY_PROPERTY(PROP_ANIMATION_PLAYING, getRunning()); - APPEND_ENTITY_PROPERTY(PROP_ANIMATION_LOOP, getLoop()); - APPEND_ENTITY_PROPERTY(PROP_ANIMATION_FIRST_FRAME, getFirstFrame()); - APPEND_ENTITY_PROPERTY(PROP_ANIMATION_LAST_FRAME, getLastFrame()); - APPEND_ENTITY_PROPERTY(PROP_ANIMATION_HOLD, getHold()); - APPEND_ENTITY_PROPERTY(PROP_ANIMATION_START_AUTOMATICALLY, getStartAutomatically()); - } else { APPEND_ENTITY_PROPERTY(PROP_ANIMATION_FPS, _animationLoop->getFPS()); APPEND_ENTITY_PROPERTY(PROP_ANIMATION_FRAME_INDEX, _animationLoop->getFrameIndex()); APPEND_ENTITY_PROPERTY(PROP_ANIMATION_PLAYING, _animationLoop->getRunning()); @@ -395,6 +389,16 @@ void AnimationPropertyGroup::appendSubclassData(OctreePacketData* packetData, En APPEND_ENTITY_PROPERTY(PROP_ANIMATION_HOLD, _animationLoop->getHold()); APPEND_ENTITY_PROPERTY(PROP_ANIMATION_START_AUTOMATICALLY, _animationLoop->getStartAutomatically()); } + else { + APPEND_ENTITY_PROPERTY(PROP_ANIMATION_FPS, getFPS()); + APPEND_ENTITY_PROPERTY(PROP_ANIMATION_FRAME_INDEX, getFrameIndex()); + APPEND_ENTITY_PROPERTY(PROP_ANIMATION_PLAYING, getRunning()); + APPEND_ENTITY_PROPERTY(PROP_ANIMATION_LOOP, getLoop()); + APPEND_ENTITY_PROPERTY(PROP_ANIMATION_FIRST_FRAME, getFirstFrame()); + APPEND_ENTITY_PROPERTY(PROP_ANIMATION_LAST_FRAME, getLastFrame()); + APPEND_ENTITY_PROPERTY(PROP_ANIMATION_HOLD, getHold()); + APPEND_ENTITY_PROPERTY(PROP_ANIMATION_START_AUTOMATICALLY, getStartAutomatically()); + } } int AnimationPropertyGroup::readEntitySubclassDataFromBuffer(const unsigned char* data, int bytesLeftToRead, @@ -410,7 +414,7 @@ int AnimationPropertyGroup::readEntitySubclassDataFromBuffer(const unsigned char if (_animationLoop) { // apply new properties to our associated AnimationLoop - //qDebug() << "AnimationPropertyGroup::readEntitySubclassDataFromBuffer() -- apply new properties to our associated AnimationLoop"; + qDebug() << "AnimationPropertyGroup::readEntitySubclassDataFromBuffer() -- apply new properties to our associated AnimationLoop"; READ_ENTITY_PROPERTY(PROP_ANIMATION_FPS, float, _animationLoop->setFPS); READ_ENTITY_PROPERTY(PROP_ANIMATION_FRAME_INDEX, float, _animationLoop->setFrameIndex); READ_ENTITY_PROPERTY(PROP_ANIMATION_PLAYING, bool, _animationLoop->setRunning); @@ -420,6 +424,7 @@ int AnimationPropertyGroup::readEntitySubclassDataFromBuffer(const unsigned char READ_ENTITY_PROPERTY(PROP_ANIMATION_HOLD, bool, _animationLoop->setHold); READ_ENTITY_PROPERTY(PROP_ANIMATION_START_AUTOMATICALLY, bool, _animationLoop->setStartAutomatically); } else { + qDebug() << "AnimationPropertyGroup::readEntitySubclassDataFromBuffer() -- NO AnimationLoop store locally"; READ_ENTITY_PROPERTY(PROP_ANIMATION_FPS, float, setFPS); READ_ENTITY_PROPERTY(PROP_ANIMATION_FRAME_INDEX, float, setFrameIndex); READ_ENTITY_PROPERTY(PROP_ANIMATION_PLAYING, bool, setRunning); @@ -430,6 +435,10 @@ int AnimationPropertyGroup::readEntitySubclassDataFromBuffer(const unsigned char READ_ENTITY_PROPERTY(PROP_ANIMATION_START_AUTOMATICALLY, bool, setStartAutomatically); } + if (_animationLoop) { + qDebug() << "_animationLoop->isRunning():" << _animationLoop->isRunning(); + } + return bytesRead; } diff --git a/libraries/entities/src/EntityItemProperties.cpp b/libraries/entities/src/EntityItemProperties.cpp index 8b4d4660bf..cdd6c5b2ca 100644 --- a/libraries/entities/src/EntityItemProperties.cpp +++ b/libraries/entities/src/EntityItemProperties.cpp @@ -176,6 +176,7 @@ void EntityItemProperties::debugDump() const { qCDebug(entities) << " _modelURL=" << _modelURL; qCDebug(entities) << " _compoundShapeURL=" << _compoundShapeURL; + getAnimation().debugDump(); getAtmosphere().debugDump(); getSkybox().debugDump(); diff --git a/libraries/entities/src/ModelEntityItem.cpp b/libraries/entities/src/ModelEntityItem.cpp index e2111fb9c1..f7b4e014db 100644 --- a/libraries/entities/src/ModelEntityItem.cpp +++ b/libraries/entities/src/ModelEntityItem.cpp @@ -49,6 +49,8 @@ ModelEntityItem::ModelEntityItem(const EntityItemID& entityItemID, const EntityI EntityItemProperties ModelEntityItem::getProperties(EntityPropertyFlags desiredProperties) const { EntityItemProperties properties = EntityItem::getProperties(desiredProperties); // get the properties from our base class + //qDebug() << "ModelEntityItem::getProperties() id:" << getEntityItemID(); + COPY_ENTITY_PROPERTY_TO_PROPERTIES(color, getXColor); COPY_ENTITY_PROPERTY_TO_PROPERTIES(modelURL, getModelURL); COPY_ENTITY_PROPERTY_TO_PROPERTIES(compoundShapeURL, getCompoundShapeURL); @@ -58,6 +60,8 @@ EntityItemProperties ModelEntityItem::getProperties(EntityPropertyFlags desiredP _animationProperties.getProperties(properties); + //properties.debugDump(); + return properties; } @@ -73,7 +77,11 @@ bool ModelEntityItem::setProperties(const EntityItemProperties& properties) { SET_ENTITY_PROPERTY_FROM_PROPERTIES(textures, setTextures); SET_ENTITY_PROPERTY_FROM_PROPERTIES(shapeType, updateShapeType); + qDebug() << "ModelEntityItem::setProperties() id:" << getEntityItemID() << "modelURL:" << getModelURL(); + qDebug() << "ModelEntityItem::setProperties() id:" << getEntityItemID() << "calling _animationProperties.setProperties()"; bool somethingChangedInAnimations = _animationProperties.setProperties(properties); + qDebug() << "ModelEntityItem::setProperties() id:" << getEntityItemID() << "AFTER _animationProperties.setProperties() running:" << _animationLoop.getRunning(); + qDebug() << "ModelEntityItem::setProperties() id:" << getEntityItemID() << "AFTER _animationProperties.setProperties() frameIndex:" << _animationLoop.getFrameIndex(); somethingChanged = somethingChanged || somethingChangedInAnimations; @@ -102,17 +110,15 @@ int ModelEntityItem::readEntitySubclassDataFromBuffer(const unsigned char* data, READ_ENTITY_PROPERTY(PROP_MODEL_URL, QString, setModelURL); if (args.bitstreamVersion < VERSION_ENTITIES_HAS_COLLISION_MODEL) { setCompoundShapeURL(""); - } else if (args.bitstreamVersion == VERSION_ENTITIES_HAS_COLLISION_MODEL) { - READ_ENTITY_PROPERTY(PROP_COMPOUND_SHAPE_URL, QString, setCompoundShapeURL); } else { READ_ENTITY_PROPERTY(PROP_COMPOUND_SHAPE_URL, QString, setCompoundShapeURL); } - READ_ENTITY_PROPERTY(PROP_ANIMATION_URL, QString, setAnimationURL); // Because we're using AnimationLoop which will reset the frame index if you change it's running state // we want to read these values in the order they appear in the buffer, but call our setters in an // order that allows AnimationLoop to preserve the correct frame rate. if (args.bitstreamVersion < VERSION_ENTITIES_ANIMATION_PROPERTIES_GROUP) { + READ_ENTITY_PROPERTY(PROP_ANIMATION_URL, QString, setAnimationURL); READ_ENTITY_PROPERTY(PROP_ANIMATION_FPS, float, setAnimationFPS); READ_ENTITY_PROPERTY(PROP_ANIMATION_FRAME_INDEX, float, setAnimationFrameIndex); READ_ENTITY_PROPERTY(PROP_ANIMATION_PLAYING, bool, setAnimationIsPlaying); @@ -135,6 +141,9 @@ int ModelEntityItem::readEntitySubclassDataFromBuffer(const unsigned char* data, READ_ENTITY_PROPERTY(PROP_SHAPE_TYPE, ShapeType, updateShapeType); + qDebug() << "ModelEntityItem::readEntitySubclassDataFromBuffer()"; + debugDump(); + return bytesRead; } @@ -278,7 +287,9 @@ void ModelEntityItem::update(const quint64& now) { float deltaTime = (float)(now - _lastAnimated) / (float)USECS_PER_SECOND; _lastAnimated = now; _animationLoop.simulate(deltaTime); - } else { + //qDebug() << "ModelEntityItem::update() id:" << getEntityItemID() << "frameIndex:" << _animationLoop.getFrameIndex(); + } + else { _lastAnimated = now; } EntityItem::update(now); // let our base class handle it's updates... @@ -290,7 +301,8 @@ void ModelEntityItem::debugDump() const { qCDebug(entities) << " position:" << getPosition(); qCDebug(entities) << " dimensions:" << getDimensions(); qCDebug(entities) << " model URL:" << getModelURL(); - qCDebug(entities) << " compound shape URL:" << getCompoundShapeURL(); + qCDebug(entities) << " _animationLoop.isRunning():" << _animationLoop.isRunning(); + //qCDebug(entities) << " compound shape URL:" << getCompoundShapeURL(); } void ModelEntityItem::updateShapeType(ShapeType type) {