1
0
Fork 0

Reposition slowdown settimer fixes.

Definitely problems in aar.nas, seaport.nas; as these were hanging off a fdm-initialized.

The others have timers that are started from a listener and as such are more suited to use maketimer rather than settimer

The modules that use the loopid technique are probably fine, but these are also more suited (and easier to understand) using a maketimer
This commit is contained in:
Richard Harrison 2018-09-14 22:50:47 +02:00
parent c3e20b0ffd
commit 40ff13b65b
6 changed files with 38 additions and 39 deletions

View file

@ -9,9 +9,7 @@
# + fuel-consumed-lbs - Output from the FDM, zeroed by this script # + fuel-consumed-lbs - Output from the FDM, zeroed by this script
# + out-of-fuel - boolean, set by this code. # + out-of-fuel - boolean, set by this code.
var UPDATE_PERIOD = 0.3; var UPDATE_PERIOD = 0.3;
var enabled = nil; var enabled = nil;
var serviceable = nil; var serviceable = nil;
var fuel_freeze = nil; var fuel_freeze = nil;
@ -176,9 +174,11 @@ var update_loop = func {
foreach (var e; engines) foreach (var e; engines)
e.getNode("out-of-fuel", 1).setBoolValue(out_of_fuel); e.getNode("out-of-fuel", 1).setBoolValue(out_of_fuel);
settimer(update_loop, UPDATE_PERIOD); aarTimer.restart(UPDATE_PERIOD);
} }
var aarTimer = maketimer(UPDATE_PERIOD, update_loop);
aarTimer.simulatedTime = 1;
setlistener("/sim/signals/fdm-initialized", func { setlistener("/sim/signals/fdm-initialized", func {
@ -213,7 +213,7 @@ setlistener("/sim/signals/fdm-initialized", func {
setlistener("sim/freeze/fuel", func(n) fuel_freeze = n.getBoolValue(), 1); setlistener("sim/freeze/fuel", func(n) fuel_freeze = n.getBoolValue(), 1);
setlistener("sim/ai/enabled", func(n) ai_enabled = n.getBoolValue(), 1); setlistener("sim/ai/enabled", func(n) ai_enabled = n.getBoolValue(), 1);
setlistener("systems/refuel/serviceable", func(n) serviceable = n.getBoolValue(), 1); setlistener("systems/refuel/serviceable", func(n) serviceable = n.getBoolValue(), 1);
update_loop(); aarTimer.restart(UPDATE_PERIOD);
}); });

View file

@ -182,8 +182,6 @@ if (0) {
var loop = func { var loop = func {
if (view_number == cam_view and targetN != nil) if (view_number == cam_view and targetN != nil)
update(); update();
settimer(loop, 0);
} }
@ -301,6 +299,8 @@ setlistener("/sim/cam/lock", func(n) {
}); });
} }
camTimer = maketimer(0, loop);
camTimer.simulatedTime = 1;
setlistener("/sim/signals/fdm-initialized", func { setlistener("/sim/signals/fdm-initialized", func {
var views = props.globals.getNode("/sim").getChildren("view"); var views = props.globals.getNode("/sim").getChildren("view");
@ -311,7 +311,7 @@ setlistener("/sim/signals/fdm-initialized", func {
setprop("/sim/current-view/view-number", cam_view); setprop("/sim/current-view/view-number", cam_view);
setprop("/engines/engine/speed-max-mps", 500); setprop("/engines/engine/speed-max-mps", 500);
update_aircraft(); update_aircraft();
loop(); camTimer.start();
}); });

View file

@ -20,11 +20,11 @@ updateContrail = func{
} else { } else {
contrail_Node.setValue(0); contrail_Node.setValue(0);
} }
settimer(updateContrail,30)
} }
### Contrail ### Contrail
contrailTimer = maketimer(30, updateContrail);
contrailTimer.simulatedTime = 1;
_setlistener("/sim/signals/nasal-dir-initialized", func { _setlistener("/sim/signals/nasal-dir-initialized", func {
printlog ("debug", "init contrail"); printlog ("debug", "init contrail");
@ -35,5 +35,5 @@ _setlistener("/sim/signals/nasal-dir-initialized", func {
var static_contrail_node = props.globals.getNode("sim/ai/aircraft/contrail", 1); var static_contrail_node = props.globals.getNode("sim/ai/aircraft/contrail", 1);
var time_node = props.globals.getNode("sim/time/elapsed-sec", 1); var time_node = props.globals.getNode("sim/time/elapsed-sec", 1);
updateContrail(); contrailTimer.restart(30);
}); });

View file

@ -1,13 +1,18 @@
_setlistener("/sim/signals/nasal-dir-initialized", func { seaportLoop = func {
_setlistener("/sim/presets/latitude-deg", func {
printlog("info", "*** NEW LOCATION ***");
settimer(func {
var typ = getprop("/sim/type"); var typ = getprop("/sim/type");
var lat = getprop("/position/latitude-deg"); var lat = getprop("/position/latitude-deg");
var lon = getprop("/position/longitude-deg"); var lon = getprop("/position/longitude-deg");
var g = geodinfo(lat, lon); var g = geodinfo(lat, lon);
if ((g != nil and g[1] != nil and g[1].solid) and (typ == "seaplane") ) if ((g != nil and g[1] != nil and g[1].solid) and (typ == "seaplane") )
fgcommand("dialog-show", props.Node.new({ "dialog-name": "seaport" })); fgcommand("dialog-show", props.Node.new({ "dialog-name": "seaport" }));
}, 8); };
seaportTimer = maketimer(8, seaportLoop);
seaportTimer.simulatedTime = 1;
_setlistener("/sim/signals/nasal-dir-initialized", func {
_setlistener("/sim/presets/latitude-deg", func {
printlog("info", "*** NEW LOCATION ***");
seaportTimer.restart(8);
}, 1); }, 1);
}); });

View file

@ -22,6 +22,7 @@ var SAVEDIR = getprop("/sim/fg-home") ~ "/Wildfire/";
# Maximum number of ignite events a single user can send per second. # Maximum number of ignite events a single user can send per second.
var MAX_IGNITE_RATE = 0.25; var MAX_IGNITE_RATE = 0.25;
var wildfireScoreReportTimer = nil;
############################################################################### ###############################################################################
## External API ## External API
@ -164,7 +165,6 @@ var score_report_loop = func {
old_score.protected = score.protected; old_score.protected = score.protected;
old_score.waste = score.waste; old_score.waste = score.waste;
} }
settimer(score_report_loop, CAFire.GENERATION_DURATION);
} }
############################################################################### ###############################################################################
@ -439,7 +439,6 @@ CAFireModels.MODEL = { # Model paths
CAFireModels.grid = {}; # Sparse cell model grid storage. CAFireModels.grid = {}; # Sparse cell model grid storage.
CAFireModels.pending = []; # List of pending model changes. CAFireModels.pending = []; # List of pending model changes.
CAFireModels.models_enabled = 1; CAFireModels.models_enabled = 1;
CAFireModels.loopid = 0;
###################################################################### ######################################################################
# Public operations # Public operations
############################################################ ############################################################
@ -470,14 +469,13 @@ CAFireModels.reset = func (enabled) {
############################################################ ############################################################
# Start the CA model grid. # Start the CA model grid.
CAFireModels.start = func { CAFireModels.start = func {
me.loopid += 1; me.timer.restart(0.033); # 30hz should be fast enough.
me._loop_(me.loopid);
} }
############################################################ ############################################################
# Stop the CA model grid. # Stop the CA model grid.
# Note that it will catch up lost time when started again. # Note that it will catch up lost time when started again.
CAFireModels.stop = func { CAFireModels.stop = func {
me.loopid += 1; me.timer.stop();
} }
############################################################ ############################################################
# Add a new cell model. # Add a new cell model.
@ -516,12 +514,6 @@ CAFireModels.update = func {
} }
} }
} }
############################################################
CAFireModels._loop_ = func(id) {
id == me.loopid or return;
me.update();
settimer(func { me._loop_(id); }, 0);
}
############################################################################### ###############################################################################
############################################################################### ###############################################################################
@ -543,7 +535,6 @@ CAFire.cells_burning = 0;
CAFire.pass = 0; # Update pass within the current full update. CAFire.pass = 0; # Update pass within the current full update.
CAFire.pass_work = 0; # Cells to update in each pass. CAFire.pass_work = 0; # Cells to update in each pass.
CAFire.remaining_work = []; # Work remaining in this full update. CAFire.remaining_work = []; # Work remaining in this full update.
CAFire.loopid = 0;
CAFire.event_log = []; # List of all events that has occured so far. CAFire.event_log = []; # List of all events that has occured so far.
CAFire.load_count = 0; CAFire.load_count = 0;
CAFire.BURN_RATE = { # Burn rate DB. grid widths per second CAFire.BURN_RATE = { # Burn rate DB. grid widths per second
@ -580,6 +571,8 @@ CAFire.NEIGHBOURS = # Neighbour index offsets. First row and column
############################################################ ############################################################
CAFire.init = func { CAFire.init = func {
# Initialization. # Initialization.
CAFireModels.timer = maketimer(0.03, me, me.loop);
CAFireModels.timer.simulatedTime = 1;
me.reset(1, SimTime.current_time()); me.reset(1, SimTime.current_time());
} }
############################################################ ############################################################
@ -612,15 +605,12 @@ CAFire.reset = func (enabled, sim_time) {
CAFire.start = func { CAFire.start = func {
CAFireModels.start(); CAFireModels.start();
broadcast.start(); broadcast.start();
me.loopid += 1;
me._loop_(me.loopid);
} }
############################################################ ############################################################
# Stop the CA. Note that it will catch up lost time when started again. # Stop the CA. Note that it will catch up lost time when started again.
CAFire.stop = func { CAFire.stop = func {
CAFireModels.stop(); CAFireModels.stop();
broadcast.stop(); broadcast.stop();
me.loopid += 1;
} }
############################################################ ############################################################
# Start a fire in the cell at pos. # Start a fire in the cell at pos.
@ -931,12 +921,12 @@ CAFire.update = func {
} }
} }
############################################################ ############################################################
CAFire._loop_ = func(id) { CAFire.loop = func {
id == me.loopid or return;
me.update(); me.update();
settimer(func { me._loop_(id); }, CAFireModels.timer.restart(me.GENERATION_DURATION
me.GENERATION_DURATION * (me.generation + 1/me.PASSES) - * (me.generation + 1/me.PASSES)
SimTime.current_time()); - SimTime.current_time()
);
} }
############################################################################### ###############################################################################
@ -973,7 +963,11 @@ _setlistener("/sim/signals/nasal-dir-initialized", func {
CAFire.init(); CAFire.init();
# Start the score reporting. # Start the score reporting.
settimer(score_report_loop, CAFire.GENERATION_DURATION); if (wildfireScoreReportTimer == nil){
wildfireScoreReportTimer = maketimer(CAFire.GENERATION_DURATION, score_report_loop);
wildfireScoreReportTimer.simulatedTime = 1;
wildfireScoreReportTimer.start();
}
setlistener("/sim/signals/exit", func { setlistener("/sim/signals/exit", func {
if (getprop(report_score_pp) and (CAFire.cells_created > 0)) if (getprop(report_score_pp) and (CAFire.cells_created > 0))

View file

@ -22,7 +22,7 @@ var windsock = func {
interpolate("/environment/windsock/wind-speed-12.5kt", total, 0.1); interpolate("/environment/windsock/wind-speed-12.5kt", total, 0.1);
dt += 0.08 + 0.02*(math.sin(dt)+math.cos(dt/(mag2+0.01))*0.33); dt += 0.08 + 0.02*(math.sin(dt)+math.cos(dt/(mag2+0.01))*0.33);
settimer(windsock, 0.25);
} }
windsockTimer = maketimer(0.25, windsock);
windsock(); windsockTimer.simulatedTime = 1;
windsockTimer.start();