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