author | terom |
Mon, 08 Dec 2008 16:44:38 +0000 | |
changeset 294 | fd58e7d01bec |
parent 277 | 40f4a03917e2 |
child 296 | 4d3ebaa29430 |
permissions | -rw-r--r-- |
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
1 |
#ifndef NETWORKCLIENT_HH |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
2 |
#define NETWORKCLIENT_HH |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
3 |
|
186 | 4 |
#include "../GameState.hh" |
5 |
#include "Session.hh" |
|
6 |
#include "Object.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 |
// forward-declare |
274
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
263
diff
changeset
|
9 |
class NetworkClient; |
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
10 |
class NetworkClientLocalPlayer; |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
11 |
class NetworkClientRemotePlayer; |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
12 |
|
294 | 13 |
/** |
14 |
* Our specialized NetworkObject_ClientController that overrides handle_create to create the right kind of |
|
15 |
* object (a subclass of NetowrkClientObject). |
|
16 |
*/ |
|
274
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
263
diff
changeset
|
17 |
class NetworkClientController : public NetworkObject_ClientController { |
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
263
diff
changeset
|
18 |
protected: |
294 | 19 |
/** |
20 |
* The NetworkClient |
|
21 |
*/ |
|
274
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
263
diff
changeset
|
22 |
NetworkClient &client; |
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
263
diff
changeset
|
23 |
|
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
263
diff
changeset
|
24 |
public: |
294 | 25 |
/** |
26 |
* Control objects on the given client using the client.netsession's NETCHAN_CORE channel |
|
27 |
*/ |
|
274
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
263
diff
changeset
|
28 |
NetworkClientController (NetworkClient &client); |
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
263
diff
changeset
|
29 |
|
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
263
diff
changeset
|
30 |
protected: |
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
263
diff
changeset
|
31 |
/** |
294 | 32 |
* We override handle_create from NetworkObject_ClientController to call one of the on_* methods, which creates |
33 |
* a NetworkClientObject subclass |
|
34 |
* |
|
35 |
* @see NetworkObject_ClientController::handle_create |
|
274
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
263
diff
changeset
|
36 |
*/ |
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
263
diff
changeset
|
37 |
virtual void handle_create (NetworkObjectID obj_id, NetworkMessageID msg_id, NetworkPacketInput &pkt, NetworkNode *node); |
294 | 38 |
|
39 |
/** |
|
40 |
* Handle NETMSG_SERVER_HELLO -> NetworkClientLocalPlayer |
|
41 |
*/ |
|
274
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
263
diff
changeset
|
42 |
void on_server_hello (NetworkObjectID obj_id, NetworkPacketInput &pkt); |
294 | 43 |
|
44 |
/** |
|
45 |
* Handle NETMSG_PLAYER_INFO -> NetworkClientRemotePlayer |
|
46 |
*/ |
|
274
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
263
diff
changeset
|
47 |
void on_player_info (NetworkObjectID obj_id, NetworkPacketInput &pkt); |
294 | 48 |
|
49 |
/** |
|
50 |
* Handle NETMSG_PLAYER_JOIN -> NetworkClientRemotePlayer |
|
51 |
*/ |
|
274
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
263
diff
changeset
|
52 |
void on_player_join (NetworkObjectID obj_id, NetworkPacketInput &pkt); |
294 | 53 |
|
54 |
/** |
|
55 |
* Handle NETMSG_PROJECTILE_PLAYER_FIRED -> NetworkClientProjectile |
|
56 |
*/ |
|
276
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
274
diff
changeset
|
57 |
void on_projectile_player_fired (NetworkObjectID obj_id, NetworkPacketInput &pkt); |
274
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
263
diff
changeset
|
58 |
}; |
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
263
diff
changeset
|
59 |
|
294 | 60 |
/** |
61 |
* Our NetworkClient, that connects to a NetworkServer. This has the GameState, NetworkSession, NetworkClientController, etc. |
|
62 |
*/ |
|
187 | 63 |
class NetworkClient { |
274
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
263
diff
changeset
|
64 |
friend class NetworkClientController; |
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
263
diff
changeset
|
65 |
friend class NetworkClientObject; |
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
263
diff
changeset
|
66 |
friend class NetworkClientPlayerBase; |
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
67 |
friend class NetworkClientLocalPlayer; |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
68 |
friend class NetworkClientRemotePlayer; |
223 | 69 |
friend class NetworkClientProjectile; |
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
70 |
|
187 | 71 |
protected: |
294 | 72 |
/** |
73 |
* The GameState |
|
74 |
*/ |
|
187 | 75 |
GameState &state; |
294 | 76 |
|
187 | 77 |
CL_SlotContainer slots; |
294 | 78 |
|
79 |
/** |
|
80 |
* The connect()-mode NetworkSession |
|
81 |
*/ |
|
82 |
NetworkSession netsession; |
|
187 | 83 |
|
294 | 84 |
/** |
85 |
* The server NetworkNode from Netsession::connect |
|
86 |
*/ |
|
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
87 |
NetworkNode *server; |
294 | 88 |
|
89 |
/** |
|
90 |
* Our specialized NetworkObject_ClientController |
|
91 |
*/ |
|
274
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
263
diff
changeset
|
92 |
NetworkClientController controller; |
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
93 |
|
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
94 |
public: |
294 | 95 |
/** |
96 |
* Create a NetworkClient with the given GameState, connecting a server on the given NetworkAddress |
|
97 |
* |
|
98 |
* @param state the GameState to use |
|
99 |
* @param connect_to the address to connect to |
|
100 |
*/ |
|
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
101 |
NetworkClient (GameState &state, const NetworkAddress &connect_to); |
274
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
263
diff
changeset
|
102 |
|
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
263
diff
changeset
|
103 |
protected: |
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
263
diff
changeset
|
104 |
/** |
294 | 105 |
* Receive the NETCHAN_TERRAIN_ARRAY message from the server and apply it to our GameState::world terrain |
274
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
263
diff
changeset
|
106 |
*/ |
203
3ec7ab40755f
send initial terrain data to clients using a new NETCHAN_TERRAIN_ARRAY channel using raw BigNetworkPacket
terom
parents:
200
diff
changeset
|
107 |
void on_terrain_array (NetworkPacketInput &pkt, NetworkNode *node); |
185
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 |
public: |
294 | 110 |
/** |
111 |
* Called by NetworkClientRemotePlayer when they get disconnected. Doesn't do anything currently |
|
112 |
*/ |
|
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
113 |
void player_quit (NetworkClientRemotePlayer *player); |
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 |
|
294 | 116 |
/** |
117 |
* Our base NetworkObject_Client object, containing the NetworkClient and a CL_SlotContainer for conveniance |
|
118 |
*/ |
|
274
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
263
diff
changeset
|
119 |
class NetworkClientObject : public NetworkObject_Client { |
200
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
187
diff
changeset
|
120 |
protected: |
294 | 121 |
/** |
122 |
* The NetworkClient |
|
123 |
*/ |
|
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
124 |
NetworkClient &client; |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
125 |
|
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
126 |
CL_SlotContainer slots; |
294 | 127 |
|
128 |
/** |
|
129 |
* Construct this using the given client and obj_id, passing the client.controller and obj_id to the |
|
130 |
* NetworkObject_Client's constructor |
|
131 |
*/ |
|
274
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
263
diff
changeset
|
132 |
NetworkClientObject (NetworkClient &client, NetworkObjectID obj_id); |
223 | 133 |
}; |
134 |
||
294 | 135 |
/** |
136 |
* Our base class for NetworkClient Players, this implements most of the server -> client messages |
|
137 |
* |
|
138 |
* This inherits from NetworkClientObject and virtually from Player, as classes should inherit from both this and |
|
139 |
* LocalPlayer/RemotePlayer |
|
140 |
*/ |
|
274
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
263
diff
changeset
|
141 |
class NetworkClientPlayerBase : public NetworkClientObject, public virtual Player { |
200
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
187
diff
changeset
|
142 |
protected: |
294 | 143 |
/** |
144 |
* Dummy-initialize Player, initialize NetworkClientObject, and hook up our signals |
|
145 |
*/ |
|
274
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
263
diff
changeset
|
146 |
NetworkClientPlayerBase (NetworkClient &client, NetworkObjectID obj_id, Vector position); |
200
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
187
diff
changeset
|
147 |
|
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
187
diff
changeset
|
148 |
private: |
294 | 149 |
/** |
150 |
* NETMSG_PLAYER_POSITION -> PhysicsObject::updatePhysics |
|
151 |
*/ |
|
200
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
187
diff
changeset
|
152 |
void on_position (NetworkPacketInput &pkt); |
294 | 153 |
|
154 |
/** |
|
155 |
* NETMSG_PLAYER_DIG -> Player::handleDig |
|
156 |
*/ |
|
200
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
187
diff
changeset
|
157 |
void on_dig (NetworkPacketInput &pkt); |
294 | 158 |
|
159 |
/** |
|
160 |
* NETMSG_PLAYER_WEAPON_CHANGE -> Player::rope.handleChangeWeapon |
|
161 |
*/ |
|
239
550397d9d479
implement network weapon changes and fix weapon firing
terom
parents:
224
diff
changeset
|
162 |
void on_weapon_change (NetworkPacketInput &pkt); |
294 | 163 |
|
164 |
/** |
|
165 |
* NETMSG_PLAYER_ROPE_THROW -> Player::rope.updateState(ROPE_FLYING) |
|
166 |
*/ |
|
241 | 167 |
void on_rope_throw (NetworkPacketInput &pkt); |
294 | 168 |
|
169 |
/** |
|
170 |
* NETMSG_PLAYER_ROPE_FIXED -> Player::rope.updateState(ROPE_FIXED) |
|
171 |
*/ |
|
241 | 172 |
void on_rope_fixed (NetworkPacketInput &pkt); |
294 | 173 |
|
174 |
/** |
|
175 |
* NETMSG_PLAYER_ROPE_RELEASED -> Player::rope.updateState(ROPE_FOLDED) |
|
176 |
*/ |
|
241 | 177 |
void on_rope_released (NetworkPacketInput &pkt); |
294 | 178 |
|
179 |
/** |
|
180 |
* NETMSG_PLAYER_ROPE_LENGTH -> Player::Rope.updateLength |
|
181 |
*/ |
|
241 | 182 |
void on_rope_length (NetworkPacketInput &pkt); |
200
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
187
diff
changeset
|
183 |
}; |
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
187
diff
changeset
|
184 |
|
294 | 185 |
/** |
186 |
* Our NetworkClientPlayerBase + LocalPlayer specialization, this lets us handle local input |
|
187 |
*/ |
|
274
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
263
diff
changeset
|
188 |
class NetworkClientLocalPlayer : public NetworkClientPlayerBase, public LocalPlayer { |
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
189 |
public: |
294 | 190 |
/** |
191 |
* Calls NetworkClientPlayerBase/Player constructors, calls GameState::setLocalPlayer |
|
192 |
*/ |
|
274
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
263
diff
changeset
|
193 |
NetworkClientLocalPlayer (NetworkClient &client, NetworkObjectID obj_id, Vector position); |
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
194 |
|
294 | 195 |
/** |
196 |
* Overriden from LocalPlayer to send a NETMSG_CLIENT_INPUT message without executing LocalPlayer::handleInput |
|
197 |
* locally |
|
198 |
*/ |
|
277 | 199 |
virtual void handleInput (PlayerInput input, TimeMS dt); |
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
200 |
}; |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
201 |
|
294 | 202 |
/** |
203 |
* Our NetworkClientPlayerBase + RemotePlayer specialization, this lets us handle players quitting |
|
204 |
*/ |
|
274
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
263
diff
changeset
|
205 |
class NetworkClientRemotePlayer : public NetworkClientPlayerBase, public RemotePlayer { |
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
206 |
public: |
294 | 207 |
/** |
208 |
* Calls NetworkClientPlayerBase/Player constructors and hooks up signals |
|
209 |
*/ |
|
274
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
263
diff
changeset
|
210 |
NetworkClientRemotePlayer (NetworkClient &client, NetworkObjectID obj_id, Vector position); |
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
211 |
|
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
212 |
private: |
294 | 213 |
/** |
214 |
* Calls NetworkClient::player_quit, and then destroys ourselves |
|
215 |
*/ |
|
200
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
187
diff
changeset
|
216 |
void on_quit (NetworkPacketInput &pkt); |
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
217 |
}; |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
218 |
|
294 | 219 |
/** |
220 |
* A Projectile that was created on the server |
|
221 |
*/ |
|
274
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
263
diff
changeset
|
222 |
class NetworkClientProjectile : public NetworkClientObject, public Projectile { |
223 | 223 |
public: |
294 | 224 |
/** |
225 |
* Call Projectile's constructor, hook up signals and call player->weaponFired |
|
226 |
*/ |
|
276
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
274
diff
changeset
|
227 |
NetworkClientProjectile (NetworkClient &client, NetworkObjectID obj_id, Player *player, Vector position, |
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
274
diff
changeset
|
228 |
Vector velocity, Weapon *weapon); |
224
e6faefba2ec1
fixed logger, and network projectiles should work reasonably well now
terom
parents:
223
diff
changeset
|
229 |
|
e6faefba2ec1
fixed logger, and network projectiles should work reasonably well now
terom
parents:
223
diff
changeset
|
230 |
protected: |
294 | 231 |
/** |
232 |
* Overrides Projectile::onDestroy to ignore this, as we must wait for the server to tell us where it impacted |
|
233 |
* so that we can remove the ground reliably |
|
234 |
*/ |
|
224
e6faefba2ec1
fixed logger, and network projectiles should work reasonably well now
terom
parents:
223
diff
changeset
|
235 |
virtual void onDestroy (Vector position, bool removeGround); |
e6faefba2ec1
fixed logger, and network projectiles should work reasonably well now
terom
parents:
223
diff
changeset
|
236 |
|
e6faefba2ec1
fixed logger, and network projectiles should work reasonably well now
terom
parents:
223
diff
changeset
|
237 |
private: |
294 | 238 |
/** |
239 |
* NETMSG_PROJECTILE_DESTROY -> Projectile::onDestory |
|
240 |
*/ |
|
224
e6faefba2ec1
fixed logger, and network projectiles should work reasonably well now
terom
parents:
223
diff
changeset
|
241 |
void on_destroy (NetworkPacketInput &pkt); |
223 | 242 |
}; |
243 |
||
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
244 |
#endif |