diff --git a/Nasal/mp_broadcast.nas b/Nasal/mp_broadcast.nas index 702a3372d..63323bc11 100644 --- a/Nasal/mp_broadcast.nas +++ b/Nasal/mp_broadcast.nas @@ -2,7 +2,7 @@ ## ## 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. ## ############################################################################### @@ -69,7 +69,7 @@ BroadcastChannel.new = func (mpp_path, process, "BroadcastChannel invalid send node."); return nil; } - settimer(func { obj._loop_(obj.loopid); }, 0, 1); + obj.start(); return obj; } @@ -89,6 +89,13 @@ BroadcastChannel.die = func { me.loopid += 1; # 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. @@ -101,8 +108,8 @@ BroadcastChannel.update = func { var mpplayers = props.globals.getNode("/ai/models").getChildren("multiplayer"); foreach (var pilot; mpplayers) { - if ((pilot.getChild("valid") != nil) and - pilot.getChild("valid").getValue() and + var valid = pilot.getChild("valid"); + if ((valid != nil) and valid.getValue() and !contains(multiplayer.ignore, pilot.getChild("callsign").getValue())) { if ((me.peers[pilot.getIndex()] == nil) and diff --git a/Nasal/wildfire.nas b/Nasal/wildfire.nas index cdde00c41..1f6e96b4c 100644 --- a/Nasal/wildfire.nas +++ b/Nasal/wildfire.nas @@ -3,7 +3,7 @@ ## A cellular automaton forest fire model with the ability to ## 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. ## ############################################################################### @@ -192,7 +192,7 @@ var foam_drop_msg = func (pos, radius, volume) { } 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 type = Binary.decodeByte(substr(msg, 5)); if (type == 1) { @@ -459,10 +459,23 @@ CAFireModels.reset = func (enabled) { me.grid = {}; me.pending = []; + if (enabled) { + me.start(); + } +} +############################################################ +# Start the CA model grid. +CAFireModels.start = func { me.loopid += 1; 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. CAFireModels.add = func(x, y, alt) { append(me.pending, { x: x, y: y, alt: alt }); @@ -584,10 +597,28 @@ CAFire.reset = func (enabled, sim_time) { me.event_log = []; 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._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. CAFire.ignite = func (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"); SimTime.init(); - CAFire.init(); broadcast = 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 { 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); }, 3); } - # Start the score reporting. - settimer(score_report_loop, CAFire.GENERATION_DURATION); # Detect aircraft crash. setlistener("sim/crashed", func(n) { @@ -920,7 +952,7 @@ _setlistener("/sim/signals/nasal-dir-initialized", func { wildfire.ignite(geo.aircraft_position()); }); -# Detect impact + # Detect impact var impact_node = props.globals.getNode("sim/ai/aircraft/impact/bomb", 1); setlistener("sim/ai/aircraft/impact/bomb", func(n) {