From dd83ff05380277fb3398984f7d00fa0c1a2b5ce4 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 31 Jan 2014 14:36:50 -0800 Subject: [PATCH 1/3] move isAvatar property access to Agent object --- assignment-client/src/Agent.cpp | 3 +++ assignment-client/src/Agent.h | 5 +++++ libraries/script-engine/src/ScriptEngine.cpp | 2 +- libraries/script-engine/src/ScriptEngine.h | 2 -- 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/assignment-client/src/Agent.cpp b/assignment-client/src/Agent.cpp index 84714259e5..2694bf83e2 100644 --- a/assignment-client/src/Agent.cpp +++ b/assignment-client/src/Agent.cpp @@ -101,6 +101,9 @@ void Agent::run() { // give this AvatarData object to the script engine _scriptEngine.setAvatarData(&scriptedAvatar, "Avatar"); + + // register ourselves to the script engine + _scriptEngine.registerGlobalObject("Agent", this); _scriptEngine.setScriptContents(scriptContents); _scriptEngine.run(); diff --git a/assignment-client/src/Agent.h b/assignment-client/src/Agent.h index 146cb71df4..8b2038a8b0 100644 --- a/assignment-client/src/Agent.h +++ b/assignment-client/src/Agent.h @@ -21,9 +21,14 @@ class Agent : public ThreadedAssignment { Q_OBJECT + + Q_PROPERTY(bool isAvatar READ isAvatar WRITE setIsAvatar) public: Agent(const QByteArray& packet); + void setIsAvatar(bool isAvatar) { _scriptEngine.setIsAvatar(isAvatar); } + bool isAvatar() const { return _scriptEngine.isAvatar(); } + public slots: void run(); diff --git a/libraries/script-engine/src/ScriptEngine.cpp b/libraries/script-engine/src/ScriptEngine.cpp index 6ea3742592..9a7a9197b0 100644 --- a/libraries/script-engine/src/ScriptEngine.cpp +++ b/libraries/script-engine/src/ScriptEngine.cpp @@ -133,7 +133,7 @@ void ScriptEngine::init() { QScriptValue injectionOptionValue = _engine.scriptValueFromQMetaObject(); _engine.globalObject().setProperty("AudioInjectionOptions", injectionOptionValue); - registerGlobalObject("Agent", this); + registerGlobalObject("Script", this); registerGlobalObject("Audio", &_audioScriptingInterface); registerGlobalObject("Controller", _controllerScriptingInterface); registerGlobalObject("Data", &_dataServerScriptingInterface); diff --git a/libraries/script-engine/src/ScriptEngine.h b/libraries/script-engine/src/ScriptEngine.h index c2188cca63..8f29379266 100644 --- a/libraries/script-engine/src/ScriptEngine.h +++ b/libraries/script-engine/src/ScriptEngine.h @@ -31,8 +31,6 @@ const QString NO_SCRIPT(""); class ScriptEngine : public QObject { Q_OBJECT - - Q_PROPERTY(bool isAvatar READ isAvatar WRITE setIsAvatar) public: ScriptEngine(const QString& scriptContents = NO_SCRIPT, bool wantMenuItems = false, const QString& scriptMenuName = QString(""), AbstractMenuInterface* menu = NULL, From 9015b24aa5ec5af9da0508aa5c831c6e3a4399a2 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 31 Jan 2014 14:41:24 -0800 Subject: [PATCH 2/3] update the script examples for new nomenclature --- examples/clap.js | 2 +- examples/collidingParticles.js | 6 +++--- examples/controllerExample.js | 4 ++-- examples/count.js | 4 ++-- examples/drumStick.js | 2 +- examples/editParticleExample.js | 8 ++++---- examples/findParticleExample.js | 8 ++++---- examples/fountain.js | 4 ++-- examples/gameoflife.js | 2 +- examples/gun.js | 2 +- examples/lookWithMouse.js | 4 ++-- examples/movingVoxel.js | 2 +- examples/paintGun.js | 2 +- examples/particleBird.js | 4 ++-- examples/particleModelExample.js | 6 +++--- examples/playSound.js | 2 +- examples/rideAlongWithAParticleExample.js | 4 ++-- examples/toyball.js | 2 +- examples/voxelBird.js | 2 +- 19 files changed, 35 insertions(+), 35 deletions(-) diff --git a/examples/clap.js b/examples/clap.js index fdd2b29aa2..81ccda64b7 100644 --- a/examples/clap.js +++ b/examples/clap.js @@ -62,4 +62,4 @@ function maybePlaySound() { } // Connect a call back that happens every frame -Agent.willSendVisualDataCallback.connect(maybePlaySound); \ No newline at end of file +Script.willSendVisualDataCallback.connect(maybePlaySound); \ No newline at end of file diff --git a/examples/collidingParticles.js b/examples/collidingParticles.js index cf1fce5660..d202b31d97 100644 --- a/examples/collidingParticles.js +++ b/examples/collidingParticles.js @@ -1,4 +1,4 @@ -// +Script// // collidingParticles.js // hifi // @@ -132,7 +132,7 @@ function draw() { print(scriptB); numberParticlesAdded++; } else { - Agent.stop(); + Script.stop(); } print("Particles Stats: " + Particles.getLifetimeInSeconds() + " seconds," + @@ -150,5 +150,5 @@ function draw() { // register the call back so it fires before each data send print("here...\n"); Particles.setPacketsPerSecond(40000); -Agent.willSendVisualDataCallback.connect(draw); +Script.willSendVisualDataCallback.connect(draw); print("and here...\n"); diff --git a/examples/controllerExample.js b/examples/controllerExample.js index 95561dc9dc..43eb516cee 100644 --- a/examples/controllerExample.js +++ b/examples/controllerExample.js @@ -82,7 +82,7 @@ function touchEndEvent(event) { } // register the call back so it fires before each data send -Agent.willSendVisualDataCallback.connect(checkController); +Script.willSendVisualDataCallback.connect(checkController); // Map keyPress and mouse move events to our callbacks Controller.keyPressEvent.connect(keyPressEvent); @@ -199,4 +199,4 @@ function scriptEnding() { Controller.releaseTouchEvents(); } -Agent.scriptEnding.connect(scriptEnding); +Script.scriptEnding.connect(scriptEnding); diff --git a/examples/count.js b/examples/count.js index 917bec342d..29799a8271 100644 --- a/examples/count.js +++ b/examples/count.js @@ -20,7 +20,7 @@ function scriptEnding() { } // register the call back so it fires before each data send -Agent.willSendVisualDataCallback.connect(displayCount); +Script.willSendVisualDataCallback.connect(displayCount); // register our scriptEnding callback -Agent.scriptEnding.connect(scriptEnding); +Script.scriptEnding.connect(scriptEnding); diff --git a/examples/drumStick.js b/examples/drumStick.js index 955fddbdee..78de8351db 100644 --- a/examples/drumStick.js +++ b/examples/drumStick.js @@ -69,4 +69,4 @@ function checkSticks() { } // Connect a call back that happens every frame -Agent.willSendVisualDataCallback.connect(checkSticks); \ No newline at end of file +Script.willSendVisualDataCallback.connect(checkSticks); \ No newline at end of file diff --git a/examples/editParticleExample.js b/examples/editParticleExample.js index 61e32c4d55..5774eda689 100644 --- a/examples/editParticleExample.js +++ b/examples/editParticleExample.js @@ -44,7 +44,7 @@ var particleID = Particles.addParticle(originalProperties); function moveParticle() { if (count >= moveUntil) { - //Agent.stop(); + //Script.stop(); // delete it... if (count == moveUntil) { @@ -54,8 +54,8 @@ function moveParticle() { // stop it... if (count >= stopAfter) { - print("calling Agent.stop()"); - Agent.stop(); + print("calling Script.stop()"); + Script.stop(); } count++; @@ -86,5 +86,5 @@ function moveParticle() { // register the call back so it fires before each data send -Agent.willSendVisualDataCallback.connect(moveParticle); +Script.willSendVisualDataCallback.connect(moveParticle); diff --git a/examples/findParticleExample.js b/examples/findParticleExample.js index bd20e6ded7..5eb257d502 100644 --- a/examples/findParticleExample.js +++ b/examples/findParticleExample.js @@ -65,8 +65,8 @@ function findParticles() { // run for a while, then clean up // stop it... if (iteration >= 100) { - print("calling Agent.stop()"); - Agent.stop(); + print("calling Script.stop()"); + Script.stop(); } print("--------------------------"); @@ -122,7 +122,7 @@ function findParticles() { // register the call back so it fires before each data send -Agent.willSendVisualDataCallback.connect(findParticles); +Script.willSendVisualDataCallback.connect(findParticles); // register our scriptEnding callback -Agent.scriptEnding.connect(scriptEnding); +Script.scriptEnding.connect(scriptEnding); diff --git a/examples/fountain.js b/examples/fountain.js index a095f91ed3..3c943d72a0 100644 --- a/examples/fountain.js +++ b/examples/fountain.js @@ -60,8 +60,8 @@ function makeFountain() { totalParticles++; } if (totalParticles > 100) { - Agent.stop(); + Script.stop(); } } // register the call back so it fires before each data send -Agent.willSendVisualDataCallback.connect(makeFountain); \ No newline at end of file +Script.willSendVisualDataCallback.connect(makeFountain); \ No newline at end of file diff --git a/examples/gameoflife.js b/examples/gameoflife.js index 09fae07204..6779941dc7 100644 --- a/examples/gameoflife.js +++ b/examples/gameoflife.js @@ -128,6 +128,6 @@ print("step()..."); } print("here"); -Agent.willSendVisualDataCallback.connect(step); +Script.willSendVisualDataCallback.connect(step); Voxels.setPacketsPerSecond(200); print("now here"); diff --git a/examples/gun.js b/examples/gun.js index 3f8eefe3e2..e7cd2973e2 100644 --- a/examples/gun.js +++ b/examples/gun.js @@ -99,4 +99,4 @@ function checkController() { // register the call back so it fires before each data send -Agent.willSendVisualDataCallback.connect(checkController); +Script.willSendVisualDataCallback.connect(checkController); diff --git a/examples/lookWithMouse.js b/examples/lookWithMouse.js index 79fad76a1b..f404019bc1 100644 --- a/examples/lookWithMouse.js +++ b/examples/lookWithMouse.js @@ -70,5 +70,5 @@ MyAvatar.bodyPitch = 0; MyAvatar.bodyRoll = 0; // would be nice to change to update -Agent.willSendVisualDataCallback.connect(update); -Agent.scriptEnding.connect(scriptEnding); +Script.willSendVisualDataCallback.connect(update); +Script.scriptEnding.connect(scriptEnding); diff --git a/examples/movingVoxel.js b/examples/movingVoxel.js index 0aadf7b30c..14a7e671c6 100644 --- a/examples/movingVoxel.js +++ b/examples/movingVoxel.js @@ -41,4 +41,4 @@ function moveVoxel() { Voxels.setPacketsPerSecond(300); // Connect a call back that happens every frame -Agent.willSendVisualDataCallback.connect(moveVoxel); \ No newline at end of file +Script.willSendVisualDataCallback.connect(moveVoxel); \ No newline at end of file diff --git a/examples/paintGun.js b/examples/paintGun.js index b78e6abb0b..56e916a183 100644 --- a/examples/paintGun.js +++ b/examples/paintGun.js @@ -93,4 +93,4 @@ function checkController() { // register the call back so it fires before each data send -Agent.willSendVisualDataCallback.connect(checkController); +Script.willSendVisualDataCallback.connect(checkController); diff --git a/examples/particleBird.js b/examples/particleBird.js index 6a4cf79a40..c1c26058e6 100644 --- a/examples/particleBird.js +++ b/examples/particleBird.js @@ -95,7 +95,7 @@ function moveBird() { var nowTimeInSeconds = new Date().getTime() / 1000; if ((nowTimeInSeconds - startTimeInSeconds) >= birdLifetime) { print("our bird is dying, stop our script"); - Agent.stop(); + Script.stop(); return; } @@ -171,4 +171,4 @@ function moveBird() { } } // register the call back so it fires before each data send -Agent.willSendVisualDataCallback.connect(moveBird); +Script.willSendVisualDataCallback.connect(moveBird); diff --git a/examples/particleModelExample.js b/examples/particleModelExample.js index 9f19069ee9..e95cc0c2bf 100644 --- a/examples/particleModelExample.js +++ b/examples/particleModelExample.js @@ -37,8 +37,8 @@ var ballParticleID = Particles.addParticle(ballProperties); function endAfterAWhile() { // stop it... if (count >= stopAfter) { - print("calling Agent.stop()"); - Agent.stop(); + print("calling Script.stop()"); + Script.stop(); } print("count =" + count); @@ -47,5 +47,5 @@ function endAfterAWhile() { // register the call back so it fires before each data send -Agent.willSendVisualDataCallback.connect(endAfterAWhile); +Script.willSendVisualDataCallback.connect(endAfterAWhile); diff --git a/examples/playSound.js b/examples/playSound.js index 6631d5526a..657f052aa5 100644 --- a/examples/playSound.js +++ b/examples/playSound.js @@ -17,4 +17,4 @@ function maybePlaySound() { } // Connect a call back that happens every frame -Agent.willSendVisualDataCallback.connect(maybePlaySound); \ No newline at end of file +Script.willSendVisualDataCallback.connect(maybePlaySound); \ No newline at end of file diff --git a/examples/rideAlongWithAParticleExample.js b/examples/rideAlongWithAParticleExample.js index eca9fe7f4c..b2b6627063 100644 --- a/examples/rideAlongWithAParticleExample.js +++ b/examples/rideAlongWithAParticleExample.js @@ -37,7 +37,7 @@ function rideWithParticle() { y: propertiesA.position.y + 2, z: propertiesA.position.z }; } else { - Agent.stop(); + Script.stop(); } iteration++; @@ -46,5 +46,5 @@ function rideWithParticle() { // register the call back so it fires before each data send -Agent.willSendVisualDataCallback.connect(rideWithParticle); +Script.willSendVisualDataCallback.connect(rideWithParticle); diff --git a/examples/toyball.js b/examples/toyball.js index 6c40fc2932..c5672877f7 100644 --- a/examples/toyball.js +++ b/examples/toyball.js @@ -226,4 +226,4 @@ function checkController() { // register the call back so it fires before each data send -Agent.willSendVisualDataCallback.connect(checkController); +Script.willSendVisualDataCallback.connect(checkController); diff --git a/examples/voxelBird.js b/examples/voxelBird.js index 54c0129045..254f93c21e 100644 --- a/examples/voxelBird.js +++ b/examples/voxelBird.js @@ -130,4 +130,4 @@ function moveBird() { Voxels.setPacketsPerSecond(10000); // Connect a call back that happens every frame -Agent.willSendVisualDataCallback.connect(moveBird); \ No newline at end of file +Script.willSendVisualDataCallback.connect(moveBird); \ No newline at end of file From dba7fbceac46799b4e9495158cd6e307ead97038 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 31 Jan 2014 15:00:35 -0800 Subject: [PATCH 3/3] remove extra Script and commented out line --- examples/collidingParticles.js | 2 +- examples/editParticleExample.js | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/examples/collidingParticles.js b/examples/collidingParticles.js index d202b31d97..81ccfe108b 100644 --- a/examples/collidingParticles.js +++ b/examples/collidingParticles.js @@ -1,4 +1,4 @@ -Script// +// // collidingParticles.js // hifi // diff --git a/examples/editParticleExample.js b/examples/editParticleExample.js index 5774eda689..152bb18fca 100644 --- a/examples/editParticleExample.js +++ b/examples/editParticleExample.js @@ -44,7 +44,6 @@ var particleID = Particles.addParticle(originalProperties); function moveParticle() { if (count >= moveUntil) { - //Script.stop(); // delete it... if (count == moveUntil) {