From e36ee2a96130328ecddf1704edfc498905245e6c Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Wed, 17 Dec 2014 12:19:34 -0800 Subject: [PATCH 1/9] more correct creation and edit times for entities --- libraries/entities/src/EntityItem.cpp | 75 ++++++++++++------- libraries/entities/src/EntityItem.h | 5 +- libraries/entities/src/EntityItemProperties.h | 4 +- libraries/entities/src/EntityTypes.cpp | 8 +- 4 files changed, 55 insertions(+), 37 deletions(-) diff --git a/libraries/entities/src/EntityItem.cpp b/libraries/entities/src/EntityItem.cpp index b271439662..22cfeb3674 100644 --- a/libraries/entities/src/EntityItem.cpp +++ b/libraries/entities/src/EntityItem.cpp @@ -53,14 +53,13 @@ void EntityItem::initFromEntityItemID(const EntityItemID& entityItemID) { _creatorTokenID = entityItemID.creatorTokenID; // init values with defaults before calling setProperties - //uint64_t now = usecTimestampNow(); _lastEdited = 0; _lastEditedFromRemote = 0; _lastEditedFromRemoteInRemoteTime = 0; _lastSimulated = 0; _lastUpdated = 0; - _created = 0; // TODO: when do we actually want to make this "now" + _created = usecTimestampNow(); _changedOnServer = 0; _position = glm::vec3(0,0,0); @@ -99,16 +98,20 @@ EntityItem::EntityItem(const EntityItemID& entityItemID) { EntityItem::EntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) { _type = EntityTypes::Unknown; - _lastEdited = 0; + quint64 now = usecTimestampNow(); + _created = properties.getCreated() < now ? properties.getCreated() : now; + _lastEdited = _lastEditedFromRemote = _lastSimulated = _lastUpdated = _lastEditedFromRemoteInRemoteTime = _created; _lastEditedFromRemote = 0; _lastEditedFromRemoteInRemoteTime = 0; _lastSimulated = 0; _lastUpdated = 0; - _created = properties.getCreated(); _dirtyFlags = 0; _changedOnServer = 0; initFromEntityItemID(entityItemID); setProperties(properties, true); // force copy + if (_lastEdited == 0) { + _lastEdited = _created; + } } EntityPropertyFlags EntityItem::getEntityProperties(EncodeBitstreamParams& params) const { @@ -367,7 +370,12 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef bytesRead += sizeof(createdFromBuffer); createdFromBuffer -= clockSkew; - _created = createdFromBuffer; // TODO: do we ever want to discard this??? + if (createdFromBuffer < _created) { + // the server claims that this entity has an older creation time + // so we accept it and clear _lastEdited + _created = createdFromBuffer; + _lastEdited = 0; + } if (wantDebug) { quint64 lastEdited = getLastEdited(); @@ -416,14 +424,14 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef if (fromSameServerEdit) { // If this is from the same sever packet, then check against any local changes since we got // the most recent packet from this server time - if (_lastEdited > _lastEditedFromRemote) { + if (_lastEdited >= _lastEditedFromRemote) { ignoreServerPacket = true; } } else { // If this isn't from the same sever packet, then honor our skew adjusted times... // If we've changed our local tree more recently than the new data from this packet // then we will not be changing our values, instead we just read and skip the data - if (_lastEdited > lastEditedFromBufferAdjusted) { + if (_lastEdited >= lastEditedFromBufferAdjusted) { ignoreServerPacket = true; } } @@ -439,7 +447,8 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef qDebug() << "USING NEW data from server!!! ****************"; } - _lastEdited = lastEditedFromBufferAdjusted; + // don't allow _lastEdited to be in the future + _lastEdited = lastEditedFromBufferAdjusted < now ? lastEditedFromBufferAdjusted : now; _lastEditedFromRemote = now; _lastEditedFromRemoteInRemoteTime = lastEditedFromBuffer; @@ -451,7 +460,8 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef ByteCountCoded updateDeltaCoder = encodedUpdateDelta; quint64 updateDelta = updateDeltaCoder; if (overwriteLocalData) { - _lastSimulated = _lastUpdated = lastEditedFromBufferAdjusted + updateDelta; // don't adjust for clock skew since we already did that for _lastEdited + _lastUpdated = lastEditedFromBufferAdjusted + updateDelta; // don't adjust for clock skew since we already did that for _lastEdited + _lastSimulated = now; if (wantDebug) { qDebug() << "_lastUpdated =" << _lastUpdated; qDebug() << "_lastEdited=" << _lastEdited; @@ -576,7 +586,7 @@ void EntityItem::simulate(const quint64& now) { float timeElapsed = (float)(now - _lastSimulated) / (float)(USECS_PER_SECOND); if (wantDebug) { - qDebug() << "********** EntityItem::update()"; + qDebug() << "********** EntityItem::simulate()"; qDebug() << " entity ID=" << getEntityItemID(); qDebug() << " now=" << now; qDebug() << " _lastSimulated=" << _lastSimulated; @@ -612,10 +622,8 @@ void EntityItem::simulate(const quint64& now) { } } - _lastSimulated = now; - if (wantDebug) { - qDebug() << " ********** EntityItem::update() .... SETTING _lastSimulated=" << _lastSimulated; + qDebug() << " ********** EntityItem::simulate() .... SETTING _lastSimulated=" << _lastSimulated; } if (hasAngularVelocity()) { @@ -645,13 +653,13 @@ void EntityItem::simulate(const quint64& now) { } } - if (hasVelocity() || hasGravity()) { + if (hasVelocity()) { glm::vec3 position = getPosition(); glm::vec3 velocity = getVelocity(); glm::vec3 newPosition = position + (velocity * timeElapsed); if (wantDebug) { - qDebug() << " EntityItem::update()...."; + qDebug() << " EntityItem::simulate()...."; qDebug() << " timeElapsed:" << timeElapsed; qDebug() << " old AACube:" << getMaximumAACube(); qDebug() << " old position:" << position; @@ -677,15 +685,15 @@ void EntityItem::simulate(const quint64& now) { } // handle gravity.... - if (hasGravity() && !isRestingOnSurface()) { - velocity += getGravity() * timeElapsed; - } - - // handle resting on surface case, this is definitely a bit of a hack, and it only works on the - // "ground" plane of the domain, but for now it - if (hasGravity() && isRestingOnSurface()) { - velocity.y = 0.0f; - position.y = getDistanceToBottomOfEntity(); + if (hasGravity()) { + // handle resting on surface case, this is definitely a bit of a hack, and it only works on the + // "ground" plane of the domain, but for now it what we've got + if (isRestingOnSurface()) { + velocity.y = 0.0f; + position.y = getDistanceToBottomOfEntity(); + } else { + velocity += getGravity() * timeElapsed; + } } // handle damping for velocity @@ -721,10 +729,12 @@ void EntityItem::simulate(const quint64& now) { qDebug() << " old getAABox:" << getAABox(); } } + + _lastSimulated = now; } bool EntityItem::isMoving() const { - return hasVelocity() || (hasGravity() && !isRestingOnSurface()) || hasAngularVelocity(); + return hasVelocity() || hasAngularVelocity(); } bool EntityItem::lifetimeHasExpired() const { @@ -773,10 +783,13 @@ bool EntityItem::setProperties(const EntityItemProperties& properties, bool forc // handle the setting of created timestamps for the basic new entity case if (forceCopy) { + quint64 now = usecTimestampNow(); if (properties.getCreated() == UNKNOWN_CREATED_TIME) { - _created = usecTimestampNow(); + _created = now; } else if (properties.getCreated() != USE_EXISTING_CREATED_TIME) { - _created = properties.getCreated(); + quint64 created = properties.getCreated(); + // don't allow _created to be in the future + _created = created < now ? created : now; } } @@ -803,13 +816,17 @@ bool EntityItem::setProperties(const EntityItemProperties& properties, bool forc if (somethingChanged) { somethingChangedNotification(); // notify derived classes that something has changed bool wantDebug = false; + uint64_t now = usecTimestampNow(); if (wantDebug) { - uint64_t now = usecTimestampNow(); int elapsed = now - getLastEdited(); qDebug() << "EntityItem::setProperties() AFTER update... edited AGO=" << elapsed << "now=" << now << " getLastEdited()=" << getLastEdited(); } - setLastEdited(properties._lastEdited); + // don't allow _lastEdited to be in the future + setLastEdited(properties._lastEdited < now ? properties._lastEdited : now); + if (getDirtyFlags() & EntityItem::DIRTY_POSITION) { + _lastSimulated = usecTimestampNow(); + } } return somethingChanged; diff --git a/libraries/entities/src/EntityItem.h b/libraries/entities/src/EntityItem.h index d5a4689657..7455b96f6b 100644 --- a/libraries/entities/src/EntityItem.h +++ b/libraries/entities/src/EntityItem.h @@ -85,7 +85,7 @@ public: /// Last edited time of this entity universal usecs quint64 getLastEdited() const { return _lastEdited; } void setLastEdited(quint64 lastEdited) - { _lastEdited = _lastSimulated = _lastUpdated = lastEdited; _changedOnServer = glm::max(lastEdited, _changedOnServer); } + { _lastEdited = _lastUpdated = lastEdited; _changedOnServer = glm::max(lastEdited, _changedOnServer); } float getEditedAgo() const /// Elapsed seconds since this entity was last edited { return (float)(usecTimestampNow() - getLastEdited()) / (float)USECS_PER_SECOND; } @@ -120,9 +120,6 @@ public: static int expectedBytes(); - static bool encodeEntityEditMessageDetails(PacketType command, EntityItemID id, const EntityItemProperties& details, - unsigned char* bufferOut, int sizeIn, int& sizeOut); - static void adjustEditPacketForClockSkew(unsigned char* codeColorBuffer, size_t length, int clockSkew); // perform update diff --git a/libraries/entities/src/EntityItemProperties.h b/libraries/entities/src/EntityItemProperties.h index 642e24beec..e5f78e8fc7 100644 --- a/libraries/entities/src/EntityItemProperties.h +++ b/libraries/entities/src/EntityItemProperties.h @@ -95,8 +95,8 @@ enum EntityPropertyList { typedef PropertyFlags EntityPropertyFlags; -const quint64 UNKNOWN_CREATED_TIME = (quint64)(-1); -const quint64 USE_EXISTING_CREATED_TIME = (quint64)(-2); +const quint64 UNKNOWN_CREATED_TIME = 0; +const quint64 USE_EXISTING_CREATED_TIME = 1; /// A collection of properties of an entity item used in the scripting API. Translates between the actual properties of an diff --git a/libraries/entities/src/EntityTypes.cpp b/libraries/entities/src/EntityTypes.cpp index 194df024e0..f7806445bc 100644 --- a/libraries/entities/src/EntityTypes.cpp +++ b/libraries/entities/src/EntityTypes.cpp @@ -71,7 +71,6 @@ bool EntityTypes::registerEntityType(EntityType entityType, const char* name, En EntityItem* EntityTypes::constructEntityItem(EntityType entityType, const EntityItemID& entityID, const EntityItemProperties& properties) { - EntityItem* newEntityItem = NULL; EntityTypeFactory factory = NULL; if (entityType >= 0 && entityType <= LAST) { @@ -129,7 +128,12 @@ EntityItem* EntityTypes::constructEntityItem(const unsigned char* data, int byte EntityItemID tempEntityID(actualID); EntityItemProperties tempProperties; - tempProperties.setCreated(usecTimestampNow()); // this is temporary... + + // we set the Creation and Edit times to 'now', but if the server submits an earlier Creation time + // then it will be accepted + quint64 now = usecTimestampNow(); + tempProperties.setCreated(now); + tempProperties.setLastEdited(now); return constructEntityItem(entityType, tempEntityID, tempProperties); } From 1e5c44f117c9d3ea47681feabaa86caa7e598bbf Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Wed, 17 Dec 2014 15:48:49 -0800 Subject: [PATCH 2/9] accept changes with the same Edit timestamp --- libraries/entities/src/EntityItem.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/libraries/entities/src/EntityItem.cpp b/libraries/entities/src/EntityItem.cpp index 22cfeb3674..f62cd278c8 100644 --- a/libraries/entities/src/EntityItem.cpp +++ b/libraries/entities/src/EntityItem.cpp @@ -109,9 +109,6 @@ EntityItem::EntityItem(const EntityItemID& entityItemID, const EntityItemPropert _changedOnServer = 0; initFromEntityItemID(entityItemID); setProperties(properties, true); // force copy - if (_lastEdited == 0) { - _lastEdited = _created; - } } EntityPropertyFlags EntityItem::getEntityProperties(EncodeBitstreamParams& params) const { @@ -424,14 +421,14 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef if (fromSameServerEdit) { // If this is from the same sever packet, then check against any local changes since we got // the most recent packet from this server time - if (_lastEdited >= _lastEditedFromRemote) { + if (_lastEdited > _lastEditedFromRemote) { ignoreServerPacket = true; } } else { // If this isn't from the same sever packet, then honor our skew adjusted times... // If we've changed our local tree more recently than the new data from this packet // then we will not be changing our values, instead we just read and skip the data - if (_lastEdited >= lastEditedFromBufferAdjusted) { + if (_lastEdited > lastEditedFromBufferAdjusted) { ignoreServerPacket = true; } } From 44ebf37510e971cc6c0410ebc6ee7b5b4e4cb052 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Wed, 17 Dec 2014 15:52:34 -0800 Subject: [PATCH 3/9] handle case where obj at rest but still falls --- libraries/entities/src/EntityItem.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/entities/src/EntityItem.cpp b/libraries/entities/src/EntityItem.cpp index f62cd278c8..4ad2770d05 100644 --- a/libraries/entities/src/EntityItem.cpp +++ b/libraries/entities/src/EntityItem.cpp @@ -650,7 +650,7 @@ void EntityItem::simulate(const quint64& now) { } } - if (hasVelocity()) { + if (hasVelocity() || hasGravity()) { glm::vec3 position = getPosition(); glm::vec3 velocity = getVelocity(); glm::vec3 newPosition = position + (velocity * timeElapsed); @@ -731,7 +731,7 @@ void EntityItem::simulate(const quint64& now) { } bool EntityItem::isMoving() const { - return hasVelocity() || hasAngularVelocity(); + return hasVelocity() (hasGravity() && !isRestingOnSurface()) || hasAngularVelocity(); } bool EntityItem::lifetimeHasExpired() const { From 75d468da9e14f0f1a8b9a65bb9ab357e36f01ed9 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Wed, 17 Dec 2014 15:59:16 -0800 Subject: [PATCH 4/9] set _lastEdited to _created rather than to zero --- libraries/entities/src/EntityItem.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/libraries/entities/src/EntityItem.cpp b/libraries/entities/src/EntityItem.cpp index 4ad2770d05..a72eb86b0c 100644 --- a/libraries/entities/src/EntityItem.cpp +++ b/libraries/entities/src/EntityItem.cpp @@ -368,10 +368,9 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef createdFromBuffer -= clockSkew; if (createdFromBuffer < _created) { - // the server claims that this entity has an older creation time - // so we accept it and clear _lastEdited + // the server claims that this entity has an older creation time so we accept it _created = createdFromBuffer; - _lastEdited = 0; + _lastEdited = _created; } if (wantDebug) { From 756d09d895465452d27255565805cb3968b5f696 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Wed, 17 Dec 2014 16:06:15 -0800 Subject: [PATCH 5/9] fix typo that broke the build --- libraries/entities/src/EntityItem.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/entities/src/EntityItem.cpp b/libraries/entities/src/EntityItem.cpp index a72eb86b0c..cd34cd55c6 100644 --- a/libraries/entities/src/EntityItem.cpp +++ b/libraries/entities/src/EntityItem.cpp @@ -730,7 +730,7 @@ void EntityItem::simulate(const quint64& now) { } bool EntityItem::isMoving() const { - return hasVelocity() (hasGravity() && !isRestingOnSurface()) || hasAngularVelocity(); + return hasVelocity() || (hasGravity() && !isRestingOnSurface()) || hasAngularVelocity(); } bool EntityItem::lifetimeHasExpired() const { From 28381a3b7092fc956153df7561029059616c2a0b Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Thu, 18 Dec 2014 11:39:02 -0800 Subject: [PATCH 6/9] cleanup of EntityItem::_created timestamp logic EntityItem::_created initializes to 0 in ctor and must be set either by EntityItemProperties (via server update) or manually whenever a script creates a fresh entity --- libraries/entities/src/EntityItem.cpp | 101 +++++++++++------- libraries/entities/src/EntityItem.h | 3 +- .../entities/src/EntityItemProperties.cpp | 14 ++- libraries/entities/src/EntityItemProperties.h | 6 +- .../entities/src/EntityItemPropertiesMacros.h | 4 +- libraries/entities/src/EntityTree.cpp | 17 ++- libraries/entities/src/EntityTypes.cpp | 17 +-- 7 files changed, 95 insertions(+), 67 deletions(-) diff --git a/libraries/entities/src/EntityItem.cpp b/libraries/entities/src/EntityItem.cpp index cd34cd55c6..348efac9a3 100644 --- a/libraries/entities/src/EntityItem.cpp +++ b/libraries/entities/src/EntityItem.cpp @@ -53,13 +53,13 @@ void EntityItem::initFromEntityItemID(const EntityItemID& entityItemID) { _creatorTokenID = entityItemID.creatorTokenID; // init values with defaults before calling setProperties + quint64 now = usecTimestampNow(); + _lastSimulated = now; + _lastUpdated = now; _lastEdited = 0; _lastEditedFromRemote = 0; _lastEditedFromRemoteInRemoteTime = 0; - - _lastSimulated = 0; - _lastUpdated = 0; - _created = usecTimestampNow(); + _created = UNKNOWN_CREATED_TIME; _changedOnServer = 0; _position = glm::vec3(0,0,0); @@ -85,12 +85,13 @@ void EntityItem::initFromEntityItemID(const EntityItemID& entityItemID) { EntityItem::EntityItem(const EntityItemID& entityItemID) { _type = EntityTypes::Unknown; + quint64 now = usecTimestampNow(); + _lastSimulated = now; + _lastUpdated = now; _lastEdited = 0; _lastEditedFromRemote = 0; _lastEditedFromRemoteInRemoteTime = 0; - _lastSimulated = 0; - _lastUpdated = 0; - _created = 0; + _created = UNKNOWN_CREATED_TIME; _dirtyFlags = 0; _changedOnServer = 0; initFromEntityItemID(entityItemID); @@ -99,16 +100,16 @@ EntityItem::EntityItem(const EntityItemID& entityItemID) { EntityItem::EntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) { _type = EntityTypes::Unknown; quint64 now = usecTimestampNow(); - _created = properties.getCreated() < now ? properties.getCreated() : now; - _lastEdited = _lastEditedFromRemote = _lastSimulated = _lastUpdated = _lastEditedFromRemoteInRemoteTime = _created; + _lastSimulated = now; + _lastUpdated = now; + _lastEdited = 0; _lastEditedFromRemote = 0; _lastEditedFromRemoteInRemoteTime = 0; - _lastSimulated = 0; - _lastUpdated = 0; + _created = UNKNOWN_CREATED_TIME; _dirtyFlags = 0; _changedOnServer = 0; initFromEntityItemID(entityItemID); - setProperties(properties, true); // force copy + setProperties(properties); } EntityPropertyFlags EntityItem::getEntityProperties(EncodeBitstreamParams& params) const { @@ -365,12 +366,15 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef memcpy(&createdFromBuffer, dataAt, sizeof(createdFromBuffer)); dataAt += sizeof(createdFromBuffer); bytesRead += sizeof(createdFromBuffer); - createdFromBuffer -= clockSkew; - - if (createdFromBuffer < _created) { - // the server claims that this entity has an older creation time so we accept it + + quint64 now = usecTimestampNow(); + if (_created == UNKNOWN_CREATED_TIME) { + // we don't yet have a _created timestamp, so we accept this one + createdFromBuffer -= clockSkew; + if (createdFromBuffer > now || createdFromBuffer == UNKNOWN_CREATED_TIME) { + createdFromBuffer = now; + } _created = createdFromBuffer; - _lastEdited = _created; } if (wantDebug) { @@ -385,7 +389,6 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef qDebug() << " ago=" << editedAgo << "seconds - " << agoAsString; } - quint64 now = usecTimestampNow(); quint64 lastEditedFromBuffer = 0; quint64 lastEditedFromBufferAdjusted = 0; @@ -395,6 +398,9 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef dataAt += sizeof(lastEditedFromBuffer); bytesRead += sizeof(lastEditedFromBuffer); lastEditedFromBufferAdjusted = lastEditedFromBuffer - clockSkew; + if (lastEditedFromBufferAdjusted > now) { + lastEditedFromBufferAdjusted = now; + } bool fromSameServerEdit = (lastEditedFromBuffer == _lastEditedFromRemoteInRemoteTime); @@ -444,10 +450,12 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef } // don't allow _lastEdited to be in the future - _lastEdited = lastEditedFromBufferAdjusted < now ? lastEditedFromBufferAdjusted : now; + _lastEdited = lastEditedFromBufferAdjusted; _lastEditedFromRemote = now; _lastEditedFromRemoteInRemoteTime = lastEditedFromBuffer; + // TODO: only send this notification if something ACTUALLY changed (hint, we haven't yet parsed + // the properties out of the bitstream (see below)) somethingChangedNotification(); // notify derived classes that something has changed } @@ -456,8 +464,7 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef ByteCountCoded updateDeltaCoder = encodedUpdateDelta; quint64 updateDelta = updateDeltaCoder; if (overwriteLocalData) { - _lastUpdated = lastEditedFromBufferAdjusted + updateDelta; // don't adjust for clock skew since we already did that for _lastEdited - _lastSimulated = now; + _lastUpdated = lastEditedFromBufferAdjusted + updateDelta; // don't adjust for clock skew since we already did that if (wantDebug) { qDebug() << "_lastUpdated =" << _lastUpdated; qDebug() << "_lastEdited=" << _lastEdited; @@ -529,6 +536,9 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef bytesRead += readEntitySubclassDataFromBuffer(dataAt, (bytesLeftToRead - bytesRead), args, propertyFlags, overwriteLocalData); recalculateCollisionShape(); + if (overwriteLocalData && (getDirtyFlags() & EntityItem::DIRTY_POSITION)) { + _lastSimulated = now; + } } return bytesRead; } @@ -774,21 +784,9 @@ EntityItemProperties EntityItem::getProperties() const { return properties; } -bool EntityItem::setProperties(const EntityItemProperties& properties, bool forceCopy) { +bool EntityItem::setProperties(const EntityItemProperties& properties) { bool somethingChanged = false; - // handle the setting of created timestamps for the basic new entity case - if (forceCopy) { - quint64 now = usecTimestampNow(); - if (properties.getCreated() == UNKNOWN_CREATED_TIME) { - _created = now; - } else if (properties.getCreated() != USE_EXISTING_CREATED_TIME) { - quint64 created = properties.getCreated(); - // don't allow _created to be in the future - _created = created < now ? created : now; - } - } - SET_ENTITY_PROPERTY_FROM_PROPERTIES(position, updatePositionInMeters); // this will call recalculate collision shape if needed SET_ENTITY_PROPERTY_FROM_PROPERTIES(dimensions, updateDimensionsInMeters); // NOTE: radius is obsolete SET_ENTITY_PROPERTY_FROM_PROPERTIES(rotation, updateRotation); @@ -818,16 +816,43 @@ bool EntityItem::setProperties(const EntityItemProperties& properties, bool forc qDebug() << "EntityItem::setProperties() AFTER update... edited AGO=" << elapsed << "now=" << now << " getLastEdited()=" << getLastEdited(); } - // don't allow _lastEdited to be in the future - setLastEdited(properties._lastEdited < now ? properties._lastEdited : now); + if (_created != UNKNOWN_CREATED_TIME) { + setLastEdited(now); + } if (getDirtyFlags() & EntityItem::DIRTY_POSITION) { - _lastSimulated = usecTimestampNow(); + _lastSimulated = now; } } - + + // timestamps + quint64 timestamp = properties.getCreated(); + if (_created == UNKNOWN_CREATED_TIME && timestamp != UNKNOWN_CREATED_TIME) { + quint64 now = usecTimestampNow(); + if (timestamp > now) { + timestamp = now; + } + _created = timestamp; + + timestamp = properties.getLastEdited(); + if (timestamp > now) { + timestamp = now; + } else if (timestamp < _created) { + timestamp = _created; + } + _lastEdited = timestamp; + } + return somethingChanged; } +void EntityItem::recordCreationTime() { + assert(_created == UNKNOWN_CREATED_TIME); + _created = usecTimestampNow(); + _lastEdited = _created; + _lastUpdated = _created; + _lastSimulated = _created; +} + // TODO: is this really correct? how do we use size, does it need to handle rotation? float EntityItem::getSize() const { diff --git a/libraries/entities/src/EntityItem.h b/libraries/entities/src/EntityItem.h index 7455b96f6b..0d0aa96706 100644 --- a/libraries/entities/src/EntityItem.h +++ b/libraries/entities/src/EntityItem.h @@ -74,12 +74,13 @@ public: virtual EntityItemProperties getProperties() const; /// returns true if something changed - virtual bool setProperties(const EntityItemProperties& properties, bool forceCopy = false); + virtual bool setProperties(const EntityItemProperties& properties); /// Override this in your derived class if you'd like to be informed when something about the state of the entity /// has changed. This will be called with properties change or when new data is loaded from a stream virtual void somethingChangedNotification() { } + void recordCreationTime(); // set _created to 'now' quint64 getLastSimulated() const { return _lastSimulated; } /// Last simulated time of this entity universal usecs /// Last edited time of this entity universal usecs diff --git a/libraries/entities/src/EntityItemProperties.cpp b/libraries/entities/src/EntityItemProperties.cpp index 11c9646cbc..58b110c4b0 100644 --- a/libraries/entities/src/EntityItemProperties.cpp +++ b/libraries/entities/src/EntityItemProperties.cpp @@ -156,6 +156,17 @@ void EntityItemProperties::debugDump() const { props.debugDumpBits(); } +void EntityItemProperties::setCreated(quint64 usecTime) { + _created = usecTime; + if (_lastEdited < _created) { + _lastEdited = _created; + } +} + +void EntityItemProperties::setLastEdited(quint64 usecTime) { + _lastEdited = usecTime > _created ? usecTime : _created; +} + EntityPropertyFlags EntityItemProperties::getChangedProperties() const { EntityPropertyFlags changedProperties; @@ -652,9 +663,6 @@ bool EntityItemProperties::decodeEntityEditPacket(const unsigned char* data, int entityID.creatorTokenID = UNKNOWN_ENTITY_TOKEN; entityID.isKnownID = true; valid = true; - - // created time is lastEdited time - properties.setCreated(USE_EXISTING_CREATED_TIME); } // Entity Type... diff --git a/libraries/entities/src/EntityItemProperties.h b/libraries/entities/src/EntityItemProperties.h index e5f78e8fc7..b843c85327 100644 --- a/libraries/entities/src/EntityItemProperties.h +++ b/libraries/entities/src/EntityItemProperties.h @@ -96,8 +96,6 @@ enum EntityPropertyList { typedef PropertyFlags EntityPropertyFlags; const quint64 UNKNOWN_CREATED_TIME = 0; -const quint64 USE_EXISTING_CREATED_TIME = 1; - /// A collection of properties of an entity item used in the scripting API. Translates between the actual properties of an /// entity and a JavaScript style hash/QScriptValue storing a set of properties. Used in scripting to set/get the complete @@ -134,7 +132,7 @@ public: AABox getAABoxInMeters() const; void debugDump() const; - void setLastEdited(quint64 usecTime) { _lastEdited = usecTime; } + void setLastEdited(quint64 usecTime); DEFINE_PROPERTY(PROP_VISIBLE, Visible, visible, bool); DEFINE_PROPERTY_REF_WITH_SETTER(PROP_POSITION, Position, position, glm::vec3); @@ -180,7 +178,7 @@ public: float getAge() const { return (float)(usecTimestampNow() - _created) / (float)USECS_PER_SECOND; } quint64 getCreated() const { return _created; } - void setCreated(quint64 usecTime) { _created = usecTime; } + void setCreated(quint64 usecTime); bool hasCreatedTime() const { return (_created != UNKNOWN_CREATED_TIME); } bool containsBoundsProperties() const { return (_positionChanged || _dimensionsChanged); } diff --git a/libraries/entities/src/EntityItemPropertiesMacros.h b/libraries/entities/src/EntityItemPropertiesMacros.h index 3288e56a3d..9f86156422 100644 --- a/libraries/entities/src/EntityItemPropertiesMacros.h +++ b/libraries/entities/src/EntityItemPropertiesMacros.h @@ -137,13 +137,13 @@ } #define SET_ENTITY_PROPERTY_FROM_PROPERTIES(P,M) \ - if (properties._##P##Changed || forceCopy) { \ + if (properties._##P##Changed) { \ M(properties._##P); \ somethingChanged = true; \ } #define SET_ENTITY_PROPERTY_FROM_PROPERTIES_GETTER(C,G,S) \ - if (properties.C() || forceCopy) { \ + if (properties.C()) { \ S(properties.G()); \ somethingChanged = true; \ } diff --git a/libraries/entities/src/EntityTree.cpp b/libraries/entities/src/EntityTree.cpp index fb8e4345f4..3580e64b35 100644 --- a/libraries/entities/src/EntityTree.cpp +++ b/libraries/entities/src/EntityTree.cpp @@ -164,9 +164,17 @@ EntityItem* EntityTree::addEntity(const EntityItemID& entityID, const EntityItem // NOTE: This method is used in the client and the server tree. In the client, it's possible to create EntityItems // that do not yet have known IDs. In the server tree however we don't want to have entities without known IDs. - if (getIsServer() && !entityID.isKnownID) { - qDebug() << "UNEXPECTED!!! ----- EntityTree::addEntity()... (getIsSever() && !entityID.isKnownID)"; - return result; + bool recordCreationTime = false; + if (!entityID.isKnownID) { + if (getIsServer()) { + qDebug() << "UNEXPECTED!!! ----- EntityTree::addEntity()... (getIsSever() && !entityID.isKnownID)"; + return result; + } + if (properties.getCreated() == UNKNOWN_CREATED_TIME) { + // the entity's creation time was not specified in properties, which means this is a NEW entity + // and we must record its creation time + recordCreationTime = true; + } } // You should not call this on existing entities that are already part of the tree! Call updateEntity() @@ -182,6 +190,9 @@ EntityItem* EntityTree::addEntity(const EntityItemID& entityID, const EntityItem result = EntityTypes::constructEntityItem(type, entityID, properties); if (result) { + if (recordCreationTime) { + result->recordCreationTime(); + } // Recurse the tree and store the entity in the correct tree element AddEntityOperator theOperator(this, result); recurseTreeWithOperator(&theOperator); diff --git a/libraries/entities/src/EntityTypes.cpp b/libraries/entities/src/EntityTypes.cpp index f7806445bc..fd9484e0d6 100644 --- a/libraries/entities/src/EntityTypes.cpp +++ b/libraries/entities/src/EntityTypes.cpp @@ -77,15 +77,7 @@ EntityItem* EntityTypes::constructEntityItem(EntityType entityType, const Entity factory = _factories[entityType]; } if (factory) { - // NOTE: if someone attempts to create an entity with properties that do not include a proper "created" time - // then set the created time to now - if (!properties.hasCreatedTime()) { - EntityItemProperties mutableProperties = properties; - mutableProperties.setCreated(usecTimestampNow()); - newEntityItem = factory(entityID, mutableProperties); - } else { - newEntityItem = factory(entityID, properties); - } + newEntityItem = factory(entityID, properties); } return newEntityItem; } @@ -128,13 +120,6 @@ EntityItem* EntityTypes::constructEntityItem(const unsigned char* data, int byte EntityItemID tempEntityID(actualID); EntityItemProperties tempProperties; - - // we set the Creation and Edit times to 'now', but if the server submits an earlier Creation time - // then it will be accepted - quint64 now = usecTimestampNow(); - tempProperties.setCreated(now); - tempProperties.setLastEdited(now); - return constructEntityItem(entityType, tempEntityID, tempProperties); } From b03e6c53e1b34c7b110c8ba4b0b6af01c7748e30 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Thu, 18 Dec 2014 11:41:20 -0800 Subject: [PATCH 7/9] fixing derived classes to use new EntityItem API remove 'forceCopy' argument in EntityItem::setProperties() --- .../entities-renderer/src/RenderableModelEntityItem.cpp | 4 ++-- libraries/entities-renderer/src/RenderableModelEntityItem.h | 2 +- libraries/entities/src/BoxEntityItem.cpp | 6 +++--- libraries/entities/src/BoxEntityItem.h | 2 +- libraries/entities/src/LightEntityItem.cpp | 6 +++--- libraries/entities/src/LightEntityItem.h | 2 +- libraries/entities/src/ModelEntityItem.cpp | 6 +++--- libraries/entities/src/ModelEntityItem.h | 2 +- libraries/entities/src/SphereEntityItem.cpp | 6 +++--- libraries/entities/src/SphereEntityItem.h | 2 +- libraries/entities/src/TextEntityItem.cpp | 6 +++--- libraries/entities/src/TextEntityItem.h | 2 +- 12 files changed, 23 insertions(+), 23 deletions(-) diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp index 3e5118d203..92e925d73e 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp @@ -34,9 +34,9 @@ RenderableModelEntityItem::~RenderableModelEntityItem() { } } -bool RenderableModelEntityItem::setProperties(const EntityItemProperties& properties, bool forceCopy) { +bool RenderableModelEntityItem::setProperties(const EntityItemProperties& properties) { QString oldModelURL = getModelURL(); - bool somethingChanged = ModelEntityItem::setProperties(properties, forceCopy); + bool somethingChanged = ModelEntityItem::setProperties(properties); if (somethingChanged && oldModelURL != getModelURL()) { _needsModelReload = true; } diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.h b/libraries/entities-renderer/src/RenderableModelEntityItem.h index 6f61a1b9db..65cded0207 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.h +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.h @@ -35,7 +35,7 @@ public: virtual ~RenderableModelEntityItem(); virtual EntityItemProperties getProperties() const; - virtual bool setProperties(const EntityItemProperties& properties, bool forceCopy); + virtual bool setProperties(const EntityItemProperties& properties); virtual int readEntitySubclassDataFromBuffer(const unsigned char* data, int bytesLeftToRead, ReadBitstreamToTreeParams& args, EntityPropertyFlags& propertyFlags, bool overwriteLocalData); diff --git a/libraries/entities/src/BoxEntityItem.cpp b/libraries/entities/src/BoxEntityItem.cpp index 16204f0c16..cece544263 100644 --- a/libraries/entities/src/BoxEntityItem.cpp +++ b/libraries/entities/src/BoxEntityItem.cpp @@ -29,7 +29,7 @@ BoxEntityItem::BoxEntityItem(const EntityItemID& entityItemID, const EntityItemP { _type = EntityTypes::Box; _created = properties.getCreated(); - setProperties(properties, true); + setProperties(properties); } EntityItemProperties BoxEntityItem::getProperties() const { @@ -44,9 +44,9 @@ EntityItemProperties BoxEntityItem::getProperties() const { return properties; } -bool BoxEntityItem::setProperties(const EntityItemProperties& properties, bool forceCopy) { +bool BoxEntityItem::setProperties(const EntityItemProperties& properties) { bool somethingChanged = false; - somethingChanged = EntityItem::setProperties(properties, forceCopy); // set the properties in our base class + somethingChanged = EntityItem::setProperties(properties); // set the properties in our base class SET_ENTITY_PROPERTY_FROM_PROPERTIES(color, setColor); diff --git a/libraries/entities/src/BoxEntityItem.h b/libraries/entities/src/BoxEntityItem.h index b5f4521f96..da9e7544c6 100644 --- a/libraries/entities/src/BoxEntityItem.h +++ b/libraries/entities/src/BoxEntityItem.h @@ -24,7 +24,7 @@ public: // methods for getting/setting all properties of an entity virtual EntityItemProperties getProperties() const; - virtual bool setProperties(const EntityItemProperties& properties, bool forceCopy = false); + virtual bool setProperties(const EntityItemProperties& properties); // TODO: eventually only include properties changed since the params.lastViewFrustumSent time virtual EntityPropertyFlags getEntityProperties(EncodeBitstreamParams& params) const; diff --git a/libraries/entities/src/LightEntityItem.cpp b/libraries/entities/src/LightEntityItem.cpp index 44b83bc94e..c125364e63 100644 --- a/libraries/entities/src/LightEntityItem.cpp +++ b/libraries/entities/src/LightEntityItem.cpp @@ -41,7 +41,7 @@ LightEntityItem::LightEntityItem(const EntityItemID& entityItemID, const EntityI _exponent = 0.0f; _cutoff = PI; - setProperties(properties, true); + setProperties(properties); // a light is not collide-able so we make it's shape be a tiny sphere at origin _emptyShape.setTranslation(glm::vec3(0.0f, 0.0f, 0.0f)); @@ -71,8 +71,8 @@ EntityItemProperties LightEntityItem::getProperties() const { return properties; } -bool LightEntityItem::setProperties(const EntityItemProperties& properties, bool forceCopy) { - bool somethingChanged = EntityItem::setProperties(properties, forceCopy); // set the properties in our base class +bool LightEntityItem::setProperties(const EntityItemProperties& properties) { + bool somethingChanged = EntityItem::setProperties(properties); // set the properties in our base class SET_ENTITY_PROPERTY_FROM_PROPERTIES(isSpotlight, setIsSpotlight); SET_ENTITY_PROPERTY_FROM_PROPERTIES(diffuseColor, setDiffuseColor); diff --git a/libraries/entities/src/LightEntityItem.h b/libraries/entities/src/LightEntityItem.h index 6ebb85beda..249a4c8472 100644 --- a/libraries/entities/src/LightEntityItem.h +++ b/libraries/entities/src/LightEntityItem.h @@ -28,7 +28,7 @@ public: // methods for getting/setting all properties of an entity virtual EntityItemProperties getProperties() const; - virtual bool setProperties(const EntityItemProperties& properties, bool forceCopy = false); + virtual bool setProperties(const EntityItemProperties& properties); virtual EntityPropertyFlags getEntityProperties(EncodeBitstreamParams& params) const; diff --git a/libraries/entities/src/ModelEntityItem.cpp b/libraries/entities/src/ModelEntityItem.cpp index b14248b3bc..02ebbebdb4 100644 --- a/libraries/entities/src/ModelEntityItem.cpp +++ b/libraries/entities/src/ModelEntityItem.cpp @@ -34,7 +34,7 @@ ModelEntityItem::ModelEntityItem(const EntityItemID& entityItemID, const EntityI EntityItem(entityItemID, properties) { _type = EntityTypes::Model; - setProperties(properties, true); + setProperties(properties); _lastAnimated = usecTimestampNow(); _jointMappingCompleted = false; _color[0] = _color[1] = _color[2] = 0; @@ -55,9 +55,9 @@ EntityItemProperties ModelEntityItem::getProperties() const { return properties; } -bool ModelEntityItem::setProperties(const EntityItemProperties& properties, bool forceCopy) { +bool ModelEntityItem::setProperties(const EntityItemProperties& properties) { bool somethingChanged = false; - somethingChanged = EntityItem::setProperties(properties, forceCopy); // set the properties in our base class + somethingChanged = EntityItem::setProperties(properties); // set the properties in our base class SET_ENTITY_PROPERTY_FROM_PROPERTIES(color, setColor); SET_ENTITY_PROPERTY_FROM_PROPERTIES(modelURL, setModelURL); diff --git a/libraries/entities/src/ModelEntityItem.h b/libraries/entities/src/ModelEntityItem.h index 6b4ca2416a..4c14dca177 100644 --- a/libraries/entities/src/ModelEntityItem.h +++ b/libraries/entities/src/ModelEntityItem.h @@ -26,7 +26,7 @@ public: // methods for getting/setting all properties of an entity virtual EntityItemProperties getProperties() const; - virtual bool setProperties(const EntityItemProperties& properties, bool forceCopy = false); + virtual bool setProperties(const EntityItemProperties& properties); // TODO: eventually only include properties changed since the params.lastViewFrustumSent time virtual EntityPropertyFlags getEntityProperties(EncodeBitstreamParams& params) const; diff --git a/libraries/entities/src/SphereEntityItem.cpp b/libraries/entities/src/SphereEntityItem.cpp index b0df310ad2..06035f6b6e 100644 --- a/libraries/entities/src/SphereEntityItem.cpp +++ b/libraries/entities/src/SphereEntityItem.cpp @@ -31,7 +31,7 @@ SphereEntityItem::SphereEntityItem(const EntityItemID& entityItemID, const Entit EntityItem(entityItemID, properties) { _type = EntityTypes::Sphere; - setProperties(properties, true); + setProperties(properties); } EntityItemProperties SphereEntityItem::getProperties() const { @@ -40,8 +40,8 @@ EntityItemProperties SphereEntityItem::getProperties() const { return properties; } -bool SphereEntityItem::setProperties(const EntityItemProperties& properties, bool forceCopy) { - bool somethingChanged = EntityItem::setProperties(properties, forceCopy); // set the properties in our base class +bool SphereEntityItem::setProperties(const EntityItemProperties& properties) { + bool somethingChanged = EntityItem::setProperties(properties); // set the properties in our base class SET_ENTITY_PROPERTY_FROM_PROPERTIES(color, setColor); diff --git a/libraries/entities/src/SphereEntityItem.h b/libraries/entities/src/SphereEntityItem.h index 74cc7d1635..3b7dccaff9 100644 --- a/libraries/entities/src/SphereEntityItem.h +++ b/libraries/entities/src/SphereEntityItem.h @@ -25,7 +25,7 @@ public: // methods for getting/setting all properties of an entity virtual EntityItemProperties getProperties() const; - virtual bool setProperties(const EntityItemProperties& properties, bool forceCopy = false); + virtual bool setProperties(const EntityItemProperties& properties); virtual EntityPropertyFlags getEntityProperties(EncodeBitstreamParams& params) const; diff --git a/libraries/entities/src/TextEntityItem.cpp b/libraries/entities/src/TextEntityItem.cpp index bb76a2e690..c43638f827 100644 --- a/libraries/entities/src/TextEntityItem.cpp +++ b/libraries/entities/src/TextEntityItem.cpp @@ -37,7 +37,7 @@ TextEntityItem::TextEntityItem(const EntityItemID& entityItemID, const EntityIte { _type = EntityTypes::Text; _created = properties.getCreated(); - setProperties(properties, true); + setProperties(properties); } void TextEntityItem::setDimensions(const glm::vec3& value) { @@ -57,9 +57,9 @@ EntityItemProperties TextEntityItem::getProperties() const { return properties; } -bool TextEntityItem::setProperties(const EntityItemProperties& properties, bool forceCopy) { +bool TextEntityItem::setProperties(const EntityItemProperties& properties) { bool somethingChanged = false; - somethingChanged = EntityItem::setProperties(properties, forceCopy); // set the properties in our base class + somethingChanged = EntityItem::setProperties(properties); // set the properties in our base class SET_ENTITY_PROPERTY_FROM_PROPERTIES(text, setText); SET_ENTITY_PROPERTY_FROM_PROPERTIES(lineHeight, setLineHeight); diff --git a/libraries/entities/src/TextEntityItem.h b/libraries/entities/src/TextEntityItem.h index 83143b1134..1f0bd7d85e 100644 --- a/libraries/entities/src/TextEntityItem.h +++ b/libraries/entities/src/TextEntityItem.h @@ -27,7 +27,7 @@ public: // methods for getting/setting all properties of an entity virtual EntityItemProperties getProperties() const; - virtual bool setProperties(const EntityItemProperties& properties, bool forceCopy = false); + virtual bool setProperties(const EntityItemProperties& properties); // TODO: eventually only include properties changed since the params.lastViewFrustumSent time virtual EntityPropertyFlags getEntityProperties(EncodeBitstreamParams& params) const; From 47d8b0b062ee4bd2179d0fe93acc923192575b10 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Thu, 18 Dec 2014 16:24:26 -0800 Subject: [PATCH 8/9] Replace Game Of Life with intructions --- .../resources/web/assignment/placeholder.js | 134 +----------------- 1 file changed, 3 insertions(+), 131 deletions(-) diff --git a/domain-server/resources/web/assignment/placeholder.js b/domain-server/resources/web/assignment/placeholder.js index 46a706999f..663215fc7e 100644 --- a/domain-server/resources/web/assignment/placeholder.js +++ b/domain-server/resources/web/assignment/placeholder.js @@ -1,131 +1,3 @@ -// Add your JavaScript for assignment below this line - -// The following is an example of Conway's Game of Life (http://en.wikipedia.org/wiki/Conway's_Game_of_Life) - -var NUMBER_OF_CELLS_EACH_DIMENSION = 64; -var NUMBER_OF_CELLS = NUMBER_OF_CELLS_EACH_DIMENSION * NUMBER_OF_CELLS_EACH_DIMENSION; - -var currentCells = []; -var nextCells = []; - -var METER_LENGTH = 1; -var cellScale = (NUMBER_OF_CELLS_EACH_DIMENSION * METER_LENGTH) / NUMBER_OF_CELLS_EACH_DIMENSION; - -// randomly populate the cell start values -for (var i = 0; i < NUMBER_OF_CELLS_EACH_DIMENSION; i++) { - // create the array to hold this row - currentCells[i] = []; - - // create the array to hold this row in the nextCells array - nextCells[i] = []; - - for (var j = 0; j < NUMBER_OF_CELLS_EACH_DIMENSION; j++) { - currentCells[i][j] = Math.floor(Math.random() * 2); - - // put the same value in the nextCells array for first board draw - nextCells[i][j] = currentCells[i][j]; - } -} - -function isNeighbourAlive(i, j) { - if (i < 0 || i >= NUMBER_OF_CELLS_EACH_DIMENSION - || i < 0 || j >= NUMBER_OF_CELLS_EACH_DIMENSION) { - return 0; - } else { - return currentCells[i][j]; - } -} - -function updateCells() { - var i = 0; - var j = 0; - - for (i = 0; i < NUMBER_OF_CELLS_EACH_DIMENSION; i++) { - for (j = 0; j < NUMBER_OF_CELLS_EACH_DIMENSION; j++) { - // figure out the number of live neighbours for the i-j cell - var liveNeighbours = - isNeighbourAlive(i + 1, j - 1) + isNeighbourAlive(i + 1, j) + isNeighbourAlive(i + 1, j + 1) + - isNeighbourAlive(i, j - 1) + isNeighbourAlive(i, j + 1) + - isNeighbourAlive(i - 1, j - 1) + isNeighbourAlive(i - 1, j) + isNeighbourAlive(i - 1, j + 1); - - if (currentCells[i][j]) { - // live cell - - if (liveNeighbours < 2) { - // rule #1 - under-population - this cell will die - // mark it zero to mark the change - nextCells[i][j] = 0; - } else if (liveNeighbours < 4) { - // rule #2 - this cell lives - // mark it -1 to mark no change - nextCells[i][j] = -1; - } else { - // rule #3 - overcrowding - this cell dies - // mark it zero to mark the change - nextCells[i][j] = 0; - } - } else { - // dead cell - if (liveNeighbours == 3) { - // rule #4 - reproduction - this cell revives - // mark it one to mark the change - nextCells[i][j] = 1; - } else { - // this cell stays dead - // mark it -1 for no change - nextCells[i][j] = -1; - } - } - - if (Math.random() < 0.001) { - // Random mutation to keep things interesting in there. - nextCells[i][j] = 1; - } - } - } - - for (i = 0; i < NUMBER_OF_CELLS_EACH_DIMENSION; i++) { - for (j = 0; j < NUMBER_OF_CELLS_EACH_DIMENSION; j++) { - if (nextCells[i][j] != -1) { - // there has been a change to this cell, change the value in the currentCells array - currentCells[i][j] = nextCells[i][j]; - } - } - } -} - -function sendNextCells() { - for (var i = 0; i < NUMBER_OF_CELLS_EACH_DIMENSION; i++) { - for (var j = 0; j < NUMBER_OF_CELLS_EACH_DIMENSION; j++) { - if (nextCells[i][j] != -1) { - // there has been a change to the state of this cell, send it - - // find the x and y position for this voxel, z = 0 - var x = j * cellScale; - var y = i * cellScale; - - // queue a packet to add a voxel for the new cell - var color = (nextCells[i][j] == 1) ? 255 : 1; - Voxels.setVoxel(x, y, 0, cellScale, color, color, color); - } - } - } -} - -var sentFirstBoard = false; - -function step(deltaTime) { - if (sentFirstBoard) { - // we've already sent the first full board, perform a step in time - updateCells(); - } else { - // this will be our first board send - sentFirstBoard = true; - } - - sendNextCells(); -} - - -Script.update.connect(step); -Voxels.setPacketsPerSecond(200); \ No newline at end of file +// Here you can put a script that will be run by an Assignement Client (AC) +// For examples, please go to http://public.highfidelity.io/scripts +// The directory named acScripts contains Assignement Clients specific scripts you can try. \ No newline at end of file From e6123ec4a7721c427f43728d951eb492c1c5d7c4 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Thu, 18 Dec 2014 16:31:19 -0800 Subject: [PATCH 9/9] Typo --- domain-server/resources/web/assignment/placeholder.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/domain-server/resources/web/assignment/placeholder.js b/domain-server/resources/web/assignment/placeholder.js index 663215fc7e..2c1d8253aa 100644 --- a/domain-server/resources/web/assignment/placeholder.js +++ b/domain-server/resources/web/assignment/placeholder.js @@ -1,3 +1,3 @@ -// Here you can put a script that will be run by an Assignement Client (AC) +// Here you can put a script that will be run by an assignment-client (AC) // For examples, please go to http://public.highfidelity.io/scripts -// The directory named acScripts contains Assignement Clients specific scripts you can try. \ No newline at end of file +// The directory named acScripts contains assignment-client specific scripts you can try.