Disable most loops when wildfire is disabled.
This commit is contained in:
parent
290a85b7b8
commit
2f79bdb473
2 changed files with 49 additions and 10 deletions
|
@ -2,7 +2,7 @@
|
||||||
##
|
##
|
||||||
## A message based information broadcast for the multiplayer network.
|
## A message based information broadcast for the multiplayer network.
|
||||||
##
|
##
|
||||||
## Copyright (C) 2008 - 2010 Anders Gidenstam (anders(at)gidenstam.org)
|
## Copyright (C) 2008 - 2011 Anders Gidenstam (anders(at)gidenstam.org)
|
||||||
## This file is licensed under the GPL license version 2 or later.
|
## This file is licensed under the GPL license version 2 or later.
|
||||||
##
|
##
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
@ -69,7 +69,7 @@ BroadcastChannel.new = func (mpp_path, process,
|
||||||
"BroadcastChannel invalid send node.");
|
"BroadcastChannel invalid send node.");
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
settimer(func { obj._loop_(obj.loopid); }, 0, 1);
|
obj.start();
|
||||||
|
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
@ -89,6 +89,13 @@ BroadcastChannel.die = func {
|
||||||
me.loopid += 1;
|
me.loopid += 1;
|
||||||
# print("BroadcastChannel[" ~ me.mpp_path ~ "] ... destroyed.");
|
# print("BroadcastChannel[" ~ me.mpp_path ~ "] ... destroyed.");
|
||||||
}
|
}
|
||||||
|
BroadcastChannel.start = func {
|
||||||
|
me.loopid += 1;
|
||||||
|
settimer(func { me._loop_(me.loopid); }, 0, 1);
|
||||||
|
}
|
||||||
|
BroadcastChannel.stop = func {
|
||||||
|
me.loopid += 1;
|
||||||
|
}
|
||||||
|
|
||||||
############################################################
|
############################################################
|
||||||
# Internals.
|
# Internals.
|
||||||
|
@ -101,8 +108,8 @@ BroadcastChannel.update = func {
|
||||||
var mpplayers =
|
var mpplayers =
|
||||||
props.globals.getNode("/ai/models").getChildren("multiplayer");
|
props.globals.getNode("/ai/models").getChildren("multiplayer");
|
||||||
foreach (var pilot; mpplayers) {
|
foreach (var pilot; mpplayers) {
|
||||||
if ((pilot.getChild("valid") != nil) and
|
var valid = pilot.getChild("valid");
|
||||||
pilot.getChild("valid").getValue() and
|
if ((valid != nil) and valid.getValue() and
|
||||||
!contains(multiplayer.ignore,
|
!contains(multiplayer.ignore,
|
||||||
pilot.getChild("callsign").getValue())) {
|
pilot.getChild("callsign").getValue())) {
|
||||||
if ((me.peers[pilot.getIndex()] == nil) and
|
if ((me.peers[pilot.getIndex()] == nil) and
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
## A cellular automaton forest fire model with the ability to
|
## A cellular automaton forest fire model with the ability to
|
||||||
## spread over the multiplayer network.
|
## spread over the multiplayer network.
|
||||||
##
|
##
|
||||||
## Copyright (C) 2007 - 2010 Anders Gidenstam (anders(at)gidenstam.org)
|
## Copyright (C) 2007 - 2011 Anders Gidenstam (anders(at)gidenstam.org)
|
||||||
## This file is licensed under the GPL license version 2 or later.
|
## This file is licensed under the GPL license version 2 or later.
|
||||||
##
|
##
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
@ -192,7 +192,7 @@ var foam_drop_msg = func (pos, radius, volume) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var parse_msg = func (source, msg) {
|
var parse_msg = func (source, msg) {
|
||||||
if (!getprop(MP_share_pp)) return;
|
if (!getprop(MP_share_pp) or !getprop(CA_enabled_pp)) return;
|
||||||
var cur_time = systime();
|
var cur_time = systime();
|
||||||
var type = Binary.decodeByte(substr(msg, 5));
|
var type = Binary.decodeByte(substr(msg, 5));
|
||||||
if (type == 1) {
|
if (type == 1) {
|
||||||
|
@ -459,10 +459,23 @@ CAFireModels.reset = func (enabled) {
|
||||||
me.grid = {};
|
me.grid = {};
|
||||||
me.pending = [];
|
me.pending = [];
|
||||||
|
|
||||||
|
if (enabled) {
|
||||||
|
me.start();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
############################################################
|
||||||
|
# Start the CA model grid.
|
||||||
|
CAFireModels.start = func {
|
||||||
me.loopid += 1;
|
me.loopid += 1;
|
||||||
me._loop_(me.loopid);
|
me._loop_(me.loopid);
|
||||||
}
|
}
|
||||||
############################################################
|
############################################################
|
||||||
|
# Stop the CA model grid.
|
||||||
|
# Note that it will catch up lost time when started again.
|
||||||
|
CAFireModels.stop = func {
|
||||||
|
me.loopid += 1;
|
||||||
|
}
|
||||||
|
############################################################
|
||||||
# Add a new cell model.
|
# Add a new cell model.
|
||||||
CAFireModels.add = func(x, y, alt) {
|
CAFireModels.add = func(x, y, alt) {
|
||||||
append(me.pending, { x: x, y: y, alt: alt });
|
append(me.pending, { x: x, y: y, alt: alt });
|
||||||
|
@ -584,10 +597,28 @@ CAFire.reset = func (enabled, sim_time) {
|
||||||
me.event_log = [];
|
me.event_log = [];
|
||||||
|
|
||||||
me.enabled = enabled;
|
me.enabled = enabled;
|
||||||
|
if (me.enabled) {
|
||||||
|
me.start();
|
||||||
|
} else {
|
||||||
|
me.stop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
############################################################
|
||||||
|
# Start the CA.
|
||||||
|
CAFire.start = func {
|
||||||
|
CAFireModels.start();
|
||||||
|
broadcast.start();
|
||||||
me.loopid += 1;
|
me.loopid += 1;
|
||||||
me._loop_(me.loopid);
|
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.
|
# Start a fire in the cell at pos.
|
||||||
CAFire.ignite = func (lat, lon) {
|
CAFire.ignite = func (lat, lon) {
|
||||||
trace("CAFire.ignite: Fire at " ~ lat ~", " ~ lon ~ ".");
|
trace("CAFire.ignite: Fire at " ~ lat ~", " ~ lon ~ ".");
|
||||||
|
@ -894,9 +925,12 @@ _setlistener("/sim/signals/nasal-dir-initialized", func {
|
||||||
props.globals.initNode(smoke_LOD_pp, 10, "INT");
|
props.globals.initNode(smoke_LOD_pp, 10, "INT");
|
||||||
|
|
||||||
SimTime.init();
|
SimTime.init();
|
||||||
CAFire.init();
|
|
||||||
broadcast =
|
broadcast =
|
||||||
mp_broadcast.BroadcastChannel.new(msg_channel_mpp, parse_msg);
|
mp_broadcast.BroadcastChannel.new(msg_channel_mpp, parse_msg);
|
||||||
|
CAFire.init();
|
||||||
|
|
||||||
|
# Start the score reporting.
|
||||||
|
settimer(score_report_loop, CAFire.GENERATION_DURATION);
|
||||||
|
|
||||||
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))
|
||||||
|
@ -911,8 +945,6 @@ _setlistener("/sim/signals/nasal-dir-initialized", func {
|
||||||
CAFire.load_event_log(SAVEDIR ~ "fire_log.xml", 1);
|
CAFire.load_event_log(SAVEDIR ~ "fire_log.xml", 1);
|
||||||
}, 3);
|
}, 3);
|
||||||
}
|
}
|
||||||
# Start the score reporting.
|
|
||||||
settimer(score_report_loop, CAFire.GENERATION_DURATION);
|
|
||||||
|
|
||||||
# Detect aircraft crash.
|
# Detect aircraft crash.
|
||||||
setlistener("sim/crashed", func(n) {
|
setlistener("sim/crashed", func(n) {
|
||||||
|
@ -920,7 +952,7 @@ _setlistener("/sim/signals/nasal-dir-initialized", func {
|
||||||
wildfire.ignite(geo.aircraft_position());
|
wildfire.ignite(geo.aircraft_position());
|
||||||
});
|
});
|
||||||
|
|
||||||
# Detect impact
|
# Detect impact
|
||||||
var impact_node = props.globals.getNode("sim/ai/aircraft/impact/bomb", 1);
|
var impact_node = props.globals.getNode("sim/ai/aircraft/impact/bomb", 1);
|
||||||
setlistener("sim/ai/aircraft/impact/bomb", func(n) {
|
setlistener("sim/ai/aircraft/impact/bomb", func(n) {
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue