Roger.
Its done as a property rules now.
Here is the rules file: (not sure what the standard for $FGData headers are)
- Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<!--
###################################################################################
## ##
## Improved redout/blackout system for Flightgear ##
## ##
## Author: Nikolai V. Chr. ##
## ##
## Todo: Tie in with Thorstens ALS greyout and tunnel vision filters ##
## ##
## ##
## Version 2.02 License: GPL 2.0 ##
## ##
###################################################################################
-->
<PropertyList>
<params>
<onset-b>sim/rendering/redout/parameters/blackout-onset-g</onset-b>
<fast-b>sim/rendering/redout/parameters/blackout-complete-g</fast-b>
<onset-r>sim/rendering/redout/parameters/redout-onset-g</onset-r>
<fast-r>sim/rendering/redout/parameters/redout-complete-g</fast-r>
<onset-t-b>sim/rendering/redout/parameters/onset-blackout-sec</onset-t-b>
<fast-t-b>sim/rendering/redout/parameters/fast-blackout-sec</fast-t-b>
<onset-t-r>sim/rendering/redout/parameters/onset-redout-sec</onset-t-r>
<fast-t-r>sim/rendering/redout/parameters/fast-redout-sec</fast-t-r>
<rec-f>sim/rendering/redout/parameters/recover-fast-sec</rec-f>
<rec-s>sim/rendering/redout/parameters/recover-slow-sec</rec-s>
<log>
<g-force>sim/rendering/redout/internal/log/g-force</g-force>
<onset-b>sim/rendering/redout/internal/log/onset-b</onset-b>
<fast-b>sim/rendering/redout/internal/log/fast-b</fast-b>
<g-force-r>sim/rendering/redout/internal/log/g-force-r</g-force-r>
<onset-r>sim/rendering/redout/internal/log/onset-r</onset-r>
<fast-r>sim/rendering/redout/internal/log/fast-r</fast-r>
</log>
<g-force>sim/rendering/redout/internal/g-force</g-force>
<g-force-inv>sim/rendering/redout/internal/g-force-inv</g-force-inv>
<blackout>sim/rendering/redout/internal/blackout</blackout>
<redout>sim/rendering/redout/internal/redout</redout>
<alpha>sim/rendering/redout/alpha</alpha>
<red>sim/rendering/redout/red</red>
<inside>sim/current-view/internal</inside>
<sum>sim/rendering/redout/internal/sum</sum>
<enable>sim/rendering/redout/enabled</enable>
</params>
<filter><!-- check for NaN -->
<type>gain</type>
<gain>0</gain>
<enable>
<condition>
<property alias="/params/enable"/>
<not>
<less-than>
<property alias="/params/blackout"/>
<value>1000.0</value>
</less-than>
<greater-than>
<property alias="/params/blackout"/>
<value>-1000.0</value>
</greater-than>
</not>
</condition>
</enable>
<input>
<value>0</value>
</input>
<output alias="/params/blackout"/>
</filter>
<filter><!-- check for NaN -->
<type>gain</type>
<gain>0</gain>
<enable>
<condition>
<property alias="/params/enable"/>
<not>
<less-than>
<property alias="/params/redout"/>
<value>1000.0</value>
</less-than>
<greater-than>
<property alias="/params/redout"/>
<value>-1000.0</value>
</greater-than>
</not>
</condition>
</enable>
<input>
<value>0</value>
</input>
<output alias="/params/redout"/>
</filter>
<filter>
<type>gain</type>
<gain>-1</gain>
<enable>
<!-- check if JSBSim is the FDM. -->
<condition>
<property alias="/params/enable"/>
<less-than>
<property>fdm/jsbsim/aero/alpha-deg</property>
<value>180.0</value>
</less-than>
<greater-than>
<property>fdm/jsbsim/aero/alpha-deg</property>
<value>-180.0</value>
</greater-than>
</condition>
</enable>
<input>
<expression>
<div>
<property>accelerations/pilot/z-accel-fps_sec</property>
<value>32.174</value>
</div>
</expression>
</input>
<output alias="/params/g-force"/>
</filter>
<filter>
<type>gain</type>
<gain>1</gain>
<enable>
<!-- check if YaSim is the FDM. -->
<condition>
<property alias="/params/enable"/>
<not>
<less-than>
<property>fdm/jsbsim/aero/alpha-deg</property>
<value>180.0</value>
</less-than>
<greater-than>
<property>fdm/jsbsim/aero/alpha-deg</property>
<value>-180.0</value>
</greater-than>
</not>
</condition>
</enable>
<input>
<property>accelerations/pilot-g[0]</property>
</input>
<output alias="/params/g-force"/>
</filter>
<filter>
<type>gain</type>
<gain>1</gain>
<enable>
<condition>
<property alias="/params/enable"/>
</condition>
</enable>
<input>
<expression>
<log10>
<property alias="/params/fast-b"/>
</log10>
</expression>
</input>
<output alias="/params/log/fast-b"/>
</filter>
<filter>
<type>gain</type>
<gain>1</gain>
<enable>
<condition>
<property alias="/params/enable"/>
</condition>
</enable>
<input>
<expression>
<log10>
<property alias="/params/onset-b"/>
</log10>
</expression>
</input>
<output alias="/params/log/onset-b"/>
</filter>
<filter>
<type>gain</type>
<gain>1</gain>
<enable>
<condition>
<property alias="/params/enable"/>
<less-than-equals>
<property alias="/params/g-force"/>
<value>1</value>
</less-than-equals>
</condition>
</enable>
<input>
<value>0</value>
</input>
<output alias="/params/log/g-force"/>
</filter>
<filter>
<type>gain</type>
<gain>1</gain>
<enable>
<condition>
<property alias="/params/enable"/>
<greater-than>
<property alias="/params/g-force"/>
<value>1</value>
</greater-than>
</condition>
</enable>
<input>
<expression>
<log10>
<property alias="/params/g-force"/>
</log10>
</expression>
</input>
<output alias="/params/log/g-force"/>
</filter>
<filter><!-- reduce blackout -->
<type>gain</type>
<gain>1</gain>
<enable>
<condition>
<property alias="/params/enable"/>
<less-than>
<property alias="/params/g-force"/>
<property alias="/params/onset-b"/>
</less-than>
</condition>
</enable>
<input>
<expression>
<min>
<value>1</value>
<max>
<value>0</value>
<dif>
<property alias="/params/blackout"/>
<product>
<property>sim/time/delta-sec</property>
<div>
<value>1</value>
<max>
<value>0</value>
<sum>
<property alias="/params/rec-f"/>
<product>
<div>
<dif>
<property alias="/params/log/g-force"/>
<log10>
<value>1</value>
</log10>
</dif>
<dif>
<property alias="/params/log/onset-b"/>
<log10>
<value>1</value>
</log10>
</dif>
</div>
<dif>
<property alias="/params/rec-s"/>
<property alias="/params/rec-f"/>
</dif>
</product>
</sum>
</max>
</div>
</product>
</dif>
</max>
</min>
</expression>
</input>
<output alias="/params/blackout"/>
</filter>
<filter><!-- increase blackout -->
<type>gain</type>
<gain>1</gain>
<enable>
<condition>
<property alias="/params/enable"/>
<greater-than-equals>
<property alias="/params/g-force"/>
<property alias="/params/onset-b"/>
</greater-than-equals>
</condition>
</enable>
<input>
<expression>
<min>
<value>1</value>
<max>
<value>0</value>
<sum>
<property alias="/params/blackout"/>
<product>
<property>sim/time/delta-sec</property>
<div>
<value>1</value>
<max>
<value>0</value>
<pow>
<value>10</value>
<sum>
<log10>
<property alias="/params/onset-t-b"/>
</log10>
<product>
<div>
<dif>
<property alias="/params/log/g-force"/>
<property alias="/params/log/onset-b"/>
</dif>
<dif>
<property alias="/params/log/fast-b"/>
<property alias="/params/log/onset-b"/>
</dif>
</div>
<dif>
<log10>
<property alias="/params/fast-t-b"/>
</log10>
<log10>
<property alias="/params/onset-t-b"/>
</log10>
</dif>
</product>
</sum>
</pow>
</max>
</div>
</product>
</sum>
</max>
</min>
</expression>
</input>
<output alias="/params/blackout"/>
</filter>
<filter>
<type>gain</type>
<gain>1</gain>
<enable>
<condition>
<property alias="/params/enable"/>
</condition>
</enable>
<input>
<expression>
<log10>
<product>
<value>-1</value>
<dif>
<property alias="/params/fast-r"/>
<value>2</value>
</dif>
</product>
</log10>
</expression>
</input>
<output alias="/params/log/fast-r"/>
</filter>
<filter>
<type>gain</type>
<gain>1</gain>
<enable>
<condition>
<property alias="/params/enable"/>
</condition>
</enable>
<input>
<expression>
<log10>
<product>
<value>-1</value>
<dif>
<property alias="/params/onset-r"/>
<value>2</value>
</dif>
</product>
</log10>
</expression>
</input>
<output alias="/params/log/onset-r"/>
</filter>
<filter>
<type>gain</type>
<gain>-1</gain>
<enable>
<condition>
<property alias="/params/enable"/>
</condition>
</enable>
<input>
<expression>
<dif>
<property alias="/params/g-force"/>
<value>2</value>
</dif>
</expression>
</input>
<output alias="/params/g-force-inv"/>
</filter>
<filter>
<type>gain</type>
<gain>1</gain>
<enable>
<condition>
<property alias="/params/enable"/>
<less-than-equals>
<property alias="/params/g-force-inv"/>
<value>1</value>
</less-than-equals>
</condition>
</enable>
<input>
<value>0</value>
</input>
<output alias="/params/log/g-force-r"/>
</filter>
<filter>
<type>gain</type>
<gain>1</gain>
<enable>
<condition>
<property alias="/params/enable"/>
<greater-than>
<property alias="/params/g-force-inv"/>
<value>1</value>
</greater-than>
</condition>
</enable>
<input>
<expression>
<log10>
<property alias="/params/g-force-inv"/>
</log10>
</expression>
</input>
<output alias="/params/log/g-force-r"/>
</filter>
<filter><!-- reduce redout -->
<type>gain</type>
<gain>1</gain>
<enable>
<condition>
<property alias="/params/enable"/>
<greater-than>
<property alias="/params/g-force"/>
<property alias="/params/onset-r"/>
</greater-than>
</condition>
</enable>
<input>
<expression>
<min>
<value>1</value>
<max>
<value>0</value>
<dif>
<property alias="/params/redout"/>
<product>
<property>sim/time/delta-sec</property>
<div>
<value>1</value>
<max>
<value>0</value>
<sum>
<property alias="/params/rec-f"/>
<product>
<div>
<dif>
<property alias="/params/log/g-force-r"/>
<log10>
<value>1</value>
</log10>
</dif>
<dif>
<property alias="/params/log/onset-r"/>
<log10>
<value>1</value>
</log10>
</dif>
</div>
<dif>
<property alias="/params/rec-s"/>
<property alias="/params/rec-f"/>
</dif>
</product>
</sum>
</max>
</div>
</product>
</dif>
</max>
</min>
</expression>
</input>
<output alias="/params/redout"/>
</filter>
<filter><!-- increase redout -->
<type>gain</type>
<gain>1</gain>
<enable>
<condition>
<property alias="/params/enable"/>
<less-than-equals>
<property alias="/params/g-force"/>
<property alias="/params/onset-r"/>
</less-than-equals>
</condition>
</enable>
<input>
<expression>
<min>
<value>1</value>
<max>
<value>0</value>
<sum>
<property alias="/params/redout"/>
<product>
<property>sim/time/delta-sec</property>
<div>
<value>1</value>
<max>
<value>0</value>
<pow>
<value>10</value>
<sum>
<log10>
<property alias="/params/onset-t-r"/>
</log10>
<product>
<div>
<dif>
<property alias="/params/log/g-force-r"/>
<property alias="/params/log/onset-r"/>
</dif>
<dif>
<property alias="/params/log/fast-r"/>
<property alias="/params/log/onset-r"/>
</dif>
</div>
<dif>
<log10>
<property alias="/params/fast-t-r"/>
</log10>
<log10>
<property alias="/params/onset-t-r"/>
</log10>
</dif>
</product>
</sum>
</pow>
</max>
</div>
</product>
</sum>
</max>
</min>
</expression>
</input>
<output alias="/params/redout"/>
</filter>
<filter>
<type>gain</type>
<gain>1</gain>
<enable>
<condition>
<property alias="/params/enable"/>
</condition>
</enable>
<input>
<expression>
<dif>
<property alias="/params/blackout"/>
<property alias="/params/redout"/>
</dif>
</expression>
</input>
<output alias="/params/sum"/>
</filter>
<filter>
<type>gain</type>
<gain>1</gain>
<enable>
<condition>
<property alias="/params/enable"/>
<equals>
<property alias="/params/inside"/>
<value>1</value>
</equals>
<less-than>
<property alias="/params/sum"/>
<value>0</value>
</less-than>
</condition>
</enable>
<input>
<value>1</value>
</input>
<output alias="/params/red"/>
</filter>
<filter>
<type>gain</type>
<gain>1</gain>
<enable>
<condition>
<property alias="/params/enable"/>
<equals>
<property alias="/params/inside"/>
<value>1</value>
</equals>
<less-than>
<property alias="/params/sum"/>
<value>0</value>
</less-than>
</condition>
</enable>
<input>
<expression>
<product>
<property alias="/params/sum"/>
<value>-1</value>
</product>
</expression>
</input>
<output alias="/params/alpha"/>
</filter>
<filter>
<type>gain</type>
<gain>1</gain>
<enable>
<condition>
<property alias="/params/enable"/>
<equals>
<property alias="/params/inside"/>
<value>1</value>
</equals>
<greater-than-equals>
<property alias="/params/sum"/>
<value>0</value>
</greater-than-equals>
</condition>
</enable>
<input>
<value>0</value>
</input>
<output alias="/params/red"/>
</filter>
<filter>
<type>gain</type>
<gain>1</gain>
<enable>
<condition>
<property alias="/params/enable"/>
<equals>
<property alias="/params/inside"/>
<value>1</value>
</equals>
<greater-than-equals>
<property alias="/params/sum"/>
<value>0</value>
</greater-than-equals>
</condition>
</enable>
<input>
<property alias="/params/sum"/>
</input>
<output alias="/params/alpha"/>
</filter>
<filter>
<type>gain</type>
<gain>0</gain>
<enable>
<condition>
<or>
<not>
<property alias="/params/enable"/>
</not>
<equals>
<property alias="/params/inside"/>
<value>0</value>
</equals>
</or>
</condition>
</enable>
<input>
<value>0</value>
</input>
<output alias="/params/alpha"/>
</filter>
</PropertyList>
Here is the definition of the properties inside sim/rendering:
- Code: Select all
<redout>
<enabled type="bool">true</enabled>
<internal>
<g-force type="double">1</g-force>
<g-force-inv type="double">1</g-force-inv>
<blackout type="double">0</blackout>
<redout type="double">0</redout>
<sum type="double">0</sum>
<log>
<g-force type="double">0</g-force>
<onset-b type="double">0</onset-b>
<fast-b type="double">0</fast-b>
<g-force-r type="double">0</g-force-r>
<onset-r type="double">0</onset-r>
<fast-r type="double">0</fast-r>
</log>
</internal>
<parameters>
<blackout-onset-g type="double">2.5</blackout-onset-g>
<blackout-complete-g type="double">4</blackout-complete-g>
<onset-blackout-sec type="double">300</onset-blackout-sec>
<fast-blackout-sec type="double">10</fast-blackout-sec>
<redout-onset-g type="double">-2</redout-onset-g>
<redout-complete-g type="double">-4</redout-complete-g>
<onset-redout-sec type="double">45</onset-redout-sec>
<fast-redout-sec type="double">7.5</fast-redout-sec>
<recover-fast-sec type="double">7</recover-fast-sec>
<recover-slow-sec type="double">15</recover-slow-sec>
</parameters>
</redout>
Here is the modified $FGDATA/Nasal/redout.nas where blackout/redout has been factored out, and only head-shake is left:
- Code: Select all
# Damped G value - starts at 1.
var GDamped = 1.0;
var previousG = 1.0;
var running_compression = 0;
var fdm = "jsb";
var compression_rate = nil;
var internal = nil;
var lp_black = nil;
var lp_red = nil;
var run = func {
if (running_compression)
{
var GCurrent = 1.0;
if (fdm == "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 = lp_red.filter(GCurrent);
}
else
{
GDamped = lp_black.filter(GCurrent);
}
setprop("/accelerations/pilot-gdamped", GDamped);
if (internal)
{
if (running_compression)
{
# Apply any compression due to G-forces
if (GDamped != previousG)
{
var current_y_offset = getprop("/sim/current-view/y-offset-m");
setprop("/sim/current-view/y-offset-m", current_y_offset - (GDamped - previousG) * compression_rate);
previousG = GDamped;
}
}
}
settimer(run, 0);
}
}
var fdm_init_listener = _setlistener("/sim/signals/fdm-initialized",
func {
removelistener(fdm_init_listener); # uninstall, so we're only called once
fdm = getprop("/sim/flight-model");
running_compression = getprop("/sim/rendering/headshake/enabled");
internal = getprop("/sim/current-view/internal");
lp_black = aircraft.lowpass.new(0.2);
lp_red = aircraft.lowpass.new(0.25);
setlistener("/sim/current-view/internal", func(n) {
internal = n.getBoolValue();
});
setlistener("/sim/rendering/headshake/rate-m-g", func(n) {
compression_rate = n.getValue();
}, 1);
setlistener("/sim/rendering/headshake/enabled", func(n) {
if ((running_compression == 0) and (running_redout == 0) and n.getBoolValue())
{
running_compression = 1;
# start new timer now
run();
}
else
{
running_compression = n.getBoolValue();
}
}, 1);
# Now we've set up the listeners (which will have triggered), run it.
run();
}
);
Not tested with Yasim yet, but should work.
So do you think all parameters should be exposed in the GUI, or will that be too messy? Could work with only the two sliders that is exposed now, and let aircraft makers adjust the details.
But I guess it needs minimum a toggle for old or new system, unless that should be left up to aircraft. I really have no experience with making pretty PUI dialogs (only made an ugly simple one), but if you want me to modify the dialog, I can try.