author | nireco |
Sat, 31 Jan 2009 12:33:08 +0200 | |
changeset 443 | 5d1119729f58 |
parent 434 | a8ba81432ddd |
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; |
431
c6d7272a164b
rework Network send() code to use NetworkTarget/Node/Group::send classes, add a NetworkMessage class for sending NetworkObject messages, and fix a bug whereby the server's client TCP sockets weren't nonblocking.... I wonder how this has worked before?\!
Tero Marttila <terom@fixme.fi>
parents:
400
diff
changeset
|
41 |
|
c6d7272a164b
rework Network send() code to use NetworkTarget/Node/Group::send classes, add a NetworkMessage class for sending NetworkObject messages, and fix a bug whereby the server's client TCP sockets weren't nonblocking.... I wonder how this has worked before?\!
Tero Marttila <terom@fixme.fi>
parents:
400
diff
changeset
|
42 |
// XXX: needs to access session and channel_id |
c6d7272a164b
rework Network send() code to use NetworkTarget/Node/Group::send classes, add a NetworkMessage class for sending NetworkObject messages, and fix a bug whereby the server's client TCP sockets weren't nonblocking.... I wonder how this has worked before?\!
Tero Marttila <terom@fixme.fi>
parents:
400
diff
changeset
|
43 |
friend class NetworkMessage; |
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
44 |
|
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
45 |
private: |
290 | 46 |
/** |
47 |
* The NetworkSession that we use |
|
48 |
*/ |
|
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
49 |
NetworkSession &session; |
290 | 50 |
|
51 |
/** |
|
52 |
* The NetworkChannelID that we use to communicate |
|
53 |
*/ |
|
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
54 |
NetworkChannelID channel_id; |
290 | 55 |
|
56 |
/** |
|
57 |
* Our map of NetworkObjectID -> NetworkObject |
|
58 |
*/ |
|
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
59 |
std::map<NetworkObjectID, NetworkObject*> objects; |
290 | 60 |
|
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
61 |
CL_Slot slot_message; |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
62 |
|
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
63 |
protected: |
290 | 64 |
/** |
65 |
* Construct a NetworkObjectController to use the given NetworkSession and NetworkChannelID |
|
66 |
*/ |
|
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
67 |
NetworkObjectController (NetworkSession &session, NetworkChannelID channel_id); |
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 |
private: |
290 | 70 |
/** |
71 |
* Our NetworkSession::sig_chan_message handler |
|
72 |
* |
|
73 |
* Reads the NetworkObjectID and NetworkMessageID from the packet, and then either calls handle_create or |
|
74 |
* NetworkObject::handle_packet. |
|
75 |
*/ |
|
200
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
186
diff
changeset
|
76 |
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
|
77 |
|
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
78 |
protected: |
290 | 79 |
/** |
80 |
* Abstract method called by on_message if we recieve a message for an unknown NetworkObjectID |
|
81 |
* |
|
82 |
* @param obj_id the unknown NetworkObjectID |
|
83 |
* @param msg_id the packet's NetworkMessageID |
|
84 |
* @param pkt the packet itself, with the header read |
|
85 |
* @param node the node that we got this packet from |
|
86 |
*/ |
|
200
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
186
diff
changeset
|
87 |
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
|
88 |
|
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
223
diff
changeset
|
89 |
public: |
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 |
* Read an NetworkObjectID from the given packet, and return the corresponding NetworkObject, or NULL if: |
92 |
* * it was zero |
|
93 |
* * we don't know the object (should this thrown an exception instead?) |
|
94 |
* |
|
95 |
* @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
|
96 |
*/ |
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
223
diff
changeset
|
97 |
NetworkObject* read_object (NetworkPacketInput &pkt); |
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
98 |
}; |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
99 |
|
290 | 100 |
/** |
101 |
* A NetworkObjectController intended for use with a server. |
|
102 |
* |
|
103 |
* This has an id_pool that new NetworkObjectIDs can be generated from, and this doesn't accept unknown |
|
104 |
* NetworkObjectIDs from clients. |
|
105 |
*/ |
|
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
106 |
class NetworkObject_ServerController : public NetworkObjectController { |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
107 |
friend class NetworkObject_Server; |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
108 |
|
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
109 |
private: |
290 | 110 |
/** |
111 |
* The id_pool that we use to generate NetworkObjectIDs for new NetworkObject's |
|
112 |
*/ |
|
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
113 |
NetworkObjectID id_pool; |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
114 |
|
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
115 |
public: |
290 | 116 |
/** |
117 |
* @see NetworkObjectController |
|
118 |
*/ |
|
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
119 |
NetworkObject_ServerController (NetworkSession &session, NetworkChannelID channel_id); |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
120 |
|
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
121 |
protected: |
290 | 122 |
/** |
123 |
* Get a new NetworkObjectID |
|
124 |
*/ |
|
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
125 |
NetworkObjectID getObjectID (void); |
290 | 126 |
|
127 |
/** |
|
128 |
* Throw an error, as we don't accept unknown NetworkObjects from clients |
|
129 |
*/ |
|
200
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
186
diff
changeset
|
130 |
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
|
131 |
}; |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
132 |
|
290 | 133 |
/** |
134 |
* A NetworkObjectController intended for use with a client. |
|
135 |
* |
|
136 |
* This provides two ways to handle unknown objects: override handle_create, or use sig_create |
|
137 |
*/ |
|
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
138 |
class NetworkObject_ClientController : public NetworkObjectController { |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
139 |
friend class NetworkObject_Client; |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
140 |
|
290 | 141 |
protected: |
142 |
/** |
|
143 |
* The server node, as returned by NetworkSession::connect |
|
144 |
*/ |
|
431
c6d7272a164b
rework Network send() code to use NetworkTarget/Node/Group::send classes, add a NetworkMessage class for sending NetworkObject messages, and fix a bug whereby the server's client TCP sockets weren't nonblocking.... I wonder how this has worked before?\!
Tero Marttila <terom@fixme.fi>
parents:
400
diff
changeset
|
145 |
NetworkNode &server; |
290 | 146 |
|
147 |
/** |
|
148 |
* A mapping of NetworkMessageID -> sig_create, used by the default handle_create |
|
149 |
*/ |
|
223 | 150 |
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
|
151 |
|
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
152 |
public: |
290 | 153 |
/** |
154 |
* Construct a NetworkObjectController using the given NetworkNode (as returned by NetworkSession::connect) as |
|
155 |
* a server. |
|
156 |
* |
|
157 |
* @see NetworkObjectController |
|
158 |
*/ |
|
431
c6d7272a164b
rework Network send() code to use NetworkTarget/Node/Group::send classes, add a NetworkMessage class for sending NetworkObject messages, and fix a bug whereby the server's client TCP sockets weren't nonblocking.... I wonder how this has worked before?\!
Tero Marttila <terom@fixme.fi>
parents:
400
diff
changeset
|
159 |
NetworkObject_ClientController (NetworkSession &session, NetworkChannelID channel_id, NetworkNode &server); |
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
160 |
|
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
161 |
protected: |
290 | 162 |
/** |
163 |
* Handle unknown NetworkObjectIDs by constructing a new NetworkObject_Client and calling sig_create. |
|
164 |
* |
|
165 |
* This can be overriden to handle this differently, e.g. to create an instance of a NetworkObject_Client |
|
166 |
* subclass instead. |
|
167 |
*/ |
|
200
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
186
diff
changeset
|
168 |
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
|
169 |
|
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
170 |
public: |
290 | 171 |
/** |
172 |
* Signal triggered by default handle_create when we get a message for an unknown NetworkObject. |
|
173 |
* The signal gets the new NetworkObject_Client, and the packet itself. |
|
174 |
* |
|
175 |
* @param msg_id the NetworkMessageID to handle creates for |
|
176 |
*/ |
|
223 | 177 |
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
|
178 |
}; |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
179 |
|
290 | 180 |
/** |
181 |
* Base class of NetworkObject_(Client/Server) |
|
182 |
* |
|
183 |
* A NetworkObject has an NetworkObjectID, and can handle packets to/from this object |
|
184 |
*/ |
|
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
185 |
class NetworkObject { |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
186 |
friend class NetworkObjectController; |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
187 |
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
|
188 |
|
431
c6d7272a164b
rework Network send() code to use NetworkTarget/Node/Group::send classes, add a NetworkMessage class for sending NetworkObject messages, and fix a bug whereby the server's client TCP sockets weren't nonblocking.... I wonder how this has worked before?\!
Tero Marttila <terom@fixme.fi>
parents:
400
diff
changeset
|
189 |
// XXX: needs to access controller and obj_id |
c6d7272a164b
rework Network send() code to use NetworkTarget/Node/Group::send classes, add a NetworkMessage class for sending NetworkObject messages, and fix a bug whereby the server's client TCP sockets weren't nonblocking.... I wonder how this has worked before?\!
Tero Marttila <terom@fixme.fi>
parents:
400
diff
changeset
|
190 |
friend class NetworkMessage; |
c6d7272a164b
rework Network send() code to use NetworkTarget/Node/Group::send classes, add a NetworkMessage class for sending NetworkObject messages, and fix a bug whereby the server's client TCP sockets weren't nonblocking.... I wonder how this has worked before?\!
Tero Marttila <terom@fixme.fi>
parents:
400
diff
changeset
|
191 |
|
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
192 |
protected: |
290 | 193 |
/** |
337
ecde18d07879
implement NetworkObject destructor, and increase BounceBounce recoil
terom
parents:
328
diff
changeset
|
194 |
* Generic controller |
ecde18d07879
implement NetworkObject destructor, and increase BounceBounce recoil
terom
parents:
328
diff
changeset
|
195 |
*/ |
ecde18d07879
implement NetworkObject destructor, and increase BounceBounce recoil
terom
parents:
328
diff
changeset
|
196 |
NetworkObjectController &controller; |
ecde18d07879
implement NetworkObject destructor, and increase BounceBounce recoil
terom
parents:
328
diff
changeset
|
197 |
|
ecde18d07879
implement NetworkObject destructor, and increase BounceBounce recoil
terom
parents:
328
diff
changeset
|
198 |
/** |
290 | 199 |
* This object's object id |
200 |
*/ |
|
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
201 |
NetworkObjectID obj_id; |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
202 |
|
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
203 |
protected: |
290 | 204 |
/** |
205 |
* Construct a NetworkObject using the given controller and object id |
|
206 |
* |
|
207 |
* @param controller the NetworkObjectController (subclass) |
|
208 |
* @param obj_id our NetworkObjectID |
|
209 |
*/ |
|
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
210 |
NetworkObject (NetworkObjectController &controller, NetworkObjectID obj_id); |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
211 |
|
290 | 212 |
/** |
337
ecde18d07879
implement NetworkObject destructor, and increase BounceBounce recoil
terom
parents:
328
diff
changeset
|
213 |
* Removes this object from the controller's objects list |
ecde18d07879
implement NetworkObject destructor, and increase BounceBounce recoil
terom
parents:
328
diff
changeset
|
214 |
*/ |
ecde18d07879
implement NetworkObject destructor, and increase BounceBounce recoil
terom
parents:
328
diff
changeset
|
215 |
~NetworkObject (void); |
ecde18d07879
implement NetworkObject destructor, and increase BounceBounce recoil
terom
parents:
328
diff
changeset
|
216 |
|
ecde18d07879
implement NetworkObject destructor, and increase BounceBounce recoil
terom
parents:
328
diff
changeset
|
217 |
/** |
290 | 218 |
* Abstract method to handle packets sent to this object |
219 |
* |
|
220 |
* @param node the NetworkNode that sent this packet to us |
|
221 |
* @param msg_id the packet's NetworkMessageID |
|
222 |
* @param pkt the packet itself, with the headers read |
|
223 |
*/ |
|
200
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
186
diff
changeset
|
224 |
virtual void handle_packet (NetworkNode *node, NetworkMessageID msg_id, NetworkPacketInput &pkt) = 0; |
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
225 |
}; |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
226 |
|
290 | 227 |
/** |
228 |
* Formats the object as "<NetworkObject #" <obj_id> ">" |
|
229 |
*/ |
|
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
230 |
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
|
231 |
|
290 | 232 |
/** |
233 |
* A server-side NetworkObject |
|
234 |
*/ |
|
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
235 |
class NetworkObject_Server : public NetworkObject { |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
236 |
friend class NetworkObject_ServerController; |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
237 |
|
290 | 238 |
protected: |
239 |
/** |
|
240 |
* The NetworkObject_ServerController |
|
241 |
*/ |
|
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
242 |
NetworkObject_ServerController &controller; |
290 | 243 |
|
244 |
/** |
|
245 |
* Mapping of NetworkMessageID -> sig_message used for received messages |
|
246 |
*/ |
|
200
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
186
diff
changeset
|
247 |
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
|
248 |
|
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
249 |
public: |
290 | 250 |
/** |
251 |
* @see NetworkObject |
|
252 |
*/ |
|
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
253 |
NetworkObject_Server (NetworkObject_ServerController &controller); |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
254 |
|
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
255 |
protected: |
290 | 256 |
/** |
257 |
* Handle an incoming packet by invoking the appopriate sig_message |
|
258 |
* |
|
259 |
* @see NetworkObject::handlePacket |
|
260 |
*/ |
|
200
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
186
diff
changeset
|
261 |
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
|
262 |
|
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
263 |
public: |
290 | 264 |
/** |
265 |
* Triggered whenever we receive a message of the given type on this object, giving the node that sent it and the |
|
266 |
* packet itself |
|
267 |
* |
|
268 |
* @param msg_id the NetworkMessageID to handle |
|
269 |
*/ |
|
200
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
186
diff
changeset
|
270 |
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
|
271 |
}; |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
272 |
|
290 | 273 |
/** |
274 |
* A client-side NetworkObject |
|
275 |
*/ |
|
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
276 |
class NetworkObject_Client : public NetworkObject { |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
277 |
friend class NetworkObject_ClientController; |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
278 |
|
290 | 279 |
protected: |
280 |
/** |
|
281 |
* Our NetworkObject_ClientController |
|
282 |
*/ |
|
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
283 |
NetworkObject_ClientController &controller; |
290 | 284 |
|
285 |
/** |
|
286 |
* Our mapping of NetworkMessageID -> sig_message, used to handle received packets |
|
287 |
*/ |
|
200
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
186
diff
changeset
|
288 |
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
|
289 |
|
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
290 |
protected: |
290 | 291 |
/** |
292 |
* @see NetworkObject |
|
293 |
*/ |
|
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
294 |
NetworkObject_Client (NetworkObject_ClientController &controller, NetworkObjectID id); |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
295 |
|
290 | 296 |
/** |
297 |
* Handle an incoming packet by invoking the appropriate sig_message. |
|
298 |
* |
|
299 |
* This assumes that packets only come from the server |
|
300 |
* |
|
301 |
* @see NetworkObject::handlePacket |
|
302 |
*/ |
|
200
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
186
diff
changeset
|
303 |
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
|
304 |
|
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
305 |
public: |
290 | 306 |
/** |
307 |
* Triggered whenever we receive a message of the given type on this object from the server. |
|
308 |
* |
|
309 |
* @param msg_id the NetworkMessageID to handle |
|
310 |
*/ |
|
200
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
186
diff
changeset
|
311 |
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
|
312 |
}; |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
313 |
|
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
314 |
#endif /* NETWORK_OBJECT_HH */ |