Howto:Transmit properties over MP: Difference between revisions

Jump to navigation Jump to search
expanded to cover new (2017.1) properties.
No edit summary
(expanded to cover new (2017.1) properties.)
 
Line 22: Line 22:
<multiplay>
<multiplay>
   <generic>
   <generic>
     <int n="0" alias="/controls/lighting/landing-light-l"/>
     <bool n="0" alias="/controls/lighting/landing-light-l"/>
     <int n="1" alias="/controls/lighting/landing-light-r"/>
     <bool n="1" alias="/controls/lighting/landing-light-r"/>
    <int n="0" alias="/consumables/fuel/total-fuel-lbs"/>
     <float n="0" alias="/controls/flight/flaps"/>
     <float n="0" alias="/controls/flight/flaps"/>
     <string n="0" alias="/sim/multiplay/callsign"/>
    <short n="0" alias="/instrumentation/airspeed-indicator/indicated-speed-kt" />
     <string n="0" alias="/sim/model/livery/texture"/>
   </generic>
   </generic>
</multiplay>
</multiplay>
Line 31: Line 33:


There are three types of properties that could be used:
There are three types of properties that could be used:
* '''float:''' decimal numbers (0.12, 5.01 ...).
* '''bool[0..90]:''' on/off, true false
* '''int(eger):''' natural numbers (... -1, 0, 1, 2 ...)
* '''float[0..39]:''' decimal numbers (0.12, 5.01 ...).
* '''string:''' alphanumeric values (PH-TST, EH01 ...).
* '''int[0..19]:''' whole/natural numbers (... -1, 0, 1, 2 ...), range +/- 2,147,483,647
'''Note:''' true and false are synonyms from 1 and 0, so in those cases (boolean properties) an integer should be used. Also note that each type is separately numbered; you can have an int n="0" beside a float n="0".
* '''short[0..79]:''' whole/natural numbers (... -1, 0, 1, 2 ...), range +/- 32767
*'''string[0..19]:''' alphanumeric values (PH-TST, EH01 ...).
'''Notes:'''  
 
# Each type is separately numbered; you can have an int n="0" beside a float n="0"
# Always use bools to represent on/off values. These are the most efficient with all 90 bools taking only 24bytes of MP packet.
# Prefer to use shorts instead of ints and floats because they use half the space (4bytes) of an int or float (8bytes)
# Avoid using strings wherever possible as a string will take 4bytes + length of string.


The value behind alias= is the (local) path to the property that has to be transmitted. Make sure that the local property has the same type as the generic MP enabled one (note that bools are automatically converted to integers so you can map an MP enabled int to a local bool). It is important to remember to not explicitly define the property type in an alias property.
The value behind alias= is the (local) path to the property that has to be transmitted. Make sure that the local property has the same type as the generic MP enabled one (note that bools are automatically converted to integers so you can map an MP enabled int to a local bool). It is important to remember to not explicitly define the property type in an alias property.
Line 41: Line 50:


If the MP enabled properties are to be used in animations it is preferable to create aliases for them on the remote systems so that the animations can be written using the logical properties rather than the "sim/multiplay/generic/..." ones. The example below creates the "fdm/jsbsim/propulsion/engine[x]/pitch-angle-rad" properties in the AI/MP aircraft property subtree as aliases for the MP properties. In that way the relevant animations can use the more meaningful property name "fdm/jsbsim/propulsion/engine[x]/pitch-angle-rad" instead of "sim/multiplay/generic/float[x]".
If the MP enabled properties are to be used in animations it is preferable to create aliases for them on the remote systems so that the animations can be written using the logical properties rather than the "sim/multiplay/generic/..." ones. The example below creates the "fdm/jsbsim/propulsion/engine[x]/pitch-angle-rad" properties in the AI/MP aircraft property subtree as aliases for the MP properties. In that way the relevant animations can use the more meaningful property name "fdm/jsbsim/propulsion/engine[x]/pitch-angle-rad" instead of "sim/multiplay/generic/float[x]".
'''NOTE:''' it is nicer to other players to avoid having any timers inside the model XML as this can have a performance impact when there are a lot of MP aircraft.
<syntaxhighlight lang="xml">
<syntaxhighlight lang="xml">
<nasal>
<nasal>
Line 62: Line 73:


Alternatively this can be done without using nasal.  Again in the model xml file:
Alternatively this can be done without using nasal.  Again in the model xml file:
<syntaxhighlight lang="xml">
<syntaxhighlight lang="xml+myghty">
<params>
<params>
   <lighting>
   <lighting>
     <landing-light-l>
     <landing-light-l>
       <property>sim/multiplay/generic/float[0]</property>
       <property>sim/multiplay/generic/bool[0]</property>
     </landing-light-l>
     </landing-light-l>
   </lighting>
   </lighting>
308

edits

Navigation menu