From dc4ad0dc801347c7c250d24b0298de8be9bc13f4 Mon Sep 17 00:00:00 2001 From: stuart Date: Sat, 16 Feb 2008 20:23:27 +0000 Subject: [PATCH] Update to generic blackout, incorporating feedback from Melchior FRANZ: - Update redout level every frame - Replace reading of properties every iteration with listeners - move -onset and -complete properties into a parameters subtree --- Nasal/redout.nas | 198 +++++++++++++++++++++++++---------------- gui/dialogs/redout.xml | 180 ++++++++++++++++++------------------- preferences.xml | 10 ++- 3 files changed, 215 insertions(+), 173 deletions(-) diff --git a/Nasal/redout.nas b/Nasal/redout.nas index 4eb2fa1c6..e810e75be 100755 --- a/Nasal/redout.nas +++ b/Nasal/redout.nas @@ -1,89 +1,129 @@ # Damped G value - starts at 1. var GDamped = 1.0; +var running = 0; +var fdm = "jsb"; -var blackout = func { +var blackout_start = nil; +var blackout_end = nil; +var redout_start = nil; +var redout_end = nil; +var internal = nil; - var enabled = getprop("/sim/rendering/redout/enabled"); - - if (enabled) +var lp_black = nil; +var lp_red = nil; + +var run = func { + + if (running) + { + var GCurrent = 1.0; + + if (fdm == "jsb") { - var blackout_start = getprop("/sim/rendering/redout/blackout-onset-g"); - var blackout_end = getprop("/sim/rendering/redout/blackout-complete-g"); - var redout_start = getprop("/sim/rendering/redout/redout-onset-g"); - var redout_end = getprop("/sim/rendering/redout/redout-complete-g"); - var internal = getprop("/sim/current-view/internal"); - - if ((blackout_start == nil) or - (blackout_end == nil) or - (redout_start == nil) or - (redout_end == nil) ) - { - # No valid properties - no point running - return; - } - - var GCurrent = 1.0; - - if (getprop("/sim/flight-model") == "jsb") - { - GCurrent = getprop("/accelerations/pilot/z-accel-fps_sec"); - if (GCurrent != nil) GCurrent = - GCurrent / 32; - } - else - { - GCurrent = getprop("/accelerations/pilot-g[0]"); - } - - - if (GCurrent == nil) { GCurrent = 1.0; } - - # Updated the GDamped using a filter. - if (GDamped < 0) - { - # Redout happens faster and clears quicker - GDamped = GDamped * 0.75 + GCurrent * 0.25; - } - else - { - GDamped = GDamped * 0.8 + GCurrent * 0.2; - } - - setprop("/accelerations/pilot-gdamped", GDamped); - - if (internal) - { - if (GDamped > blackout_start) - { - # Blackout - setprop("/sim/rendering/redout/red",0); - setprop("/sim/rendering/redout/alpha", - (GDamped - blackout_start) / (blackout_end - blackout_start)); - } - elsif (GDamped < redout_start) - { - # Redout - setprop("/sim/rendering/redout/red",1); - setprop("/sim/rendering/redout/alpha", - abs((GDamped - redout_start) / (redout_end - redout_start))); - } - else - { - setprop("/sim/rendering/redout/alpha",0); - } - } - else - { - # Not in cockpit view - remove all redout/blackout - setprop("/sim/rendering/redout/alpha",0); - } - } + GCurrent = getprop("/accelerations/pilot/z-accel-fps_sec"); + if (GCurrent != nil) GCurrent = - GCurrent / 32; + } else { - # Disabled - remove all redout/blackout - setprop("/sim/rendering/redout/alpha",0); + GCurrent = getprop("/accelerations/pilot-g[0]"); } - - settimer(blackout, 0.1); + + if (GCurrent == nil) { GCurrent = 1.0; } + + # Updated the GDamped using a filter. + if (GDamped < 0) + { + # Redout happens faster and clears quicker + GDamped = lp_red.filter(GCurrent); + } + else + { + GDamped = lp_black.filter(GCurrent); + } + + setprop("/accelerations/pilot-gdamped", GDamped); + + if (internal) + { + if (GDamped > blackout_start) + { + # Blackout + setprop("/sim/rendering/redout/red",0); + setprop("/sim/rendering/redout/alpha", + (GDamped - blackout_start) / (blackout_end - blackout_start)); + } + elsif (GDamped < redout_start) + { + # Redout + setprop("/sim/rendering/redout/red",1); + setprop("/sim/rendering/redout/alpha", + abs((GDamped - redout_start) / (redout_end - redout_start))); + } + else + { + setprop("/sim/rendering/redout/alpha",0); + } + } + else + { + # Not in cockpit view - remove all redout/blackout + setprop("/sim/rendering/redout/alpha",0); + } + + settimer(run, 0); + } + else + { + # Disabled - remove all redout/blackout + setprop("/sim/rendering/redout/alpha",0); + } } -_setlistener("/sim/signals/nasal-dir-initialized", func { blackout(); }); +var check_params = func() { + blackout_start = getprop("/sim/rendering/redout/parameters/blackout-onset-g"); + blackout_end = getprop("/sim/rendering/redout/parameters/blackout-complete-g"); + redout_start = getprop("/sim/rendering/redout/parameters/redout-onset-g"); + redout_end = getprop("/sim/rendering/redout/parameters/redout-complete-g"); + + if ((blackout_start == nil) or + (blackout_end == nil) or + (redout_start == nil) or + (redout_end == nil) ) + { + # No valid properties - no point running + running = 0; + } +} + +_setlistener("/sim/signals/nasal-dir-initialized", + func { + fdm = getprop("/sim/flight-model"); + check_params(); + running = getprop("/sim/rendering/redout/enabled"); + internal = getprop("/sim/current-view/internal"); + lp_black = aircraft.lowpass.new(0.2); + lp_red = aircraft.lowpass.new(0.25); + run(); + + setlistener("/sim/rendering/redout/enabled", func(n) { + if ((running == 0) and n.getBoolValue()) + { + running = 1; + run(); + } + else + { + running = n.getBoolValue(); + } + }); + + setlistener("/sim/rendering/redout/parameters", func { + # one parameter has changed, read them all in again + check_params(); + }, 1, 2); + + setlistener("/sim/current-view/internal", func(n) { + internal = n.getBoolValue(); + }); + } +); \ No newline at end of file diff --git a/gui/dialogs/redout.xml b/gui/dialogs/redout.xml index 9222dc353..a1a2ac1e7 100644 --- a/gui/dialogs/redout.xml +++ b/gui/dialogs/redout.xml @@ -1,40 +1,40 @@ - redout - vbox - 4 - false + redout + vbox + 4 + false - - - + + + - - - - left - - /sim/rendering/redout/enabled - - dialog-apply - - + - - - - center - - - - - table - + + left + + /sim/rendering/redout/enabled + + dialog-apply + + + + + + + center + + + + + table + 0 0 - - + + 0 @@ -43,25 +43,25 @@ %2.1f true - /sim/rendering/redout/blackout-onset-g + /sim/rendering/redout/parameters/blackout-onset-g - + 0 2 - 1.0 - 15 - /sim/rendering/redout/blackout-onset-g + 1.0 + 15 + /sim/rendering/redout/parameters/blackout-onset-g - dialog-apply - - + dialog-apply + + - + 1 0 - - + + 1 @@ -70,35 +70,35 @@ %2.1f true - /sim/rendering/redout/blackout-complete-g + /sim/rendering/redout/parameters/blackout-complete-g - + 1 2 - 1.0 - 15 - /sim/rendering/redout/blackout-complete-g + 1.0 + 15 + /sim/rendering/redout/parameters/blackout-complete-g - dialog-apply - - - - - + dialog-apply + + + - - center - - - - - table - + + + + center + + + + + table + 0 0 - - + + 0 @@ -107,25 +107,25 @@ %2.1f true - /sim/rendering/redout/redout-onset-g + /sim/rendering/redout/parameters/redout-onset-g - + 0 2 - -1.0 - -15.0 - /sim/rendering/redout/redout-onset-g + -1.0 + -15.0 + /sim/rendering/redout/parameters/redout-onset-g - dialog-apply - - - - + dialog-apply + + + + 1 0 - - + + 1 @@ -133,27 +133,27 @@ %2.1f true - /sim/rendering/redout/redout-complete-g + /sim/rendering/redout/parameters/redout-complete-g - + 1 2 - -1.0 - -15.0 - /sim/rendering/redout/redout-complete-g + -1.0 + -15.0 + /sim/rendering/redout/parameters/redout-complete-g - dialog-apply - - - + dialog-apply + + + - + diff --git a/preferences.xml b/preferences.xml index b62be1510..43c08084e 100644 --- a/preferences.xml +++ b/preferences.xml @@ -103,10 +103,12 @@ Started September 2000 by David Megginson, david@megginson.com false true - 3.5 - 5 - -2 - -4 + + 3.5 + 5 + -2 + -4 + 120