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