fix bug that was deleting actions with 0 ttl. in js interface, action parameter 'lifetime' is now called 'ttl'

This commit is contained in:
Seth Alves 2015-10-26 13:50:21 -07:00
parent 5cf936f132
commit 8d0aaed41a
9 changed files with 62 additions and 34 deletions

View file

@ -74,8 +74,8 @@ var MSEC_PER_SEC = 1000.0;
// these control how long an abandoned pointer line will hang around // these control how long an abandoned pointer line will hang around
var LIFETIME = 10; var LIFETIME = 10;
var ACTION_LIFETIME = 15; // seconds var ACTION_TTL = 15; // seconds
var ACTION_LIFETIME_REFRESH = 5; var ACTION_TTL_REFRESH = 5;
var PICKS_PER_SECOND_PER_HAND = 5; var PICKS_PER_SECOND_PER_HAND = 5;
var MSECS_PER_SEC = 1000.0; var MSECS_PER_SEC = 1000.0;
@ -422,12 +422,12 @@ function MyController(hand, triggerAction) {
targetRotation: this.currentObjectRotation, targetRotation: this.currentObjectRotation,
angularTimeScale: DISTANCE_HOLDING_ACTION_TIMEFRAME, angularTimeScale: DISTANCE_HOLDING_ACTION_TIMEFRAME,
tag: getTag(), tag: getTag(),
lifetime: ACTION_LIFETIME ttl: ACTION_TTL
}); });
if (this.actionID === NULL_ACTION_ID) { if (this.actionID === NULL_ACTION_ID) {
this.actionID = null; this.actionID = null;
} }
this.actionTimeout = now + (ACTION_LIFETIME * MSEC_PER_SEC); this.actionTimeout = now + (ACTION_TTL * MSEC_PER_SEC);
if (this.actionID !== null) { if (this.actionID !== null) {
this.setState(STATE_CONTINUE_DISTANCE_HOLDING); this.setState(STATE_CONTINUE_DISTANCE_HOLDING);
@ -524,9 +524,9 @@ function MyController(hand, triggerAction) {
linearTimeScale: DISTANCE_HOLDING_ACTION_TIMEFRAME, linearTimeScale: DISTANCE_HOLDING_ACTION_TIMEFRAME,
targetRotation: this.currentObjectRotation, targetRotation: this.currentObjectRotation,
angularTimeScale: DISTANCE_HOLDING_ACTION_TIMEFRAME, angularTimeScale: DISTANCE_HOLDING_ACTION_TIMEFRAME,
lifetime: ACTION_LIFETIME ttl: ACTION_TTL
}); });
this.actionTimeout = now + (ACTION_LIFETIME * MSEC_PER_SEC); this.actionTimeout = now + (ACTION_TTL * MSEC_PER_SEC);
}; };
this.nearGrabbing = function() { this.nearGrabbing = function() {
@ -579,12 +579,12 @@ function MyController(hand, triggerAction) {
timeScale: NEAR_GRABBING_ACTION_TIMEFRAME, timeScale: NEAR_GRABBING_ACTION_TIMEFRAME,
relativePosition: this.offsetPosition, relativePosition: this.offsetPosition,
relativeRotation: this.offsetRotation, relativeRotation: this.offsetRotation,
lifetime: ACTION_LIFETIME ttl: ACTION_TTL
}); });
if (this.actionID === NULL_ACTION_ID) { if (this.actionID === NULL_ACTION_ID) {
this.actionID = null; this.actionID = null;
} else { } else {
this.actionTimeout = now + (ACTION_LIFETIME * MSEC_PER_SEC); this.actionTimeout = now + (ACTION_TTL * MSEC_PER_SEC);
this.setState(STATE_CONTINUE_NEAR_GRABBING); this.setState(STATE_CONTINUE_NEAR_GRABBING);
if (this.hand === RIGHT_HAND) { if (this.hand === RIGHT_HAND) {
Entities.callEntityMethod(this.grabbedEntity, "setRightHand"); Entities.callEntityMethod(this.grabbedEntity, "setRightHand");
@ -624,16 +624,16 @@ function MyController(hand, triggerAction) {
this.currentObjectTime = now; this.currentObjectTime = now;
Entities.callEntityMethod(this.grabbedEntity, "continueNearGrab"); Entities.callEntityMethod(this.grabbedEntity, "continueNearGrab");
if (this.actionTimeout - now < ACTION_LIFETIME_REFRESH * MSEC_PER_SEC) { if (this.actionTimeout - now < ACTION_TTL_REFRESH * MSEC_PER_SEC) {
// if less than a 5 seconds left, refresh the actions lifetime // if less than a 5 seconds left, refresh the actions ttl
Entities.updateAction(this.grabbedEntity, this.actionID, { Entities.updateAction(this.grabbedEntity, this.actionID, {
hand: this.hand === RIGHT_HAND ? "right" : "left", hand: this.hand === RIGHT_HAND ? "right" : "left",
timeScale: NEAR_GRABBING_ACTION_TIMEFRAME, timeScale: NEAR_GRABBING_ACTION_TIMEFRAME,
relativePosition: this.offsetPosition, relativePosition: this.offsetPosition,
relativeRotation: this.offsetRotation, relativeRotation: this.offsetRotation,
lifetime: ACTION_LIFETIME ttl: ACTION_TTL
}); });
this.actionTimeout = now + (ACTION_LIFETIME * MSEC_PER_SEC); this.actionTimeout = now + (ACTION_TTL * MSEC_PER_SEC);
} }
}; };

View file

@ -47,7 +47,7 @@ var IDENTITY_QUAT = {
z: 0, z: 0,
w: 0 w: 0
}; };
var ACTION_LIFETIME = 10; // seconds var ACTION_TTL = 10; // seconds
function getTag() { function getTag() {
return "grab-" + MyAvatar.sessionUUID; return "grab-" + MyAvatar.sessionUUID;
@ -403,7 +403,7 @@ Grabber.prototype.moveEvent = function(event) {
var actionArgs = { var actionArgs = {
tag: getTag(), tag: getTag(),
lifetime: ACTION_LIFETIME ttl: ACTION_TTL
}; };
if (this.mode === "rotate") { if (this.mode === "rotate") {
@ -424,7 +424,7 @@ Grabber.prototype.moveEvent = function(event) {
targetRotation: this.lastRotation, targetRotation: this.lastRotation,
angularTimeScale: 0.1, angularTimeScale: 0.1,
tag: getTag(), tag: getTag(),
lifetime: ACTION_LIFETIME ttl: ACTION_TTL
}; };
} else { } else {
@ -459,7 +459,7 @@ Grabber.prototype.moveEvent = function(event) {
targetPosition: this.targetPosition, targetPosition: this.targetPosition,
linearTimeScale: 0.1, linearTimeScale: 0.1,
tag: getTag(), tag: getTag(),
lifetime: ACTION_LIFETIME ttl: ACTION_TTL
}; };

View file

@ -66,7 +66,8 @@ EntityActionPointer InterfaceActionFactory::factoryBA(EntityItemPointer ownerEnt
if (action) { if (action) {
action->deserialize(data); action->deserialize(data);
if (action->lifetimeIsOver()) { if (action->lifetimeIsOver()) {
qDebug() << "InterfaceActionFactory::factoryBA lifetimeIsOver during action creation"; qDebug() << "InterfaceActionFactory::factoryBA lifetimeIsOver during action creation --"
<< action->getExpires() << "<" << usecTimestampNow();
return nullptr; return nullptr;
} }
} }

View file

@ -243,7 +243,7 @@ QByteArray AvatarActionHold::serialize() const {
dataStream << _linearTimeScale; dataStream << _linearTimeScale;
dataStream << _hand; dataStream << _hand;
dataStream << _expires + getEntityServerClockSkew(); dataStream << localTimeToServerTime(_expires);
dataStream << _tag; dataStream << _tag;
dataStream << _kinematic; dataStream << _kinematic;
dataStream << _kinematicSetVelocity; dataStream << _kinematicSetVelocity;
@ -277,8 +277,10 @@ void AvatarActionHold::deserialize(QByteArray serializedArguments) {
_angularTimeScale = _linearTimeScale; _angularTimeScale = _linearTimeScale;
dataStream >> _hand; dataStream >> _hand;
dataStream >> _expires; quint64 serverExpires;
_expires -= getEntityServerClockSkew(); dataStream >> serverExpires;
_expires = serverTimeToLocalTime(serverExpires);
dataStream >> _tag; dataStream >> _tag;
dataStream >> _kinematic; dataStream >> _kinematic;
dataStream >> _kinematicSetVelocity; dataStream >> _kinematicSetVelocity;

View file

@ -47,6 +47,7 @@ public:
static QString actionTypeToString(EntityActionType actionType); static QString actionTypeToString(EntityActionType actionType);
virtual bool lifetimeIsOver() { return false; } virtual bool lifetimeIsOver() { return false; }
virtual quint64 getExpires() { return 0; }
bool locallyAddedButNotYetReceived = false; bool locallyAddedButNotYetReceived = false;

View file

@ -85,11 +85,11 @@ bool ObjectAction::updateArguments(QVariantMap arguments) {
quint64 previousExpires = _expires; quint64 previousExpires = _expires;
QString previousTag = _tag; QString previousTag = _tag;
bool lifetimeSet = true; bool ttlSet = true;
float lifetime = EntityActionInterface::extractFloatArgument("action", arguments, "lifetime", lifetimeSet, false); float ttl = EntityActionInterface::extractFloatArgument("action", arguments, "ttl", ttlSet, false);
if (lifetimeSet) { if (ttlSet) {
quint64 now = usecTimestampNow(); quint64 now = usecTimestampNow();
_expires = now + (quint64)(lifetime * USECS_PER_SECOND); _expires = now + (quint64)(ttl * USECS_PER_SECOND);
} else { } else {
_expires = 0; _expires = 0;
} }
@ -114,10 +114,10 @@ QVariantMap ObjectAction::getArguments() {
QVariantMap arguments; QVariantMap arguments;
withReadLock([&]{ withReadLock([&]{
if (_expires == 0) { if (_expires == 0) {
arguments["lifetime"] = 0.0f; arguments["ttl"] = 0.0f;
} else { } else {
quint64 now = usecTimestampNow(); quint64 now = usecTimestampNow();
arguments["lifetime"] = (float)(_expires - now) / (float)USECS_PER_SECOND; arguments["ttl"] = (float)(_expires - now) / (float)USECS_PER_SECOND;
} }
arguments["tag"] = _tag; arguments["tag"] = _tag;
}); });
@ -245,3 +245,17 @@ bool ObjectAction::lifetimeIsOver() {
} }
return false; return false;
} }
quint64 ObjectAction::localTimeToServerTime(quint64 timeValue) {
if (timeValue == 0) {
return 0;
}
return timeValue + getEntityServerClockSkew();
}
quint64 ObjectAction::serverTimeToLocalTime(quint64 timeValue) {
if (timeValue == 0) {
return 0;
}
return timeValue - getEntityServerClockSkew();
}

View file

@ -47,11 +47,10 @@ public:
virtual void deserialize(QByteArray serializedArguments) = 0; virtual void deserialize(QByteArray serializedArguments) = 0;
virtual bool lifetimeIsOver(); virtual bool lifetimeIsOver();
virtual quint64 getExpires() { return _expires; }
protected: protected:
int getEntityServerClockSkew() const;
virtual btRigidBody* getRigidBody(); virtual btRigidBody* getRigidBody();
virtual glm::vec3 getPosition(); virtual glm::vec3 getPosition();
virtual void setPosition(glm::vec3 position); virtual void setPosition(glm::vec3 position);
@ -68,6 +67,12 @@ protected:
quint64 _expires; // in seconds since epoch quint64 _expires; // in seconds since epoch
QString _tag; QString _tag;
quint64 localTimeToServerTime(quint64 timeValue);
quint64 serverTimeToLocalTime(quint64 timeValue);
private:
int getEntityServerClockSkew() const;
}; };
#endif // hifi_ObjectAction_h #endif // hifi_ObjectAction_h

View file

@ -160,7 +160,7 @@ QByteArray ObjectActionOffset::serialize() const {
dataStream << _linearDistance; dataStream << _linearDistance;
dataStream << _linearTimeScale; dataStream << _linearTimeScale;
dataStream << _positionalTargetSet; dataStream << _positionalTargetSet;
dataStream << _expires + getEntityServerClockSkew(); dataStream << localTimeToServerTime(_expires);
dataStream << _tag; dataStream << _tag;
}); });
@ -189,8 +189,11 @@ void ObjectActionOffset::deserialize(QByteArray serializedArguments) {
dataStream >> _linearDistance; dataStream >> _linearDistance;
dataStream >> _linearTimeScale; dataStream >> _linearTimeScale;
dataStream >> _positionalTargetSet; dataStream >> _positionalTargetSet;
dataStream >> _expires;
_expires -= getEntityServerClockSkew(); quint64 serverExpires;
dataStream >> serverExpires;
_expires = serverTimeToLocalTime(serverExpires);
dataStream >> _tag; dataStream >> _tag;
_active = true; _active = true;
}); });

View file

@ -198,7 +198,7 @@ QByteArray ObjectActionSpring::serialize() const {
dataStream << _rotationalTarget; dataStream << _rotationalTarget;
dataStream << _angularTimeScale; dataStream << _angularTimeScale;
dataStream << _rotationalTargetSet; dataStream << _rotationalTargetSet;
dataStream << _expires + getEntityServerClockSkew(); dataStream << localTimeToServerTime(_expires);
dataStream << _tag; dataStream << _tag;
}); });
@ -232,8 +232,10 @@ void ObjectActionSpring::deserialize(QByteArray serializedArguments) {
dataStream >> _angularTimeScale; dataStream >> _angularTimeScale;
dataStream >> _rotationalTargetSet; dataStream >> _rotationalTargetSet;
dataStream >> _expires; quint64 serverExpires;
_expires -= getEntityServerClockSkew(); dataStream >> serverExpires;
_expires = serverTimeToLocalTime(serverExpires);
dataStream >> _tag; dataStream >> _tag;
_active = true; _active = true;