Debian Codegraph @

Nasal/canvas/map/traffic.model

raw
1 # WARNING: *.model files will be deprecated, see: http://wiki.flightgear.org/MapStructure
2 var MPTrafficModel = {};
3 MPTrafficModel.new = func make(LayerModel, MPTrafficModel);
4
5 MPTrafficModel.init = func {
6 var pos = geo.Coord.new(); # FIXME: all of these should be instance variables
7 var myPosition = geo.Coord.new();
8 var myPositionVec = me._controller['get_position']();
9 myPosition.set_latlon( myPositionVec[0], myPositionVec[1]);
10 var max_dist_nm = me._controller['query_range']();
11
12 me._view.reset(); # hides: removeAllChildren()
13
14 # AI traffic
15 var traffic = props.globals.initNode("/ai/models/").getChildren( "aircraft" );
16 foreach(var t; traffic) {
17 pos.set_latlon( t.getNode("position/latitude-deg").getValue(),
18 t.getNode("position/longitude-deg").getValue()
19 );
20
21 if (pos.distance_to( myPosition ) <= max_dist_nm*NM2M )
22 me.push(t);
23 }
24 # Multiplayer traffic
25 var traffic = props.globals.initNode("/ai/models/").getChildren( "multiplayer" );
26 foreach(var t; traffic) {
27 pos.set_latlon( t.getNode("position/latitude-deg").getValue(),
28 t.getNode("position/longitude-deg").getValue()
29 );
30
31 if (pos.distance_to( myPosition ) <= max_dist_nm*NM2M )
32 me.push(t);
33 }
34
35 me.notifyView();
36
37 # update itself FIXME: this needs to be killed by the controller (e.g. when tcas layer is disabled)
38 # and the interval needs to be configurable via the controller
39 # so better use maketimer() here
40 settimer(func me.init(), 2);
41 }