Conditions: Difference between revisions
No edit summary |
|||
(3 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
'''Conditions''' (or '''<code>SGCondition</code>s''') in the SimGear library are a property-based representation of custom conditions based on comparing property values. They can be evaluated from both C++ and Nasal (see <code>$SGSOURCE/simgear/props/condition.hxx</code> and <code>[[$FG_ROOT]]/Nasal/props.nas</code>). Comparison of string-typed properties involves lexicographic ordering, as specified by the C++ operators <tt><</tt> and <tt>></tt>. | |||
'''Conditions''' (or ''' | |||
== Usage == | == Usage == | ||
Line 6: | Line 5: | ||
* All [[bindings]], all [[animations]] | * All [[bindings]], all [[animations]] | ||
* State machines | * State machines | ||
* Various parts of [[HUD]]s, 2D panels | * Various parts of [[HUD]]s, 2D panels, [[PUI]]/XML dialogs | ||
* Autopilot / PropertyRule systems | |||
… and several other places. | |||
== Sample | == Sample conditions == | ||
This is a sample expression for checking if the throttle on the first engine is above half: | This is a sample expression for checking if the throttle on the first engine is above half: | ||
<syntaxhighlight lang="xml"> | <syntaxhighlight lang="xml"> | ||
Line 21: | Line 21: | ||
== Supported elements == | == Supported elements == | ||
Each comparison (like less-than or greater-than-equals) requires either two < | Each comparison (like <code>less-than</code> or <code>greater-than-equals</code>) requires either two <code><property></code> elements (the first with index=0 and the second with index=1) or a <code><property></code> (considered first) and <code><value></code> (considered second); booleans compare each of their child conditions. A <code><condition></code> element itself functions as an <and<tt>></tt> element; that is, it can have several children, all of which must be true to make the whole condition true. | ||
<syntaxhighlight lang="xml" enclose="div"> | <syntaxhighlight lang="xml" enclose="div"> | ||
<and> | <and> | ||
Line 33: | Line 33: | ||
<greater-than-equals> | <greater-than-equals> | ||
<property> <!-- evaluates boolean value of specified property --> | <property> <!-- evaluates boolean value of specified property --> | ||
<false/> <!-- static false value (<value> does NOT work in conditions !)--> | |||
<true/><!-- static true value --> | |||
</syntaxhighlight> | </syntaxhighlight> | ||
Line 44: | Line 46: | ||
=== Source code === | === Source code === | ||
* {{ | * {{simgear source | ||
| path = simgear/props/condition.hxx | |||
| path = | |||
| text = simgear/props/condition.hxx | | text = simgear/props/condition.hxx | ||
}} | }} | ||
* {{ | * {{simgear source | ||
| path = simgear/props/condition.cxx | |||
| path = | |||
| text = simgear/props/condition.cxx | | text = simgear/props/condition.cxx | ||
}} | }} |
Latest revision as of 21:28, 7 April 2022
Conditions (or SGCondition
s) in the SimGear library are a property-based representation of custom conditions based on comparing property values. They can be evaluated from both C++ and Nasal (see $SGSOURCE/simgear/props/condition.hxx
and $FG_ROOT/Nasal/props.nas
). Comparison of string-typed properties involves lexicographic ordering, as specified by the C++ operators < and >.
Usage
Conditions are supported in
- All bindings, all animations
- State machines
- Various parts of HUDs, 2D panels, PUI/XML dialogs
- Autopilot / PropertyRule systems
… and several other places.
Sample conditions
This is a sample expression for checking if the throttle on the first engine is above half:
<condition>
<greater-than>
<property>/controls/engines/engine[0]/throttle</property>
<value type="double">0.5</value>
</greater-than>
</condition>
Supported elements
Each comparison (like less-than
or greater-than-equals
) requires either two <property>
elements (the first with index=0 and the second with index=1) or a <property>
(considered first) and <value>
(considered second); booleans compare each of their child conditions. A <condition>
element itself functions as an <and> element; that is, it can have several children, all of which must be true to make the whole condition true.
<and>
<or>
<not> <!-- acts like logical inverse of <and>, i.e. accepts child conditions -->
<equals>
<not-equals>
<less-than>
<greater-than>
<less-than-equals>
<greater-than-equals>
<property> <!-- evaluates boolean value of specified property -->
<false/> <!-- static false value (<value> does NOT work in conditions !)-->
<true/><!-- static true value -->