author | terom |
Mon, 08 Dec 2008 12:02:20 +0000 | |
changeset 282 | e0e4dfc3e528 |
parent 277 | 40f4a03917e2 |
child 294 | fd58e7d01bec |
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 |
|
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
10 |
NetworkClient::NetworkClient (GameState &state, const NetworkAddress &connect_to) : |
274
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
11 |
state(state), netsession(NETWORK_MAGIC_ID), server(netsession.connect(connect_to)), controller(*this) |
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
12 |
{ |
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
13 |
// 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
|
14 |
slots.connect(netsession.sig_chan_message(NETCHAN_TERRAIN_ARRAY), this, &NetworkClient::on_terrain_array); |
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
15 |
|
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
16 |
// XXX: sig_disconnected |
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 |
|
203
3ec7ab40755f
send initial terrain data to clients using a new NETCHAN_TERRAIN_ARRAY channel using raw BigNetworkPacket
terom
parents:
200
diff
changeset
|
19 |
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
|
20 |
// 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
|
21 |
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
|
22 |
return; |
3ec7ab40755f
send initial terrain data to clients using a new NETCHAN_TERRAIN_ARRAY channel using raw BigNetworkPacket
terom
parents:
200
diff
changeset
|
23 |
|
3ec7ab40755f
send initial terrain data to clients using a new NETCHAN_TERRAIN_ARRAY channel using raw BigNetworkPacket
terom
parents:
200
diff
changeset
|
24 |
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
|
25 |
|
3ec7ab40755f
send initial terrain data to clients using a new NETCHAN_TERRAIN_ARRAY channel using raw BigNetworkPacket
terom
parents:
200
diff
changeset
|
26 |
// 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
|
27 |
// XXX: over 2**31? |
e0e4dfc3e528
compiles cleanly with -Wall -Wextra -Wconversion, not tested, but that shouldn't break anything :)
terom
parents:
277
diff
changeset
|
28 |
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
|
29 |
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
|
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 data |
282
e0e4dfc3e528
compiles cleanly with -Wall -Wextra -Wconversion, not tested, but that shouldn't break anything :)
terom
parents:
277
diff
changeset
|
32 |
for (PixelDimension x = 0; x < map_w; x++) { |
e0e4dfc3e528
compiles cleanly with -Wall -Wextra -Wconversion, not tested, but that shouldn't break anything :)
terom
parents:
277
diff
changeset
|
33 |
for (PixelDimension y = 0; y < map_h; y++) { |
203
3ec7ab40755f
send initial terrain data to clients using a new NETCHAN_TERRAIN_ARRAY channel using raw BigNetworkPacket
terom
parents:
200
diff
changeset
|
34 |
terrain.terrain[x][y] = (TerrainType) pkt.read_uint8(); |
3ec7ab40755f
send initial terrain data to clients using a new NETCHAN_TERRAIN_ARRAY channel using raw BigNetworkPacket
terom
parents:
200
diff
changeset
|
35 |
} |
3ec7ab40755f
send initial terrain data to clients using a new NETCHAN_TERRAIN_ARRAY channel using raw BigNetworkPacket
terom
parents:
200
diff
changeset
|
36 |
} |
3ec7ab40755f
send initial terrain data to clients using a new NETCHAN_TERRAIN_ARRAY channel using raw BigNetworkPacket
terom
parents:
200
diff
changeset
|
37 |
|
3ec7ab40755f
send initial terrain data to clients using a new NETCHAN_TERRAIN_ARRAY channel using raw BigNetworkPacket
terom
parents:
200
diff
changeset
|
38 |
// update the pixbuf |
3ec7ab40755f
send initial terrain data to clients using a new NETCHAN_TERRAIN_ARRAY channel using raw BigNetworkPacket
terom
parents:
200
diff
changeset
|
39 |
terrain.generatePixelBuffer(); |
3ec7ab40755f
send initial terrain data to clients using a new NETCHAN_TERRAIN_ARRAY channel using raw BigNetworkPacket
terom
parents:
200
diff
changeset
|
40 |
} |
3ec7ab40755f
send initial terrain data to clients using a new NETCHAN_TERRAIN_ARRAY channel using raw BigNetworkPacket
terom
parents:
200
diff
changeset
|
41 |
|
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
42 |
void NetworkClient::player_quit (NetworkClientRemotePlayer *player) { |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
43 |
// inform state |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
44 |
state.removePlayer(player); |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
45 |
|
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
46 |
// delete |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
47 |
// XXX: leak because deleting the slot while it's being called breaks ClanLib |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
48 |
// delete player; |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
49 |
} |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
50 |
|
223 | 51 |
/* |
274
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
52 |
* NetworkClientController |
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
53 |
*/ |
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
54 |
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
|
55 |
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
|
56 |
{ |
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
57 |
|
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
58 |
} |
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
59 |
|
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
60 |
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
|
61 |
// XXX: should be server |
e0e4dfc3e528
compiles cleanly with -Wall -Wextra -Wconversion, not tested, but that shouldn't break anything :)
terom
parents:
277
diff
changeset
|
62 |
(void) node; |
e0e4dfc3e528
compiles cleanly with -Wall -Wextra -Wconversion, not tested, but that shouldn't break anything :)
terom
parents:
277
diff
changeset
|
63 |
|
274
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
64 |
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
|
65 |
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
|
66 |
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
|
67 |
break; |
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
68 |
|
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
69 |
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
|
70 |
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
|
71 |
break; |
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
72 |
|
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
73 |
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
|
74 |
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
|
75 |
break; |
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
76 |
|
276
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
274
diff
changeset
|
77 |
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
|
78 |
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
|
79 |
break; |
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
80 |
|
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
81 |
default: |
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
82 |
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
|
83 |
} |
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
84 |
} |
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 |
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
|
87 |
// 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
|
88 |
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
|
89 |
|
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
90 |
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
|
91 |
|
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
92 |
// 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
|
93 |
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
|
94 |
} |
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
95 |
|
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
96 |
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
|
97 |
// 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
|
98 |
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
|
99 |
|
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
100 |
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
|
101 |
|
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
102 |
// 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
|
103 |
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
|
104 |
} |
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
105 |
|
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
106 |
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
|
107 |
// 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
|
108 |
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
|
109 |
|
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
110 |
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
|
111 |
|
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
112 |
// 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
|
113 |
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
|
114 |
} |
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
115 |
|
276
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
274
diff
changeset
|
116 |
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
|
117 |
// 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
|
118 |
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
|
119 |
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
|
120 |
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
|
121 |
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
|
122 |
|
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
274
diff
changeset
|
123 |
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
|
124 |
|
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 |
// 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
|
126 |
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
|
127 |
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
|
128 |
return; |
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 |
|
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
274
diff
changeset
|
131 |
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
|
132 |
|
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
274
diff
changeset
|
133 |
// 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
|
134 |
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
|
135 |
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
|
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 |
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
|
139 |
|
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
140 |
// 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
|
141 |
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
|
142 |
} |
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 |
/* |
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
145 |
* NetworkClientObject |
223 | 146 |
*/ |
274
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
147 |
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
|
148 |
NetworkObject_Client(client.controller, obj_id), client(client) |
223 | 149 |
{ |
150 |
||
151 |
} |
|
152 |
||
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 |
* NetworkClientPlayerBase |
223 | 155 |
*/ |
274
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
156 |
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
|
157 |
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
|
158 |
NetworkClientObject(client, obj_id) |
223 | 159 |
{ |
274
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
160 |
slots.connect(sig_message(NETMSG_PLAYER_POSITION), this, &NetworkClientPlayerBase::on_position ); |
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
161 |
slots.connect(sig_message(NETMSG_PLAYER_DIG), this, &NetworkClientPlayerBase::on_dig ); |
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
162 |
slots.connect(sig_message(NETMSG_PLAYER_WEAPON_CHANGE), this, &NetworkClientPlayerBase::on_weapon_change ); |
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
163 |
slots.connect(sig_message(NETMSG_PLAYER_ROPE_THROW), this, &NetworkClientPlayerBase::on_rope_throw ); |
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
164 |
slots.connect(sig_message(NETMSG_PLAYER_ROPE_FIXED), this, &NetworkClientPlayerBase::on_rope_fixed ); |
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
165 |
slots.connect(sig_message(NETMSG_PLAYER_ROPE_RELEASED), this, &NetworkClientPlayerBase::on_rope_released ); |
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
166 |
slots.connect(sig_message(NETMSG_PLAYER_ROPE_LENGTH), this, &NetworkClientPlayerBase::on_rope_length ); |
200
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
187
diff
changeset
|
167 |
} |
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
187
diff
changeset
|
168 |
|
274
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
169 |
void NetworkClientPlayerBase::on_position (NetworkPacketInput &pkt) { |
200
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
187
diff
changeset
|
170 |
Vector position = pkt.read_vector(); |
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
187
diff
changeset
|
171 |
Vector velocity = pkt.read_vector(); |
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
187
diff
changeset
|
172 |
int flags = pkt.read_uint8(); |
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
187
diff
changeset
|
173 |
float aim = pkt.read_float32(); |
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
187
diff
changeset
|
174 |
|
255
99431fdb0dc8
add PixelDimension/PixelCoordinate types, convert Terrain to use them, and convert/clean up drawing code
terom
parents:
241
diff
changeset
|
175 |
// 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
|
176 |
|
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
187
diff
changeset
|
177 |
// just update... |
264 | 178 |
updatePhysics(position, velocity, |
179 |
flags & NETWORK_PHYSICS_INAIR, |
|
180 |
flags & NETWORK_PHYSICS_FACE_RIGHT ? FACING_RIGHT : FACING_LEFT, |
|
181 |
aim |
|
182 |
); |
|
200
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
187
diff
changeset
|
183 |
} |
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
187
diff
changeset
|
184 |
|
274
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
185 |
void NetworkClientPlayerBase::on_dig (NetworkPacketInput &pkt) { |
200
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
187
diff
changeset
|
186 |
Vector position = pkt.read_vector(); |
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
187
diff
changeset
|
187 |
float radius = pkt.read_float32(); |
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
187
diff
changeset
|
188 |
|
274
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
189 |
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
|
190 |
|
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
187
diff
changeset
|
191 |
// just update... |
209
68cc4248a508
sneak in some ugly ugly ugly Multiple Inheritance that hopefully nobody ever notices
terom
parents:
203
diff
changeset
|
192 |
handleDig(position, radius); |
200
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
187
diff
changeset
|
193 |
} |
239
550397d9d479
implement network weapon changes and fix weapon firing
terom
parents:
224
diff
changeset
|
194 |
|
274
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
195 |
void NetworkClientPlayerBase::on_weapon_change (NetworkPacketInput &pkt) { |
239
550397d9d479
implement network weapon changes and fix weapon firing
terom
parents:
224
diff
changeset
|
196 |
uint8_t weapon_index = pkt.read_uint8(); |
550397d9d479
implement network weapon changes and fix weapon firing
terom
parents:
224
diff
changeset
|
197 |
|
274
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
198 |
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
|
199 |
|
550397d9d479
implement network weapon changes and fix weapon firing
terom
parents:
224
diff
changeset
|
200 |
handleChangeWeapon(weapon_index); |
550397d9d479
implement network weapon changes and fix weapon firing
terom
parents:
224
diff
changeset
|
201 |
} |
200
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
187
diff
changeset
|
202 |
|
274
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
203 |
void NetworkClientPlayerBase::on_rope_throw (NetworkPacketInput &pkt) { |
241 | 204 |
Vector position = pkt.read_vector(); |
205 |
Vector velocity = pkt.read_vector(); |
|
206 |
float length = pkt.read_float32(); |
|
207 |
||
274
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
208 |
Engine::log(INFO, "client_player.on_rope_throw") << this << ": position=" << position << ", velocity=" << velocity << ", length=" << length; |
241 | 209 |
|
210 |
rope.updateState(ROPE_FLYING, position, velocity, length); |
|
211 |
} |
|
212 |
||
274
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
213 |
void NetworkClientPlayerBase::on_rope_fixed (NetworkPacketInput &pkt) { |
241 | 214 |
Vector position = pkt.read_vector(); |
215 |
float length = pkt.read_float32(); |
|
216 |
||
274
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
217 |
Engine::log(INFO, "client_player.on_rope_fixed") << this << ": position=" << position << ", length=" << length; |
241 | 218 |
|
219 |
rope.updateState(ROPE_FIXED, position, Vector(0, 0), length); |
|
220 |
} |
|
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_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
|
223 |
(void) pkt; |
e0e4dfc3e528
compiles cleanly with -Wall -Wextra -Wconversion, not tested, but that shouldn't break anything :)
terom
parents:
277
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_rope_released") << this; |
241 | 226 |
|
227 |
// use rope.getPosition() instead of e.g. Vector(0, 0) because it will collide there... |
|
228 |
rope.updateState(ROPE_FOLDED, rope.getPosition(), Vector(0, 0), 0); |
|
229 |
} |
|
230 |
||
274
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
231 |
void NetworkClientPlayerBase::on_rope_length (NetworkPacketInput &pkt) { |
241 | 232 |
float length = pkt.read_float32(); |
233 |
||
274
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
234 |
Engine::log(INFO, "client_player.on_rope_length") << this << ": length=" << length; |
241 | 235 |
|
236 |
rope.updateLength(length); |
|
237 |
} |
|
238 |
||
274
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
239 |
/* |
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
240 |
* NetworkClientLocalPlayer |
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
241 |
*/ |
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
242 |
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
|
243 |
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
|
244 |
{ |
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
245 |
// 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
|
246 |
state.setLocalPlayer(this); |
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
247 |
} |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
248 |
|
277 | 249 |
void NetworkClientLocalPlayer::handleInput (PlayerInput input, TimeMS dt) { |
250 |
(void) dt; |
|
251 |
||
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
252 |
// always send move, in all cases |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
253 |
NetworkPacket pkt; |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
254 |
pkt.write_uint16(input); |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
255 |
|
274
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
256 |
send(NETMSG_CLIENT_INPUT, pkt, false); |
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
257 |
|
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
258 |
// do not handle locally |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
259 |
} |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
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 |
/* |
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
262 |
* NetworkClientRemotePlayer |
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
263 |
*/ |
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
264 |
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
|
265 |
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
|
266 |
|
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
267 |
// 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
|
268 |
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
|
269 |
} |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
270 |
|
200
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
187
diff
changeset
|
271 |
void NetworkClientRemotePlayer::on_quit (NetworkPacketInput &pkt) { |
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
272 |
// pkt is empty |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
273 |
(void) pkt; |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
274 |
|
274
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
275 |
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
|
276 |
|
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
277 |
client.player_quit(this); |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
278 |
} |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
279 |
|
276
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
274
diff
changeset
|
280 |
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
|
281 |
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
|
282 |
NetworkClientObject(client, obj_id), Projectile(player, position, velocity, weapon) |
223 | 283 |
{ |
224
e6faefba2ec1
fixed logger, and network projectiles should work reasonably well now
terom
parents:
223
diff
changeset
|
284 |
// 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
|
285 |
slots.connect(sig_message(NETMSG_PROJECTILE_DESTROY), this, &NetworkClientProjectile::on_destroy); |
276
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
274
diff
changeset
|
286 |
|
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
274
diff
changeset
|
287 |
// 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
|
288 |
player->weaponFired(weapon); |
223 | 289 |
} |
200
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
187
diff
changeset
|
290 |
|
224
e6faefba2ec1
fixed logger, and network projectiles should work reasonably well now
terom
parents:
223
diff
changeset
|
291 |
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
|
292 |
(void) position; |
e0e4dfc3e528
compiles cleanly with -Wall -Wextra -Wconversion, not tested, but that shouldn't break anything :)
terom
parents:
277
diff
changeset
|
293 |
(void) removeGround; |
e0e4dfc3e528
compiles cleanly with -Wall -Wextra -Wconversion, not tested, but that shouldn't break anything :)
terom
parents:
277
diff
changeset
|
294 |
|
224
e6faefba2ec1
fixed logger, and network projectiles should work reasonably well now
terom
parents:
223
diff
changeset
|
295 |
// ignore :> |
e6faefba2ec1
fixed logger, and network projectiles should work reasonably well now
terom
parents:
223
diff
changeset
|
296 |
} |
e6faefba2ec1
fixed logger, and network projectiles should work reasonably well now
terom
parents:
223
diff
changeset
|
297 |
|
e6faefba2ec1
fixed logger, and network projectiles should work reasonably well now
terom
parents:
223
diff
changeset
|
298 |
void NetworkClientProjectile::on_destroy (NetworkPacketInput &pkt) { |
e6faefba2ec1
fixed logger, and network projectiles should work reasonably well now
terom
parents:
223
diff
changeset
|
299 |
Vector position = pkt.read_vector(); |
e6faefba2ec1
fixed logger, and network projectiles should work reasonably well now
terom
parents:
223
diff
changeset
|
300 |
uint8_t flags = pkt.read_uint8(); |
e6faefba2ec1
fixed logger, and network projectiles should work reasonably well now
terom
parents:
223
diff
changeset
|
301 |
|
274
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
302 |
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
|
303 |
|
e6faefba2ec1
fixed logger, and network projectiles should work reasonably well now
terom
parents:
223
diff
changeset
|
304 |
// XXX: leak obj, not yet implemented: obj.destory(); |
e6faefba2ec1
fixed logger, and network projectiles should work reasonably well now
terom
parents:
223
diff
changeset
|
305 |
|
e6faefba2ec1
fixed logger, and network projectiles should work reasonably well now
terom
parents:
223
diff
changeset
|
306 |
// pass on to super |
e6faefba2ec1
fixed logger, and network projectiles should work reasonably well now
terom
parents:
223
diff
changeset
|
307 |
Projectile::onDestroy(position, flags & NETWORK_PROJECTILE_REMOVE_GROUND); |
e6faefba2ec1
fixed logger, and network projectiles should work reasonably well now
terom
parents:
223
diff
changeset
|
308 |
} |
274
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
264
diff
changeset
|
309 |