Timer, Alarm, Event. Easy.
by Kilinich » Sun Jan 17, 2010 11:23 pm
Key feature is every-frame evend handler "Scene.my.event" that can be attached to any global property.
For example:
- CODE: SELECT ALL
App.Background -> {
cloudOpacity = {Scene.my.event(0.94999999)};
...};
And this is all the rest:
- CODE: SELECT ALL
Scene.my.event := (n)=>{Scene.my.evHandle; n};
Scene.my.newAlarm := (aTime, aWhat)=>{
Scene.my.events = Scene.my.events ++ [[aTime, 0, 1]];
Scene.my.eventsCount = Scene.my.eventsCount + 1;
Scene.my.actions = Scene.my.actions ++ [aWhat];
scene.my.eventsCount-1
};
Scene.my.newEvent := (eTime, eRepeat, eCount, eAction)=>{
Scene.my.events = Scene.my.events ++ [[eTime, eRepeat, eCount]];
Scene.my.eventsCount = Scene.my.eventsCount + 1;
Scene.my.actions = Scene.my.actions ++ [eAction];
scene.my.eventsCount-1
};
Scene.my.newTimer := (tTime, tWhat, tRepeat)=>{
Scene.my.events = Scene.my.events ++ [[tTime + sim.time, tTime, tRepeat ? 9999999 : 1]];
Scene.my.eventsCount = Scene.my.eventsCount + 1;
Scene.my.actions = Scene.my.actions ++ [tWhat];
scene.my.eventsCount-1
};
Scene.my.delEvent := (i)=>{
newActions = [];
newEvents = [];
Scene.my.eventsCount = Scene.my.eventsCount - 1;
for(i, (n)=>{
newActions = newActions ++ [Scene.my.actions(n)];
newEvents = newEvents ++ [Scene.my.events(n)]
});
for(Scene.my.eventsCount - i, (n)=>{
newActions = newActions ++ [Scene.my.actions(n + i + 1)];
newEvents = newEvents ++ [Scene.my.events(n + i + 1)]
});
Scene.my.events = newEvents;
Scene.my.actions = newActions
};
Scene.my.eventsCount := 0;
Scene.my.events := [];
Scene.my.actions := [];
Scene.my.evHandle := {
sim.running ? {
DelEvents = [];
DelCount = 0;
Scene.my.frame = Scene.my.frame + 1;
for(scene.my.eventsCount, (ev)=>{
scene.my.events(ev)(0) < sim.time ? {
Scene.my.actions(ev)();
Scene.my.events(ev)(2) > 1 ? {
newEvents = [];
for(ev, (n)=>{newEvents = newEvents ++ [Scene.my.events(n)]});
newEvents = newEvents ++ [[scene.my.events(ev)(1) + sim.time, scene.my.events(ev)(1), scene.my.events(ev)(2) - 1]];
for(Scene.my.eventsCount - ev - 1, (n)=>{newEvents = newEvents ++ [Scene.my.events(n + ev + 1)]});
Scene.my.events = newEvents
} : {
DelEvents = DelEvents ++ [ev];
DelCount = DelCount + 1
}
} : {}
});
for(DelCount, (ev)=>{scene.my.delEvent(DelEvents(ev))})
} : {}
};
Scene.my.timers := [];
Scene.my.frame := 0;
Last edited by Kilinich on Fri Jun 04, 2010 8:26 pm, edited 2 times in total.
Dream of Algodoo as game development engine...
Kilinich- [Best bug reporter 2010]
- Posts: 1502
- Joined: Mon Aug 31, 2009 8:27 pm
- Location: South Russia
No hay comentarios:
Publicar un comentario