<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Mon, Nov 21, 2016 at 10:53 AM, Don Brutzman <span dir="ltr"><<a href="mailto:brutzman@nps.edu" target="_blank">brutzman@nps.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Good point Patrick.  Thanks for your example too Holger.<br>
<br>
Perhaps even trickier is that events within a single event cascade are not guaranteed to be ordered.  This slight relaxation on Script semantics was necessary when we reconciled internal scripting with external EAI to produce the combined SAI.  Avoiding reliance on event ordering is also necessary if events are being produced by parallel processes.  They might all be available at the beginning of an event cascade, but such arrival ordering can't be guaranteed.<br>
<br>
Avoiding repetition of two values, please consider these variations on Holger's approach:<br>
<br>
# <a href="http://stackoverflow.com/questions/3830244/get-current-date-time-in-seconds" rel="noreferrer" target="_blank">http://stackoverflow.com/quest<wbr>ions/3830244/get-current-date-<wbr>time-in-seconds</a><br>
timestamp = new Date().getTime() / 1000;<br>
timestamp = Date.now() / 1000; // apparently equivalent<br>
<br></blockquote><div><br></div><div>There is also Performance.now() : <a href="https://developer.mozilla.org/en-US/docs/Web/API/Performance/now">https://developer.mozilla.org/en-US/docs/Web/API/Performance/now</a></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
# stop then _start_<br>
timeSensor.stopTime = timestamp;<br>
timeSensor.cycleInterval = newValue;<br>
timeSensor.startTime = timestamp;<br></blockquote><div><br></div><div>Ok, this is Holger's suggestion.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
timeSensor.enabled=false;<br>
timeSensor.cycleInterval = newValue;<br>
timeSensor.startTime = timestamp;<br>
<br></blockquote><div> </div><div>set_startTime = timeStamp will activate. ok.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
# reshuffled order of same events means (perhaps-ignored re)start then _stop_<br>
<br>
timeSensor.cycleInterval = newValue; // ignored if running<br>
timeSensor.startTime = timestamp;    // ignored if running<br>
timeSensor.stopTime = timestamp;<br>
<br></blockquote><div><br></div><div>ok, since ordering is not guaranteed above approaches may not work.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
timeSensor.cycleInterval = newValue; // ignored if running<br>
timeSensor.startTime = timestamp;    // ignored if running<br>
timeSensor.enabled=false;<br>
<br>
Ouch.  Is the TimeSensor starting or stopping?  Coin flip.  No way to be consistent in one pass when event order isn't guaranteed.<br>
<br>
Workaround: one way for an author to avoid nondeterminism is to perform one step before the other.  Two-phase commit.<br>
a. first a script stop a TimeSensor (using either .enabled or .stopTime events),<br>
b. await confirmation that TimeSensor has stopped (by receiving either isActive=false or stopTime/elapsedTime event),<br>
c. then (meaning then in follow-on event-cascade loop) use that event as a trigger to change the cycleInterval and restart.<br></blockquote><div><br></div><div>I started to try to do that using multiple scripts and routes but got confused.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
This workaround either takes a custom Script or perhaps a carefully crafted combination of event-utility nodes, along with corresponding ROUTE connections. It can be done, but is fairly detailed/onerous and certainly error prone.  Of course erroneous response is also maddening - user frantically clicking "why won't it STOP??!"<br></blockquote><div><br></div><div>Exactly what happened to me. I actually managed to freeze firefox a few times (perhaps indicating that the loop breaking rule is not sufficient, or not sufficiently implemented in cobweb). It may still be instructive to come up with the actual solution using this approach but I had to give up.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
Back to X3D design, must wonder: why don't we just allow modifying cycleInterval while a TimeSensor cycle is active?  Avoids nondeterminism and programming overhead of two-phase commit.  Perhaps TimeSensor implementers could weigh in here...<br></blockquote><div><br></div><div>I agree. Hopefully there is a simple solution like this.</div><div><br></div><div>In cobweb_dom I resolved to call a Browser.processEvents() cobweb method explicitly after each triggered input event which I think completes the cascade for this single event. It does not necessarily render a frame. Doing this probably reduces performance a bit but makes code sequence such as above possible which is what most would expect.</div><div><br></div><div>Are external SAI events delivered between .beginUpdate() and .endUpdate() guaranteed to maintain their sequencing once the browser starts to process them ?</div><div><br></div><div>-Andreas</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
On 11/21/2016 6:48 AM, Patrick Dähne wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
Hello Andreas,<br>
<br>
Setting the cycleInterval does not work because your example javascript code does not comply with X3D. Have a look at the following lines:<br>
<br>
time.enabled = false;<br>
time.cycleInterval = 5;<br>
time.enabled = true;<br>
<br>
And now have a look at the spec (X3D Language Bindings : ECMAScript (JavaScript), 4.3.5.2.2 Accessing fields and readable fields of other nodes):<br>
<br>
… Events generated by setting an input-capable field on a node are sent at the completion of the initial function call made to the user code by the browser. … Assigning to the inputOnly field multiple times during one execution of the function still only sends one event and that event shall be the last value assigned.<br>
<br>
So in X3D conformant browsers, the lines above send only two events:<br>
<br>
1. time.enabled = true<br>
2. time.cycleInterval = 5<br>
<br>
The first assignment to time.enabled gets overwritten by the second assignment, so the timer never gets disabled.<br>
<br>
Bye,<br>
<br>
Patrick<br>
<br>
<br>
<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
Am 20.11.2016 um 21:36 schrieb Andreas Plesch <<a href="mailto:andreasplesch@gmail.com" target="_blank">andreasplesch@gmail.com</a>>:<br>
<br>
I want to change the cycleTime of a TimeSensor in a x3d script:<br>
<br>
<a href="https://raw.githubusercontent.com/andreasplesch/cobweb_dom/master/tests/dynamicCycleTime.x3d" rel="noreferrer" target="_blank">https://raw.githubusercontent.<wbr>com/andreasplesch/cobweb_dom/m<wbr>aster/tests/dynamicCycleTime.x<wbr>3d</a><br>
<br>
cycleTime input events are ignored when the TimeSensor is enabled. So it is necessary to disable it first, then change the cycleTime and then reenable it.<br>
<br>
However, in all tested browser the above does not work as expected. These are cobweb, instant player and bs contact. bs contact also has this console message:<br>
Script node speeder: parse error: line 16 "time.cycleInterval = 2;" ()<br>
and therefore does not get to change the color to grey.<br>
The javascript sai does not have a SFTime constructor and allows numbers.<br>
<br>
cobweb and instant player change the color but do not slow down the ball.<br>
I first thought that cobweb does not correctly work through the sequence of events but since no browser works sofar I start to think that I am missing something.<br>
<br>
Any help or feedback appreciated,<br>
<br>
-Andreas<br>
</blockquote>
<br>
<br>
______________________________<wbr>_________________<br>
x3d-public mailing list<br>
<a href="mailto:x3d-public@web3d.org" target="_blank">x3d-public@web3d.org</a><br>
<a href="http://web3d.org/mailman/listinfo/x3d-public_web3d.org" rel="noreferrer" target="_blank">http://web3d.org/mailman/listi<wbr>nfo/x3d-public_web3d.org</a><br>
<br>
</blockquote>
<br>
<br>
all the best, Don<span class="gmail-HOEnZb"><font color="#888888"><br>
-- <br>
Don Brutzman  Naval Postgraduate School, Code USW/Br       <a href="mailto:brutzman@nps.edu" target="_blank">brutzman@nps.edu</a><br>
Watkins 270,  MOVES Institute, Monterey CA 93943-5000 USA   <a href="tel:%2B1.831.656.2149" value="+18316562149" target="_blank">+1.831.656.2149</a><br>
X3D graphics, virtual worlds, navy robotics <a href="http://faculty.nps.edu/brutzman" rel="noreferrer" target="_blank">http://faculty.nps.edu/brutzma<wbr>n</a><br>
</font></span></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature">Andreas Plesch<br>39 Barbara Rd.<br>Waltham, MA 02453</div>
</div></div>