From 5ac85581683407dc5a330dd63cd44decf9d838d8 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Wed, 6 May 2015 17:03:27 -0700 Subject: [PATCH] flash yellow box when transmitting an edit packet --- .../src/RenderableDebugableEntityItem.cpp | 19 ++++++++++--------- .../src/RenderableDebugableEntityItem.h | 2 +- .../src/RenderableModelEntityItem.cpp | 3 ++- libraries/entities/src/EntityItem.h | 5 +++++ .../entities/src/EntityScriptingInterface.cpp | 2 ++ libraries/physics/src/EntityMotionState.cpp | 1 + 6 files changed, 21 insertions(+), 11 deletions(-) diff --git a/libraries/entities-renderer/src/RenderableDebugableEntityItem.cpp b/libraries/entities-renderer/src/RenderableDebugableEntityItem.cpp index 4d38d0d747..98ec154d01 100644 --- a/libraries/entities-renderer/src/RenderableDebugableEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableDebugableEntityItem.cpp @@ -19,7 +19,8 @@ #include "RenderableDebugableEntityItem.h" -void RenderableDebugableEntityItem::renderBoundingBox(EntityItem* entity, RenderArgs* args, bool puffedOut) { +void RenderableDebugableEntityItem::renderBoundingBox(EntityItem* entity, RenderArgs* args, + float puffedOut, glm::vec4& color) { glm::vec3 position = entity->getPosition(); glm::vec3 center = entity->getCenter(); glm::vec3 dimensions = entity->getDimensions(); @@ -33,13 +34,7 @@ void RenderableDebugableEntityItem::renderBoundingBox(EntityItem* entity, Render glm::vec3 positionToCenter = center - position; glTranslatef(positionToCenter.x, positionToCenter.y, positionToCenter.z); glScalef(dimensions.x, dimensions.y, dimensions.z); - if (puffedOut) { - glm::vec4 redColor(1.0f, 0.0f, 0.0f, 1.0f); - DependencyManager::get()->renderWireCube(1.2f, redColor); - } else { - glm::vec4 greenColor(0.0f, 1.0f, 0.0f, 1.0f); - DependencyManager::get()->renderWireCube(1.0f, greenColor); - } + DependencyManager::get()->renderWireCube(1.0f + puffedOut, color); glPopMatrix(); glPopMatrix(); } @@ -76,7 +71,13 @@ void RenderableDebugableEntityItem::render(EntityItem* entity, RenderArgs* args) if (debugSimulationOwnership) { quint64 now = usecTimestampNow(); if (now - entity->getLastEditedFromRemote() < 0.1f * USECS_PER_SECOND) { - renderBoundingBox(entity, args, true); + glm::vec4 redColor(1.0f, 0.0f, 0.0f, 1.0f); + renderBoundingBox(entity, args, 0.2f, redColor); + } + + if (now - entity->getLastBroadcast() < 0.2f * USECS_PER_SECOND) { + glm::vec4 yellowColor(1.0f, 1.0f, 0.2f, 1.0f); + renderBoundingBox(entity, args, 0.3f, yellowColor); } } diff --git a/libraries/entities-renderer/src/RenderableDebugableEntityItem.h b/libraries/entities-renderer/src/RenderableDebugableEntityItem.h index f3550cb116..758bac353b 100644 --- a/libraries/entities-renderer/src/RenderableDebugableEntityItem.h +++ b/libraries/entities-renderer/src/RenderableDebugableEntityItem.h @@ -16,7 +16,7 @@ class RenderableDebugableEntityItem { public: - static void renderBoundingBox(EntityItem* entity, RenderArgs* args, bool puffedOut); + static void renderBoundingBox(EntityItem* entity, RenderArgs* args, float puffedOut, glm::vec4& color); static void renderHoverDot(EntityItem* entity, RenderArgs* args); static void render(EntityItem* entity, RenderArgs* args); }; diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp index b3232bcb57..f097ae4e2f 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp @@ -192,7 +192,8 @@ void RenderableModelEntityItem::render(RenderArgs* args) { } if (!didDraw) { - RenderableDebugableEntityItem::renderBoundingBox(this, args, false); + glm::vec4 greenColor(0.0f, 1.0f, 0.0f, 1.0f); + RenderableDebugableEntityItem::renderBoundingBox(this, args, 0.0f, greenColor); } RenderableDebugableEntityItem::render(this, args); diff --git a/libraries/entities/src/EntityItem.h b/libraries/entities/src/EntityItem.h index ed01aa7ca2..63d58fd40f 100644 --- a/libraries/entities/src/EntityItem.h +++ b/libraries/entities/src/EntityItem.h @@ -104,6 +104,10 @@ public: float getEditedAgo() const /// Elapsed seconds since this entity was last edited { return (float)(usecTimestampNow() - getLastEdited()) / (float)USECS_PER_SECOND; } + /// Last time we sent out an edit packet for this entity + quint64 getLastBroadcast() const { return _lastBroadcast; } + void setLastBroadcast(quint64 lastBroadcast) { _lastBroadcast = lastBroadcast; } + void markAsChangedOnServer() { _changedOnServer = usecTimestampNow(); } quint64 getLastChangedOnServer() const { return _changedOnServer; } @@ -328,6 +332,7 @@ protected: quint64 _lastSimulated; // last time this entity called simulate(), this includes velocity, angular velocity, and physics changes quint64 _lastUpdated; // last time this entity called update(), this includes animations and non-physics changes quint64 _lastEdited; // last official local or remote edit time + quint64 _lastBroadcast; // the last time we sent an edit packet about this entity quint64 _lastEditedFromRemote; // last time we received and edit from the server quint64 _lastEditedFromRemoteInRemoteTime; // last time we received an edit from the server (in server-time-frame) diff --git a/libraries/entities/src/EntityScriptingInterface.cpp b/libraries/entities/src/EntityScriptingInterface.cpp index 6632574db8..46ca70aa43 100644 --- a/libraries/entities/src/EntityScriptingInterface.cpp +++ b/libraries/entities/src/EntityScriptingInterface.cpp @@ -86,6 +86,7 @@ EntityItemID EntityScriptingInterface::addEntity(const EntityItemProperties& pro if (_entityTree) { _entityTree->lockForWrite(); EntityItem* entity = _entityTree->addEntity(id, propertiesWithSimID); + entity->setLastBroadcast(usecTimestampNow()); if (entity) { // This Node is creating a new object. If it's in motion, set this Node as the simulator. setSimId(propertiesWithSimID, entity); @@ -178,6 +179,7 @@ EntityItemID EntityScriptingInterface::editEntity(EntityItemID entityID, const E if (propertiesWithSimID.getType() == EntityTypes::Unknown) { EntityItem* entity = _entityTree->findEntityByEntityItemID(entityID); if (entity) { + entity->setLastBroadcast(usecTimestampNow()); propertiesWithSimID.setType(entity->getType()); setSimId(propertiesWithSimID, entity); } diff --git a/libraries/physics/src/EntityMotionState.cpp b/libraries/physics/src/EntityMotionState.cpp index 27fa51b5d4..f1c0daea26 100644 --- a/libraries/physics/src/EntityMotionState.cpp +++ b/libraries/physics/src/EntityMotionState.cpp @@ -429,6 +429,7 @@ void EntityMotionState::sendUpdate(OctreeEditPacketSender* packetSender, uint32_ #endif entityPacketSender->queueEditEntityMessage(PacketTypeEntityAddOrEdit, id, properties); + _entity->setLastBroadcast(usecTimestampNow()); } else { #ifdef WANT_DEBUG qCDebug(physics) << "EntityMotionState::sendUpdate()... NOT sending update as requested.";