|
From: Melchior F. <mf...@fl...> - 2006-12-05 19:27:42
|
Update of /var/cvs/FlightGear-0.9/data/Nasal
In directory baron:/tmp/cvs-serv8155
Modified Files:
aircraft.nas
Log Message:
- fix switch() method
- optimization (and code obfuscation ;-)
Index: aircraft.nas
===================================================================
RCS file: /var/cvs/FlightGear-0.9/data/Nasal/aircraft.nas,v
retrieving revision 1.10
retrieving revision 1.11
diff -C 2 -r1.10 -r1.11
*** aircraft.nas 4 Dec 2006 10:42:05 -0000 1.10
--- aircraft.nas 5 Dec 2006 19:17:17 -0000 1.11
***************
*** 182,186 ****
m.continuous = 0;
m.loopid = 0;
! m.switch = -1;
m.switchL = setlistener(m.switchN, func { m._switch_() }, 1);
return m;
--- 182,186 ----
m.continuous = 0;
m.loopid = 0;
! m.lastswitch = 0;
m.switchL = setlistener(m.switchN, func { m._switch_() }, 1);
return m;
***************
*** 192,196 ****
# light.switch(bool) -> set light switch (also affects other lights
# that use the same switch)
! switch : func { me.switchN.setBoolValue(arg[0]); me },
# light.toggle() -> toggle light switch
--- 192,196 ----
# light.switch(bool) -> set light switch (also affects other lights
# that use the same switch)
! switch : func(v) { me.switchN.setBoolValue(v); me },
# light.toggle() -> toggle light switch
***************
*** 198,227 ****
# light.cont() -> continuous light
! cont : func { if (!me.continuous) { me.continuous = 1; me._switch_(); } me },
# light.blink() -> blinking light (default)
! blink : func { if (me.continuous) { me.continuous = 0; me._switch_(); } me },
_switch_ : func {
var switch = me.switchN.getBoolValue();
! if (me.switch == switch) {
! return;
! }
! me.switch = switch;
me.loopid += 1;
! if (me.continuous) {
me.stateN.setBoolValue(switch);
} elsif (switch) {
- me._loop_(me.loopid);
- } else {
me.stateN.setBoolValue(0);
}
},
_loop_ : func(id) {
! if (id != me.loopid) {
! return;
! }
! me.stateN.setBoolValue(var state = !me.stateN.getBoolValue());
settimer(func { me._loop_(id) }, state ? me.ontime : me.offtime);
},
--- 198,234 ----
# light.cont() -> continuous light
! cont : func {
! me.continuous and return;
! me.continuous = 1;
! me.loopid += 1;
! me.stateN.setBoolValue(me.lastswitch);
! me;
! },
# light.blink() -> blinking light (default)
! blink : func {
! me.continuous or return;
! me.continuous = 0;
! me.lastswitch and me._loop_(me.loopid += 1);
! me;
! },
_switch_ : func {
var switch = me.switchN.getBoolValue();
! switch != me.lastswitch or return;
! me.lastswitch = switch;
me.loopid += 1;
! if (me.continuous or !switch) {
me.stateN.setBoolValue(switch);
} elsif (switch) {
me.stateN.setBoolValue(0);
+ me._loop_(me.loopid);
}
},
_loop_ : func(id) {
! id == me.loopid or return;
! var state = !me.stateN.getBoolValue();
! me.stateN.setBoolValue(state);
settimer(func { me._loop_(id) }, state ? me.ontime : me.offtime);
},
|