mirror of
https://github.com/lubosz/overte.git
synced 2025-04-16 09:29:16 +02:00
fix bug that was deleting actions with 0 ttl. in js interface, action parameter 'lifetime' is now called 'ttl'
This commit is contained in:
parent
5cf936f132
commit
8d0aaed41a
9 changed files with 62 additions and 34 deletions
|
@ -74,8 +74,8 @@ var MSEC_PER_SEC = 1000.0;
|
|||
|
||||
// these control how long an abandoned pointer line will hang around
|
||||
var LIFETIME = 10;
|
||||
var ACTION_LIFETIME = 15; // seconds
|
||||
var ACTION_LIFETIME_REFRESH = 5;
|
||||
var ACTION_TTL = 15; // seconds
|
||||
var ACTION_TTL_REFRESH = 5;
|
||||
var PICKS_PER_SECOND_PER_HAND = 5;
|
||||
var MSECS_PER_SEC = 1000.0;
|
||||
|
||||
|
@ -422,12 +422,12 @@ function MyController(hand, triggerAction) {
|
|||
targetRotation: this.currentObjectRotation,
|
||||
angularTimeScale: DISTANCE_HOLDING_ACTION_TIMEFRAME,
|
||||
tag: getTag(),
|
||||
lifetime: ACTION_LIFETIME
|
||||
ttl: ACTION_TTL
|
||||
});
|
||||
if (this.actionID === NULL_ACTION_ID) {
|
||||
this.actionID = null;
|
||||
}
|
||||
this.actionTimeout = now + (ACTION_LIFETIME * MSEC_PER_SEC);
|
||||
this.actionTimeout = now + (ACTION_TTL * MSEC_PER_SEC);
|
||||
|
||||
if (this.actionID !== null) {
|
||||
this.setState(STATE_CONTINUE_DISTANCE_HOLDING);
|
||||
|
@ -524,9 +524,9 @@ function MyController(hand, triggerAction) {
|
|||
linearTimeScale: DISTANCE_HOLDING_ACTION_TIMEFRAME,
|
||||
targetRotation: this.currentObjectRotation,
|
||||
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() {
|
||||
|
@ -579,12 +579,12 @@ function MyController(hand, triggerAction) {
|
|||
timeScale: NEAR_GRABBING_ACTION_TIMEFRAME,
|
||||
relativePosition: this.offsetPosition,
|
||||
relativeRotation: this.offsetRotation,
|
||||
lifetime: ACTION_LIFETIME
|
||||
ttl: ACTION_TTL
|
||||
});
|
||||
if (this.actionID === NULL_ACTION_ID) {
|
||||
this.actionID = null;
|
||||
} else {
|
||||
this.actionTimeout = now + (ACTION_LIFETIME * MSEC_PER_SEC);
|
||||
this.actionTimeout = now + (ACTION_TTL * MSEC_PER_SEC);
|
||||
this.setState(STATE_CONTINUE_NEAR_GRABBING);
|
||||
if (this.hand === RIGHT_HAND) {
|
||||
Entities.callEntityMethod(this.grabbedEntity, "setRightHand");
|
||||
|
@ -624,16 +624,16 @@ function MyController(hand, triggerAction) {
|
|||
this.currentObjectTime = now;
|
||||
Entities.callEntityMethod(this.grabbedEntity, "continueNearGrab");
|
||||
|
||||
if (this.actionTimeout - now < ACTION_LIFETIME_REFRESH * MSEC_PER_SEC) {
|
||||
// if less than a 5 seconds left, refresh the actions lifetime
|
||||
if (this.actionTimeout - now < ACTION_TTL_REFRESH * MSEC_PER_SEC) {
|
||||
// if less than a 5 seconds left, refresh the actions ttl
|
||||
Entities.updateAction(this.grabbedEntity, this.actionID, {
|
||||
hand: this.hand === RIGHT_HAND ? "right" : "left",
|
||||
timeScale: NEAR_GRABBING_ACTION_TIMEFRAME,
|
||||
relativePosition: this.offsetPosition,
|
||||
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);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ var IDENTITY_QUAT = {
|
|||
z: 0,
|
||||
w: 0
|
||||
};
|
||||
var ACTION_LIFETIME = 10; // seconds
|
||||
var ACTION_TTL = 10; // seconds
|
||||
|
||||
function getTag() {
|
||||
return "grab-" + MyAvatar.sessionUUID;
|
||||
|
@ -403,7 +403,7 @@ Grabber.prototype.moveEvent = function(event) {
|
|||
|
||||
var actionArgs = {
|
||||
tag: getTag(),
|
||||
lifetime: ACTION_LIFETIME
|
||||
ttl: ACTION_TTL
|
||||
};
|
||||
|
||||
if (this.mode === "rotate") {
|
||||
|
@ -424,7 +424,7 @@ Grabber.prototype.moveEvent = function(event) {
|
|||
targetRotation: this.lastRotation,
|
||||
angularTimeScale: 0.1,
|
||||
tag: getTag(),
|
||||
lifetime: ACTION_LIFETIME
|
||||
ttl: ACTION_TTL
|
||||
};
|
||||
|
||||
} else {
|
||||
|
@ -459,7 +459,7 @@ Grabber.prototype.moveEvent = function(event) {
|
|||
targetPosition: this.targetPosition,
|
||||
linearTimeScale: 0.1,
|
||||
tag: getTag(),
|
||||
lifetime: ACTION_LIFETIME
|
||||
ttl: ACTION_TTL
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -66,7 +66,8 @@ EntityActionPointer InterfaceActionFactory::factoryBA(EntityItemPointer ownerEnt
|
|||
if (action) {
|
||||
action->deserialize(data);
|
||||
if (action->lifetimeIsOver()) {
|
||||
qDebug() << "InterfaceActionFactory::factoryBA lifetimeIsOver during action creation";
|
||||
qDebug() << "InterfaceActionFactory::factoryBA lifetimeIsOver during action creation --"
|
||||
<< action->getExpires() << "<" << usecTimestampNow();
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -243,7 +243,7 @@ QByteArray AvatarActionHold::serialize() const {
|
|||
dataStream << _linearTimeScale;
|
||||
dataStream << _hand;
|
||||
|
||||
dataStream << _expires + getEntityServerClockSkew();
|
||||
dataStream << localTimeToServerTime(_expires);
|
||||
dataStream << _tag;
|
||||
dataStream << _kinematic;
|
||||
dataStream << _kinematicSetVelocity;
|
||||
|
@ -277,8 +277,10 @@ void AvatarActionHold::deserialize(QByteArray serializedArguments) {
|
|||
_angularTimeScale = _linearTimeScale;
|
||||
dataStream >> _hand;
|
||||
|
||||
dataStream >> _expires;
|
||||
_expires -= getEntityServerClockSkew();
|
||||
quint64 serverExpires;
|
||||
dataStream >> serverExpires;
|
||||
_expires = serverTimeToLocalTime(serverExpires);
|
||||
|
||||
dataStream >> _tag;
|
||||
dataStream >> _kinematic;
|
||||
dataStream >> _kinematicSetVelocity;
|
||||
|
|
|
@ -47,6 +47,7 @@ public:
|
|||
static QString actionTypeToString(EntityActionType actionType);
|
||||
|
||||
virtual bool lifetimeIsOver() { return false; }
|
||||
virtual quint64 getExpires() { return 0; }
|
||||
|
||||
bool locallyAddedButNotYetReceived = false;
|
||||
|
||||
|
|
|
@ -85,11 +85,11 @@ bool ObjectAction::updateArguments(QVariantMap arguments) {
|
|||
quint64 previousExpires = _expires;
|
||||
QString previousTag = _tag;
|
||||
|
||||
bool lifetimeSet = true;
|
||||
float lifetime = EntityActionInterface::extractFloatArgument("action", arguments, "lifetime", lifetimeSet, false);
|
||||
if (lifetimeSet) {
|
||||
bool ttlSet = true;
|
||||
float ttl = EntityActionInterface::extractFloatArgument("action", arguments, "ttl", ttlSet, false);
|
||||
if (ttlSet) {
|
||||
quint64 now = usecTimestampNow();
|
||||
_expires = now + (quint64)(lifetime * USECS_PER_SECOND);
|
||||
_expires = now + (quint64)(ttl * USECS_PER_SECOND);
|
||||
} else {
|
||||
_expires = 0;
|
||||
}
|
||||
|
@ -114,10 +114,10 @@ QVariantMap ObjectAction::getArguments() {
|
|||
QVariantMap arguments;
|
||||
withReadLock([&]{
|
||||
if (_expires == 0) {
|
||||
arguments["lifetime"] = 0.0f;
|
||||
arguments["ttl"] = 0.0f;
|
||||
} else {
|
||||
quint64 now = usecTimestampNow();
|
||||
arguments["lifetime"] = (float)(_expires - now) / (float)USECS_PER_SECOND;
|
||||
arguments["ttl"] = (float)(_expires - now) / (float)USECS_PER_SECOND;
|
||||
}
|
||||
arguments["tag"] = _tag;
|
||||
});
|
||||
|
@ -245,3 +245,17 @@ bool ObjectAction::lifetimeIsOver() {
|
|||
}
|
||||
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();
|
||||
}
|
||||
|
|
|
@ -47,11 +47,10 @@ public:
|
|||
virtual void deserialize(QByteArray serializedArguments) = 0;
|
||||
|
||||
virtual bool lifetimeIsOver();
|
||||
virtual quint64 getExpires() { return _expires; }
|
||||
|
||||
protected:
|
||||
|
||||
int getEntityServerClockSkew() const;
|
||||
|
||||
virtual btRigidBody* getRigidBody();
|
||||
virtual glm::vec3 getPosition();
|
||||
virtual void setPosition(glm::vec3 position);
|
||||
|
@ -68,6 +67,12 @@ protected:
|
|||
|
||||
quint64 _expires; // in seconds since epoch
|
||||
QString _tag;
|
||||
|
||||
quint64 localTimeToServerTime(quint64 timeValue);
|
||||
quint64 serverTimeToLocalTime(quint64 timeValue);
|
||||
|
||||
private:
|
||||
int getEntityServerClockSkew() const;
|
||||
};
|
||||
|
||||
#endif // hifi_ObjectAction_h
|
||||
|
|
|
@ -160,7 +160,7 @@ QByteArray ObjectActionOffset::serialize() const {
|
|||
dataStream << _linearDistance;
|
||||
dataStream << _linearTimeScale;
|
||||
dataStream << _positionalTargetSet;
|
||||
dataStream << _expires + getEntityServerClockSkew();
|
||||
dataStream << localTimeToServerTime(_expires);
|
||||
dataStream << _tag;
|
||||
});
|
||||
|
||||
|
@ -189,8 +189,11 @@ void ObjectActionOffset::deserialize(QByteArray serializedArguments) {
|
|||
dataStream >> _linearDistance;
|
||||
dataStream >> _linearTimeScale;
|
||||
dataStream >> _positionalTargetSet;
|
||||
dataStream >> _expires;
|
||||
_expires -= getEntityServerClockSkew();
|
||||
|
||||
quint64 serverExpires;
|
||||
dataStream >> serverExpires;
|
||||
_expires = serverTimeToLocalTime(serverExpires);
|
||||
|
||||
dataStream >> _tag;
|
||||
_active = true;
|
||||
});
|
||||
|
|
|
@ -198,7 +198,7 @@ QByteArray ObjectActionSpring::serialize() const {
|
|||
dataStream << _rotationalTarget;
|
||||
dataStream << _angularTimeScale;
|
||||
dataStream << _rotationalTargetSet;
|
||||
dataStream << _expires + getEntityServerClockSkew();
|
||||
dataStream << localTimeToServerTime(_expires);
|
||||
dataStream << _tag;
|
||||
});
|
||||
|
||||
|
@ -232,8 +232,10 @@ void ObjectActionSpring::deserialize(QByteArray serializedArguments) {
|
|||
dataStream >> _angularTimeScale;
|
||||
dataStream >> _rotationalTargetSet;
|
||||
|
||||
dataStream >> _expires;
|
||||
_expires -= getEntityServerClockSkew();
|
||||
quint64 serverExpires;
|
||||
dataStream >> serverExpires;
|
||||
_expires = serverTimeToLocalTime(serverExpires);
|
||||
|
||||
dataStream >> _tag;
|
||||
|
||||
_active = true;
|
||||
|
|
Loading…
Reference in a new issue