1
0
Fork 0

new light.new() arguments with light pattern array; error message for old

style args
This commit is contained in:
mfranz 2006-12-06 15:58:03 +00:00
parent 79fea79cae
commit 28323bcec8

View file

@ -7,8 +7,8 @@
# anonymous if you don't need further access to their members. On the # anonymous if you don't need further access to their members. On the
# other hand, you can assign the class and apply setters at the same time: # other hand, you can assign the class and apply setters at the same time:
# #
# aircraft.light.new("sim/model/foo/beacon"); # anonymous # aircraft.light.new("sim/model/foo/beacon", [1, 1]); # anonymous
# strobe = aircraft.light.new("sim/model/foo/strobe").cont().switch(1); # var strobe = aircraft.light.new("sim/model/foo/strobe", [1, 1]).cont().switch(1);
# #
# #
# Classes do create properties, but they don't usually overwrite the contents # Classes do create properties, but they don't usually overwrite the contents
@ -23,11 +23,11 @@
# always be accessed directly as member "node", and turned into a path # always be accessed directly as member "node", and turned into a path
# string with node.getPath(): # string with node.getPath():
# #
# beacon = aircraft.light.new("sim/model/foo/beacon"); # var beacon = aircraft.light.new("sim/model/foo/beacon", [1, 1]);
# print(beacon.node.getPath()); # print(beacon.node.getPath());
# #
# strobe_node = props.globals.getNode("sim/model/foo/strobe", 1); # var strobe_node = props.globals.getNode("sim/model/foo/strobe", 1);
# strobe = aircraft.light.new(strobe_node, 0.05, 1.0); # var strobe = aircraft.light.new(strobe_node, [0.05, 1.0]);
# #
# #
# The classes implement only commonly used features, but are easy to # The classes implement only commonly used features, but are easy to
@ -86,7 +86,7 @@ optarg = func {
# ./enabled (bool) (default: 1) # ./enabled (bool) (default: 1)
# #
# EXAMPLE: # EXAMPLE:
# canopy = aircraft.door.new("sim/model/foo/canopy", 5); # var canopy = aircraft.door.new("sim/model/foo/canopy", 5);
# canopy.open(); # canopy.open();
# #
door = { door = {
@ -143,11 +143,12 @@ door = {
# beacons, strobes, etc. # beacons, strobes, etc.
# #
# SYNOPSIS: # SYNOPSIS:
# light.new(<property> [, <ontime> [, <offtime> [, <switch>]]]); # light.new(<property>, <pattern> [, <switch>]);
# light.new(<property>, <stretch>, <pattern> [, <switch>]);
# #
# property ... light node: property path or node # property ... light node: property path or node
# ontime ... time that the light is on when blinking (default: 0.5 [s]) # stretch ... multiplicator for all pattern values
# offtime ... time that the light is off when blinking (default: <ontime>) # pattern ... array of on/off time intervals (in seconds)
# switch ... property path or node to use as switch (default: ./enabled) # switch ... property path or node to use as switch (default: ./enabled)
# instead of ./enabled # instead of ./enabled
# #
@ -156,19 +157,35 @@ door = {
# ./enabled (bool) (default: 0) except if <switch> given) # ./enabled (bool) (default: 0) except if <switch> given)
# #
# EXAMPLES: # EXAMPLES:
# aircraft.light.new("sim/model/foo/beacon", 0.4); # anonymous light # aircraft.light.new("sim/model/foo/beacon", [0.4, 0.4]); # anonymous light
# strobe = aircraft.light.new("sim/model/foo/strobe", 0.05, 1.0, #
# var strobe = aircraft.light.new("sim/model/foo/strobe", [0.05, 0.05, 0.05, 1],
# "controls/lighting/strobe"); # "controls/lighting/strobe");
# strobe.switch(1); # strobe.switch(1);
# #
# var pattern = [0.05, 0.05, 0.05, 1];
# aircraft.light.new("sim/model/foo/strobe-top", 1.001, pattern, "controls/lighting/strobe");
# aircraft.light.new("sim/model/foo/strobe-bot", 1.005, pattern, "controls/lighting/strobe");
#
light = { light = {
new : func { new : func {
m = { parents : [light] }; m = { parents : [light] };
m.node = makeNode(arg[0]); m.node = makeNode(arg[0]);
m.ontime = optarg(arg, 1, 0.5); var stretch = 1.0;
m.offtime = optarg(arg, 2, m.ontime); var c = 1;
if (size(arg) > 3 and arg[3] != nil) { if (typeof(arg[c]) == "scalar") {
m.switchN = makeNode(arg[3]); stretch = arg[c];
c += 1;
}
if (typeof(arg[c]) != "vector") {
die("aircraft.nas: the arguments of aircraft.light.new() have changed!\n" ~
" *** BEFORE: aircraft.light.new(property, 0.1, 0.9, switch)\n" ~
" *** NOW: aircraft.light.new(property, [0.1, 0.9], switch)");
}
m.pattern = arg[c];
c += 1;
if (size(arg) > c and arg[c] != nil) {
m.switchN = makeNode(arg[c]);
} else { } else {
m.switchN = m.node.getNode("enabled", 1); m.switchN = m.node.getNode("enabled", 1);
} }
@ -179,8 +196,12 @@ light = {
if (m.stateN.getValue() == nil) { if (m.stateN.getValue() == nil) {
m.stateN.setBoolValue(0); m.stateN.setBoolValue(0);
} }
m.continuous = 0; forindex (var i; m.pattern) {
m.pattern[i] *= stretch;
}
m.index = 0;
m.loopid = 0; m.loopid = 0;
m.continuous = 0;
m.lastswitch = 0; m.lastswitch = 0;
m.switchL = setlistener(m.switchN, func { m._switch_() }, 1); m.switchL = setlistener(m.switchN, func { m._switch_() }, 1);
return m; return m;
@ -210,6 +231,8 @@ light = {
blink : func { blink : func {
if (me.continuous) { if (me.continuous) {
me.continuous = 0; me.continuous = 0;
me.index = 0;
me.stateN.setBoolValue(0);
me.lastswitch and me._loop_(me.loopid += 1); me.lastswitch and me._loop_(me.loopid += 1);
} }
me; me;
@ -224,15 +247,18 @@ light = {
me.stateN.setBoolValue(switch); me.stateN.setBoolValue(switch);
} elsif (switch) { } elsif (switch) {
me.stateN.setBoolValue(0); me.stateN.setBoolValue(0);
me.index = 0;
me._loop_(me.loopid); me._loop_(me.loopid);
} }
}, },
_loop_ : func(id) { _loop_ : func(id) {
id == me.loopid or return; id == me.loopid or return;
var state = !me.stateN.getBoolValue(); me.stateN.setBoolValue(!me.stateN.getBoolValue());
me.stateN.setBoolValue(state); settimer(func { me._loop_(id) }, me.pattern[me.index]);
settimer(func { me._loop_(id) }, state ? me.ontime : me.offtime); if ((me.index += 1) >= size(me.pattern)) {
me.index = 0;
}
}, },
}; };