From 77aa7b242934b6875113a8e40f4406153e7a664f Mon Sep 17 00:00:00 2001 From: Inuyaksa Date: Mon, 15 Feb 2021 23:12:07 +0100 Subject: [PATCH] display water and some optimization on reference calculations --- Models/FlightDeck/a320.flightdeck.xml | 2 +- Models/Instruments/ND/canvas/ND.nas | 1 - .../ND/canvas/framework/navdisplay.nas | 6 +- Models/Instruments/ND/canvas/loaders.nas | 2 +- .../Instruments/ND/canvas/map/TERRAIN.symbol | 111 ++++++++++-------- .../ND/canvas/res/terrain/tile_s1.png | Bin 0 -> 1851 bytes Models/Instruments/ND/canvas/style.nas | 7 +- 7 files changed, 72 insertions(+), 57 deletions(-) create mode 100644 Models/Instruments/ND/canvas/res/terrain/tile_s1.png diff --git a/Models/FlightDeck/a320.flightdeck.xml b/Models/FlightDeck/a320.flightdeck.xml index 53e2b24b..d0e52b2a 100644 --- a/Models/FlightDeck/a320.flightdeck.xml +++ b/Models/FlightDeck/a320.flightdeck.xml @@ -1457,7 +1457,7 @@ property-toggle - instrumentation/efis[0]/inputs/terr + instrumentation/efis/inputs/terr diff --git a/Models/Instruments/ND/canvas/ND.nas b/Models/Instruments/ND/canvas/ND.nas index 90d5321c..543b0722 100644 --- a/Models/Instruments/ND/canvas/ND.nas +++ b/Models/Instruments/ND/canvas/ND.nas @@ -64,7 +64,6 @@ var myCockpit_switches = { "toggle_xtrk_error": {path: "/nd/xtrk-error", value: 0, type: "BOOL"}, "toggle_trk_line": {path: "/nd/trk-line", value: 0, type: "BOOL"}, "ADIRS3": {path: "/nd/ir-3", value: 0, type: "BOOL"}, - #"toggle_terrain": {path: "/nd/terrain-on-nd", value: 0, type: "BOOL"}, }; var canvas_nd_base = { diff --git a/Models/Instruments/ND/canvas/framework/navdisplay.nas b/Models/Instruments/ND/canvas/framework/navdisplay.nas index 0f5e116c..594b5fd0 100644 --- a/Models/Instruments/ND/canvas/framework/navdisplay.nas +++ b/Models/Instruments/ND/canvas/framework/navdisplay.nas @@ -375,9 +375,9 @@ canvas.NavDisplay.update = func() # FIXME: This stuff is still too aircraft spec wxr_live_enabled = 0; me.set_switch('toggle_weather_live', wxr_live_enabled); - var terr_enabled = getprop("/controls/switches/terr_on_nd_l"); - if (terr_enabled == nil) terr_enabled = 0; - if (me.get_switch('toggle_terrain') != terr_enabled) me.set_switch('toggle_terrain', terr_enabled); + #var terr_enabled = getprop("/controls/switches/terr_on_nd_l"); + #if (terr_enabled == nil) terr_enabled = 0; + #if (me.get_switch('toggle_terrain') != terr_enabled) me.set_switch('toggle_terrain', terr_enabled); call(me.update_sub, nil, nil, caller(0)[0]); # call this in the same namespace to "steal" its variables diff --git a/Models/Instruments/ND/canvas/loaders.nas b/Models/Instruments/ND/canvas/loaders.nas index ed72a08d..e8cb8782 100644 --- a/Models/Instruments/ND/canvas/loaders.nas +++ b/Models/Instruments/ND/canvas/loaders.nas @@ -28,7 +28,7 @@ setlistener("/nasal/canvas/loaded", func() { #var code = call(compile, [code], var err=[]); var code = call(func compile(code, file), [code], var err=[]); if (size(err)) { - print("handling error"); + #print("handling error"); if (substr(err[0], 0, 12) == "Parse error:") { # hack around Nasal feature var e = split(" at line ", err[0]); if (size(e) == 2) diff --git a/Models/Instruments/ND/canvas/map/TERRAIN.symbol b/Models/Instruments/ND/canvas/map/TERRAIN.symbol index eafbf4a1..2e8e963d 100644 --- a/Models/Instruments/ND/canvas/map/TERRAIN.symbol +++ b/Models/Instruments/ND/canvas/map/TERRAIN.symbol @@ -7,22 +7,27 @@ DotSym.makeinstance( name, __self__ ); var element_type = "group"; -var terrain_visible = props.globals.initNode("/custom/terrain/visible", 0,"INT"); var terrain_minalt = props.globals.initNode("/custom/terrain/min-altitude", 0,"INT"); var terrain_maxalt = props.globals.initNode("/custom/terrain/max-altitude", -9999,"INT"); -var tile_list = ["*black*","tile_01.png","tile_02.png","tile_03.png","tile_04.png","tile_06.png","tile_09.png"]; +var tile_list = ["*black*","tile_01.png","tile_02.png","tile_03.png","tile_04.png","tile_06.png","tile_09.png","tile_s1.png"]; +var is_terrain = 0; var get_elevation = func (lat, lon) { var info = geodinfo(lat, lon); var elevation = 0; - if (info != nil) { elevation = int(info[0] * 3.2808399); } + if (info != nil) { + elevation = int(info[0] * 3.2808399); + me.is_terrain = (info[1] == nil) ? 1 : info[1].solid; + } else { elevation = nil; } return elevation; } -var updateTerrain = func(r_scaled){ +var updateTerrain = func { + + if (me.reference == nil) return; if(me.fetching) return; @@ -36,18 +41,11 @@ var updateTerrain = func(r_scaled){ var RAD2DEG = 57.2957795; var DEG2RAD = 0.016774532925; - var pos = geo.aircraft_position(); - var pos_lat = pos.lat(); - var pos_lon = pos.lon(); + var pos_lat = me.reference.lat(); + var pos_lon = me.reference.lon(); - var heading = getprop("orientation/heading-magnetic-deg"); - var altitudeft = pos.alt() * 3.2808399; - - if (me.basealtitudeft == nil) { - var basealtft = me.get_elevation(pos_lat,pos_lon); - if (basealtft == nil) basealtft = 0; - me.basealtitudeft = basealtft + 400; - } + var heading = me.reference.heading; + var altitudeft = me.reference.altitudeft; var side = (math.mod(me.radar_beacon,2)==0) ? "L" : "R"; var a = int(me.radar_beacon/2); @@ -82,21 +80,26 @@ var updateTerrain = func(r_scaled){ var elev = me.get_elevation(point_lat, point_lon); var grad = 0; #black if (elev != nil) { - if (elevme.max_altitude) me.max_altitude = elev; - if (elev < me.basealtitudeft) grad = 0; # < 400 (at airport) use blank - trivial - else { - var diff = elev - altitudeft; - if (diff>=0) { - grad = int(diff/1000) + 3; - if (grad>5) grad = 5; - } else { - if (diff>-500) grad = 3; # lite yellow - else { - grad = 2 + int(diff/1000); - if (grad<0) grad = 0; + if (me.is_terrain) { + if (elevme.max_altitude) me.max_altitude = elev; + if (elev < me.basealtitudeft) grad = 0; # < 400 near runway use blank + else { + var diff = elev - altitudeft; + if (diff>=0) { + grad = int(diff/1000) + 3; + if (grad>5) grad = 5; + } else { + if (diff>-500) grad = 3; # lite yellow + else { + grad = 2 + int(diff/1000); + if (grad<0) grad = 0; + } } } + } else { + var diff = elev - altitudeft; + if (diff>=-2000) grad = 7; #sea } append(elevft,grad); # 0-5 } else { @@ -149,10 +152,11 @@ var init = func { me.radar_cycle = 0; me.radar_cleared = 1; me.request_clear = 0; - me.basealtitudeft = nil; me.visible = 0; me.min_altitude = 9999; me.max_altitude = -9999; + me.basealtitudeft = nil; + me.reference = nil; var tile = me.tile; @@ -192,14 +196,10 @@ var init = func { me.terrlayer["R" ~ c] = grprx; } - #me.update_interval = 300; - #me.last_request = 0; + setlistener("/controls/switches/terr_on_nd_l", func{ + me.request_clear = 1; + }); - #var r_scaled = (me.fetchRad*me.viewport_radius)/me.range; - #me.fetchWXRMap(r_scaled); - - #me.timeStamp = nil; - #http.load("https://api.rainviewer.com/public/maps.json").done(func(r) me.timeStamp = processRequest(r)); }; var clear = func { @@ -224,23 +224,42 @@ var clear = func { var draw = func { if(me.fetching) return; - + + if (me.radar_beacon == 0) { # update aircraft reference + + var ref = geo.aircraft_position(); + me.reference = ref; + if (ref != nil) { + me.reference.heading = getprop("orientation/heading-magnetic-deg"); + me.reference.altitudeft = ref.alt() * 3.2808399; + + if (me.basealtitudeft == nil) { + var basealtft = me.get_elevation(ref.lat,ref.lon); + if (basealtft == nil) basealtft = 0; + me.basealtitudeft = basealtft + 400; + } + + if ((fmgc.FMGCInternal.phase <= 1 or fmgc.FMGCInternal.phase >= 5) and (me.basealtitudeft == 0)) { + var basealtft = me.get_elevation(ref.lat,ref.lon); + if (basealtft == nil) basealtft = 0; + me.basealtitudeft = basealtft + 400; + # me.reference.basealtitudeft = ft + 400 # <- TODO get departure/arrival runway altitude + } + else if ((fmgc.FMGCInternal.phase > 1 and fmgc.FMGCInternal.phase < 5) and (me.basealtitudeft != 0)) { + me.basealtitudeft = 0; + } + } + } + var range = me.layer.map.getRange(); # Range of Navigation Display var update_size = (range != me.range); me.range = range; - me.fetchRad = me.model.fetchRad; # Radius of radar layer to fetch - var r_scaled = (me.fetchRad*me.viewport_radius)/me.range; if(update_size){ me.request_clear = 1; } - if(me.terrain_visible.getValue() == 0){ - me.request_clear = 1; - me.terrain_visible.setValue(1); - } - - me.updateTerrain(r_scaled); # left - if (math.mod(me.radar_beacon,2)==1) me.updateTerrain(r_scaled); # right + me.updateTerrain(); # left + if (math.mod(me.radar_beacon,2)==1) me.updateTerrain(); # right }; diff --git a/Models/Instruments/ND/canvas/res/terrain/tile_s1.png b/Models/Instruments/ND/canvas/res/terrain/tile_s1.png new file mode 100644 index 0000000000000000000000000000000000000000..ae16caf3a07fdf0a4a69bf65c3b9195d26c0aad4 GIT binary patch literal 1851 zcmV-B2gLY^P)N2bZe?^J zG%hhNHDpIvQUCx3xk*GpR7gur*ZZsAa~uco&whLVu%&I;+;(QiX2#fzv5oJ}9A}%e z`&rVGMA8yTBq9+}vPMK`gocn?SR%RSPVSe##^d>UefQF*YkCGe@@qq z9dF0X%k#LEStqV-Cr`DN*R}Nr+u-T8{*kuorkr?n{Hk`sng}e~(8dPYoOFH^=Z|Hx zWJ^0`XIpk@*7){%)%Cwwvu1TsF44IQ+rkwQ}wk&o=dTJL|@wMWz=| zX3rnTby(-8T@hr2x4z%Dyw}z})W)Yd@FUp`p;5N+goX6B&)eR=<7UtAZS%YB^sDo> zVjZ83MNm$^Cc@4EZ&*hD6TX&b&V8md^Cm(z_wY#Jm&Rf@L8M-Zghd9+QBpE_jiaX!-<~ z4=M|mCHW2m?(V(>suojY``dXBw5d0fOsQINRdkr3hJE|8#l4bc(V-1ko>-!;F3z|% zulN=aMe2(-bb$kDz)mC@d8!&i=7mp2nVedmyD;d4RW5;Jh%O({oOge_=;h>J@}X2I z&=l1@8D0J+P194QYROTO72Ej_MgYrxo<&^+R59_f_TE(Hp5KmYecjH!ZRm!N*3zP3 zj3#tQgo0g_s$JBcCUwG`{vs*WA_(x8h8eZ^aH1b!+WBn?ebeEvBDKZSoZ0Yo(R8GC zRW|AAPuk#6lo4Ishp1uRxNqE>A@VX85~dQpTc-KJ{EL%@MtTH=83s8*K>o_Mb9{$;4P^SeZiad9A* zv>+@SIy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