mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-09 09:30:09 +02:00
store action lifetime as an expires integer
This commit is contained in:
parent
06f7f92951
commit
b34ea6ded4
3 changed files with 44 additions and 15 deletions
|
@ -15,6 +15,33 @@ var ZERO_VEC3 = {x: 0, y: 0, z: 0};
|
||||||
var IDENTITY_QUAT = {x: 0, y: 0, z: 0, w: 0};
|
var IDENTITY_QUAT = {x: 0, y: 0, z: 0, w: 0};
|
||||||
|
|
||||||
|
|
||||||
|
if (typeof String.prototype.startsWith != 'function') {
|
||||||
|
// see below for better implementation!
|
||||||
|
String.prototype.startsWith = function (str){
|
||||||
|
return this.indexOf(str) === 0;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function getTag() {
|
||||||
|
return "grab-" + MyAvatar.sessionUUID;
|
||||||
|
}
|
||||||
|
|
||||||
|
function entityIsGrabbedByOther(entityID) {
|
||||||
|
var actionIDs = Entities.getActionIDs(entityID);
|
||||||
|
for (var actionIndex = 0; actionIndex < actionIDs.length; actionIndex++) {
|
||||||
|
var actionID = actionIDs[actionIndex];
|
||||||
|
var actionArguments = Entities.getActionArguments(entityID, actionID);
|
||||||
|
var tag = actionArguments["tag"];
|
||||||
|
if (tag == getTag()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (tag.startsWith("grab-")) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// helper function
|
// helper function
|
||||||
function mouseIntersectionWithPlane(pointOnPlane, planeNormal, event, maxDistance) {
|
function mouseIntersectionWithPlane(pointOnPlane, planeNormal, event, maxDistance) {
|
||||||
var cameraPosition = Camera.getPosition();
|
var cameraPosition = Camera.getPosition();
|
||||||
|
@ -288,7 +315,7 @@ Grabber.prototype.moveEvent = function(event) {
|
||||||
}
|
}
|
||||||
this.currentPosition = entityProperties.position;
|
this.currentPosition = entityProperties.position;
|
||||||
|
|
||||||
var actionArgs = {tag: "grab", lifetime: 5};
|
var actionArgs = {tag: getTag(), lifetime: 5};
|
||||||
|
|
||||||
if (this.mode === "rotate") {
|
if (this.mode === "rotate") {
|
||||||
var drag = mouse.getDrag();
|
var drag = mouse.getDrag();
|
||||||
|
@ -303,7 +330,7 @@ Grabber.prototype.moveEvent = function(event) {
|
||||||
// var qZero = entityProperties.rotation;
|
// var qZero = entityProperties.rotation;
|
||||||
//var qZero = this.lastRotation;
|
//var qZero = this.lastRotation;
|
||||||
this.lastRotation = Quat.multiply(deltaQ, this.lastRotation);
|
this.lastRotation = Quat.multiply(deltaQ, this.lastRotation);
|
||||||
actionArgs = {targetRotation: this.lastRotation, angularTimeScale: 0.1, tag: "grab", lifetime: 5};
|
actionArgs = {targetRotation: this.lastRotation, angularTimeScale: 0.1, tag: getTag(), lifetime: 5};
|
||||||
} else {
|
} else {
|
||||||
var newPointOnPlane;
|
var newPointOnPlane;
|
||||||
if (this.mode === "verticalCylinder") {
|
if (this.mode === "verticalCylinder") {
|
||||||
|
@ -327,13 +354,15 @@ Grabber.prototype.moveEvent = function(event) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.targetPosition = Vec3.subtract(newPointOnPlane, this.offset);
|
this.targetPosition = Vec3.subtract(newPointOnPlane, this.offset);
|
||||||
actionArgs = {targetPosition: this.targetPosition, linearTimeScale: 0.1, tag: "grab", lifetime: 5};
|
actionArgs = {targetPosition: this.targetPosition, linearTimeScale: 0.1, tag: getTag(), lifetime: 5};
|
||||||
|
|
||||||
beacon.updatePosition(this.targetPosition);
|
beacon.updatePosition(this.targetPosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.actionID) {
|
if (!this.actionID) {
|
||||||
this.actionID = Entities.addAction("spring", this.entityID, actionArgs);
|
if (!entityIsGrabbedByOther(this.entityID)) {
|
||||||
|
this.actionID = Entities.addAction("spring", this.entityID, actionArgs);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
Entities.updateAction(this.entityID, this.actionID, actionArgs);
|
Entities.updateAction(this.entityID, this.actionID, actionArgs);
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,8 +31,8 @@ void ObjectAction::updateAction(btCollisionWorld* collisionWorld, btScalar delta
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_expires > 0.0f) {
|
if (_expires > 0) {
|
||||||
float now = (float)usecTimestampNow() / USECS_PER_SECOND;
|
quint64 now = usecTimestampNow();
|
||||||
if (now > _expires) {
|
if (now > _expires) {
|
||||||
EntityItemPointer ownerEntity = _ownerEntity.lock();
|
EntityItemPointer ownerEntity = _ownerEntity.lock();
|
||||||
_active = false;
|
_active = false;
|
||||||
|
@ -53,10 +53,10 @@ bool ObjectAction::updateArguments(QVariantMap arguments) {
|
||||||
bool lifetimeSet = true;
|
bool lifetimeSet = true;
|
||||||
float lifetime = EntityActionInterface::extractFloatArgument("action", arguments, "lifetime", lifetimeSet, false);
|
float lifetime = EntityActionInterface::extractFloatArgument("action", arguments, "lifetime", lifetimeSet, false);
|
||||||
if (lifetimeSet) {
|
if (lifetimeSet) {
|
||||||
float now = (float)usecTimestampNow() / USECS_PER_SECOND;
|
quint64 now = usecTimestampNow();
|
||||||
_expires = now + lifetime;
|
_expires = now + (quint64)(lifetime * USECS_PER_SECOND);
|
||||||
} else {
|
} else {
|
||||||
_expires = 0.0f;
|
_expires = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool tagSet = true;
|
bool tagSet = true;
|
||||||
|
@ -72,11 +72,11 @@ bool ObjectAction::updateArguments(QVariantMap arguments) {
|
||||||
|
|
||||||
QVariantMap ObjectAction::getArguments() {
|
QVariantMap ObjectAction::getArguments() {
|
||||||
QVariantMap arguments;
|
QVariantMap arguments;
|
||||||
float now = (float)usecTimestampNow() / USECS_PER_SECOND;
|
if (_expires == 0) {
|
||||||
if (_expires == 0.0f) {
|
|
||||||
arguments["lifetime"] = 0.0f;
|
arguments["lifetime"] = 0.0f;
|
||||||
} else {
|
} else {
|
||||||
arguments["lifetime"] = _expires - now;
|
quint64 now = usecTimestampNow();
|
||||||
|
arguments["lifetime"] = (float)(_expires - now) / (float)USECS_PER_SECOND;
|
||||||
}
|
}
|
||||||
arguments["tag"] = _tag;
|
arguments["tag"] = _tag;
|
||||||
return arguments;
|
return arguments;
|
||||||
|
@ -183,11 +183,11 @@ void ObjectAction::activateBody() {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ObjectAction::lifetimeIsOver() {
|
bool ObjectAction::lifetimeIsOver() {
|
||||||
if (_expires == 0.0f) {
|
if (_expires == 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
float now = (float)usecTimestampNow() / USECS_PER_SECOND;
|
quint64 now = usecTimestampNow();
|
||||||
if (now >= _expires) {
|
if (now >= _expires) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,7 +64,7 @@ protected:
|
||||||
bool _active;
|
bool _active;
|
||||||
EntityItemWeakPointer _ownerEntity;
|
EntityItemWeakPointer _ownerEntity;
|
||||||
|
|
||||||
float _expires; // in seconds since epoch
|
quint64 _expires; // in seconds since epoch
|
||||||
QString _tag;
|
QString _tag;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue