Merge branch 'master' of https://github.com/highfidelity/hifi into rationalize-rig-settings

This commit is contained in:
Howard Stearns 2015-09-11 12:59:19 -07:00
commit 841e23e29d
8 changed files with 113 additions and 160 deletions

View file

@ -144,7 +144,7 @@ controller.prototype.checkPointer = function() {
Script.setTimeout(function() { Script.setTimeout(function() {
var props = Entities.getEntityProperties(self.pointer); var props = Entities.getEntityProperties(self.pointer);
Entities.editEntity(self.pointer, { Entities.editEntity(self.pointer, {
lifetime: props.age + EXTRA_TIME lifetime: props.age + EXTRA_TIME + LIFETIME
}); });
self.checkPointer(); self.checkPointer();
}, POINTER_CHECK_TIME); }, POINTER_CHECK_TIME);

View file

@ -1,5 +1,7 @@
(function() { (function() {
Script.include("../libraries/utils.js"); // Script.include("../libraries/utils.js");
//Need absolute path for now, for testing before PR merge and s3 cloning. Will change post-merge
Script.include("https://hifi-public.s3.amazonaws.com/scripts/libraries/utils.js");
GRAB_FRAME_USER_DATA_KEY = "grabFrame"; GRAB_FRAME_USER_DATA_KEY = "grabFrame";
this.userData = {}; this.userData = {};
@ -18,13 +20,14 @@
var self = this; var self = this;
var stopSetting = JSON.stringify({ var timeSinceLastMoved = 0;
running: false var RESET_TIME_THRESHOLD = 5;
}); var DISTANCE_FROM_HOME_THRESHOLD = 0.5;
var startSetting = JSON.stringify({ var HOME_POSITION = {
running: true x: 549.12,
}); y: 495.555,
z: 503.77
};
this.getUserData = function() { this.getUserData = function() {
@ -40,14 +43,26 @@
} }
this.update = function(deltaTime) { this.update = function(deltaTime) {
self.properties = Entities.getEntityProperties(self.entityId);
self.getUserData(); self.getUserData();
self.properties = Entities.getEntityProperties(self.entityId);
if (Vec3.length(self.properties.velocity) < 0.1 && Vec3.distance(HOME_POSITION, self.properties.position) > DISTANCE_FROM_HOME_THRESHOLD) {
timeSinceLastMoved += deltaTime;
if (timeSinceLastMoved > RESET_TIME_THRESHOLD) {
self.reset();
timeSinceLastMoved = 0;
}
} else {
timeSinceLastMoved = 0;
}
if (self.userData.grabKey && self.userData.grabKey.activated === true) { if (self.userData.grabKey && self.userData.grabKey.activated === true) {
if (self.activated !== true) { if (self.activated !== true) {
//We were just grabbed, so create a particle system
self.grab();
Entities.editEntity(self.paintStream, { Entities.editEntity(self.paintStream, {
animationSettings: startSetting animationSettings: startSetting
}); });
self.activated = true;
} }
//Move emitter to where entity is always when its activated //Move emitter to where entity is always when its activated
self.sprayStream(); self.sprayStream();
@ -59,6 +74,54 @@
} }
} }
this.grab = function() {
self.activated = true;
var animationSettings = JSON.stringify({
fps: 30,
loop: true,
firstFrame: 1,
lastFrame: 10000,
running: true
});
this.paintStream = Entities.addEntity({
type: "ParticleEffect",
animationSettings: animationSettings,
position: this.properties.position,
textures: "https://raw.githubusercontent.com/ericrius1/SantasLair/santa/assets/smokeparticle.png",
emitVelocity: ZERO_VEC,
emitAcceleration: ZERO_VEC,
velocitySpread: {
x: .02,
y: .02,
z: 0.02
},
emitRate: 100,
particleRadius: 0.01,
color: {
red: 170,
green: 20,
blue: 150
},
lifetime: 500, //probably wont be holding longer than this straight
});
}
this.letGo = function() {
self.activated = false;
Entities.deleteEntity(this.paintStream);
}
this.reset = function() {
Entities.editEntity(self.entityId, {
position: HOME_POSITION,
rotation: Quat.fromPitchYawRollDegrees(0, 0, 0),
angularVelocity: ZERO_VEC,
velocity: ZERO_VEC
});
}
this.sprayStream = function() { this.sprayStream = function() {
var forwardVec = Quat.getFront(self.properties.rotation); var forwardVec = Quat.getFront(self.properties.rotation);
forwardVec = Vec3.multiplyQbyV(Quat.fromPitchYawRollDegrees(0, 90, 0), forwardVec); forwardVec = Vec3.multiplyQbyV(Quat.fromPitchYawRollDegrees(0, 90, 0), forwardVec);
@ -134,9 +197,9 @@
blue: randInt(190, 250) blue: randInt(190, 250)
}, },
dimensions: { dimensions: {
x: 5, x: 50,
y: 5, y: 50,
z: 5 z: 50
}, },
lifetime: 100 lifetime: 100
}); });
@ -167,41 +230,8 @@
} }
setEntityCustomData(GRAB_FRAME_USER_DATA_KEY, this.entityId, data); setEntityCustomData(GRAB_FRAME_USER_DATA_KEY, this.entityId, data);
} }
this.initialize();
} }
this.initialize = function() {
var animationSettings = JSON.stringify({
fps: 30,
loop: true,
firstFrame: 1,
lastFrame: 10000,
running: false
});
this.paintStream = Entities.addEntity({
type: "ParticleEffect",
animationSettings: animationSettings,
position: this.properties.position,
textures: "https://raw.githubusercontent.com/ericrius1/SantasLair/santa/assets/smokeparticle.png",
emitVelocity: ZERO_VEC,
emitAcceleration: ZERO_VEC,
velocitySpread: {
x: .02,
y: .02,
z: 0.02
},
emitRate: 100,
particleRadius: 0.01,
color: {
red: 170,
green: 20,
blue: 150
},
lifespan: 5,
});
}
this.unload = function() { this.unload = function() {
Script.update.disconnect(this.update); Script.update.disconnect(this.update);

View file

@ -8,67 +8,31 @@
// Distributed under the Apache License, Version 2.0. // Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
var scriptURL = "entityScripts/sprayPaintCan.js"; //Just temporarily using my own bucket here so others can test the entity. Once PR is tested and merged, then the entity script will appear in its proper place in S3, and I wil switch it
var scriptURL = "https://hifi-public.s3.amazonaws.com/eric/scripts/sprayPaintCan.js?=v1";
var modelURL = "https://hifi-public.s3.amazonaws.com/eric/models/paintcan.fbx";
var center = Vec3.sum(MyAvatar.position, Vec3.multiply(1, Quat.getFront(Camera.getOrientation()))); var center = Vec3.sum(MyAvatar.position, Vec3.multiply(1, Quat.getFront(Camera.getOrientation())));
var paintGun = Entities.addEntity({ var sprayCan = Entities.addEntity({
type: "Model", type: "Model",
modelURL: "https://hifi-public.s3.amazonaws.com/eric/models/sprayGun.fbx?=v4", name: "spraycan",
position: center, modelURL: modelURL,
position: {x: 549.12, y:495.55, z:503.77},
rotation: {x: 0, y: 0, z: 0, w: 1},
dimensions: { dimensions: {
x: 0.03, x: 0.07,
y: 0.15, y: 0.17,
z: 0.34 z: 0.07
}, },
collisionsWillMove: true, collisionsWillMove: true,
shapeType: 'box', shapeType: 'box',
script: scriptURL script: scriptURL,
}); gravity: {x: 0, y: -0.5, z: 0},
velocity: {x: 0, y: -1, z: 0}
var whiteboard = Entities.addEntity({
type: "Box",
position: center,
dimensions: {
x: 2,
y: 1.5,
z: .01
},
rotation: orientationOf(Vec3.subtract(MyAvatar.position, center)),
color: {
red: 250,
green: 250,
blue: 250
},
// visible: false
}); });
function cleanup() { function cleanup() {
Entities.deleteEntity(paintGun); Entities.deleteEntity(sprayCan);
Entities.deleteEntity(whiteboard);
} }
Script.scriptEnding.connect(cleanup); Script.scriptEnding.connect(cleanup);
function orientationOf(vector) {
var Y_AXIS = {
x: 0,
y: 1,
z: 0
};
var X_AXIS = {
x: 1,
y: 0,
z: 0
};
var theta = 0.0;
var RAD_TO_DEG = 180.0 / Math.PI;
var direction, yaw, pitch;
direction = Vec3.normalize(vector);
yaw = Quat.angleAxis(Math.atan2(direction.x, direction.z) * RAD_TO_DEG, Y_AXIS);
pitch = Quat.angleAxis(Math.asin(-direction.y) * RAD_TO_DEG, X_AXIS);
return Quat.multiply(yaw, pitch);
}

View file

@ -242,7 +242,6 @@ QScriptValue EntityTreeRenderer::loadEntityScript(EntityItemPointer entity, bool
QString scriptContents = loadScriptContents(entityScript, isURL, isPending, url, reload); QString scriptContents = loadScriptContents(entityScript, isURL, isPending, url, reload);
if (isPending && isPreload && isURL) { if (isPending && isPreload && isURL) {
//qDebug() << "attempted to load script, isPending, _waitingOnPreload.insert() url:" << url << "entityID:" << entityID;
_waitingOnPreload.insert(url, entityID); _waitingOnPreload.insert(url, entityID);
} }
@ -325,8 +324,7 @@ void EntityTreeRenderer::update() {
QScriptValueList currentClickingEntityArgs = createMouseEventArgs(_currentClickingOnEntityID, _lastMouseEvent); QScriptValueList currentClickingEntityArgs = createMouseEventArgs(_currentClickingOnEntityID, _lastMouseEvent);
QScriptValue currentClickingEntity = loadEntityScript(_currentClickingOnEntityID); QScriptValue currentClickingEntity = loadEntityScript(_currentClickingOnEntityID);
if (currentClickingEntity.property("holdingClickOnEntity").isValid()) { if (currentClickingEntity.property("holdingClickOnEntity").isValid()) {
//qDebug() << "About to call holdingClickOnEntity() current thread:" << QThread::currentThread() << "entities thread:" << _entitiesScriptEngine->thread(); currentClickingEntity.property("holdingClickOnEntity").call(currentClickingEntity, currentClickingEntityArgs);
_entitiesScriptEngine->callScriptMethod("holdingClickOnEntity", currentClickingEntity, currentClickingEntityArgs);
} }
} }
@ -365,9 +363,7 @@ void EntityTreeRenderer::checkEnterLeaveEntities() {
QScriptValueList entityArgs = createEntityArgs(entityID); QScriptValueList entityArgs = createEntityArgs(entityID);
QScriptValue entityScript = loadEntityScript(entityID); QScriptValue entityScript = loadEntityScript(entityID);
if (entityScript.property("leaveEntity").isValid()) { if (entityScript.property("leaveEntity").isValid()) {
entityScript.property("leaveEntity").call(entityScript, entityArgs);
//qDebug() << "About to call leaveEntity() current thread:" << QThread::currentThread() << "entities thread:" << _entitiesScriptEngine->thread();
_entitiesScriptEngine->callScriptMethod("leaveEntity", entityScript, entityArgs);
} }
} }
@ -380,8 +376,7 @@ void EntityTreeRenderer::checkEnterLeaveEntities() {
QScriptValueList entityArgs = createEntityArgs(entityID); QScriptValueList entityArgs = createEntityArgs(entityID);
QScriptValue entityScript = loadEntityScript(entityID); QScriptValue entityScript = loadEntityScript(entityID);
if (entityScript.property("enterEntity").isValid()) { if (entityScript.property("enterEntity").isValid()) {
//qDebug() << "About to call enterEntity() current thread:" << QThread::currentThread() << "entities thread:" << _entitiesScriptEngine->thread(); entityScript.property("enterEntity").call(entityScript, entityArgs);
_entitiesScriptEngine->callScriptMethod("enterEntity", entityScript, entityArgs);
} }
} }
} }
@ -400,8 +395,7 @@ void EntityTreeRenderer::leaveAllEntities() {
QScriptValueList entityArgs = createEntityArgs(entityID); QScriptValueList entityArgs = createEntityArgs(entityID);
QScriptValue entityScript = loadEntityScript(entityID); QScriptValue entityScript = loadEntityScript(entityID);
if (entityScript.property("leaveEntity").isValid()) { if (entityScript.property("leaveEntity").isValid()) {
//qDebug() << "About to call leaveEntity() current thread:" << QThread::currentThread() << "entities thread:" << _entitiesScriptEngine->thread(); entityScript.property("leaveEntity").call(entityScript, entityArgs);
_entitiesScriptEngine->callScriptMethod("leaveEntity", entityScript, entityArgs);
} }
} }
_currentEntitiesInside.clear(); _currentEntitiesInside.clear();
@ -857,7 +851,7 @@ void EntityTreeRenderer::mousePressEvent(QMouseEvent* event, unsigned int device
bool precisionPicking = !_dontDoPrecisionPicking; bool precisionPicking = !_dontDoPrecisionPicking;
RayToEntityIntersectionResult rayPickResult = findRayIntersectionWorker(ray, Octree::Lock, precisionPicking); RayToEntityIntersectionResult rayPickResult = findRayIntersectionWorker(ray, Octree::Lock, precisionPicking);
if (rayPickResult.intersects) { if (rayPickResult.intersects) {
qCDebug(entitiesrenderer) << "mousePressEvent over entity:" << rayPickResult.entityID; //qCDebug(entitiesrenderer) << "mousePressEvent over entity:" << rayPickResult.entityID;
QString urlString = rayPickResult.properties.getHref(); QString urlString = rayPickResult.properties.getHref();
QUrl url = QUrl(urlString, QUrl::StrictMode); QUrl url = QUrl(urlString, QUrl::StrictMode);
@ -871,15 +865,13 @@ void EntityTreeRenderer::mousePressEvent(QMouseEvent* event, unsigned int device
QScriptValueList entityScriptArgs = createMouseEventArgs(rayPickResult.entityID, event, deviceID); QScriptValueList entityScriptArgs = createMouseEventArgs(rayPickResult.entityID, event, deviceID);
QScriptValue entityScript = loadEntityScript(rayPickResult.entity); QScriptValue entityScript = loadEntityScript(rayPickResult.entity);
if (entityScript.property("mousePressOnEntity").isValid()) { if (entityScript.property("mousePressOnEntity").isValid()) {
//qDebug() << "About to call mousePressOnEntity() current thread:" << QThread::currentThread() << "entities thread:" << _entitiesScriptEngine->thread(); entityScript.property("mousePressOnEntity").call(entityScript, entityScriptArgs);
_entitiesScriptEngine->callScriptMethod("mousePressOnEntity", entityScript, entityScriptArgs);
} }
_currentClickingOnEntityID = rayPickResult.entityID; _currentClickingOnEntityID = rayPickResult.entityID;
emit clickDownOnEntity(_currentClickingOnEntityID, MouseEvent(*event, deviceID)); emit clickDownOnEntity(_currentClickingOnEntityID, MouseEvent(*event, deviceID));
if (entityScript.property("clickDownOnEntity").isValid()) { if (entityScript.property("clickDownOnEntity").isValid()) {
//qDebug() << "About to call clickDownOnEntity() current thread:" << QThread::currentThread() << "entities thread:" << _entitiesScriptEngine->thread(); entityScript.property("clickDownOnEntity").call(entityScript, entityScriptArgs);
_entitiesScriptEngine->callScriptMethod("clickDownOnEntity", entityScript, entityScriptArgs);
} }
} else { } else {
emit mousePressOffEntity(rayPickResult, event, deviceID); emit mousePressOffEntity(rayPickResult, event, deviceID);
@ -905,7 +897,7 @@ void EntityTreeRenderer::mouseReleaseEvent(QMouseEvent* event, unsigned int devi
QScriptValueList entityScriptArgs = createMouseEventArgs(rayPickResult.entityID, event, deviceID); QScriptValueList entityScriptArgs = createMouseEventArgs(rayPickResult.entityID, event, deviceID);
QScriptValue entityScript = loadEntityScript(rayPickResult.entity); QScriptValue entityScript = loadEntityScript(rayPickResult.entity);
if (entityScript.property("mouseReleaseOnEntity").isValid()) { if (entityScript.property("mouseReleaseOnEntity").isValid()) {
_entitiesScriptEngine->callScriptMethod("mouseReleaseOnEntity", entityScript, entityScriptArgs); entityScript.property("mouseReleaseOnEntity").call(entityScript, entityScriptArgs);
} }
} }
@ -917,8 +909,7 @@ void EntityTreeRenderer::mouseReleaseEvent(QMouseEvent* event, unsigned int devi
QScriptValueList currentClickingEntityArgs = createMouseEventArgs(_currentClickingOnEntityID, event, deviceID); QScriptValueList currentClickingEntityArgs = createMouseEventArgs(_currentClickingOnEntityID, event, deviceID);
QScriptValue currentClickingEntity = loadEntityScript(_currentClickingOnEntityID); QScriptValue currentClickingEntity = loadEntityScript(_currentClickingOnEntityID);
if (currentClickingEntity.property("clickReleaseOnEntity").isValid()) { if (currentClickingEntity.property("clickReleaseOnEntity").isValid()) {
//qDebug() << "About to call clickReleaseOnEntity() current thread:" << QThread::currentThread() << "entities thread:" << _entitiesScriptEngine->thread(); currentClickingEntity.property("clickReleaseOnEntity").call(currentClickingEntity, currentClickingEntityArgs);
_entitiesScriptEngine->callScriptMethod("clickReleaseOnEntity", currentClickingEntity, currentClickingEntityArgs);
} }
} }
@ -946,13 +937,11 @@ void EntityTreeRenderer::mouseMoveEvent(QMouseEvent* event, unsigned int deviceI
// load the entity script if needed... // load the entity script if needed...
QScriptValue entityScript = loadEntityScript(rayPickResult.entity); QScriptValue entityScript = loadEntityScript(rayPickResult.entity);
if (entityScript.property("mouseMoveEvent").isValid()) { if (entityScript.property("mouseMoveEvent").isValid()) {
//qDebug() << "About to call mouseMoveEvent() current thread:" << QThread::currentThread() << "entities thread:" << _entitiesScriptEngine->thread(); entityScript.property("mouseMoveEvent").call(entityScript, entityScriptArgs);
_entitiesScriptEngine->callScriptMethod("mouseMoveEvent", entityScript, entityScriptArgs);
} }
emit mouseMoveOnEntity(rayPickResult, event, deviceID); emit mouseMoveOnEntity(rayPickResult, event, deviceID);
if (entityScript.property("mouseMoveOnEntity").isValid()) { if (entityScript.property("mouseMoveOnEntity").isValid()) {
//qDebug() << "About to call mouseMoveOnEntity() current thread:" << QThread::currentThread() << "entities thread:" << _entitiesScriptEngine->thread(); entityScript.property("mouseMoveOnEntity").call(entityScript, entityScriptArgs);
_entitiesScriptEngine->callScriptMethod("mouseMoveOnEntity", entityScript, entityScriptArgs);
} }
// handle the hover logic... // handle the hover logic...
@ -966,9 +955,7 @@ void EntityTreeRenderer::mouseMoveEvent(QMouseEvent* event, unsigned int deviceI
QScriptValue currentHoverEntity = loadEntityScript(_currentHoverOverEntityID); QScriptValue currentHoverEntity = loadEntityScript(_currentHoverOverEntityID);
if (currentHoverEntity.property("hoverLeaveEntity").isValid()) { if (currentHoverEntity.property("hoverLeaveEntity").isValid()) {
//qDebug() << "About to call hoverLeaveEntity() current thread:" << QThread::currentThread() << "entities thread:" << _entitiesScriptEngine->thread(); currentHoverEntity.property("hoverLeaveEntity").call(currentHoverEntity, currentHoverEntityArgs);
_entitiesScriptEngine->callScriptMethod("hoverLeaveEntity", currentHoverEntity, currentHoverEntityArgs);
} }
} }
@ -977,8 +964,7 @@ void EntityTreeRenderer::mouseMoveEvent(QMouseEvent* event, unsigned int deviceI
if (rayPickResult.entityID != _currentHoverOverEntityID) { if (rayPickResult.entityID != _currentHoverOverEntityID) {
emit hoverEnterEntity(rayPickResult.entityID, MouseEvent(*event, deviceID)); emit hoverEnterEntity(rayPickResult.entityID, MouseEvent(*event, deviceID));
if (entityScript.property("hoverEnterEntity").isValid()) { if (entityScript.property("hoverEnterEntity").isValid()) {
//qDebug() << "About to call hoverEnterEntity() current thread:" << QThread::currentThread() << "entities thread:" << _entitiesScriptEngine->thread(); entityScript.property("hoverEnterEntity").call(entityScript, entityScriptArgs);
_entitiesScriptEngine->callScriptMethod("hoverEnterEntity", entityScript, entityScriptArgs);
} }
} }
@ -986,8 +972,7 @@ void EntityTreeRenderer::mouseMoveEvent(QMouseEvent* event, unsigned int deviceI
// we should send our hover over event // we should send our hover over event
emit hoverOverEntity(rayPickResult.entityID, MouseEvent(*event, deviceID)); emit hoverOverEntity(rayPickResult.entityID, MouseEvent(*event, deviceID));
if (entityScript.property("hoverOverEntity").isValid()) { if (entityScript.property("hoverOverEntity").isValid()) {
//qDebug() << "About to call hoverOverEntity() current thread:" << QThread::currentThread() << "entities thread:" << _entitiesScriptEngine->thread(); entityScript.property("hoverOverEntity").call(entityScript, entityScriptArgs);
_entitiesScriptEngine->callScriptMethod("hoverOverEntity", entityScript, entityScriptArgs);
} }
// remember what we're hovering over // remember what we're hovering over
@ -1004,8 +989,7 @@ void EntityTreeRenderer::mouseMoveEvent(QMouseEvent* event, unsigned int deviceI
QScriptValue currentHoverEntity = loadEntityScript(_currentHoverOverEntityID); QScriptValue currentHoverEntity = loadEntityScript(_currentHoverOverEntityID);
if (currentHoverEntity.property("hoverLeaveEntity").isValid()) { if (currentHoverEntity.property("hoverLeaveEntity").isValid()) {
//qDebug() << "About to call hoverLeaveEntity() current thread:" << QThread::currentThread() << "entities thread:" << _entitiesScriptEngine->thread(); currentHoverEntity.property("hoverLeaveEntity").call(currentHoverEntity, currentHoverEntityArgs);
_entitiesScriptEngine->callScriptMethod("hoverLeaveEntity", currentHoverEntity, currentHoverEntityArgs);
} }
_currentHoverOverEntityID = UNKNOWN_ENTITY_ID; // makes it the unknown ID _currentHoverOverEntityID = UNKNOWN_ENTITY_ID; // makes it the unknown ID
@ -1021,8 +1005,7 @@ void EntityTreeRenderer::mouseMoveEvent(QMouseEvent* event, unsigned int deviceI
QScriptValue currentClickingEntity = loadEntityScript(_currentClickingOnEntityID); QScriptValue currentClickingEntity = loadEntityScript(_currentClickingOnEntityID);
if (currentClickingEntity.property("holdingClickOnEntity").isValid()) { if (currentClickingEntity.property("holdingClickOnEntity").isValid()) {
//qDebug() << "About to call holdingClickOnEntity() current thread:" << QThread::currentThread() << "entities thread:" << _entitiesScriptEngine->thread(); currentClickingEntity.property("holdingClickOnEntity").call(currentClickingEntity, currentClickingEntityArgs);
_entitiesScriptEngine->callScriptMethod("holdingClickOnEntity", currentClickingEntity, currentClickingEntityArgs);
} }
} }
_lastMouseEvent = MouseEvent(*event, deviceID); _lastMouseEvent = MouseEvent(*event, deviceID);
@ -1077,8 +1060,7 @@ void EntityTreeRenderer::checkAndCallPreload(const EntityItemID& entityID, const
QScriptValue entityScript = loadEntityScript(entityID, true, reload); // is preload! QScriptValue entityScript = loadEntityScript(entityID, true, reload); // is preload!
if (entityScript.property("preload").isValid()) { if (entityScript.property("preload").isValid()) {
QScriptValueList entityArgs = createEntityArgs(entityID); QScriptValueList entityArgs = createEntityArgs(entityID);
//qDebug() << "About to call preload() current thread:" << QThread::currentThread() << "entities thread:" << _entitiesScriptEngine->thread(); entityScript.property("preload").call(entityScript, entityArgs);
_entitiesScriptEngine->callScriptMethod("preload", entityScript, entityArgs);
} }
} }
} }
@ -1088,8 +1070,7 @@ void EntityTreeRenderer::checkAndCallUnload(const EntityItemID& entityID) {
QScriptValue entityScript = getPreviouslyLoadedEntityScript(entityID); QScriptValue entityScript = getPreviouslyLoadedEntityScript(entityID);
if (entityScript.property("unload").isValid()) { if (entityScript.property("unload").isValid()) {
QScriptValueList entityArgs = createEntityArgs(entityID); QScriptValueList entityArgs = createEntityArgs(entityID);
//qDebug() << "About to call unload() current thread:" << QThread::currentThread() << "entities thread:" << _entitiesScriptEngine->thread(); entityScript.property("unload").call(entityScript, entityArgs);
_entitiesScriptEngine->callScriptMethod("unload", entityScript, entityArgs);
} }
} }
} }
@ -1174,9 +1155,7 @@ void EntityTreeRenderer::entityCollisionWithEntity(const EntityItemID& idA, cons
args << idA.toScriptValue(_entitiesScriptEngine); args << idA.toScriptValue(_entitiesScriptEngine);
args << idB.toScriptValue(_entitiesScriptEngine); args << idB.toScriptValue(_entitiesScriptEngine);
args << collisionToScriptValue(_entitiesScriptEngine, collision); args << collisionToScriptValue(_entitiesScriptEngine, collision);
entityScriptA.property("collisionWithEntity").call(entityScriptA, args);
//qDebug() << "About to call collisionWithEntity() current thread:" << QThread::currentThread() << "entities thread:" << _entitiesScriptEngine->thread();
_entitiesScriptEngine->callScriptMethod("collisionWithEntity", entityScriptA, args);
} }
emit collisionWithEntity(idB, idA, collision); emit collisionWithEntity(idB, idA, collision);
@ -1186,9 +1165,7 @@ void EntityTreeRenderer::entityCollisionWithEntity(const EntityItemID& idA, cons
args << idB.toScriptValue(_entitiesScriptEngine); args << idB.toScriptValue(_entitiesScriptEngine);
args << idA.toScriptValue(_entitiesScriptEngine); args << idA.toScriptValue(_entitiesScriptEngine);
args << collisionToScriptValue(_entitiesScriptEngine, collision); args << collisionToScriptValue(_entitiesScriptEngine, collision);
entityScriptB.property("collisionWithEntity").call(entityScriptA, args);
//qDebug() << "About to call collisionWithEntity() current thread:" << QThread::currentThread() << "entities thread:" << _entitiesScriptEngine->thread();
_entitiesScriptEngine->callScriptMethod("collisionWithEntity", entityScriptB, args);
} }
} }

View file

@ -68,7 +68,6 @@ void ScriptCache::scriptDownloaded() {
qCDebug(scriptengine) << "Done downloading script at:" << url.toString(); qCDebug(scriptengine) << "Done downloading script at:" << url.toString();
foreach(ScriptUser* user, scriptUsers) { foreach(ScriptUser* user, scriptUsers) {
// FIXME - I sometimes get a crash deep below here inside of Qt while evaluating the script
user->scriptContentsAvailable(url, _scriptCache[url]); user->scriptContentsAvailable(url, _scriptCache[url]);
} }
} else { } else {

View file

@ -261,20 +261,6 @@ bool ScriptEngine::setScriptContents(const QString& scriptContents, const QStrin
return true; return true;
} }
void ScriptEngine::callScriptMethod(QString methodName, QScriptValue script, QScriptValueList args) {
if (QThread::currentThread() != thread()) {
QMetaObject::invokeMethod(this,
"callScriptMethod",
Q_ARG(QString, methodName),
Q_ARG(QScriptValue, script),
Q_ARG(QScriptValueList, args));
return;
}
//qDebug() << "About to call " << methodName << "() current thread : " << QThread::currentThread() << "engine thread : " << thread();
script.property(methodName).call(script, args);
}
void ScriptEngine::loadURL(const QUrl& scriptURL, bool reload) { void ScriptEngine::loadURL(const QUrl& scriptURL, bool reload) {
if (_isRunning) { if (_isRunning) {
return; return;

View file

@ -65,8 +65,6 @@ public:
int numArguments = -1); int numArguments = -1);
Q_INVOKABLE void setIsAvatar(bool isAvatar); Q_INVOKABLE void setIsAvatar(bool isAvatar);
Q_INVOKABLE void callScriptMethod(QString methodName, QScriptValue script, QScriptValueList args);
bool isAvatar() const { return _isAvatar; } bool isAvatar() const { return _isAvatar; }
void setAvatarData(AvatarData* avatarData, const QString& objectName); void setAvatarData(AvatarData* avatarData, const QString& objectName);

View file

@ -26,8 +26,7 @@ static int quatMetaTypeId = qRegisterMetaType<glm::quat>();
static int xColorMetaTypeId = qRegisterMetaType<xColor>(); static int xColorMetaTypeId = qRegisterMetaType<xColor>();
static int pickRayMetaTypeId = qRegisterMetaType<PickRay>(); static int pickRayMetaTypeId = qRegisterMetaType<PickRay>();
static int collisionMetaTypeId = qRegisterMetaType<Collision>(); static int collisionMetaTypeId = qRegisterMetaType<Collision>();
static int qMapURLStringMetaTypeId = qRegisterMetaType<QMap<QUrl, QString>>(); static int qMapURLStringMetaTypeId = qRegisterMetaType<QMap<QUrl,QString>>();
static int qScriptValueListMetaTypeId = qRegisterMetaType<QScriptValueList>("QScriptValueList");
void registerMetaTypes(QScriptEngine* engine) { void registerMetaTypes(QScriptEngine* engine) {
qScriptRegisterMetaType(engine, vec4toScriptValue, vec4FromScriptValue); qScriptRegisterMetaType(engine, vec4toScriptValue, vec4FromScriptValue);