1
0
Fork 0

Canvas ND: Do del() on reinit

This also makes sure the /canvas/by-index/canvas[3/4]/ nodes are removed
and then recrated, as well as making sure the MapStructure del() path is
followed and working. Unfortunately the NDs are still blank after reinit.
This commit is contained in:
Philosopher 2014-01-23 21:13:54 -06:00
parent f61a391e45
commit a4f289ecee
4 changed files with 27 additions and 26 deletions

View file

@ -1,3 +1,5 @@
var _MP_dbg_lvl = "info";
var dump_obj = func(m) { var dump_obj = func(m) {
var h = {}; var h = {};
foreach (var k; keys(m)) foreach (var k; keys(m))
@ -235,11 +237,9 @@ var DotSym = {
), ),
}; };
if (m.controller != nil) { if (m.controller != nil) {
#print("Creating controller");
temp = m.controller.new(m.model,m); temp = m.controller.new(m.model,m);
if (temp != nil) if (temp != nil)
m.controller = temp; m.controller = temp;
#print("Initializing controller");
m.controller.init(model); m.controller.init(model);
} }
else die("default controller not found"); else die("default controller not found");
@ -248,7 +248,7 @@ var DotSym = {
return m; return m;
}, },
del: func() { del: func() {
#print("DotSym.del()"); printlog(_MP_dbg_lvl, "DotSym.del()");
me.deinit(); me.deinit();
if (me.controller != nil) if (me.controller != nil)
me.controller.del(me.model); me.controller.del(me.model);
@ -333,7 +333,7 @@ var SymbolLayer = {
e.update(); e.update();
}, },
del: func() { del: func() {
#print("SymbolLayer.del()"); printlog(_MP_dbg_lvl, "SymbolLayer.del()");
me.controller.del(); me.controller.del();
foreach (var e; me.list) foreach (var e; me.list)
e.del(); e.del();

View file

@ -422,26 +422,16 @@ var Map = {
df_controller: nil, df_controller: nil,
new: func(ghost) new: func(ghost)
{ {
return { parents: [Map, Group.new(ghost)] }; return { parents: [Map, Group.new(ghost)] }.setController();
}, },
del: func() del: func()
{ {
#print("canvas.Map.del()"); #print("canvas.Map.del()");
call(func { if (me.controller != nil)
me.controller.del(me); me.controller.del(me);
}, var err=[]); foreach (var k; keys(me.layers)) {
if (size(err)) { me.layers[k].del();
debug.printerror(err); delete(me.layers, k);
setsize(err, 0);
}
call(func {
foreach (var l; me.layers)
call(l[0].del, nil, l[0]);
setsize(me.layers, 0);
}, err);
if (size(err)) {
debug.printerror(err);
setsize(err, 0);
} }
# call inherited 'del' # call inherited 'del'
me.parents = subvec(me.parents,1); me.parents = subvec(me.parents,1);

View file

@ -30,7 +30,7 @@ var new = func(layer) {
return m; return m;
}; };
var del = func() { var del = func() {
#print("VOR.lcontroller.del()"); printlog(_MP_dbg_lvl, "VOR.lcontroller.del()");
foreach (var l; me.listeners) foreach (var l; me.listeners)
removelistener(l); removelistener(l);
}; };
@ -49,7 +49,7 @@ var changed_freq = func(update=1) {
if (update) me.layer.update(); if (update) me.layer.update();
}; };
var searchCmd = func { var searchCmd = func {
#print("Running query:", me.query_type); printlog(_MP_dbg_lvl, "Running query:", me.query_type);
return positioned.findWithinRange(100, me.query_type); # the range should also be exposed, it will typically be controlled via a GUI widget or NavDisplay switch return positioned.findWithinRange(100, me.query_type); # the range should also be exposed, it will typically be controlled via a GUI widget or NavDisplay switch
}; };

View file

@ -383,11 +383,17 @@ var NavDisplay = {
# reset handler # reset handler
handle_reinit: func { handle_reinit: func {
print("Cleaning up NavDisplay listeners"); print("Cleaning up NavDisplay");
# shut down all timers and other loops here # shut down all timers and other loops here
me.update_timer.stop(); me.update_timer.stop();
foreach(var l; me.listeners) foreach(var l; me.listeners)
removelistener(l); removelistener(l);
# clean up MapStructure
me.map.del();
# destroy the canvas
if (me.canvas_handle != nil)
me.canvas_handle.del();
me.inited = 0;
}, },
listen: func(p,c) { listen: func(p,c) {
@ -434,6 +440,8 @@ var NavDisplay = {
new : func(prop1, switches=default_switches, style='Boeing') { new : func(prop1, switches=default_switches, style='Boeing') {
var m = { parents : [NavDisplay]}; var m = { parents : [NavDisplay]};
m.inited = 0;
m.listeners=[]; # for cleanup handling m.listeners=[]; # for cleanup handling
m.aircraft_source = NDSourceDriver.new(); # uses the main aircraft as the driver/source (speeds, position, heading) m.aircraft_source = NDSourceDriver.new(); # uses the main aircraft as the driver/source (speeds, position, heading)
@ -484,11 +492,14 @@ var NavDisplay = {
return m; return m;
}, },
newMFD: func(canvas_group) newMFD: func(canvas_group, parent=nil)
{ {
me.listen("/sim/signals/reinit", func me.handle_reinit() ); if (me.inited) die("MFD already was added to scene");
me.inited = 1;
me.listen("/sim/signals/reinit", func(n) me.handle_reinit() );
me.update_timer = maketimer(0.05, func me.update() ); # TODO: make interval configurable via ctor me.update_timer = maketimer(0.05, func me.update() ); # TODO: make interval configurable via ctor
me.nd = canvas_group; me.nd = canvas_group;
me.canvas_handle = parent;
# load the specified SVG file into the me.nd group and populate all sub groups # load the specified SVG file into the me.nd group and populate all sub groups
@ -587,7 +598,7 @@ var NavDisplay = {
if(!layer['isMapStructure']) if(!layer['isMapStructure'])
the_layer = me.layers[layer.name] = canvas.MAP_LAYERS[layer.name].new( render_target, layer.name, controller ); the_layer = me.layers[layer.name] = canvas.MAP_LAYERS[layer.name].new( render_target, layer.name, controller );
else { else {
#print("Setting up MapStructure-based layer for ND, name:", layer.name); printlog(_MP_dbg_lvl, "Setting up MapStructure-based layer for ND, name:", layer.name);
render_target.addLayer(factory: canvas.SymbolLayer, type_arg: layer.name); render_target.addLayer(factory: canvas.SymbolLayer, type_arg: layer.name);
the_layer = me.layers[layer.name] = render_target.getLayer(layer.name); the_layer = me.layers[layer.name] = render_target.getLayer(layer.name);
} }
@ -990,7 +1001,7 @@ var NavDisplay = {
me.symbols.planArcs.setVisible(me.in_mode('toggle_display_mode', ['PLAN'])); me.symbols.planArcs.setVisible(me.in_mode('toggle_display_mode', ['PLAN']));
if (abs(userVSpd) > 5) { if (abs(userVSpd) > 5) {
var altDiff = getprop("autopilot/settings/target-altitude-ft")-getprop("instrumentation/altimeter/indicated-altitude-ft"); var altDiff = (getprop("autopilot/settings/target-altitude-ft") or 0)-(getprop("instrumentation/altimeter/indicated-altitude-ft") or 0);
if (abs(altDiff) > 50 and altDiff/userVSpd > 0) { if (abs(altDiff) > 50 and altDiff/userVSpd > 0) {
var altRangeNm = altDiff/userVSpd*userSpd*KT2MPS*M2NM; var altRangeNm = altDiff/userVSpd*userSpd*KT2MPS*M2NM;
if(altRangeNm > 1) { if(altRangeNm > 1) {