From fdb94555401b2435260567cddda994fe692ca37b Mon Sep 17 00:00:00 2001 From: Brad Hefta-Gaub Date: Tue, 29 Sep 2015 13:12:55 -0700 Subject: [PATCH 1/7] debug --- examples/acScripts/flickeringLight.js | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/acScripts/flickeringLight.js b/examples/acScripts/flickeringLight.js index edf8332eb5..ea7f7f9c68 100644 --- a/examples/acScripts/flickeringLight.js +++ b/examples/acScripts/flickeringLight.js @@ -77,6 +77,7 @@ function update(deltaTime) { var intensity = (MINIMUM_LIGHT_INTENSITY + (MAXIMUM_LIGHT_INTENSITY + (Math.sin(totalTime) * MAXIMUM_LIGHT_INTENSITY))); intensity += randFloat(-LIGHT_INTENSITY_RANDOMNESS, LIGHT_INTENSITY_RANDOMNESS); var properties = Entities.getEntityProperties(LightMaker.light, "age"); + print("age:" + properties.age); Entities.editEntity(LightMaker.light, { intensity: intensity, lifetime: properties.age + EPHEMERAL_LIFETIME }); } } From 4abb2517289c561101120a744def2b05d1e02c26 Mon Sep 17 00:00:00 2001 From: Brad Hefta-Gaub Date: Tue, 29 Sep 2015 13:28:45 -0700 Subject: [PATCH 2/7] more debug --- examples/acScripts/flickeringLight.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/examples/acScripts/flickeringLight.js b/examples/acScripts/flickeringLight.js index ea7f7f9c68..93264e192c 100644 --- a/examples/acScripts/flickeringLight.js +++ b/examples/acScripts/flickeringLight.js @@ -76,9 +76,13 @@ function update(deltaTime) { totalTime += deltaTime; var intensity = (MINIMUM_LIGHT_INTENSITY + (MAXIMUM_LIGHT_INTENSITY + (Math.sin(totalTime) * MAXIMUM_LIGHT_INTENSITY))); intensity += randFloat(-LIGHT_INTENSITY_RANDOMNESS, LIGHT_INTENSITY_RANDOMNESS); - var properties = Entities.getEntityProperties(LightMaker.light, "age"); + var properties = Entities.getEntityProperties(LightMaker.light, ["age", "lifetime"]); + print("props:" +JSON.stringify(properties)); print("age:" + properties.age); - Entities.editEntity(LightMaker.light, { intensity: intensity, lifetime: properties.age + EPHEMERAL_LIFETIME }); + print("lifetime:" + properties.lifetime); + var newLifetime = properties.age + EPHEMERAL_LIFETIME; + print("newLifetime:" + newLifetime); + Entities.editEntity(LightMaker.light, { intensity : intensity, lifetime: newLifetime }); } } From 9c199b23a2b9b4240dba1b5bce535783fb9f64dc Mon Sep 17 00:00:00 2001 From: Brad Hefta-Gaub Date: Tue, 29 Sep 2015 13:32:28 -0700 Subject: [PATCH 3/7] more debug --- examples/acScripts/flickeringLight.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/acScripts/flickeringLight.js b/examples/acScripts/flickeringLight.js index 93264e192c..571684b385 100644 --- a/examples/acScripts/flickeringLight.js +++ b/examples/acScripts/flickeringLight.js @@ -77,12 +77,12 @@ function update(deltaTime) { var intensity = (MINIMUM_LIGHT_INTENSITY + (MAXIMUM_LIGHT_INTENSITY + (Math.sin(totalTime) * MAXIMUM_LIGHT_INTENSITY))); intensity += randFloat(-LIGHT_INTENSITY_RANDOMNESS, LIGHT_INTENSITY_RANDOMNESS); var properties = Entities.getEntityProperties(LightMaker.light, ["age", "lifetime"]); - print("props:" +JSON.stringify(properties)); - print("age:" + properties.age); - print("lifetime:" + properties.lifetime); + //print("props:" +JSON.stringify(properties)); + //print("age:" + properties.age); + //print("lifetime:" + properties.lifetime); var newLifetime = properties.age + EPHEMERAL_LIFETIME; - print("newLifetime:" + newLifetime); - Entities.editEntity(LightMaker.light, { intensity : intensity, lifetime: newLifetime }); + //print("newLifetime:" + newLifetime); + Entities.editEntity(LightMaker.light, { type: "Light", intensity : intensity, lifetime: newLifetime }); } } From 6a01c10453bfa1dfe73c0be014d15c209ced83c3 Mon Sep 17 00:00:00 2001 From: Brad Hefta-Gaub Date: Tue, 29 Sep 2015 13:35:16 -0700 Subject: [PATCH 4/7] more debug --- examples/acScripts/flickeringLight.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/acScripts/flickeringLight.js b/examples/acScripts/flickeringLight.js index 571684b385..03ea4681ef 100644 --- a/examples/acScripts/flickeringLight.js +++ b/examples/acScripts/flickeringLight.js @@ -78,10 +78,10 @@ function update(deltaTime) { intensity += randFloat(-LIGHT_INTENSITY_RANDOMNESS, LIGHT_INTENSITY_RANDOMNESS); var properties = Entities.getEntityProperties(LightMaker.light, ["age", "lifetime"]); //print("props:" +JSON.stringify(properties)); - //print("age:" + properties.age); - //print("lifetime:" + properties.lifetime); + print("age:" + properties.age); + print("lifetime:" + properties.lifetime); var newLifetime = properties.age + EPHEMERAL_LIFETIME; - //print("newLifetime:" + newLifetime); + print("newLifetime:" + newLifetime); Entities.editEntity(LightMaker.light, { type: "Light", intensity : intensity, lifetime: newLifetime }); } } From f83eae4d4259e56d657863eb2a73ca51ade4858c Mon Sep 17 00:00:00 2001 From: Brad Hefta-Gaub Date: Tue, 29 Sep 2015 14:45:24 -0700 Subject: [PATCH 5/7] more debugging --- examples/acScripts/flickeringLight.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/examples/acScripts/flickeringLight.js b/examples/acScripts/flickeringLight.js index 03ea4681ef..367b604567 100644 --- a/examples/acScripts/flickeringLight.js +++ b/examples/acScripts/flickeringLight.js @@ -43,7 +43,7 @@ var totalTime = 0; var MINIMUM_LIGHT_INTENSITY = 0.75; var MAXIMUM_LIGHT_INTENSITY = 2.75; var LIGHT_INTENSITY_RANDOMNESS = 0.3; -var EPHEMERAL_LIFETIME = 10; // ephemeral entities will live for 10 seconds after script stops running +var EPHEMERAL_LIFETIME = 60; // ephemeral entities will live for 60 seconds after script stops running var LightMaker = { light: null, @@ -78,11 +78,13 @@ function update(deltaTime) { intensity += randFloat(-LIGHT_INTENSITY_RANDOMNESS, LIGHT_INTENSITY_RANDOMNESS); var properties = Entities.getEntityProperties(LightMaker.light, ["age", "lifetime"]); //print("props:" +JSON.stringify(properties)); - print("age:" + properties.age); - print("lifetime:" + properties.lifetime); + //print("deltaTime:" + deltaTime); + //print("age:" + properties.age); + //print("lifetime:" + properties.lifetime); var newLifetime = properties.age + EPHEMERAL_LIFETIME; - print("newLifetime:" + newLifetime); - Entities.editEntity(LightMaker.light, { type: "Light", intensity : intensity, lifetime: newLifetime }); + //print("newLifetime:" + newLifetime); + Entities.editEntity(LightMaker.light, { type: "Light", intensity: intensity, lifetime: newLifetime }); + //print("packetsToSendCount:" + Entities.packetsToSendCount()); } } From 90afeb4ce1ad9692af4b38e3d23648832478d587 Mon Sep 17 00:00:00 2001 From: Brad Hefta-Gaub Date: Tue, 29 Sep 2015 15:45:29 -0700 Subject: [PATCH 6/7] more debugging --- examples/acScripts/flickeringLight.js | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/examples/acScripts/flickeringLight.js b/examples/acScripts/flickeringLight.js index 367b604567..cf3dd70934 100644 --- a/examples/acScripts/flickeringLight.js +++ b/examples/acScripts/flickeringLight.js @@ -39,11 +39,13 @@ var ZERO_VEC = { }; var totalTime = 0; +var lastUpdate = 0; +var UPDATE_INTERVAL = 1 / 30; // 30fps var MINIMUM_LIGHT_INTENSITY = 0.75; var MAXIMUM_LIGHT_INTENSITY = 2.75; var LIGHT_INTENSITY_RANDOMNESS = 0.3; -var EPHEMERAL_LIFETIME = 60; // ephemeral entities will live for 60 seconds after script stops running +var EPHEMERAL_LIFETIME = 10; // ephemeral entities will live for 60 seconds after script stops running var LightMaker = { light: null, @@ -74,17 +76,17 @@ function update(deltaTime) { LightMaker.spawnLight(); } else { totalTime += deltaTime; - var intensity = (MINIMUM_LIGHT_INTENSITY + (MAXIMUM_LIGHT_INTENSITY + (Math.sin(totalTime) * MAXIMUM_LIGHT_INTENSITY))); - intensity += randFloat(-LIGHT_INTENSITY_RANDOMNESS, LIGHT_INTENSITY_RANDOMNESS); - var properties = Entities.getEntityProperties(LightMaker.light, ["age", "lifetime"]); - //print("props:" +JSON.stringify(properties)); - //print("deltaTime:" + deltaTime); - //print("age:" + properties.age); - //print("lifetime:" + properties.lifetime); - var newLifetime = properties.age + EPHEMERAL_LIFETIME; - //print("newLifetime:" + newLifetime); - Entities.editEntity(LightMaker.light, { type: "Light", intensity: intensity, lifetime: newLifetime }); - //print("packetsToSendCount:" + Entities.packetsToSendCount()); + + // We don't want to edit the entity EVERY update cycle, because that's just a lot + // of wasted bandwidth and extra effort on the server for very little visual gain + if (totalTime - lastUpdate > UPDATE_INTERVAL) { + var intensity = (MINIMUM_LIGHT_INTENSITY + (MAXIMUM_LIGHT_INTENSITY + (Math.sin(totalTime) * MAXIMUM_LIGHT_INTENSITY))); + intensity += randFloat(-LIGHT_INTENSITY_RANDOMNESS, LIGHT_INTENSITY_RANDOMNESS); + var properties = Entities.getEntityProperties(LightMaker.light, "age"); + var newLifetime = properties.age + EPHEMERAL_LIFETIME; + Entities.editEntity(LightMaker.light, { type: "Light", intensity: intensity, lifetime: newLifetime }); + lastUpdate = totalTime; + } } } From 67823b79d5de72120e2c1b33478dd29ffdb370d8 Mon Sep 17 00:00:00 2001 From: Brad Hefta-Gaub Date: Tue, 29 Sep 2015 15:48:46 -0700 Subject: [PATCH 7/7] change additional lifetime to 60 seconds to avoid processing hiccups --- examples/acScripts/flickeringLight.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/acScripts/flickeringLight.js b/examples/acScripts/flickeringLight.js index cf3dd70934..ed60d56c86 100644 --- a/examples/acScripts/flickeringLight.js +++ b/examples/acScripts/flickeringLight.js @@ -45,7 +45,7 @@ var UPDATE_INTERVAL = 1 / 30; // 30fps var MINIMUM_LIGHT_INTENSITY = 0.75; var MAXIMUM_LIGHT_INTENSITY = 2.75; var LIGHT_INTENSITY_RANDOMNESS = 0.3; -var EPHEMERAL_LIFETIME = 10; // ephemeral entities will live for 60 seconds after script stops running +var EPHEMERAL_LIFETIME = 60; // ephemeral entities will live for 60 seconds after script stops running var LightMaker = { light: null,