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

View file

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

View file

@ -30,7 +30,7 @@ var new = func(layer) {
return m;
};
var del = func() {
#print("VOR.lcontroller.del()");
printlog(_MP_dbg_lvl, "VOR.lcontroller.del()");
foreach (var l; me.listeners)
removelistener(l);
};
@ -49,7 +49,7 @@ var changed_freq = func(update=1) {
if (update) me.layer.update();
};
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
};

View file

@ -383,11 +383,17 @@ var NavDisplay = {
# reset handler
handle_reinit: func {
print("Cleaning up NavDisplay listeners");
print("Cleaning up NavDisplay");
# shut down all timers and other loops here
me.update_timer.stop();
foreach(var l; me.listeners)
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) {
@ -434,6 +440,8 @@ var NavDisplay = {
new : func(prop1, switches=default_switches, style='Boeing') {
var m = { parents : [NavDisplay]};
m.inited = 0;
m.listeners=[]; # for cleanup handling
m.aircraft_source = NDSourceDriver.new(); # uses the main aircraft as the driver/source (speeds, position, heading)
@ -484,11 +492,14 @@ var NavDisplay = {
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.nd = canvas_group;
me.canvas_handle = parent;
# load the specified SVG file into the me.nd group and populate all sub groups
@ -587,7 +598,7 @@ var NavDisplay = {
if(!layer['isMapStructure'])
the_layer = me.layers[layer.name] = canvas.MAP_LAYERS[layer.name].new( render_target, layer.name, controller );
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);
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']));
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) {
var altRangeNm = altDiff/userVSpd*userSpd*KT2MPS*M2NM;
if(altRangeNm > 1) {