author | Tero Marttila <terom@fixme.fi> |
Fri, 16 Jan 2009 22:03:49 +0200 | |
changeset 400 | d64bf28c4340 |
parent 337 | ecde18d07879 |
child 431 | c6d7272a164b |
permissions | -rw-r--r-- |
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
1 |
#ifndef NETWORK_OBJECT_HH |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
2 |
#define NETWORK_OBJECT_HH |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
3 |
|
400
d64bf28c4340
more documentation tweaking, all Network/ files now have a @file comment. Fix Platform.h -> Platform.hh, and Buffer.hh + Packet.cc
Tero Marttila <terom@fixme.fi>
parents:
337
diff
changeset
|
4 |
/** |
d64bf28c4340
more documentation tweaking, all Network/ files now have a @file comment. Fix Platform.h -> Platform.hh, and Buffer.hh + Packet.cc
Tero Marttila <terom@fixme.fi>
parents:
337
diff
changeset
|
5 |
* @file |
d64bf28c4340
more documentation tweaking, all Network/ files now have a @file comment. Fix Platform.h -> Platform.hh, and Buffer.hh + Packet.cc
Tero Marttila <terom@fixme.fi>
parents:
337
diff
changeset
|
6 |
* |
d64bf28c4340
more documentation tweaking, all Network/ files now have a @file comment. Fix Platform.h -> Platform.hh, and Buffer.hh + Packet.cc
Tero Marttila <terom@fixme.fi>
parents:
337
diff
changeset
|
7 |
* Object-based network protocol for use with NetworkSession |
d64bf28c4340
more documentation tweaking, all Network/ files now have a @file comment. Fix Platform.h -> Platform.hh, and Buffer.hh + Packet.cc
Tero Marttila <terom@fixme.fi>
parents:
337
diff
changeset
|
8 |
*/ |
d64bf28c4340
more documentation tweaking, all Network/ files now have a @file comment. Fix Platform.h -> Platform.hh, and Buffer.hh + Packet.cc
Tero Marttila <terom@fixme.fi>
parents:
337
diff
changeset
|
9 |
|
186 | 10 |
#include "Session.hh" |
11 |
#include "Node.hh" |
|
12 |
#include "../Logger.hh" |
|
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
13 |
|
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
14 |
#include <map> |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
15 |
|
290 | 16 |
/** |
17 |
* A NetworkObject's ID is a 32-bit integer |
|
18 |
*/ |
|
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
19 |
typedef uint32_t NetworkObjectID; |
290 | 20 |
|
21 |
/** |
|
22 |
* A NetworkObject's message type is a 16-bit integer |
|
23 |
*/ |
|
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
24 |
typedef uint16_t NetworkMessageID; |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
25 |
|
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
26 |
// forward-declare |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
27 |
class NetworkObject; |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
28 |
class NetworkObject_Client; |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
29 |
class NetworkObject_Server; |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
30 |
|
290 | 31 |
/** |
32 |
* A NetworkObjectController contains a mapping of NetworkObjectID -> NetworkObject, and handles the |
|
33 |
* messages received on our channel from the NetworkSession. |
|
34 |
* |
|
35 |
* Additionally, this provides methods to read/write NetworkObject references from/to a NetworkPacket |
|
36 |
*/ |
|
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
37 |
class NetworkObjectController { |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
38 |
friend class NetworkObject; |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
39 |
friend class NetworkObject_Server; |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
40 |
friend class NetworkObject_Client; |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
41 |
|
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
42 |
private: |
290 | 43 |
/** |
44 |
* The NetworkSession that we use |
|
45 |
*/ |
|
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
46 |
NetworkSession &session; |
290 | 47 |
|
48 |
/** |
|
49 |
* The NetworkChannelID that we use to communicate |
|
50 |
*/ |
|
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
51 |
NetworkChannelID channel_id; |
290 | 52 |
|
53 |
/** |
|
54 |
* Our map of NetworkObjectID -> NetworkObject |
|
55 |
*/ |
|
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
56 |
std::map<NetworkObjectID, NetworkObject*> objects; |
290 | 57 |
|
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
58 |
CL_Slot slot_message; |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
59 |
|
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
60 |
protected: |
290 | 61 |
/** |
62 |
* Construct a NetworkObjectController to use the given NetworkSession and NetworkChannelID |
|
63 |
*/ |
|
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
64 |
NetworkObjectController (NetworkSession &session, NetworkChannelID channel_id); |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
65 |
|
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
66 |
private: |
290 | 67 |
/** |
68 |
* Our NetworkSession::sig_chan_message handler |
|
69 |
* |
|
70 |
* Reads the NetworkObjectID and NetworkMessageID from the packet, and then either calls handle_create or |
|
71 |
* NetworkObject::handle_packet. |
|
72 |
*/ |
|
200
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
186
diff
changeset
|
73 |
void on_message (NetworkPacketInput &pkt, NetworkNode *node); |
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
74 |
|
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
75 |
protected: |
290 | 76 |
/** |
77 |
* Abstract method called by on_message if we recieve a message for an unknown NetworkObjectID |
|
78 |
* |
|
79 |
* @param obj_id the unknown NetworkObjectID |
|
80 |
* @param msg_id the packet's NetworkMessageID |
|
81 |
* @param pkt the packet itself, with the header read |
|
82 |
* @param node the node that we got this packet from |
|
83 |
*/ |
|
200
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
186
diff
changeset
|
84 |
virtual void handle_create (NetworkObjectID obj_id, NetworkMessageID msg_id, NetworkPacketInput &pkt, NetworkNode *node) = 0; |
276
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
223
diff
changeset
|
85 |
|
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
223
diff
changeset
|
86 |
public: |
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
223
diff
changeset
|
87 |
/** |
328 | 88 |
* Read an NetworkObjectID from the given packet, and return the corresponding NetworkObject, or NULL if: |
89 |
* * it was zero |
|
90 |
* * we don't know the object (should this thrown an exception instead?) |
|
91 |
* |
|
92 |
* @return the NetworkObject* corresponding to the NetworkObjectID in the packet, or NULL if zero/not found |
|
276
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
223
diff
changeset
|
93 |
*/ |
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
223
diff
changeset
|
94 |
NetworkObject* read_object (NetworkPacketInput &pkt); |
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
223
diff
changeset
|
95 |
|
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
223
diff
changeset
|
96 |
/** |
328 | 97 |
* Write the given Object's NetworkObjectID (or 0, if the obj is NULL) to the given packet |
98 |
* |
|
99 |
* @param the NetworkObject* whose NetworkObjectID to write to the packet, or NULL to write zero |
|
276
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
223
diff
changeset
|
100 |
*/ |
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
223
diff
changeset
|
101 |
void write_object (NetworkPacketOutput &pkt, NetworkObject *obj); |
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
102 |
}; |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
103 |
|
290 | 104 |
/** |
105 |
* A NetworkObjectController intended for use with a server. |
|
106 |
* |
|
107 |
* This has an id_pool that new NetworkObjectIDs can be generated from, and this doesn't accept unknown |
|
108 |
* NetworkObjectIDs from clients. |
|
109 |
*/ |
|
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
110 |
class NetworkObject_ServerController : public NetworkObjectController { |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
111 |
friend class NetworkObject_Server; |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
112 |
|
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
113 |
private: |
290 | 114 |
/** |
115 |
* The id_pool that we use to generate NetworkObjectIDs for new NetworkObject's |
|
116 |
*/ |
|
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
117 |
NetworkObjectID id_pool; |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
118 |
|
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
119 |
public: |
290 | 120 |
/** |
121 |
* @see NetworkObjectController |
|
122 |
*/ |
|
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
123 |
NetworkObject_ServerController (NetworkSession &session, NetworkChannelID channel_id); |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
124 |
|
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
125 |
protected: |
290 | 126 |
/** |
127 |
* Get a new NetworkObjectID |
|
128 |
*/ |
|
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
129 |
NetworkObjectID getObjectID (void); |
290 | 130 |
|
131 |
/** |
|
132 |
* Throw an error, as we don't accept unknown NetworkObjects from clients |
|
133 |
*/ |
|
200
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
186
diff
changeset
|
134 |
virtual void handle_create (NetworkObjectID obj_id, NetworkMessageID msg_id, NetworkPacketInput &pkt, NetworkNode *node); |
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
135 |
}; |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
136 |
|
290 | 137 |
/** |
138 |
* A NetworkObjectController intended for use with a client. |
|
139 |
* |
|
140 |
* This provides two ways to handle unknown objects: override handle_create, or use sig_create |
|
141 |
*/ |
|
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
142 |
class NetworkObject_ClientController : public NetworkObjectController { |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
143 |
friend class NetworkObject_Client; |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
144 |
|
290 | 145 |
protected: |
146 |
/** |
|
147 |
* The server node, as returned by NetworkSession::connect |
|
148 |
*/ |
|
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
149 |
NetworkNode *server; |
290 | 150 |
|
151 |
/** |
|
152 |
* A mapping of NetworkMessageID -> sig_create, used by the default handle_create |
|
153 |
*/ |
|
223 | 154 |
std::map<NetworkMessageID, CL_Signal_v2<NetworkObject_Client*, NetworkPacketInput&> > _map_sig_create; |
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
155 |
|
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
156 |
public: |
290 | 157 |
/** |
158 |
* Construct a NetworkObjectController using the given NetworkNode (as returned by NetworkSession::connect) as |
|
159 |
* a server. |
|
160 |
* |
|
161 |
* @see NetworkObjectController |
|
162 |
*/ |
|
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
163 |
NetworkObject_ClientController (NetworkSession &session, NetworkChannelID channel_id, NetworkNode *server); |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
164 |
|
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
165 |
protected: |
290 | 166 |
/** |
167 |
* Handle unknown NetworkObjectIDs by constructing a new NetworkObject_Client and calling sig_create. |
|
168 |
* |
|
169 |
* This can be overriden to handle this differently, e.g. to create an instance of a NetworkObject_Client |
|
170 |
* subclass instead. |
|
171 |
*/ |
|
200
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
186
diff
changeset
|
172 |
virtual void handle_create (NetworkObjectID obj_id, NetworkMessageID msg_id, NetworkPacketInput &pkt, NetworkNode *node); |
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
173 |
|
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
174 |
public: |
290 | 175 |
/** |
176 |
* Signal triggered by default handle_create when we get a message for an unknown NetworkObject. |
|
177 |
* The signal gets the new NetworkObject_Client, and the packet itself. |
|
178 |
* |
|
179 |
* @param msg_id the NetworkMessageID to handle creates for |
|
180 |
*/ |
|
223 | 181 |
CL_Signal_v2<NetworkObject_Client*, NetworkPacketInput&>& sig_create (NetworkMessageID msg_id) { return _map_sig_create[msg_id]; } |
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
182 |
}; |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
183 |
|
290 | 184 |
/** |
185 |
* Base class of NetworkObject_(Client/Server) |
|
186 |
* |
|
187 |
* A NetworkObject has an NetworkObjectID, and can handle packets to/from this object |
|
188 |
*/ |
|
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
189 |
class NetworkObject { |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
190 |
friend class NetworkObjectController; |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
191 |
friend std::ostream& operator<< (std::ostream &s, const NetworkObject &obj); |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
192 |
|
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
193 |
protected: |
290 | 194 |
/** |
337
ecde18d07879
implement NetworkObject destructor, and increase BounceBounce recoil
terom
parents:
328
diff
changeset
|
195 |
* Generic controller |
ecde18d07879
implement NetworkObject destructor, and increase BounceBounce recoil
terom
parents:
328
diff
changeset
|
196 |
*/ |
ecde18d07879
implement NetworkObject destructor, and increase BounceBounce recoil
terom
parents:
328
diff
changeset
|
197 |
NetworkObjectController &controller; |
ecde18d07879
implement NetworkObject destructor, and increase BounceBounce recoil
terom
parents:
328
diff
changeset
|
198 |
|
ecde18d07879
implement NetworkObject destructor, and increase BounceBounce recoil
terom
parents:
328
diff
changeset
|
199 |
/** |
290 | 200 |
* This object's object id |
201 |
*/ |
|
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
202 |
NetworkObjectID obj_id; |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
203 |
|
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
204 |
protected: |
290 | 205 |
/** |
206 |
* Construct a NetworkObject using the given controller and object id |
|
207 |
* |
|
208 |
* @param controller the NetworkObjectController (subclass) |
|
209 |
* @param obj_id our NetworkObjectID |
|
210 |
*/ |
|
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
211 |
NetworkObject (NetworkObjectController &controller, NetworkObjectID obj_id); |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
212 |
|
290 | 213 |
/** |
337
ecde18d07879
implement NetworkObject destructor, and increase BounceBounce recoil
terom
parents:
328
diff
changeset
|
214 |
* Removes this object from the controller's objects list |
ecde18d07879
implement NetworkObject destructor, and increase BounceBounce recoil
terom
parents:
328
diff
changeset
|
215 |
*/ |
ecde18d07879
implement NetworkObject destructor, and increase BounceBounce recoil
terom
parents:
328
diff
changeset
|
216 |
~NetworkObject (void); |
ecde18d07879
implement NetworkObject destructor, and increase BounceBounce recoil
terom
parents:
328
diff
changeset
|
217 |
|
ecde18d07879
implement NetworkObject destructor, and increase BounceBounce recoil
terom
parents:
328
diff
changeset
|
218 |
/** |
290 | 219 |
* Abstract method to handle packets sent to this object |
220 |
* |
|
221 |
* @param node the NetworkNode that sent this packet to us |
|
222 |
* @param msg_id the packet's NetworkMessageID |
|
223 |
* @param pkt the packet itself, with the headers read |
|
224 |
*/ |
|
200
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
186
diff
changeset
|
225 |
virtual void handle_packet (NetworkNode *node, NetworkMessageID msg_id, NetworkPacketInput &pkt) = 0; |
290 | 226 |
|
227 |
/** |
|
228 |
* Prepare an outgoing packet, writing the header and the payload |
|
229 |
* |
|
230 |
* @param pkt the packet to prepare |
|
231 |
* @param msg_id the packet's message id |
|
232 |
* @param payload the packet's payload |
|
233 |
*/ |
|
200
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
186
diff
changeset
|
234 |
void buildPacket (NetworkPacketOutput &pkt, NetworkMessageID msg_id, const NetworkPacketBuffer &payload); |
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
235 |
}; |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
236 |
|
290 | 237 |
/** |
238 |
* Formats the object as "<NetworkObject #" <obj_id> ">" |
|
239 |
*/ |
|
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
240 |
std::ostream& operator<< (std::ostream &s, const NetworkObject &obj); |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
241 |
|
290 | 242 |
/** |
243 |
* A server-side NetworkObject |
|
244 |
*/ |
|
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
245 |
class NetworkObject_Server : public NetworkObject { |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
246 |
friend class NetworkObject_ServerController; |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
247 |
|
290 | 248 |
protected: |
249 |
/** |
|
250 |
* The NetworkObject_ServerController |
|
251 |
*/ |
|
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
252 |
NetworkObject_ServerController &controller; |
290 | 253 |
|
254 |
/** |
|
255 |
* Mapping of NetworkMessageID -> sig_message used for received messages |
|
256 |
*/ |
|
200
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
186
diff
changeset
|
257 |
std::map<NetworkMessageID, CL_Signal_v2<NetworkNode*, NetworkPacketInput&> > _map_sig_message; |
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
258 |
|
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
259 |
public: |
290 | 260 |
/** |
261 |
* @see NetworkObject |
|
262 |
*/ |
|
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
263 |
NetworkObject_Server (NetworkObject_ServerController &controller); |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
264 |
|
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
265 |
protected: |
290 | 266 |
/** |
267 |
* Handle an incoming packet by invoking the appopriate sig_message |
|
268 |
* |
|
269 |
* @see NetworkObject::handlePacket |
|
270 |
*/ |
|
200
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
186
diff
changeset
|
271 |
virtual void handle_packet (NetworkNode *node, NetworkMessageID msg_id, NetworkPacketInput &pkt); |
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
272 |
|
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
273 |
public: |
290 | 274 |
/** |
275 |
* Send a message on this object to the given node |
|
276 |
* |
|
277 |
* @param dst the NetworkNode to send the message to |
|
278 |
* @param msg_id the type of message to send |
|
279 |
* @param pkt the packet payload |
|
280 |
* @param reliable Whether to use TCP or UDP |
|
281 |
*/ |
|
200
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
186
diff
changeset
|
282 |
void send_to (NetworkNode *dst, NetworkMessageID msg_id, const NetworkPacketBuffer &pkt, bool reliable = true); |
290 | 283 |
|
284 |
/** |
|
285 |
* Send a message on this object to all nodes on our controller's NetworkSession |
|
286 |
* |
|
287 |
* @param msg_id the type of message to send |
|
288 |
* @param pkt the packet payload |
|
289 |
* @param reliable Whether to use TCP or UDP |
|
290 |
*/ |
|
200
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
186
diff
changeset
|
291 |
void send_all (NetworkMessageID msg_id, const NetworkPacketBuffer &pkt, bool reliable = true); |
290 | 292 |
|
293 |
/** |
|
294 |
* Send a message on this object to all nodes on our controller's NetworkSession, except the given node |
|
295 |
* |
|
296 |
* @param msg_id the type of message to send |
|
297 |
* @param pkt the packet payload |
|
298 |
* @param black_sheep the node to *NOT* send the message to |
|
299 |
* @param reliable Whether to use TCP or UDP |
|
300 |
*/ |
|
200
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
186
diff
changeset
|
301 |
void send_all_except (NetworkMessageID msg_id, const NetworkPacketBuffer &pkt, NetworkNode *black_sheep, bool reliable = true); |
290 | 302 |
|
303 |
/** |
|
304 |
* Triggered whenever we receive a message of the given type on this object, giving the node that sent it and the |
|
305 |
* packet itself |
|
306 |
* |
|
307 |
* @param msg_id the NetworkMessageID to handle |
|
308 |
*/ |
|
200
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
186
diff
changeset
|
309 |
CL_Signal_v2<NetworkNode*, NetworkPacketInput&>& sig_message (NetworkMessageID msg_id) { return _map_sig_message[msg_id]; } |
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
310 |
}; |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
311 |
|
290 | 312 |
/** |
313 |
* A client-side NetworkObject |
|
314 |
*/ |
|
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
315 |
class NetworkObject_Client : public NetworkObject { |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
316 |
friend class NetworkObject_ClientController; |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
317 |
|
290 | 318 |
protected: |
319 |
/** |
|
320 |
* Our NetworkObject_ClientController |
|
321 |
*/ |
|
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
322 |
NetworkObject_ClientController &controller; |
290 | 323 |
|
324 |
/** |
|
325 |
* Our mapping of NetworkMessageID -> sig_message, used to handle received packets |
|
326 |
*/ |
|
200
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
186
diff
changeset
|
327 |
std::map<NetworkMessageID, CL_Signal_v1<NetworkPacketInput&> > _map_sig_message; |
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
328 |
|
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
329 |
protected: |
290 | 330 |
/** |
331 |
* @see NetworkObject |
|
332 |
*/ |
|
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
333 |
NetworkObject_Client (NetworkObject_ClientController &controller, NetworkObjectID id); |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
334 |
|
290 | 335 |
/** |
336 |
* Handle an incoming packet by invoking the appropriate sig_message. |
|
337 |
* |
|
338 |
* This assumes that packets only come from the server |
|
339 |
* |
|
340 |
* @see NetworkObject::handlePacket |
|
341 |
*/ |
|
200
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
186
diff
changeset
|
342 |
virtual void handle_packet (NetworkNode *node, NetworkMessageID msg_id, NetworkPacketInput &pkt); |
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
343 |
|
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
344 |
public: |
290 | 345 |
/** |
346 |
* Send a message on this object to the server |
|
347 |
* |
|
348 |
* @param msg_id the type of message to send |
|
349 |
* @param pkt the packet payload |
|
350 |
* @param reliable Whether to use TCP or UDP |
|
351 |
*/ |
|
200
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
186
diff
changeset
|
352 |
void send (NetworkMessageID msg_id, const NetworkPacketBuffer &pkt, bool reliable = true); |
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
353 |
|
290 | 354 |
/** |
355 |
* Triggered whenever we receive a message of the given type on this object from the server. |
|
356 |
* |
|
357 |
* @param msg_id the NetworkMessageID to handle |
|
358 |
*/ |
|
200
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
186
diff
changeset
|
359 |
CL_Signal_v1<NetworkPacketInput&>& sig_message (NetworkMessageID msg_id) { return _map_sig_message[msg_id]; } |
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
360 |
}; |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
361 |
|
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
362 |
#endif /* NETWORK_OBJECT_HH */ |