The first is a timer that fits inside of the GMP framework. I like
using this timer over setInterval, because 1) it works within the GMP
framework, and doesn't interrupt its housekeeping functions (if any);
and 2) it works with the GMP notion of ticks rather then milliseconds.
You use it by calling Chronos.run() in your main AI function. You
can set up an interval with us run every x ticks, or a timer, which is
only run once after x ticks.
Chronos = {
intervals: {},
addInterval: function(name, ticks, f) {
this.intervals[name] = {
"ticks": ticks,
"runAt": G.iteration,
"f":f ,
"remove": false };
},
removeInterval: function(name) {
delete this.intervals[name];
},
addTimer: function(name, ticks, f) {
this.intervals[name] = {
"ticks": ticks,
"runAt": ticks + G.iteration,
"f": f ,
"remove": true };
},
run: function() {
for(var i in this.intervals) {
if (this.intervals[i].runAt < G.iteration) {
this.intervals[i].f();
if (this.intervals[i].remove) {
this.removeInterval(i);
} else {
this.intervals[i].runAt = this.intervals[i].ticks + G.iteration;
}
}
}
}
}
My games are full of tedious animation counters which this can
abstract away.
This code is so useful that I want to put it into the main engine
code. What do you say? Full credit for you in the code and in the
license of course, and GMP is released GPL/MIT license, so this is all
about free anyway.
If you are interested, I'll do the following:
1) Add Chronos to the 'G' namespace so that the engine variable space
is still contained (It would have it's own area in the code, like
G.Block or G.Mouse. Other than that, the code stays as is.
2) Add you to the MIT/GPL license at the top of the gmp-engine.js code
files, something like 'Chronos code contributed by Jon...@gmail.com
(or what ever you want)', etc.
3) Add a brief comment at the location of the code saying thanks to
Jon...@gmail.com (thanks!)
4) Write up some docs for the new code and put them on the
gogomakeplay.com site. Credits here also.
5) Add credits for you in the google code page(s) for gmp-engine.
6) Make a blog post on the front page of gogomakeplay.com letting
everyone know there's new code and docs, credits here also.
Fwiw, the code repository is still in house because I'm lazy, but I'll
put the code and docs in github, google code, etc in heartbeat when we
get some activity (your the first person that I know of that is
modding the code). For now, I'll just add stuff in as a benevolent
dictator.
Let me know if you want your code added to the engine, and if so, let
me know how you want to be credited.
If you don't want it back in the code, I'd like to post it to the main
page of gogomakeplay.com (again, let me know if that's ok).
Trev
Go ahead and add it to the main engine. Thanks! You can credit it to
Jonathan Arkell (jon...@jonnay.net).
I'll keep you abreast of any updates I make to it. :)
It's been over 8 months since I asked your permission to integrate your Chronos code in the main GMP engine, and I just wanted to let you know why nothing has happened.
I really like Chronos, but integrating it directly into the engine keeps moving down my priority list. I don't like adding something without being prepared to support it fully, with examples, docs, etc. and I don't see it happening before I get to many other items on my GMP to-do list.
That said, I'm taking Chronos off my list of things to add to the engine in the near future (the same 'near future' that is always rapidly receding out of my view. :)
Best,
Trevor
> --
> You received this message because you are subscribed to the Google Groups "gmp-engine" group.
> To post to this group, send email to gmp-e...@googlegroups.com.
> To unsubscribe from this group, send email to gmp-engine+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/gmp-engine?hl=en.
>