Howto:Transmit properties over MP: Difference between revisions

From FlightGear wiki
Jump to navigation Jump to search
m (+cat: Multiplayer)
No edit summary
(12 intermediate revisions by 9 users not shown)
Line 1: Line 1:
{{stub}}
{{stub}}
{{Warning|if an aircraft defines all possible properties in the protocol, it tries to send 14988 bytes per packet, almost 12.5 times the allowed limit! Your idea of sending properties in a round-robin fashion is good IMHO but good MP debugging tools are necessary for aircraft developers.<ref>{{cite web
  |url    =  https://sourceforge.net/p/flightgear/mailman/message/35441502/
  |title  =  <nowiki> Re: [Flightgear-devel] C172 MP alert on console </nowiki>
  |author =  <nowiki> Ludovic Brenta </nowiki>
  |date  =  Oct 21st, 2016
  |added  =  Oct 21st, 2016
  |script_version = 0.40
  }}</ref>
}}
This wiki article will teach you '''how to transmit properties over a network'''.


Certain [[Property Tree|properties]] (eg. rudder deflection, flaps setting and gear position) are transmitted by default over the [[Howto: Multiplayer|multiplayer network]]. However there are still lots of (mostly [[aircraft]] specific) properties that are not. Due to this limitation, certain animations (eg. opening of a door or landing lights) won't be visible for a pilot's virtual-colleagues.  
Certain [[Property Tree|properties]] (eg. rudder deflection, flaps setting and gear position) are transmitted by default over the [[Howto: Multiplayer|multiplayer network]]. However there are still lots of (mostly [[aircraft]] specific) properties that are not. Due to this limitation, certain animations (eg. opening of a door or landing lights) won't be visible for a pilot's virtual-colleagues.  


This wiki article will teach you '''how to transmit properties over a network'''.
The number of properties that can be sent over MP is limited. If you have properties that do not need to be sent frequently (e.g. only when a certain event happens) these can be sent more efficiently using mp_broadcast.nas in $FG_ROOT/Nasal, please see [[Howto:Using mp_broadcast.nas]], or using the time-sharing (TDM) or bit-packed components (SwitchEncoder/Decoder) for booleans in Aircraft/Generic/DualControl/dual-control-tools.nas.
 
The method described here will send the properties in question in every multiplayer packet. This is appropriate for parts that need continuous animation but wasteful for many other uses. On the other hand, the method described here is easy to use so if you only have a small number of properties to share it may still be preferable.


== -set.xml ==
== -set.xml ==
 
<syntaxhighlight lang="xml">
<multiplay>
<multiplay>
   <generic>
   <generic>
  <int n="0" alias="/controls/lighting/landing-light-l"/>
    <int n="0" alias="/controls/lighting/landing-light-l"/>
  <int n="1" alias="/controls/lighting/landing-light-r"/>
    <int n="1" alias="/controls/lighting/landing-light-r"/>
  <float n="0" alias="/controls/flight/flaps"/>
    <float n="0" alias="/controls/flight/flaps"/>
  <string n="0" alias="/sim/multiplay/callsign"/>
    <string n="0" alias="/sim/multiplay/callsign"/>
   </generic>
   </generic>
</multiplay>
</multiplay>
</syntaxhighlight>


There are three types of properties that could be used:
There are three types of properties that could be used:
Line 20: Line 34:
* '''int(eger):''' natural numbers (... -1, 0, 1, 2 ...)
* '''int(eger):''' natural numbers (... -1, 0, 1, 2 ...)
* '''string:''' alphanumeric values (PH-TST, EH01 ...).
* '''string:''' alphanumeric values (PH-TST, EH01 ...).
'''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 seperately numbered; you can have an int n="0" besided a float n="0".
'''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".


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.
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.


== In the 3d model XML file ==
== In the 3d model XML file ==


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]".
 
<syntaxhighlight lang="xml">
<nasal>
<nasal>
   <load>
   <load>
   ##############################################################################
   ##############################################################################
Line 44: Line 58:
   ##############################################################################
   ##############################################################################
   </load>
   </load>
  </nasal>
</nasal>
</syntaxhighlight>
 
Alternatively this can be done without using nasal. Again in the model xml file:
<syntaxhighlight lang="xml">
<params>
  <lighting>
    <landing-light-l>
      <property>sim/multiplay/generic/float[0]</property>
    </landing-light-l>
  </lighting>
</params>
</syntaxhighlight>
 
Then in the animation use:
 
<property alias="../../params/lighting/landing-light-l/property"/>
 
== Related content ==
* [[Aircraft-set.xml]]
* [[Aircraft properties reference]]
* [[Multiplayer protocol]]
* [[Howto:Using mp broadcast.nas]]
* [[Livery_over_MP]]


[[Category:Aircraft enhancement|Transmit properties over MP]]
[[Category:Aircraft enhancement]]
[[Category:Nasal|Transmit properties over MP]]
[[Category:Nasal howto]]
[[Category:Multiplayer]]
[[Category:Multiplayer]]
[[Category:Property Tree]]

Revision as of 08:50, 22 October 2016

This article is a stub. You can help the wiki by expanding it.
Warning  if an aircraft defines all possible properties in the protocol, it tries to send 14988 bytes per packet, almost 12.5 times the allowed limit! Your idea of sending properties in a round-robin fashion is good IMHO but good MP debugging tools are necessary for aircraft developers.[1]

This wiki article will teach you how to transmit properties over a network.

Certain properties (eg. rudder deflection, flaps setting and gear position) are transmitted by default over the multiplayer network. However there are still lots of (mostly aircraft specific) properties that are not. Due to this limitation, certain animations (eg. opening of a door or landing lights) won't be visible for a pilot's virtual-colleagues.

The number of properties that can be sent over MP is limited. If you have properties that do not need to be sent frequently (e.g. only when a certain event happens) these can be sent more efficiently using mp_broadcast.nas in $FG_ROOT/Nasal, please see Howto:Using mp_broadcast.nas, or using the time-sharing (TDM) or bit-packed components (SwitchEncoder/Decoder) for booleans in Aircraft/Generic/DualControl/dual-control-tools.nas.

The method described here will send the properties in question in every multiplayer packet. This is appropriate for parts that need continuous animation but wasteful for many other uses. On the other hand, the method described here is easy to use so if you only have a small number of properties to share it may still be preferable.

-set.xml

<multiplay>
  <generic>
    <int n="0" alias="/controls/lighting/landing-light-l"/>
    <int n="1" alias="/controls/lighting/landing-light-r"/>
    <float n="0" alias="/controls/flight/flaps"/>
    <string n="0" alias="/sim/multiplay/callsign"/>
  </generic>
</multiplay>

There are three types of properties that could be used:

  • float: decimal numbers (0.12, 5.01 ...).
  • int(eger): natural numbers (... -1, 0, 1, 2 ...)
  • string: alphanumeric values (PH-TST, EH01 ...).

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".

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.

In the 3d model XML file

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]".

<nasal>
  <load>
   ##############################################################################
   # The on-load Nasal is not executed when this file is loaded as the user
   # aircraft.
   ##############################################################################
   var rplayer = cmdarg();
   # Set up property aliases for animations.
   rplayer.getNode("fdm/jsbsim/propulsion/engine[0]/pitch-angle-rad", 1).
     alias(rplayer.getNode("sim/multiplay/generic/float[0]"));
   rplayer.getNode("fdm/jsbsim/propulsion/engine[1]/pitch-angle-rad", 1).
     alias(rplayer.getNode("sim/multiplay/generic/float[1]"));
   rplayer.getNode("fdm/jsbsim/propulsion/engine[2]/pitch-angle-rad", 1).
     alias(rplayer.getNode("sim/multiplay/generic/float[2]"));
   ##############################################################################
  </load>
</nasal>

Alternatively this can be done without using nasal. Again in the model xml file:

<params>
  <lighting>
    <landing-light-l>
      <property>sim/multiplay/generic/float[0]</property>
    </landing-light-l>
  </lighting>
</params>

Then in the animation use:

<property alias="../../params/lighting/landing-light-l/property"/>

Related content

  1. Ludovic Brenta  (Oct 21st, 2016).  Re: [Flightgear-devel] C172 MP alert on console .