XPMP2
X-Plane multiplayer library 2 - using instancing
Remote.h
Go to the documentation of this file.
1 
26 #ifndef _Remote_h_
27 #define _Remote_h_
28 
29 namespace XPMP2 {
30 
31 //
32 // MARK: ENQUEUE Data Structure for Caching and Passing from main to network thread
33 //
34 
36 struct RmtAcCacheTy {
37  const unsigned fullUpdGrp;
38  float ts;
39  double lat;
40  double lon;
41  double alt_ft;
42  XPLMDrawInfo_t drawInfo;
43  std::vector<float> v;
44  bool bValid : 1;
45  bool bVisible : 1;
46  bool bRender : 1;
47  const CSLModel* pCSLMdl;
48 
50  RmtAcCacheTy (const Aircraft& ac, double _lat, double _lon, double _alt_ft);
52  void UpdateFrom (const Aircraft& ac, double _lat, double _lon, double _alt_ft);
53 };
54 
56 typedef std::map<XPMPPlaneID,RmtAcCacheTy> mapRmtAcCacheTy;
57 
58 
59 
62 public:
64 public:
68  virtual ~RmtDataBaseTy() {}
69 };
70 
72 typedef std::unique_ptr<RmtDataBaseTy> ptrRmtDataBaseTy;
74 typedef std::queue<ptrRmtDataBaseTy,std::list<ptrRmtDataBaseTy> > queueRmtDataTy;
75 
76 
78 template <class ElemTy, RemoteMsgTy MsgTy>
80 public:
82  ElemTy data;
83 public:
87  RmtDataEnqeueTy (const ElemTy& _elem) : RmtDataBaseTy(MsgTy), data(_elem) {}
88 };
89 
90 // predefine required template instances
94 
100 public:
101  union {
103  RemoteAcAnimTy data;
105  char bufSize[RemoteAcAnimTy::msgSize(V_COUNT)];
106  };
107 public:
111  void add (DR_VALS idx, float f);
112 };
113 
115 typedef std::unique_ptr<RmtDataAcAnimTy> ptrRmtDataAcAnimTy;
116 
117 //
118 // MARK: SENDING Data Structures
119 //
120 
122 template <class ElemTy, RemoteMsgTy MsgTy, std::uint8_t msgVer>
123 class RmtMsgBufTy {
124 public:
125  void* pMsg = nullptr;
126  size_t elemCount = 0;
127  size_t size = 0;
128 public:
134  void free ();
136  void init ();
138  bool add (const ElemTy& _elem);
140  bool empty () const { return !elemCount; }
142  void send (UDPMulticast& _mc);
144  bool add_send (const ElemTy& _elem, UDPMulticast& _mc);
145 };
146 
147 
148 //
149 // MARK: Global Functions
150 //
151 
153 void RemoteInit ();
154 
156 void RemoteCleanup ();
157 
160 
161 
164 void RemoteAcEnqueueStarts (float now);
165 
168 void RemoteAcEnqueue (const Aircraft& ac);
169 
171 void RemoteAcEnqueueDone ();
172 
174 void RemoteAcRemove (const Aircraft& ac);
175 
177 void RemoteAcClearAll ();
178 
179 }
180 #endif
unsigned XPMPPlaneID
Unique ID for an aircraft created by a plugin.
Definition: XPMPMultiplayer.h:252
Actual representation of all aircraft in XPMP2.
Definition: XPMPAircraft.h:178
Represents a CSL model as it is saved on disk.
Definition: CSLModels.h:113
Animation dataRef requires a special queue data type as each msg element is already of variable lengt...
Definition: Remote.h:99
RmtDataAcAnimTy(XPMPPlaneID _id)
Default constructor only sets message type and id, makes sure data is initialized.
Definition: Remote.h:109
void add(DR_VALS idx, float f)
Add a pair of animation type and value to the structure.
Definition: Remote.cpp:495
Base structure for passing information from XP's main thread to the multicast thread.
Definition: Remote.h:61
RmtDataBaseTy(RemoteMsgTy _ty)
Constructor just set the message type.
Definition: Remote.h:66
RemoteMsgTy msgTy
which message to send?
Definition: Remote.h:63
virtual ~RmtDataBaseTy()
Virtual destructor makes sure correct deletion of derived class' objects even through (smart) pointer...
Definition: Remote.h:68
Passing information about any data type (like a/c full detail message); the data is contained as copy...
Definition: Remote.h:79
RmtDataEnqeueTy(const ElemTy &_elem)
Data copy constructor copies the passed-in data.
Definition: Remote.h:87
RmtDataEnqeueTy()
Default constructor only sets message type, leaves rest defaulted.
Definition: Remote.h:85
ElemTy data
the payload data
Definition: Remote.h:82
Helper class to manage the temporary buffers in which the network message are put together.
Definition: Remote.h:123
~RmtMsgBufTy()
Destructor makes sure the buffer is freed up.
Definition: Remote.h:132
size_t size
current message size
Definition: Remote.h:127
bool add_send(const ElemTy &_elem, UDPMulticast &_mc)
Perform add(), then if necessary send(); returns if sent.
Definition: Remote.cpp:480
void init()
If necessary allocate the required buffer, then initialize it to an empty message.
Definition: Remote.cpp:434
bool empty() const
is empty, contains no payload?
Definition: Remote.h:140
bool add(const ElemTy &_elem)
Add another element to the buffer, returns if successful (otherwise full!)
Definition: Remote.cpp:451
size_t elemCount
number of elements already added to the message
Definition: Remote.h:126
void free()
Free up the buffer, basically a reset.
Definition: Remote.cpp:424
RmtMsgBufTy()
Constructor: everything stays zeroed.
Definition: Remote.h:130
void send(UDPMulticast &_mc)
send the message (if there is any), then reset the buffer
Definition: Remote.cpp:470
void * pMsg
points to the actual message buffer of size glob.remoteBufSize
Definition: Remote.h:125
UDP Multicast, always binding to INADDR_ANY.
Definition: Network.h:211
Definition: XPMPAircraft.h:70
std::map< XPMPPlaneID, RmtAcCacheTy > mapRmtAcCacheTy
Defines a map with the plane id as key and the aboce cache structure as payload.
Definition: Remote.h:56
void RemoteAcClearAll()
Informs us that there are no more aircraft, clear our caches!
Definition: Remote.cpp:1378
void RemoteAcEnqueueDone()
Informs us that all a/c have been processed: All pending messages to be sent now.
Definition: Remote.cpp:1317
void RemoteAcRemove(const Aircraft &ac)
Informs us about an aircraft deletion.
Definition: Remote.cpp:1350
void RemoteAcEnqueueStarts(float now)
Definition: Remote.cpp:1192
RemoteMsgTy
Message type.
Definition: XPMPRemote.h:77
@ RMT_MSG_AC_ANIM
aircraft animation values (dataRef values) only
Definition: XPMPRemote.h:83
void RemoteSenderUpdateStatus()
Compares current vs. expected status and takes appropriate action.
Definition: Remote.cpp:1155
std::unique_ptr< RmtDataBaseTy > ptrRmtDataBaseTy
Smart pointer to XPMP2::RmtDataBaseTy by which we manage objects of this and derived types.
Definition: Remote.h:72
RmtDataEnqeueTy< RemoteAcRemoveTy, RMT_MSG_AC_REMOVE > RmtDataAcRemoveTy
A/C Removal queue type.
Definition: Remote.h:93
void RemoteCleanup()
Grace cleanup, stops all threads.
Definition: Remote.cpp:1132
void RemoteAcEnqueue(const Aircraft &ac)
Regularly called from the flight loop callback to send a/c date onto the network.
Definition: Remote.cpp:1223
std::queue< ptrRmtDataBaseTy, std::list< ptrRmtDataBaseTy > > queueRmtDataTy
A queue managing the information objects, used to transfer data between main thread and network threa...
Definition: Remote.h:74
std::unique_ptr< RmtDataAcAnimTy > ptrRmtDataAcAnimTy
Smart pointer to XPMP2::RmtDataAcAnimTy.
Definition: Remote.h:115
void RemoteInit()
Initialize the module.
Definition: Remote.cpp:1123
RmtDataEnqeueTy< RemoteAcPosUpdateTy, RMT_MSG_AC_POS_UPDATE > RmtDataAcPosUpdateTy
A/C Position Update queue type.
Definition: Remote.h:92
DR_VALS
The dataRefs provided by XPMP2 to the CSL models.
Definition: XPMPAircraft.h:87
@ V_COUNT
always last, number of dataRefs XPMP2 pre-defines
Definition: XPMPAircraft.h:137
RmtDataEnqeueTy< RemoteAcDetailTy, RMT_MSG_AC_DETAILED > RmtDataAcDetailTy
A/C Detail queue type.
Definition: Remote.h:91
A/C animation dataRef changes.
Definition: XPMPRemote.h:333
size_t msgSize() const
current message size
Definition: XPMPRemote.h:351
Holds a copy of some aircraft data as was sent out last.
Definition: Remote.h:36
float ts
timestamp this position was valid (XP network time)
Definition: Remote.h:38
const CSLModel * pCSLMdl
the CSL model in use
Definition: Remote.h:47
bool bRender
Shall the CSL model be drawn in 3D world?
Definition: Remote.h:46
std::vector< float > v
dataRef values
Definition: Remote.h:43
double lat
degree latitude
Definition: Remote.h:39
double alt_ft
feet altitude
Definition: Remote.h:41
XPLMDrawInfo_t drawInfo
position and orientation last sent
Definition: Remote.h:42
RmtAcCacheTy(const Aircraft &ac, double _lat, double _lon, double _alt_ft)
Constructor copies relevant values from the passed-in aircraft.
Definition: Remote.cpp:109
bool bValid
is this object valid? (Will be reset in case of exceptions)
Definition: Remote.h:44
bool bVisible
Shall this plane be drawn at the moment?
Definition: Remote.h:45
double lon
degree longitude
Definition: Remote.h:40
void UpdateFrom(const Aircraft &ac, double _lat, double _lon, double _alt_ft)
Updates current values from given aircraft.
Definition: Remote.cpp:123
const unsigned fullUpdGrp
full update group, with which planes are distributed to load balance sending XPMP2::RMT_MSG_AC_DETAIL...
Definition: Remote.h:37