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:
parent
c3e20b0ffd
commit
40ff13b65b
6 changed files with 38 additions and 39 deletions
|
@ -9,9 +9,7 @@
|
|||
# + fuel-consumed-lbs - Output from the FDM, zeroed by this script
|
||||
# + out-of-fuel - boolean, set by this code.
|
||||
|
||||
|
||||
var UPDATE_PERIOD = 0.3;
|
||||
|
||||
var enabled = nil;
|
||||
var serviceable = nil;
|
||||
var fuel_freeze = nil;
|
||||
|
@ -176,9 +174,11 @@ var update_loop = func {
|
|||
foreach (var e; engines)
|
||||
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 {
|
||||
|
@ -213,7 +213,7 @@ setlistener("/sim/signals/fdm-initialized", func {
|
|||
setlistener("sim/freeze/fuel", func(n) fuel_freeze = n.getBoolValue(), 1);
|
||||
setlistener("sim/ai/enabled", func(n) ai_enabled = n.getBoolValue(), 1);
|
||||
setlistener("systems/refuel/serviceable", func(n) serviceable = n.getBoolValue(), 1);
|
||||
update_loop();
|
||||
aarTimer.restart(UPDATE_PERIOD);
|
||||
});
|
||||
|
||||
|
||||
|
|
|
@ -182,8 +182,6 @@ if (0) {
|
|||
var loop = func {
|
||||
if (view_number == cam_view and targetN != nil)
|
||||
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 {
|
||||
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("/engines/engine/speed-max-mps", 500);
|
||||
update_aircraft();
|
||||
loop();
|
||||
camTimer.start();
|
||||
});
|
||||
|
||||
|
||||
|
|
|
@ -20,11 +20,11 @@ updateContrail = func{
|
|||
} else {
|
||||
contrail_Node.setValue(0);
|
||||
}
|
||||
|
||||
settimer(updateContrail,30)
|
||||
}
|
||||
|
||||
### Contrail
|
||||
contrailTimer = maketimer(30, updateContrail);
|
||||
contrailTimer.simulatedTime = 1;
|
||||
|
||||
_setlistener("/sim/signals/nasal-dir-initialized", func {
|
||||
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 time_node = props.globals.getNode("sim/time/elapsed-sec", 1);
|
||||
|
||||
updateContrail();
|
||||
contrailTimer.restart(30);
|
||||
});
|
||||
|
|
|
@ -1,13 +1,18 @@
|
|||
_setlistener("/sim/signals/nasal-dir-initialized", func {
|
||||
_setlistener("/sim/presets/latitude-deg", func {
|
||||
printlog("info", "*** NEW LOCATION ***");
|
||||
settimer(func {
|
||||
seaportLoop = func {
|
||||
var typ = getprop("/sim/type");
|
||||
var lat = getprop("/position/latitude-deg");
|
||||
var lon = getprop("/position/longitude-deg");
|
||||
var g = geodinfo(lat, lon);
|
||||
if ((g != nil and g[1] != nil and g[1].solid) and (typ == "seaplane") )
|
||||
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);
|
||||
});
|
||||
|
|
|
@ -22,6 +22,7 @@ var SAVEDIR = getprop("/sim/fg-home") ~ "/Wildfire/";
|
|||
|
||||
# Maximum number of ignite events a single user can send per second.
|
||||
var MAX_IGNITE_RATE = 0.25;
|
||||
var wildfireScoreReportTimer = nil;
|
||||
|
||||
###############################################################################
|
||||
## External API
|
||||
|
@ -164,7 +165,6 @@ var score_report_loop = func {
|
|||
old_score.protected = score.protected;
|
||||
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.pending = []; # List of pending model changes.
|
||||
CAFireModels.models_enabled = 1;
|
||||
CAFireModels.loopid = 0;
|
||||
######################################################################
|
||||
# Public operations
|
||||
############################################################
|
||||
|
@ -470,14 +469,13 @@ CAFireModels.reset = func (enabled) {
|
|||
############################################################
|
||||
# Start the CA model grid.
|
||||
CAFireModels.start = func {
|
||||
me.loopid += 1;
|
||||
me._loop_(me.loopid);
|
||||
me.timer.restart(0.033); # 30hz should be fast enough.
|
||||
}
|
||||
############################################################
|
||||
# Stop the CA model grid.
|
||||
# Note that it will catch up lost time when started again.
|
||||
CAFireModels.stop = func {
|
||||
me.loopid += 1;
|
||||
me.timer.stop();
|
||||
}
|
||||
############################################################
|
||||
# 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_work = 0; # Cells to update in each pass.
|
||||
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.load_count = 0;
|
||||
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 {
|
||||
# Initialization.
|
||||
CAFireModels.timer = maketimer(0.03, me, me.loop);
|
||||
CAFireModels.timer.simulatedTime = 1;
|
||||
me.reset(1, SimTime.current_time());
|
||||
}
|
||||
############################################################
|
||||
|
@ -612,15 +605,12 @@ CAFire.reset = func (enabled, sim_time) {
|
|||
CAFire.start = func {
|
||||
CAFireModels.start();
|
||||
broadcast.start();
|
||||
me.loopid += 1;
|
||||
me._loop_(me.loopid);
|
||||
}
|
||||
############################################################
|
||||
# Stop the CA. Note that it will catch up lost time when started again.
|
||||
CAFire.stop = func {
|
||||
CAFireModels.stop();
|
||||
broadcast.stop();
|
||||
me.loopid += 1;
|
||||
}
|
||||
############################################################
|
||||
# Start a fire in the cell at pos.
|
||||
|
@ -931,12 +921,12 @@ CAFire.update = func {
|
|||
}
|
||||
}
|
||||
############################################################
|
||||
CAFire._loop_ = func(id) {
|
||||
id == me.loopid or return;
|
||||
CAFire.loop = func {
|
||||
me.update();
|
||||
settimer(func { me._loop_(id); },
|
||||
me.GENERATION_DURATION * (me.generation + 1/me.PASSES) -
|
||||
SimTime.current_time());
|
||||
CAFireModels.timer.restart(me.GENERATION_DURATION
|
||||
* (me.generation + 1/me.PASSES)
|
||||
- SimTime.current_time()
|
||||
);
|
||||
}
|
||||
###############################################################################
|
||||
|
||||
|
@ -973,7 +963,11 @@ _setlistener("/sim/signals/nasal-dir-initialized", func {
|
|||
CAFire.init();
|
||||
|
||||
# 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 {
|
||||
if (getprop(report_score_pp) and (CAFire.cells_created > 0))
|
||||
|
|
|
@ -22,7 +22,7 @@ var windsock = func {
|
|||
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);
|
||||
settimer(windsock, 0.25);
|
||||
}
|
||||
|
||||
windsock();
|
||||
windsockTimer = maketimer(0.25, windsock);
|
||||
windsockTimer.simulatedTime = 1;
|
||||
windsockTimer.start();
|
||||
|
|
Loading…
Reference in a new issue