author | Tero Marttila <terom@fixme.fi> |
Tue, 20 Jan 2009 23:30:18 +0200 | |
changeset 408 | e6cfc44266af |
parent 400 | d64bf28c4340 |
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 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 |
|
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:
381
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:
381
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:
381
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:
381
diff
changeset
|
7 |
* Game client implementation |
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:
381
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:
381
diff
changeset
|
9 |
|
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
10 |
// forward-declare |
408
e6cfc44266af
reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents:
400
diff
changeset
|
11 |
class NetworkClientConnect; |
274
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
263
diff
changeset
|
12 |
class NetworkClient; |
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
13 |
class NetworkClientLocalPlayer; |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
14 |
class NetworkClientRemotePlayer; |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
15 |
|
332
78657bf06302
handle NetworkClient server-disconnect by logging an error and stopping the engine
terom
parents:
330
diff
changeset
|
16 |
#include "../GameState.hh" |
78657bf06302
handle NetworkClient server-disconnect by logging an error and stopping the engine
terom
parents:
330
diff
changeset
|
17 |
#include "../Engine.hh" |
78657bf06302
handle NetworkClient server-disconnect by logging an error and stopping the engine
terom
parents:
330
diff
changeset
|
18 |
#include "Session.hh" |
78657bf06302
handle NetworkClient server-disconnect by logging an error and stopping the engine
terom
parents:
330
diff
changeset
|
19 |
#include "Object.hh" |
78657bf06302
handle NetworkClient server-disconnect by logging an error and stopping the engine
terom
parents:
330
diff
changeset
|
20 |
|
294 | 21 |
/** |
22 |
* Our specialized NetworkObject_ClientController that overrides handle_create to create the right kind of |
|
23 |
* object (a subclass of NetowrkClientObject). |
|
24 |
*/ |
|
274
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
263
diff
changeset
|
25 |
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
|
26 |
protected: |
294 | 27 |
/** |
28 |
* The NetworkClient |
|
29 |
*/ |
|
274
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
263
diff
changeset
|
30 |
NetworkClient &client; |
408
e6cfc44266af
reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents:
400
diff
changeset
|
31 |
|
274
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
263
diff
changeset
|
32 |
public: |
294 | 33 |
/** |
34 |
* Control objects on the given client using the client.netsession's NETCHAN_CORE channel |
|
35 |
*/ |
|
274
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
263
diff
changeset
|
36 |
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
|
37 |
|
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
263
diff
changeset
|
38 |
protected: |
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
263
diff
changeset
|
39 |
/** |
294 | 40 |
* We override handle_create from NetworkObject_ClientController to call one of the on_* methods, which creates |
41 |
* a NetworkClientObject subclass |
|
42 |
* |
|
43 |
* @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
|
44 |
*/ |
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
263
diff
changeset
|
45 |
virtual void handle_create (NetworkObjectID obj_id, NetworkMessageID msg_id, NetworkPacketInput &pkt, NetworkNode *node); |
294 | 46 |
|
47 |
/** |
|
48 |
* Handle NETMSG_SERVER_HELLO -> NetworkClientLocalPlayer |
|
49 |
*/ |
|
274
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
263
diff
changeset
|
50 |
void on_server_hello (NetworkObjectID obj_id, NetworkPacketInput &pkt); |
294 | 51 |
|
52 |
/** |
|
53 |
* Handle NETMSG_PLAYER_INFO -> NetworkClientRemotePlayer |
|
54 |
*/ |
|
274
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
263
diff
changeset
|
55 |
void on_player_info (NetworkObjectID obj_id, NetworkPacketInput &pkt); |
294 | 56 |
|
57 |
/** |
|
58 |
* Handle NETMSG_PLAYER_JOIN -> NetworkClientRemotePlayer |
|
59 |
*/ |
|
274
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
263
diff
changeset
|
60 |
void on_player_join (NetworkObjectID obj_id, NetworkPacketInput &pkt); |
294 | 61 |
|
62 |
/** |
|
63 |
* Handle NETMSG_PROJECTILE_PLAYER_FIRED -> NetworkClientProjectile |
|
64 |
*/ |
|
276
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
274
diff
changeset
|
65 |
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
|
66 |
}; |
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
263
diff
changeset
|
67 |
|
294 | 68 |
/** |
69 |
* Our NetworkClient, that connects to a NetworkServer. This has the GameState, NetworkSession, NetworkClientController, etc. |
|
70 |
*/ |
|
187 | 71 |
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
|
72 |
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
|
73 |
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
|
74 |
friend class NetworkClientPlayerBase; |
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
75 |
friend class NetworkClientLocalPlayer; |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
76 |
friend class NetworkClientRemotePlayer; |
223 | 77 |
friend class NetworkClientProjectile; |
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
78 |
|
187 | 79 |
protected: |
294 | 80 |
/** |
332
78657bf06302
handle NetworkClient server-disconnect by logging an error and stopping the engine
terom
parents:
330
diff
changeset
|
81 |
* The Engine |
78657bf06302
handle NetworkClient server-disconnect by logging an error and stopping the engine
terom
parents:
330
diff
changeset
|
82 |
*/ |
78657bf06302
handle NetworkClient server-disconnect by logging an error and stopping the engine
terom
parents:
330
diff
changeset
|
83 |
Engine &engine; |
78657bf06302
handle NetworkClient server-disconnect by logging an error and stopping the engine
terom
parents:
330
diff
changeset
|
84 |
|
78657bf06302
handle NetworkClient server-disconnect by logging an error and stopping the engine
terom
parents:
330
diff
changeset
|
85 |
/** |
294 | 86 |
* The GameState |
87 |
*/ |
|
187 | 88 |
GameState &state; |
294 | 89 |
|
90 |
/** |
|
91 |
* The connect()-mode NetworkSession |
|
92 |
*/ |
|
408
e6cfc44266af
reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents:
400
diff
changeset
|
93 |
NetworkSession &netsession; |
187 | 94 |
|
294 | 95 |
/** |
96 |
* The server NetworkNode from Netsession::connect |
|
97 |
*/ |
|
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
98 |
NetworkNode *server; |
294 | 99 |
|
100 |
/** |
|
101 |
* Our specialized NetworkObject_ClientController |
|
102 |
*/ |
|
274
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
263
diff
changeset
|
103 |
NetworkClientController controller; |
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
104 |
|
408
e6cfc44266af
reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents:
400
diff
changeset
|
105 |
CL_SlotContainer slots; |
e6cfc44266af
reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents:
400
diff
changeset
|
106 |
|
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
107 |
public: |
294 | 108 |
/** |
381
9b35bc329d23
separate sockaddr stuff out of NetworkAddress... now called NetworkEndpoint
terom
parents:
332
diff
changeset
|
109 |
* Create a NetworkClient with the given GameState, connecting a server on the given NetworkEndpoint |
294 | 110 |
* |
332
78657bf06302
handle NetworkClient server-disconnect by logging an error and stopping the engine
terom
parents:
330
diff
changeset
|
111 |
* @param engine the Engine we're running as |
294 | 112 |
* @param state the GameState to use |
113 |
* @param connect_to the address to connect to |
|
114 |
*/ |
|
408
e6cfc44266af
reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents:
400
diff
changeset
|
115 |
NetworkClient (Engine &engine, GameState &state, NetworkSession &netsession, NetworkNode *server); |
e6cfc44266af
reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents:
400
diff
changeset
|
116 |
|
e6cfc44266af
reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents:
400
diff
changeset
|
117 |
public: |
e6cfc44266af
reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents:
400
diff
changeset
|
118 |
/** |
e6cfc44266af
reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents:
400
diff
changeset
|
119 |
* Called by NetworkClientRemotePlayer when they get disconnected. Doesn't do anything currently |
e6cfc44266af
reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents:
400
diff
changeset
|
120 |
*/ |
e6cfc44266af
reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents:
400
diff
changeset
|
121 |
void player_quit (NetworkClientRemotePlayer *player); |
e6cfc44266af
reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents:
400
diff
changeset
|
122 |
}; |
e6cfc44266af
reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents:
400
diff
changeset
|
123 |
|
e6cfc44266af
reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents:
400
diff
changeset
|
124 |
/** |
e6cfc44266af
reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents:
400
diff
changeset
|
125 |
* This handles the actual connection process to the server, and handles the initial data from the server. Once the |
e6cfc44266af
reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents:
400
diff
changeset
|
126 |
* Engine has a game running, we can create the actual NetworkClient object. |
e6cfc44266af
reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents:
400
diff
changeset
|
127 |
*/ |
e6cfc44266af
reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents:
400
diff
changeset
|
128 |
class NetworkClientConnect { |
e6cfc44266af
reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents:
400
diff
changeset
|
129 |
protected: |
e6cfc44266af
reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents:
400
diff
changeset
|
130 |
/** |
e6cfc44266af
reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents:
400
diff
changeset
|
131 |
* The Engine we are running under |
e6cfc44266af
reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents:
400
diff
changeset
|
132 |
*/ |
e6cfc44266af
reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents:
400
diff
changeset
|
133 |
Engine &engine; |
e6cfc44266af
reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents:
400
diff
changeset
|
134 |
|
e6cfc44266af
reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents:
400
diff
changeset
|
135 |
/** |
e6cfc44266af
reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents:
400
diff
changeset
|
136 |
* The NetworkSession we are using |
e6cfc44266af
reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents:
400
diff
changeset
|
137 |
*/ |
e6cfc44266af
reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents:
400
diff
changeset
|
138 |
NetworkSession netsession; |
e6cfc44266af
reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents:
400
diff
changeset
|
139 |
|
e6cfc44266af
reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents:
400
diff
changeset
|
140 |
/** |
e6cfc44266af
reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents:
400
diff
changeset
|
141 |
* The server we've connected to |
e6cfc44266af
reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents:
400
diff
changeset
|
142 |
*/ |
e6cfc44266af
reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents:
400
diff
changeset
|
143 |
NetworkNode *server; |
e6cfc44266af
reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents:
400
diff
changeset
|
144 |
|
e6cfc44266af
reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents:
400
diff
changeset
|
145 |
/** |
e6cfc44266af
reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents:
400
diff
changeset
|
146 |
* The NetworkClient that we eventually create |
e6cfc44266af
reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents:
400
diff
changeset
|
147 |
*/ |
e6cfc44266af
reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents:
400
diff
changeset
|
148 |
NetworkClient *client; |
e6cfc44266af
reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents:
400
diff
changeset
|
149 |
|
e6cfc44266af
reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents:
400
diff
changeset
|
150 |
CL_SlotContainer slots; |
e6cfc44266af
reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents:
400
diff
changeset
|
151 |
|
e6cfc44266af
reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents:
400
diff
changeset
|
152 |
public: |
e6cfc44266af
reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents:
400
diff
changeset
|
153 |
/** |
e6cfc44266af
reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents:
400
diff
changeset
|
154 |
* Begin the connection process. Once it is complete, we will callback to Engine::networkClientConnected |
e6cfc44266af
reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents:
400
diff
changeset
|
155 |
*/ |
e6cfc44266af
reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents:
400
diff
changeset
|
156 |
NetworkClientConnect (Engine &engine, const NetworkEndpoint &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
|
157 |
|
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
263
diff
changeset
|
158 |
protected: |
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
263
diff
changeset
|
159 |
/** |
332
78657bf06302
handle NetworkClient server-disconnect by logging an error and stopping the engine
terom
parents:
330
diff
changeset
|
160 |
* We have disconnected from the server |
78657bf06302
handle NetworkClient server-disconnect by logging an error and stopping the engine
terom
parents:
330
diff
changeset
|
161 |
*/ |
78657bf06302
handle NetworkClient server-disconnect by logging an error and stopping the engine
terom
parents:
330
diff
changeset
|
162 |
void on_disconnected (void); |
78657bf06302
handle NetworkClient server-disconnect by logging an error and stopping the engine
terom
parents:
330
diff
changeset
|
163 |
|
78657bf06302
handle NetworkClient server-disconnect by logging an error and stopping the engine
terom
parents:
330
diff
changeset
|
164 |
/** |
294 | 165 |
* 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
|
166 |
*/ |
203
3ec7ab40755f
send initial terrain data to clients using a new NETCHAN_TERRAIN_ARRAY channel using raw BigNetworkPacket
terom
parents:
200
diff
changeset
|
167 |
void on_terrain_array (NetworkPacketInput &pkt, NetworkNode *node); |
408
e6cfc44266af
reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents:
400
diff
changeset
|
168 |
|
294 | 169 |
/** |
408
e6cfc44266af
reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents:
400
diff
changeset
|
170 |
* Finished connecting |
294 | 171 |
*/ |
408
e6cfc44266af
reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents:
400
diff
changeset
|
172 |
void connectDone (Terrain *terrain); |
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 |
|
294 | 175 |
/** |
176 |
* Our base NetworkObject_Client object, containing the NetworkClient and a CL_SlotContainer for conveniance |
|
177 |
*/ |
|
274
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
263
diff
changeset
|
178 |
class NetworkClientObject : public NetworkObject_Client { |
200
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
187
diff
changeset
|
179 |
protected: |
294 | 180 |
/** |
181 |
* The NetworkClient |
|
182 |
*/ |
|
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
183 |
NetworkClient &client; |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
184 |
|
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
185 |
CL_SlotContainer slots; |
294 | 186 |
|
187 |
/** |
|
188 |
* Construct this using the given client and obj_id, passing the client.controller and obj_id to the |
|
189 |
* NetworkObject_Client's constructor |
|
190 |
*/ |
|
274
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
263
diff
changeset
|
191 |
NetworkClientObject (NetworkClient &client, NetworkObjectID obj_id); |
223 | 192 |
}; |
193 |
||
294 | 194 |
/** |
195 |
* Our base class for NetworkClient Players, this implements most of the server -> client messages |
|
196 |
* |
|
197 |
* This inherits from NetworkClientObject and virtually from Player, as classes should inherit from both this and |
|
198 |
* LocalPlayer/RemotePlayer |
|
199 |
*/ |
|
274
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
263
diff
changeset
|
200 |
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
|
201 |
protected: |
294 | 202 |
/** |
203 |
* Dummy-initialize Player, initialize NetworkClientObject, and hook up our signals |
|
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 |
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
|
206 |
|
302 | 207 |
protected: |
208 |
// @{ |
|
209 |
/** |
|
210 |
* These should never be called directly, always via the network |
|
211 |
*/ |
|
212 |
virtual void spawn (Vector position); |
|
213 |
virtual void respawn (TimeMS dt); |
|
214 |
// @} |
|
303 | 215 |
|
216 |
/** |
|
217 |
* Ignore, the servers tells us this |
|
218 |
*/ |
|
219 |
virtual void die (bool start_timer = true); |
|
302 | 220 |
|
200
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
187
diff
changeset
|
221 |
private: |
294 | 222 |
/** |
223 |
* NETMSG_PLAYER_POSITION -> PhysicsObject::updatePhysics |
|
224 |
*/ |
|
200
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
187
diff
changeset
|
225 |
void on_position (NetworkPacketInput &pkt); |
294 | 226 |
|
227 |
/** |
|
228 |
* NETMSG_PLAYER_DIG -> Player::handleDig |
|
229 |
*/ |
|
200
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
187
diff
changeset
|
230 |
void on_dig (NetworkPacketInput &pkt); |
294 | 231 |
|
232 |
/** |
|
233 |
* NETMSG_PLAYER_WEAPON_CHANGE -> Player::rope.handleChangeWeapon |
|
234 |
*/ |
|
239
550397d9d479
implement network weapon changes and fix weapon firing
terom
parents:
224
diff
changeset
|
235 |
void on_weapon_change (NetworkPacketInput &pkt); |
294 | 236 |
|
237 |
/** |
|
238 |
* NETMSG_PLAYER_ROPE_THROW -> Player::rope.updateState(ROPE_FLYING) |
|
239 |
*/ |
|
241 | 240 |
void on_rope_throw (NetworkPacketInput &pkt); |
294 | 241 |
|
242 |
/** |
|
243 |
* NETMSG_PLAYER_ROPE_FIXED -> Player::rope.updateState(ROPE_FIXED) |
|
244 |
*/ |
|
241 | 245 |
void on_rope_fixed (NetworkPacketInput &pkt); |
294 | 246 |
|
247 |
/** |
|
248 |
* NETMSG_PLAYER_ROPE_RELEASED -> Player::rope.updateState(ROPE_FOLDED) |
|
249 |
*/ |
|
241 | 250 |
void on_rope_released (NetworkPacketInput &pkt); |
294 | 251 |
|
252 |
/** |
|
253 |
* NETMSG_PLAYER_ROPE_LENGTH -> Player::Rope.updateLength |
|
254 |
*/ |
|
241 | 255 |
void on_rope_length (NetworkPacketInput &pkt); |
302 | 256 |
|
257 |
/** |
|
258 |
* NETMSG_PLAYER_SPAWN -> Player::spawn |
|
259 |
*/ |
|
260 |
void on_spawn (NetworkPacketInput &pkt); |
|
261 |
||
262 |
/** |
|
263 |
* NETMSG_PLAYER_Die -> Player::die |
|
264 |
*/ |
|
265 |
void on_die (NetworkPacketInput &pkt); |
|
200
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
187
diff
changeset
|
266 |
}; |
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
187
diff
changeset
|
267 |
|
294 | 268 |
/** |
269 |
* Our NetworkClientPlayerBase + LocalPlayer specialization, this lets us handle local input |
|
270 |
*/ |
|
274
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
263
diff
changeset
|
271 |
class NetworkClientLocalPlayer : public NetworkClientPlayerBase, public LocalPlayer { |
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
272 |
public: |
294 | 273 |
/** |
274 |
* Calls NetworkClientPlayerBase/Player constructors, calls GameState::setLocalPlayer |
|
275 |
*/ |
|
274
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
263
diff
changeset
|
276 |
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
|
277 |
|
294 | 278 |
/** |
279 |
* Overriden from LocalPlayer to send a NETMSG_CLIENT_INPUT message without executing LocalPlayer::handleInput |
|
280 |
* locally |
|
281 |
*/ |
|
277 | 282 |
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
|
283 |
}; |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
284 |
|
294 | 285 |
/** |
286 |
* Our NetworkClientPlayerBase + RemotePlayer specialization, this lets us handle players quitting |
|
287 |
*/ |
|
274
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
263
diff
changeset
|
288 |
class NetworkClientRemotePlayer : public NetworkClientPlayerBase, public RemotePlayer { |
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
289 |
public: |
294 | 290 |
/** |
291 |
* Calls NetworkClientPlayerBase/Player constructors and hooks up signals |
|
292 |
*/ |
|
274
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
263
diff
changeset
|
293 |
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
|
294 |
|
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
295 |
private: |
294 | 296 |
/** |
297 |
* Calls NetworkClient::player_quit, and then destroys ourselves |
|
298 |
*/ |
|
200
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
187
diff
changeset
|
299 |
void on_quit (NetworkPacketInput &pkt); |
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
300 |
}; |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
301 |
|
294 | 302 |
/** |
303 |
* A Projectile that was created on the server |
|
304 |
*/ |
|
274
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
263
diff
changeset
|
305 |
class NetworkClientProjectile : public NetworkClientObject, public Projectile { |
223 | 306 |
public: |
294 | 307 |
/** |
308 |
* Call Projectile's constructor, hook up signals and call player->weaponFired |
|
309 |
*/ |
|
276
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
274
diff
changeset
|
310 |
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
|
311 |
Vector velocity, Weapon *weapon); |
224
e6faefba2ec1
fixed logger, and network projectiles should work reasonably well now
terom
parents:
223
diff
changeset
|
312 |
|
e6faefba2ec1
fixed logger, and network projectiles should work reasonably well now
terom
parents:
223
diff
changeset
|
313 |
protected: |
294 | 314 |
/** |
315 |
* Overrides Projectile::onDestroy to ignore this, as we must wait for the server to tell us where it impacted |
|
316 |
* so that we can remove the ground reliably |
|
317 |
*/ |
|
224
e6faefba2ec1
fixed logger, and network projectiles should work reasonably well now
terom
parents:
223
diff
changeset
|
318 |
virtual void onDestroy (Vector position, bool removeGround); |
296
4d3ebaa29430
add separate Types.hh, and fix projectile-worm collisions on network
terom
parents:
294
diff
changeset
|
319 |
|
4d3ebaa29430
add separate Types.hh, and fix projectile-worm collisions on network
terom
parents:
294
diff
changeset
|
320 |
/** |
4d3ebaa29430
add separate Types.hh, and fix projectile-worm collisions on network
terom
parents:
294
diff
changeset
|
321 |
* Overrides Projectile::onHitPlayer to ignore this, as we must wait for the server to tell us if it really did |
4d3ebaa29430
add separate Types.hh, and fix projectile-worm collisions on network
terom
parents:
294
diff
changeset
|
322 |
* happen. |
4d3ebaa29430
add separate Types.hh, and fix projectile-worm collisions on network
terom
parents:
294
diff
changeset
|
323 |
*/ |
330 | 324 |
virtual void onHitPlayer (Player *player); |
224
e6faefba2ec1
fixed logger, and network projectiles should work reasonably well now
terom
parents:
223
diff
changeset
|
325 |
|
e6faefba2ec1
fixed logger, and network projectiles should work reasonably well now
terom
parents:
223
diff
changeset
|
326 |
private: |
294 | 327 |
/** |
328 |
* NETMSG_PROJECTILE_DESTROY -> Projectile::onDestory |
|
329 |
*/ |
|
224
e6faefba2ec1
fixed logger, and network projectiles should work reasonably well now
terom
parents:
223
diff
changeset
|
330 |
void on_destroy (NetworkPacketInput &pkt); |
296
4d3ebaa29430
add separate Types.hh, and fix projectile-worm collisions on network
terom
parents:
294
diff
changeset
|
331 |
|
4d3ebaa29430
add separate Types.hh, and fix projectile-worm collisions on network
terom
parents:
294
diff
changeset
|
332 |
/** |
4d3ebaa29430
add separate Types.hh, and fix projectile-worm collisions on network
terom
parents:
294
diff
changeset
|
333 |
* NETMSG_PROJECTILE_HIT_PLAYER -> Projectile::onHitPlayer |
4d3ebaa29430
add separate Types.hh, and fix projectile-worm collisions on network
terom
parents:
294
diff
changeset
|
334 |
*/ |
4d3ebaa29430
add separate Types.hh, and fix projectile-worm collisions on network
terom
parents:
294
diff
changeset
|
335 |
void on_hit_player (NetworkPacketInput &pkt); |
223 | 336 |
}; |
337 |
||
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
338 |
#endif |