author | Tero Marttila <terom@fixme.fi> |
Thu, 22 Jan 2009 02:47:53 +0200 | |
branch | new_graphics |
changeset 419 | 9cd4e54693b6 |
parent 417 | c503e0c6a740 |
child 420 | 278020dcd9b7 |
permissions | -rw-r--r-- |
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
1 |
|
186 | 2 |
#include "Client.hh" |
187 | 3 |
#include "Protocol.hh" |
417
c503e0c6a740
support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents:
408
diff
changeset
|
4 |
#include "../Config.hh" |
186 | 5 |
#include "../Engine.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 <cassert> |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
9 |
|
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:
406
diff
changeset
|
10 |
/* |
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:
406
diff
changeset
|
11 |
* 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:
406
diff
changeset
|
12 |
*/ |
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:
406
diff
changeset
|
13 |
NetworkClientConnect::NetworkClientConnect (Engine &engine, const NetworkEndpoint &connect_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:
406
diff
changeset
|
14 |
engine(engine), netsession(NETWORK_MAGIC_ID) |
274
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
15 |
{ |
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:
406
diff
changeset
|
16 |
// connect NetworkSession to get server node (this is still blocking) |
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:
406
diff
changeset
|
17 |
server = netsession.connect(connect_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:
406
diff
changeset
|
18 |
|
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
19 |
// connect slots |
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:
406
diff
changeset
|
20 |
slots.connect(netsession.sig_chan_message(NETCHAN_TERRAIN_ARRAY), this, &NetworkClientConnect::on_terrain_array); |
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:
406
diff
changeset
|
21 |
slots.connect(server->sig_disconnected(), this, &NetworkClientConnect::on_disconnected); |
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:
406
diff
changeset
|
22 |
|
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:
406
diff
changeset
|
23 |
// then we must wait for the terrain data |
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
24 |
} |
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:
406
diff
changeset
|
25 |
|
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:
406
diff
changeset
|
26 |
void NetworkClientConnect::on_disconnected (void) { |
332
78657bf06302
handle NetworkClient server-disconnect by logging an error and stopping the engine
terom
parents:
330
diff
changeset
|
27 |
Engine::log(ERROR, "client.on_disconnect") << "Disconnected from server"; |
78657bf06302
handle NetworkClient server-disconnect by logging an error and stopping the engine
terom
parents:
330
diff
changeset
|
28 |
engine.stop(); |
78657bf06302
handle NetworkClient server-disconnect by logging an error and stopping the engine
terom
parents:
330
diff
changeset
|
29 |
} |
78657bf06302
handle NetworkClient server-disconnect by logging an error and stopping the engine
terom
parents:
330
diff
changeset
|
30 |
|
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:
406
diff
changeset
|
31 |
void NetworkClientConnect::on_terrain_array (NetworkPacketInput &pkt, NetworkNode *node) { |
203
3ec7ab40755f
send initial terrain data to clients using a new NETCHAN_TERRAIN_ARRAY channel using raw BigNetworkPacket
terom
parents:
200
diff
changeset
|
32 |
// ignore if not from server |
3ec7ab40755f
send initial terrain data to clients using a new NETCHAN_TERRAIN_ARRAY channel using raw BigNetworkPacket
terom
parents:
200
diff
changeset
|
33 |
if (node != server) |
3ec7ab40755f
send initial terrain data to clients using a new NETCHAN_TERRAIN_ARRAY channel using raw BigNetworkPacket
terom
parents:
200
diff
changeset
|
34 |
return; |
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:
406
diff
changeset
|
35 |
|
203
3ec7ab40755f
send initial terrain data to clients using a new NETCHAN_TERRAIN_ARRAY channel using raw BigNetworkPacket
terom
parents:
200
diff
changeset
|
36 |
// read map width/height |
282
e0e4dfc3e528
compiles cleanly with -Wall -Wextra -Wconversion, not tested, but that shouldn't break anything :)
terom
parents:
277
diff
changeset
|
37 |
PixelDimension map_w = pkt.read_uint32(); |
e0e4dfc3e528
compiles cleanly with -Wall -Wextra -Wconversion, not tested, but that shouldn't break anything :)
terom
parents:
277
diff
changeset
|
38 |
PixelDimension map_h = pkt.read_uint32(); |
203
3ec7ab40755f
send initial terrain data to clients using a new NETCHAN_TERRAIN_ARRAY channel using raw BigNetworkPacket
terom
parents:
200
diff
changeset
|
39 |
|
387
294ce7ae8140
dirty implementation of compressed terrain array data
terom
parents:
381
diff
changeset
|
40 |
// the terrain byte array |
294ce7ae8140
dirty implementation of compressed terrain array data
terom
parents:
381
diff
changeset
|
41 |
size_t terrain_size = map_w * map_h; |
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:
406
diff
changeset
|
42 |
TerrainPixel *terrain_buf = new TerrainPixel[map_w * map_h]; |
391
59c2499fe7bb
add compressed read/write NetworkPacket API and move zlib stuff out of NetworkServer/Client
Tero Marttila <terom@fixme.fi>
parents:
387
diff
changeset
|
43 |
|
59c2499fe7bb
add compressed read/write NetworkPacket API and move zlib stuff out of NetworkServer/Client
Tero Marttila <terom@fixme.fi>
parents:
387
diff
changeset
|
44 |
// read uncompressed terrain data |
59c2499fe7bb
add compressed read/write NetworkPacket API and move zlib stuff out of NetworkServer/Client
Tero Marttila <terom@fixme.fi>
parents:
387
diff
changeset
|
45 |
size_t inflate_size = pkt.read_uncompressed(terrain_buf, terrain_size); |
387
294ce7ae8140
dirty implementation of compressed terrain array data
terom
parents:
381
diff
changeset
|
46 |
|
294ce7ae8140
dirty implementation of compressed terrain array data
terom
parents:
381
diff
changeset
|
47 |
// invalid data? |
294ce7ae8140
dirty implementation of compressed terrain array data
terom
parents:
381
diff
changeset
|
48 |
if (inflate_size != terrain_size) |
294ce7ae8140
dirty implementation of compressed terrain array data
terom
parents:
381
diff
changeset
|
49 |
throw Error("Corrupt terrain data"); |
294ce7ae8140
dirty implementation of compressed terrain array data
terom
parents:
381
diff
changeset
|
50 |
|
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:
406
diff
changeset
|
51 |
// create the terrain object that we then use, and hand over terrain_buf to it |
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:
406
diff
changeset
|
52 |
Terrain *terrain = new Terrain(map_w, map_h, terrain_buf); |
203
3ec7ab40755f
send initial terrain data to clients using a new NETCHAN_TERRAIN_ARRAY channel using raw BigNetworkPacket
terom
parents:
200
diff
changeset
|
53 |
|
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:
406
diff
changeset
|
54 |
// execute connectDone |
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:
406
diff
changeset
|
55 |
connectDone(terrain); |
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:
406
diff
changeset
|
56 |
} |
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:
406
diff
changeset
|
57 |
|
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:
406
diff
changeset
|
58 |
void NetworkClientConnect::connectDone (Terrain *terrain) { |
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:
406
diff
changeset
|
59 |
// pass Terrain to engine to create game |
419
9cd4e54693b6
fix Engine <-> NetworkClient interaction
Tero Marttila <terom@fixme.fi>
parents:
417
diff
changeset
|
60 |
GameState &gs = engine.onNetworkClientConnected(terrain); |
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:
406
diff
changeset
|
61 |
|
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:
406
diff
changeset
|
62 |
// create our new 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:
406
diff
changeset
|
63 |
client = new NetworkClient(engine, gs, netsession, 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:
406
diff
changeset
|
64 |
} |
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:
406
diff
changeset
|
65 |
|
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:
406
diff
changeset
|
66 |
/* |
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:
406
diff
changeset
|
67 |
* NetworkClient |
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:
406
diff
changeset
|
68 |
*/ |
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:
406
diff
changeset
|
69 |
NetworkClient::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:
406
diff
changeset
|
70 |
engine(engine), state(state), netsession(netsession), server(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:
406
diff
changeset
|
71 |
controller(*this) |
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:
406
diff
changeset
|
72 |
{ |
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:
406
diff
changeset
|
73 |
|
203
3ec7ab40755f
send initial terrain data to clients using a new NETCHAN_TERRAIN_ARRAY channel using raw BigNetworkPacket
terom
parents:
200
diff
changeset
|
74 |
} |
3ec7ab40755f
send initial terrain data to clients using a new NETCHAN_TERRAIN_ARRAY channel using raw BigNetworkPacket
terom
parents:
200
diff
changeset
|
75 |
|
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
76 |
void NetworkClient::player_quit (NetworkClientRemotePlayer *player) { |
294 | 77 |
(void) player; |
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
78 |
} |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
79 |
|
223 | 80 |
/* |
274
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
81 |
* NetworkClientController |
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
82 |
*/ |
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
83 |
NetworkClientController::NetworkClientController (NetworkClient &client) : |
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
84 |
NetworkObject_ClientController(client.netsession, NETCHAN_CORE, client.server), client(client) |
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
85 |
{ |
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
86 |
|
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
87 |
} |
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
88 |
|
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
89 |
void NetworkClientController::handle_create (NetworkObjectID obj_id, NetworkMessageID msg_id, NetworkPacketInput &pkt, NetworkNode *node) { |
282
e0e4dfc3e528
compiles cleanly with -Wall -Wextra -Wconversion, not tested, but that shouldn't break anything :)
terom
parents:
277
diff
changeset
|
90 |
// XXX: should be server |
e0e4dfc3e528
compiles cleanly with -Wall -Wextra -Wconversion, not tested, but that shouldn't break anything :)
terom
parents:
277
diff
changeset
|
91 |
(void) node; |
e0e4dfc3e528
compiles cleanly with -Wall -Wextra -Wconversion, not tested, but that shouldn't break anything :)
terom
parents:
277
diff
changeset
|
92 |
|
274
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
93 |
switch (msg_id) { |
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
94 |
case NETMSG_SERVER_HELLO: |
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
95 |
on_server_hello(obj_id, pkt); |
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
96 |
break; |
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
97 |
|
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
98 |
case NETMSG_PLAYER_INFO: |
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
99 |
on_player_info(obj_id, pkt); |
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
100 |
break; |
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
101 |
|
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
102 |
case NETMSG_PLAYER_JOIN: |
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
103 |
on_player_join(obj_id, pkt); |
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
104 |
break; |
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
105 |
|
276
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
274
diff
changeset
|
106 |
case NETMSG_PROJECTILE_PLAYER_FIRED: |
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
274
diff
changeset
|
107 |
on_projectile_player_fired(obj_id, pkt); |
274
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
108 |
break; |
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
109 |
|
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
110 |
default: |
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
111 |
Engine::log(WARN, "client.handle_create") << "Unknown object create message: obj_id=" << obj_id << ", msg_id=" << msg_id; |
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
112 |
} |
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
113 |
} |
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
114 |
|
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
115 |
void NetworkClientController::on_server_hello (NetworkObjectID obj_id, NetworkPacketInput &pkt) { |
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
116 |
// read the packet |
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
117 |
Vector position = pkt.read_vector(); |
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
118 |
|
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
119 |
Engine::log(INFO, "client.on_server_hello") << this << ": pos=" << position; |
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
120 |
|
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
121 |
// create the LocalPlayer object |
419
9cd4e54693b6
fix Engine <-> NetworkClient interaction
Tero Marttila <terom@fixme.fi>
parents:
417
diff
changeset
|
122 |
NetworkClientLocalPlayer *player = new NetworkClientLocalPlayer(client, obj_id, position); |
9cd4e54693b6
fix Engine <-> NetworkClient interaction
Tero Marttila <terom@fixme.fi>
parents:
417
diff
changeset
|
123 |
|
9cd4e54693b6
fix Engine <-> NetworkClient interaction
Tero Marttila <terom@fixme.fi>
parents:
417
diff
changeset
|
124 |
// pass it on to engine |
9cd4e54693b6
fix Engine <-> NetworkClient interaction
Tero Marttila <terom@fixme.fi>
parents:
417
diff
changeset
|
125 |
client.engine.onNetworkClientPlayer(player); |
274
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
126 |
} |
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
127 |
|
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
128 |
void NetworkClientController::on_player_info (NetworkObjectID obj_id, NetworkPacketInput &pkt) { |
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
129 |
// read the packet |
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
130 |
Vector position = pkt.read_vector(); |
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
131 |
|
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
132 |
Engine::log(INFO, "client.on_player_info") << this << ": pos=" << position; |
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
133 |
|
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
134 |
// create the LocalPlayer object |
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
135 |
new NetworkClientRemotePlayer(client, obj_id, position); |
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
136 |
} |
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
137 |
|
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
138 |
void NetworkClientController::on_player_join (NetworkObjectID obj_id, NetworkPacketInput &pkt) { |
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
139 |
// read the packet |
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
140 |
Vector position = pkt.read_vector(); |
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
141 |
|
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
142 |
Engine::log(INFO, "client.on_player_join") << this << ": pos=" << position; |
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
143 |
|
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
144 |
// create the RemotePlayer object |
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
145 |
new NetworkClientRemotePlayer(client, obj_id, position); |
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
146 |
} |
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
147 |
|
276
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
274
diff
changeset
|
148 |
void NetworkClientController::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:
264
diff
changeset
|
149 |
// read the packet |
276
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
274
diff
changeset
|
150 |
NetworkObject *player_obj = client.controller.read_object(pkt); |
274
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
151 |
Vector position = pkt.read_vector(); |
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
152 |
Vector velocity = pkt.read_vector(); |
276
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
274
diff
changeset
|
153 |
WeaponID weapon_id = pkt.read_uint8(); |
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
274
diff
changeset
|
154 |
|
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
274
diff
changeset
|
155 |
NetworkClientPlayerBase *player; |
274
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
156 |
|
276
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
274
diff
changeset
|
157 |
// ignore for invalid players |
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
274
diff
changeset
|
158 |
if ((player = dynamic_cast<NetworkClientPlayerBase*>(player_obj)) == NULL) { |
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
274
diff
changeset
|
159 |
Engine::log(ERROR, "client.on_projectile_player_fired") << this << ": Unknown player object"; |
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
274
diff
changeset
|
160 |
return; |
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
274
diff
changeset
|
161 |
} |
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
274
diff
changeset
|
162 |
|
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
274
diff
changeset
|
163 |
Weapon *weapon; |
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
274
diff
changeset
|
164 |
|
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
274
diff
changeset
|
165 |
// try and get the weapon |
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
274
diff
changeset
|
166 |
if ((weapon = player->getWeapon(weapon_id)) == NULL) { |
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
274
diff
changeset
|
167 |
Engine::log(ERROR, "client.on_projectile_player_fired") << this << ": Unknown weapon id: player=" << player << ", weapon_id=" << weapon_id; |
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
274
diff
changeset
|
168 |
} |
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
274
diff
changeset
|
169 |
|
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
274
diff
changeset
|
170 |
Engine::log(INFO, "client.on_projectile_create") << this << ": player=" << player << ", pos=" << position << ", velocity=" << velocity << ", weapon=" << weapon; |
274
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
171 |
|
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
172 |
// create the NetworkClientPorjectile object |
276
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
274
diff
changeset
|
173 |
new NetworkClientProjectile(client, obj_id, player, position, velocity, weapon); |
274
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
174 |
} |
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
175 |
|
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
176 |
/* |
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
177 |
* NetworkClientObject |
223 | 178 |
*/ |
274
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
179 |
NetworkClientObject::NetworkClientObject (NetworkClient &client, NetworkObjectID obj_id) : |
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
180 |
NetworkObject_Client(client.controller, obj_id), client(client) |
223 | 181 |
{ |
182 |
||
183 |
} |
|
184 |
||
185 |
/* |
|
274
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
186 |
* NetworkClientPlayerBase |
223 | 187 |
*/ |
274
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
188 |
NetworkClientPlayerBase::NetworkClientPlayerBase (NetworkClient &client, NetworkObjectID obj_id, Vector position) : |
282
e0e4dfc3e528
compiles cleanly with -Wall -Wextra -Wconversion, not tested, but that shouldn't break anything :)
terom
parents:
277
diff
changeset
|
189 |
Player(client.state, position, true), |
e0e4dfc3e528
compiles cleanly with -Wall -Wextra -Wconversion, not tested, but that shouldn't break anything :)
terom
parents:
277
diff
changeset
|
190 |
NetworkClientObject(client, obj_id) |
223 | 191 |
{ |
302 | 192 |
slots.connect(sig_message(NETMSG_PLAYER_POSITION), this, &NetworkClientPlayerBase::on_position ); |
193 |
slots.connect(sig_message(NETMSG_PLAYER_DIG), this, &NetworkClientPlayerBase::on_dig ); |
|
194 |
slots.connect(sig_message(NETMSG_PLAYER_WEAPON_CHANGE), this, &NetworkClientPlayerBase::on_weapon_change ); |
|
195 |
slots.connect(sig_message(NETMSG_PLAYER_ROPE_THROW), this, &NetworkClientPlayerBase::on_rope_throw ); |
|
196 |
slots.connect(sig_message(NETMSG_PLAYER_ROPE_FIXED), this, &NetworkClientPlayerBase::on_rope_fixed ); |
|
197 |
slots.connect(sig_message(NETMSG_PLAYER_ROPE_RELEASED), this, &NetworkClientPlayerBase::on_rope_released ); |
|
198 |
slots.connect(sig_message(NETMSG_PLAYER_ROPE_LENGTH), this, &NetworkClientPlayerBase::on_rope_length ); |
|
199 |
slots.connect(sig_message(NETMSG_PLAYER_SPAWN), this, &NetworkClientPlayerBase::on_spawn ); |
|
200 |
slots.connect(sig_message(NETMSG_PLAYER_DIE), this, &NetworkClientPlayerBase::on_die ); |
|
201 |
} |
|
202 |
||
203 |
void NetworkClientPlayerBase::spawn (Vector position) { |
|
204 |
(void) position; |
|
205 |
||
206 |
throw Error("NetworkClientPlayerBase::spawn called"); |
|
207 |
} |
|
208 |
||
209 |
void NetworkClientPlayerBase::respawn (TimeMS dt) { |
|
210 |
(void) dt; |
|
211 |
||
212 |
throw Error("NetworkClientPlayerBase::respawn called"); |
|
200
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
187
diff
changeset
|
213 |
} |
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
187
diff
changeset
|
214 |
|
303 | 215 |
void NetworkClientPlayerBase::die (bool start_timer) { |
216 |
(void) start_timer; |
|
217 |
||
218 |
// ignore :> |
|
219 |
} |
|
220 |
||
274
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
221 |
void NetworkClientPlayerBase::on_position (NetworkPacketInput &pkt) { |
200
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
187
diff
changeset
|
222 |
Vector position = pkt.read_vector(); |
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
187
diff
changeset
|
223 |
Vector velocity = pkt.read_vector(); |
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
187
diff
changeset
|
224 |
int flags = pkt.read_uint8(); |
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
187
diff
changeset
|
225 |
float aim = pkt.read_float32(); |
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
187
diff
changeset
|
226 |
|
255
99431fdb0dc8
add PixelDimension/PixelCoordinate types, convert Terrain to use them, and convert/clean up drawing code
terom
parents:
241
diff
changeset
|
227 |
// Engine::log(INFO, "client_player.on_position") << "obj=" << obj << ", position=" << position << ", velocity=" << velocity << ", aim=" << aim << ", [" << flags << "]"; |
200
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
187
diff
changeset
|
228 |
|
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
187
diff
changeset
|
229 |
// just update... |
264 | 230 |
updatePhysics(position, velocity, |
231 |
flags & NETWORK_PHYSICS_INAIR, |
|
232 |
flags & NETWORK_PHYSICS_FACE_RIGHT ? FACING_RIGHT : FACING_LEFT, |
|
233 |
aim |
|
234 |
); |
|
200
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
187
diff
changeset
|
235 |
} |
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
187
diff
changeset
|
236 |
|
274
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
237 |
void NetworkClientPlayerBase::on_dig (NetworkPacketInput &pkt) { |
200
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
187
diff
changeset
|
238 |
Vector position = pkt.read_vector(); |
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
187
diff
changeset
|
239 |
float radius = pkt.read_float32(); |
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
187
diff
changeset
|
240 |
|
274
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
241 |
Engine::log(INFO, "client_player.on_dig") << this << ": position=" << position << ", radius=" << radius; |
200
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
187
diff
changeset
|
242 |
|
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
187
diff
changeset
|
243 |
// just update... |
209
68cc4248a508
sneak in some ugly ugly ugly Multiple Inheritance that hopefully nobody ever notices
terom
parents:
203
diff
changeset
|
244 |
handleDig(position, radius); |
200
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
187
diff
changeset
|
245 |
} |
239
550397d9d479
implement network weapon changes and fix weapon firing
terom
parents:
224
diff
changeset
|
246 |
|
274
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
247 |
void NetworkClientPlayerBase::on_weapon_change (NetworkPacketInput &pkt) { |
239
550397d9d479
implement network weapon changes and fix weapon firing
terom
parents:
224
diff
changeset
|
248 |
uint8_t weapon_index = pkt.read_uint8(); |
550397d9d479
implement network weapon changes and fix weapon firing
terom
parents:
224
diff
changeset
|
249 |
|
274
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
250 |
Engine::log(INFO, "client_player.on_weapon_change") << this << ": weapon_index=" << weapon_index; |
239
550397d9d479
implement network weapon changes and fix weapon firing
terom
parents:
224
diff
changeset
|
251 |
|
550397d9d479
implement network weapon changes and fix weapon firing
terom
parents:
224
diff
changeset
|
252 |
handleChangeWeapon(weapon_index); |
550397d9d479
implement network weapon changes and fix weapon firing
terom
parents:
224
diff
changeset
|
253 |
} |
200
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
187
diff
changeset
|
254 |
|
274
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
255 |
void NetworkClientPlayerBase::on_rope_throw (NetworkPacketInput &pkt) { |
241 | 256 |
Vector position = pkt.read_vector(); |
257 |
Vector velocity = pkt.read_vector(); |
|
258 |
float length = pkt.read_float32(); |
|
259 |
||
274
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
260 |
Engine::log(INFO, "client_player.on_rope_throw") << this << ": position=" << position << ", velocity=" << velocity << ", length=" << length; |
241 | 261 |
|
328 | 262 |
rope.updateState(ROPE_FLYING, position, velocity, length, NULL); |
241 | 263 |
} |
264 |
||
274
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
265 |
void NetworkClientPlayerBase::on_rope_fixed (NetworkPacketInput &pkt) { |
241 | 266 |
Vector position = pkt.read_vector(); |
267 |
float length = pkt.read_float32(); |
|
328 | 268 |
NetworkObject *player_obj = controller.read_object(pkt); |
269 |
||
270 |
NetworkClientPlayerBase *player = NULL; |
|
271 |
||
272 |
if (player_obj != NULL && (player = dynamic_cast<NetworkClientPlayerBase*>(player_obj)) == NULL) { |
|
273 |
Engine::log(ERROR, "client.on_rope_fixed") << this << ": Unknown player object"; |
|
274 |
return; |
|
275 |
} |
|
241 | 276 |
|
328 | 277 |
Engine::log(INFO, "client_player.on_rope_fixed") << this << ": position=" << position << ", length=" << length |
278 |
<< ", player=" << player; |
|
241 | 279 |
|
328 | 280 |
rope.updateState(ROPE_FIXED, position, Vector(0, 0), length, player); |
241 | 281 |
} |
282 |
||
274
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
283 |
void NetworkClientPlayerBase::on_rope_released (NetworkPacketInput &pkt) { |
282
e0e4dfc3e528
compiles cleanly with -Wall -Wextra -Wconversion, not tested, but that shouldn't break anything :)
terom
parents:
277
diff
changeset
|
284 |
(void) pkt; |
e0e4dfc3e528
compiles cleanly with -Wall -Wextra -Wconversion, not tested, but that shouldn't break anything :)
terom
parents:
277
diff
changeset
|
285 |
|
274
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
286 |
Engine::log(INFO, "client_player.on_rope_released") << this; |
241 | 287 |
|
288 |
// use rope.getPosition() instead of e.g. Vector(0, 0) because it will collide there... |
|
328 | 289 |
rope.updateState(ROPE_FOLDED, rope.getPosition(), Vector(0, 0), 0, NULL); |
241 | 290 |
} |
291 |
||
274
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
292 |
void NetworkClientPlayerBase::on_rope_length (NetworkPacketInput &pkt) { |
241 | 293 |
float length = pkt.read_float32(); |
294 |
||
274
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
295 |
Engine::log(INFO, "client_player.on_rope_length") << this << ": length=" << length; |
241 | 296 |
|
297 |
rope.updateLength(length); |
|
298 |
} |
|
302 | 299 |
|
300 |
void NetworkClientPlayerBase::on_spawn (NetworkPacketInput &pkt) { |
|
301 |
// read packet |
|
302 |
Vector position = pkt.read_vector(); |
|
303 |
||
304 |
Engine::log(INFO, "client_player.on_spawn") << this << ": position=" << position; |
|
305 |
||
306 |
// super |
|
307 |
Player::spawn(position); |
|
308 |
} |
|
309 |
||
310 |
void NetworkClientPlayerBase::on_die (NetworkPacketInput &pkt) { |
|
311 |
(void) pkt; |
|
312 |
||
313 |
Engine::log(INFO, "client_player.on_die") << this; |
|
314 |
||
315 |
// super, but don't start the respawn_timer |
|
316 |
Player::die(false); |
|
317 |
} |
|
241 | 318 |
|
274
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
319 |
/* |
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
320 |
* NetworkClientLocalPlayer |
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
321 |
*/ |
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
322 |
NetworkClientLocalPlayer::NetworkClientLocalPlayer (NetworkClient &client, NetworkObjectID obj_id, Vector position) : |
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
323 |
Player(client.state, position, true), NetworkClientPlayerBase(client, obj_id, position) |
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
324 |
{ |
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
325 |
// set ourselves as the local player |
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
326 |
state.setLocalPlayer(this); |
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
327 |
} |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
328 |
|
277 | 329 |
void NetworkClientLocalPlayer::handleInput (PlayerInput input, TimeMS dt) { |
334 | 330 |
NetworkPacket pkt; |
277 | 331 |
|
334 | 332 |
// write packet |
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
333 |
pkt.write_uint16(input); |
334 | 334 |
pkt.write_uint32(dt); |
335 |
||
336 |
// send |
|
274
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
337 |
send(NETMSG_CLIENT_INPUT, pkt, false); |
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
338 |
|
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
339 |
// do not handle locally |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
340 |
} |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
341 |
|
274
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
342 |
/* |
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
343 |
* NetworkClientRemotePlayer |
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
344 |
*/ |
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
345 |
NetworkClientRemotePlayer::NetworkClientRemotePlayer (NetworkClient &client, NetworkObjectID obj_id, Vector position) : |
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
346 |
Player(client.state, position, true), NetworkClientPlayerBase(client, obj_id, position) { |
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
347 |
|
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
348 |
// receive messages |
274
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
349 |
slots.connect(sig_message(NETMSG_PLAYER_QUIT), this, &NetworkClientRemotePlayer::on_quit); |
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
350 |
} |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
351 |
|
200
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
187
diff
changeset
|
352 |
void NetworkClientRemotePlayer::on_quit (NetworkPacketInput &pkt) { |
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
353 |
// pkt is empty |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
354 |
(void) pkt; |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
355 |
|
274
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
356 |
Engine::log(INFO, "client_player.on_quit") << this; |
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
357 |
|
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
358 |
client.player_quit(this); |
294 | 359 |
|
360 |
// delete |
|
361 |
// XXX: leak because deleting the slot while it's being called breaks ClanLib |
|
362 |
// delete this; |
|
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
363 |
} |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
364 |
|
294 | 365 |
/* |
366 |
* NetworkClientProjectile |
|
367 |
*/ |
|
276
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
274
diff
changeset
|
368 |
NetworkClientProjectile::NetworkClientProjectile (NetworkClient &client, NetworkObjectID obj_id, Player *player, |
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
274
diff
changeset
|
369 |
Vector position, Vector velocity, Weapon *weapon) : |
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
274
diff
changeset
|
370 |
NetworkClientObject(client, obj_id), Projectile(player, position, velocity, weapon) |
223 | 371 |
{ |
224
e6faefba2ec1
fixed logger, and network projectiles should work reasonably well now
terom
parents:
223
diff
changeset
|
372 |
// hook up signals |
274
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
373 |
slots.connect(sig_message(NETMSG_PROJECTILE_DESTROY), this, &NetworkClientProjectile::on_destroy); |
296
4d3ebaa29430
add separate Types.hh, and fix projectile-worm collisions on network
terom
parents:
294
diff
changeset
|
374 |
slots.connect(sig_message(NETMSG_PROJECTILE_HIT_PLAYER), this, &NetworkClientProjectile::on_hit_player); |
276
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
274
diff
changeset
|
375 |
|
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
274
diff
changeset
|
376 |
// tell Player |
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
274
diff
changeset
|
377 |
player->weaponFired(weapon); |
223 | 378 |
} |
200
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
187
diff
changeset
|
379 |
|
224
e6faefba2ec1
fixed logger, and network projectiles should work reasonably well now
terom
parents:
223
diff
changeset
|
380 |
void NetworkClientProjectile::onDestroy (Vector position, bool removeGround) { |
282
e0e4dfc3e528
compiles cleanly with -Wall -Wextra -Wconversion, not tested, but that shouldn't break anything :)
terom
parents:
277
diff
changeset
|
381 |
(void) position; |
e0e4dfc3e528
compiles cleanly with -Wall -Wextra -Wconversion, not tested, but that shouldn't break anything :)
terom
parents:
277
diff
changeset
|
382 |
(void) removeGround; |
e0e4dfc3e528
compiles cleanly with -Wall -Wextra -Wconversion, not tested, but that shouldn't break anything :)
terom
parents:
277
diff
changeset
|
383 |
|
224
e6faefba2ec1
fixed logger, and network projectiles should work reasonably well now
terom
parents:
223
diff
changeset
|
384 |
// ignore :> |
e6faefba2ec1
fixed logger, and network projectiles should work reasonably well now
terom
parents:
223
diff
changeset
|
385 |
} |
296
4d3ebaa29430
add separate Types.hh, and fix projectile-worm collisions on network
terom
parents:
294
diff
changeset
|
386 |
|
330 | 387 |
void NetworkClientProjectile::onHitPlayer (Player *player) { |
296
4d3ebaa29430
add separate Types.hh, and fix projectile-worm collisions on network
terom
parents:
294
diff
changeset
|
388 |
(void) player; |
4d3ebaa29430
add separate Types.hh, and fix projectile-worm collisions on network
terom
parents:
294
diff
changeset
|
389 |
|
4d3ebaa29430
add separate Types.hh, and fix projectile-worm collisions on network
terom
parents:
294
diff
changeset
|
390 |
// ignore :> |
4d3ebaa29430
add separate Types.hh, and fix projectile-worm collisions on network
terom
parents:
294
diff
changeset
|
391 |
} |
224
e6faefba2ec1
fixed logger, and network projectiles should work reasonably well now
terom
parents:
223
diff
changeset
|
392 |
|
e6faefba2ec1
fixed logger, and network projectiles should work reasonably well now
terom
parents:
223
diff
changeset
|
393 |
void NetworkClientProjectile::on_destroy (NetworkPacketInput &pkt) { |
e6faefba2ec1
fixed logger, and network projectiles should work reasonably well now
terom
parents:
223
diff
changeset
|
394 |
Vector position = pkt.read_vector(); |
e6faefba2ec1
fixed logger, and network projectiles should work reasonably well now
terom
parents:
223
diff
changeset
|
395 |
uint8_t flags = pkt.read_uint8(); |
e6faefba2ec1
fixed logger, and network projectiles should work reasonably well now
terom
parents:
223
diff
changeset
|
396 |
|
274
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
397 |
Engine::log(INFO, "client_projectile.on_destroy") << this << ": position=" << position << ", flags=" << flags; |
224
e6faefba2ec1
fixed logger, and network projectiles should work reasonably well now
terom
parents:
223
diff
changeset
|
398 |
|
e6faefba2ec1
fixed logger, and network projectiles should work reasonably well now
terom
parents:
223
diff
changeset
|
399 |
// pass on to super |
e6faefba2ec1
fixed logger, and network projectiles should work reasonably well now
terom
parents:
223
diff
changeset
|
400 |
Projectile::onDestroy(position, flags & NETWORK_PROJECTILE_REMOVE_GROUND); |
e6faefba2ec1
fixed logger, and network projectiles should work reasonably well now
terom
parents:
223
diff
changeset
|
401 |
} |
274
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
402 |
|
296
4d3ebaa29430
add separate Types.hh, and fix projectile-worm collisions on network
terom
parents:
294
diff
changeset
|
403 |
void NetworkClientProjectile::on_hit_player (NetworkPacketInput &pkt) { |
4d3ebaa29430
add separate Types.hh, and fix projectile-worm collisions on network
terom
parents:
294
diff
changeset
|
404 |
// read packet |
4d3ebaa29430
add separate Types.hh, and fix projectile-worm collisions on network
terom
parents:
294
diff
changeset
|
405 |
NetworkObject *player_obj = controller.read_object(pkt); |
4d3ebaa29430
add separate Types.hh, and fix projectile-worm collisions on network
terom
parents:
294
diff
changeset
|
406 |
|
4d3ebaa29430
add separate Types.hh, and fix projectile-worm collisions on network
terom
parents:
294
diff
changeset
|
407 |
NetworkClientPlayerBase *player; |
4d3ebaa29430
add separate Types.hh, and fix projectile-worm collisions on network
terom
parents:
294
diff
changeset
|
408 |
|
4d3ebaa29430
add separate Types.hh, and fix projectile-worm collisions on network
terom
parents:
294
diff
changeset
|
409 |
// ignore for invalid players |
4d3ebaa29430
add separate Types.hh, and fix projectile-worm collisions on network
terom
parents:
294
diff
changeset
|
410 |
if ((player = dynamic_cast<NetworkClientPlayerBase*>(player_obj)) == NULL) { |
4d3ebaa29430
add separate Types.hh, and fix projectile-worm collisions on network
terom
parents:
294
diff
changeset
|
411 |
Engine::log(ERROR, "client.on_hit_player") << this << ": Unknown player object"; |
4d3ebaa29430
add separate Types.hh, and fix projectile-worm collisions on network
terom
parents:
294
diff
changeset
|
412 |
return; |
4d3ebaa29430
add separate Types.hh, and fix projectile-worm collisions on network
terom
parents:
294
diff
changeset
|
413 |
} |
4d3ebaa29430
add separate Types.hh, and fix projectile-worm collisions on network
terom
parents:
294
diff
changeset
|
414 |
|
330 | 415 |
Engine::log(INFO, "client_projectile.hit_player") << this << ": player=" << player; |
296
4d3ebaa29430
add separate Types.hh, and fix projectile-worm collisions on network
terom
parents:
294
diff
changeset
|
416 |
|
4d3ebaa29430
add separate Types.hh, and fix projectile-worm collisions on network
terom
parents:
294
diff
changeset
|
417 |
// pass on to super |
308
60f4b55d5713
Calculates kills and deaths. You get frags by killing yourself \o/
saiam
parents:
303
diff
changeset
|
418 |
Projectile::onHitPlayer(player); |
296
4d3ebaa29430
add separate Types.hh, and fix projectile-worm collisions on network
terom
parents:
294
diff
changeset
|
419 |
} |
4d3ebaa29430
add separate Types.hh, and fix projectile-worm collisions on network
terom
parents:
294
diff
changeset
|
420 |