1
0
Fork 0

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
This commit is contained in:
stuart 2008-02-16 20:23:27 +00:00
parent df780e1304
commit dc4ad0dc80
3 changed files with 215 additions and 173 deletions

View file

@ -1,89 +1,129 @@
# Damped G value - starts at 1. # Damped G value - starts at 1.
var GDamped = 1.0; 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"); var lp_black = nil;
var lp_red = nil;
if (enabled)
var run = func {
if (running)
{
var GCurrent = 1.0;
if (fdm == "jsb")
{ {
var blackout_start = getprop("/sim/rendering/redout/blackout-onset-g"); GCurrent = getprop("/accelerations/pilot/z-accel-fps_sec");
var blackout_end = getprop("/sim/rendering/redout/blackout-complete-g"); if (GCurrent != nil) GCurrent = - GCurrent / 32;
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);
}
}
else else
{ {
# Disabled - remove all redout/blackout GCurrent = getprop("/accelerations/pilot-g[0]");
setprop("/sim/rendering/redout/alpha",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();
});
}
);

View file

@ -1,40 +1,40 @@
<?xml version="1.0"?> <?xml version="1.0"?>
<PropertyList> <PropertyList>
<name>redout</name> <name>redout</name>
<layout>vbox</layout> <layout>vbox</layout>
<default-padding>4</default-padding> <default-padding>4</default-padding>
<modal>false</modal> <modal>false</modal>
<text> <text>
<label>G-Force Blackout Settings</label> <label>G-Force Blackout Settings</label>
</text> </text>
<hrule/> <hrule/>
<checkbox>
<halign>left</halign>
<label>Enable Blackout and Redout due to G-force.</label>
<property>/sim/rendering/redout/enabled</property>
<binding>
<command>dialog-apply</command>
</binding>
</checkbox>
<hrule/> <checkbox>
<halign>left</halign>
<text> <label>Enable Blackout and Redout due to G-force.</label>
<halign>center</halign> <property>/sim/rendering/redout/enabled</property>
<label>Blackout</label> <binding>
</text> <command>dialog-apply</command>
</binding>
<group> </checkbox>
<layout>table</layout>
<text> <hrule/>
<text>
<halign>center</halign>
<label>Blackout</label>
</text>
<group>
<layout>table</layout>
<text>
<row>0</row> <row>0</row>
<col>0</col> <col>0</col>
<label>Onset</label> <label>Onset</label>
</text> </text>
<text> <text>
<row>0</row> <row>0</row>
@ -43,25 +43,25 @@
<label>15.0</label> <label>15.0</label>
<format>%2.1f</format> <format>%2.1f</format>
<live>true</live> <live>true</live>
<property>/sim/rendering/redout/blackout-onset-g</property> <property>/sim/rendering/redout/parameters/blackout-onset-g</property>
</text> </text>
<slider> <slider>
<row>0</row> <row>0</row>
<col>2</col> <col>2</col>
<min>1.0</min> <min>1.0</min>
<max>15</max> <max>15</max>
<property>/sim/rendering/redout/blackout-onset-g</property> <property>/sim/rendering/redout/parameters/blackout-onset-g</property>
<binding> <binding>
<command>dialog-apply</command> <command>dialog-apply</command>
</binding> </binding>
</slider> </slider>
<text> <text>
<row>1</row> <row>1</row>
<col>0</col> <col>0</col>
<label>Complete</label> <label>Complete</label>
</text> </text>
<text> <text>
<row>1</row> <row>1</row>
@ -70,35 +70,35 @@
<label>15.0</label> <label>15.0</label>
<format>%2.1f</format> <format>%2.1f</format>
<live>true</live> <live>true</live>
<property>/sim/rendering/redout/blackout-complete-g</property> <property>/sim/rendering/redout/parameters/blackout-complete-g</property>
</text> </text>
<slider> <slider>
<row>1</row> <row>1</row>
<col>2</col> <col>2</col>
<min>1.0</min> <min>1.0</min>
<max>15</max> <max>15</max>
<property>/sim/rendering/redout/blackout-complete-g</property> <property>/sim/rendering/redout/parameters/blackout-complete-g</property>
<binding> <binding>
<command>dialog-apply</command> <command>dialog-apply</command>
</binding> </binding>
</slider> </slider>
</group> </group>
<hrule/>
<text> <hrule/>
<halign>center</halign>
<label>Redout</label> <text>
</text> <halign>center</halign>
<label>Redout</label>
<group> </text>
<layout>table</layout>
<text> <group>
<layout>table</layout>
<text>
<row>0</row> <row>0</row>
<col>0</col> <col>0</col>
<label>Onset</label> <label>Onset</label>
</text> </text>
<text> <text>
<row>0</row> <row>0</row>
@ -107,25 +107,25 @@
<label>15.0</label> <label>15.0</label>
<format>%2.1f</format> <format>%2.1f</format>
<live>true</live> <live>true</live>
<property>/sim/rendering/redout/redout-onset-g</property> <property>/sim/rendering/redout/parameters/redout-onset-g</property>
</text> </text>
<slider> <slider>
<row>0</row> <row>0</row>
<col>2</col> <col>2</col>
<min>-1.0</min> <min>-1.0</min>
<max>-15.0</max> <max>-15.0</max>
<property>/sim/rendering/redout/redout-onset-g</property> <property>/sim/rendering/redout/parameters/redout-onset-g</property>
<binding> <binding>
<command>dialog-apply</command> <command>dialog-apply</command>
</binding> </binding>
</slider> </slider>
<text> <text>
<row>1</row> <row>1</row>
<col>0</col> <col>0</col>
<label>Complete</label> <label>Complete</label>
</text> </text>
<text> <text>
<row>1</row> <row>1</row>
@ -133,27 +133,27 @@
<label>15.0</label> <label>15.0</label>
<format>%2.1f</format> <format>%2.1f</format>
<live>true</live> <live>true</live>
<property>/sim/rendering/redout/redout-complete-g</property> <property>/sim/rendering/redout/parameters/redout-complete-g</property>
</text> </text>
<slider> <slider>
<row>1</row> <row>1</row>
<col>2</col> <col>2</col>
<min>-1.0</min> <min>-1.0</min>
<max>-15.0</max> <max>-15.0</max>
<property>/sim/rendering/redout/redout-complete-g</property> <property>/sim/rendering/redout/parameters/redout-complete-g</property>
<binding> <binding>
<command>dialog-apply</command> <command>dialog-apply</command>
</binding> </binding>
</slider> </slider>
</group> </group>
<button> <button>
<legend>Close</legend> <legend>Close</legend>
<default>true</default> <default>true</default>
<key>Esc</key> <key>Esc</key>
<binding> <binding>
<command>dialog-close</command> <command>dialog-close</command>
</binding> </binding>
</button> </button>
</PropertyList> </PropertyList>

View file

@ -103,10 +103,12 @@ Started September 2000 by David Megginson, david@megginson.com
<glide-slope-tunnel type="bool" userarchive="y">false</glide-slope-tunnel> <glide-slope-tunnel type="bool" userarchive="y">false</glide-slope-tunnel>
<redout> <redout>
<enabled type="bool" userarchive="y">true</enabled> <enabled type="bool" userarchive="y">true</enabled>
<blackout-onset-g>3.5</blackout-onset-g> <parameters>
<blackout-complete-g>5</blackout-complete-g> <blackout-onset-g>3.5</blackout-onset-g>
<redout-onset-g>-2</redout-onset-g> <blackout-complete-g>5</blackout-complete-g>
<redout-complete-g>-4</redout-complete-g> <redout-onset-g>-2</redout-onset-g>
<redout-complete-g>-4</redout-complete-g>
</parameters>
</redout> </redout>
</rendering> </rendering>
<model-hz type="int">120</model-hz> <model-hz type="int">120</model-hz>