Subj : Re: Javascript for scripting a computer game To : smileyhamster From : Igor Bukanov Date : Fri Nov 19 2004 06:49 pm S wrote: > Igor Bukanov wrote in message news:<419CF8C3.7030205@fastmail.fm>... > >>S wrote: >> >>... >> >>>What is the best way to implement this? >> >>What is the definition of "best"? Best in memory usage/speed/programming >>simplicity/maintenance easiness? > > > Just in general. For all I know, there could be > Context.pauseExecution() and Content.resumeExecution() methods that > are fast and memory effecient. Using continuations means that my code > has to be interpreted so my might get speed issues later. For numerically intense code the interpretation mode can indeed run up to 10 times slower, but for many simple scripts/functions that mostly access properties, call other functions and especially access Java objects the difference should be minimal. > > > That's pretty much exactly what I'm doing at the moment. Thanks for > the code. http://cocoon.apache.org/ uses code like that to pause/resume server-side scripts among other thinks so you have to thank Cocoon folks and in particular Christopher Oliver who implemented original continuations support in a Rhino fork. >> >>See http://www.mozilla.org/rhino/scopes.html and pay attention to the >>shared scope section. > > > I'm not at my home computer right now so I can't try anything out. So > I could have one "bullet object scope" and give that to each bullet so > they could all reuse the same scope I just compiled? Doesn't this mean > they'll share variables between each other and could possibly > interfere which each other? I don't want each, for example, bullet > objects to share data directly from the same scope if this is what > this does. I read the page but I'm having trouble understand exactly > what shared scope implies. > The idea of shared scopes is to define standard library objects, JS functions and any other objects that suppose to be read-only in a shared scope and then for each script give a private scope that points through its prototype to the shared scope. Then all variables that the script defines would be stored in the private scope. To ensure read-only access you can seal the shared scope to prevent its modifications using ScriptabkleObject.sealObject(). Regards, Igor .