4 #include "../GameState.hh" |
4 #include "../GameState.hh" |
5 #include "Session.hh" |
5 #include "Session.hh" |
6 #include "Object.hh" |
6 #include "Object.hh" |
7 |
7 |
8 // forward-declare |
8 // forward-declare |
|
9 class NetworkClient; |
9 class NetworkClientLocalPlayer; |
10 class NetworkClientLocalPlayer; |
10 class NetworkClientRemotePlayer; |
11 class NetworkClientRemotePlayer; |
11 |
12 |
|
13 class NetworkClientController : public NetworkObject_ClientController { |
|
14 protected: |
|
15 NetworkClient &client; |
|
16 |
|
17 public: |
|
18 NetworkClientController (NetworkClient &client); |
|
19 |
|
20 protected: |
|
21 /** |
|
22 * We override handle_create from NetworkObject_ClientController to construct the correct |
|
23 * NetworkClientObject-deriving object (LocalPlayer, RemotePlayer, Projectile) ourselves |
|
24 */ |
|
25 virtual void handle_create (NetworkObjectID obj_id, NetworkMessageID msg_id, NetworkPacketInput &pkt, NetworkNode *node); |
|
26 |
|
27 void on_server_hello (NetworkObjectID obj_id, NetworkPacketInput &pkt); |
|
28 void on_player_info (NetworkObjectID obj_id, NetworkPacketInput &pkt); |
|
29 void on_player_join (NetworkObjectID obj_id, NetworkPacketInput &pkt); |
|
30 void on_projectile_create (NetworkObjectID obj_id, NetworkPacketInput &pkt); |
|
31 }; |
|
32 |
12 class NetworkClient { |
33 class NetworkClient { |
13 friend class NetworkClientPlayerHelper; |
34 friend class NetworkClientController; |
|
35 friend class NetworkClientObject; |
|
36 friend class NetworkClientPlayerBase; |
14 friend class NetworkClientLocalPlayer; |
37 friend class NetworkClientLocalPlayer; |
15 friend class NetworkClientRemotePlayer; |
38 friend class NetworkClientRemotePlayer; |
16 friend class NetworkClientProjectile; |
39 friend class NetworkClientProjectile; |
17 |
40 |
18 protected: |
41 protected: |
19 GameState &state; |
42 GameState &state; |
20 CL_SlotContainer slots; |
43 CL_SlotContainer slots; |
21 |
44 |
22 NetworkSession netsession; |
45 NetworkSession netsession; |
23 NetworkNode *server; |
46 NetworkNode *server; |
|
47 NetworkClientController controller; |
24 |
48 |
25 NetworkObject_ClientController netobjs; |
|
26 |
|
27 public: |
49 public: |
28 NetworkClient (GameState &state, const NetworkAddress &connect_to); |
50 NetworkClient (GameState &state, const NetworkAddress &connect_to); |
29 |
51 |
30 private: |
52 protected: |
31 void on_create (NetworkObject_Client *obj, NetworkMessageID msg_id, NetworkPacketInput &pkt); |
53 |
32 |
54 /** |
33 void on_server_hello (NetworkObject_Client *obj, NetworkPacketInput &pkt); |
55 * Receive the terrain array from the server and apply it to the state.world's terrain |
34 void on_player_info (NetworkObject_Client *obj, NetworkPacketInput &pkt); |
56 */ |
35 void on_player_join (NetworkObject_Client *obj, NetworkPacketInput &pkt); |
|
36 void on_projectile_create (NetworkObject_Client *obj, NetworkPacketInput &pkt); |
|
37 |
|
38 void on_terrain_array (NetworkPacketInput &pkt, NetworkNode *node); |
57 void on_terrain_array (NetworkPacketInput &pkt, NetworkNode *node); |
39 |
58 |
40 public: |
59 public: |
41 void player_quit (NetworkClientRemotePlayer *player); |
60 void player_quit (NetworkClientRemotePlayer *player); |
42 }; |
61 }; |
43 |
62 |
44 class NetworkClientObjectHelper { |
63 class NetworkClientObject : public NetworkObject_Client { |
45 protected: |
64 protected: |
46 NetworkClient &client; |
65 NetworkClient &client; |
47 |
66 |
48 CL_SlotContainer slots; |
67 CL_SlotContainer slots; |
49 |
68 |
50 NetworkObject_Client *obj; |
69 NetworkClientObject (NetworkClient &client, NetworkObjectID obj_id); |
51 |
|
52 NetworkClientObjectHelper (NetworkClient &client, NetworkObject_Client *obj); |
|
53 }; |
70 }; |
54 |
71 |
55 class NetworkClientPlayerHelper : public NetworkClientObjectHelper, public virtual Player { |
72 class NetworkClientPlayerBase : public NetworkClientObject, public virtual Player { |
56 protected: |
73 protected: |
57 NetworkClientPlayerHelper (NetworkClient &client, Vector position, NetworkObject_Client *obj); |
74 NetworkClientPlayerBase (NetworkClient &client, NetworkObjectID obj_id, Vector position); |
58 |
75 |
59 private: |
76 private: |
60 void on_position (NetworkPacketInput &pkt); |
77 void on_position (NetworkPacketInput &pkt); |
61 void on_dig (NetworkPacketInput &pkt); |
78 void on_dig (NetworkPacketInput &pkt); |
62 void on_weapon_change (NetworkPacketInput &pkt); |
79 void on_weapon_change (NetworkPacketInput &pkt); |
64 void on_rope_fixed (NetworkPacketInput &pkt); |
81 void on_rope_fixed (NetworkPacketInput &pkt); |
65 void on_rope_released (NetworkPacketInput &pkt); |
82 void on_rope_released (NetworkPacketInput &pkt); |
66 void on_rope_length (NetworkPacketInput &pkt); |
83 void on_rope_length (NetworkPacketInput &pkt); |
67 }; |
84 }; |
68 |
85 |
69 class NetworkClientLocalPlayer : public NetworkClientPlayerHelper, public LocalPlayer { |
86 class NetworkClientLocalPlayer : public NetworkClientPlayerBase, public LocalPlayer { |
70 public: |
87 public: |
71 NetworkClientLocalPlayer (NetworkClient &client, NetworkObject_Client *obj, Vector position); |
88 NetworkClientLocalPlayer (NetworkClient &client, NetworkObjectID obj_id, Vector position); |
72 |
89 |
73 virtual void handleInput (PlayerInput input); |
90 virtual void handleInput (PlayerInput input); |
74 }; |
91 }; |
75 |
92 |
76 class NetworkClientRemotePlayer : public NetworkClientPlayerHelper, public RemotePlayer { |
93 class NetworkClientRemotePlayer : public NetworkClientPlayerBase, public RemotePlayer { |
77 public: |
94 public: |
78 NetworkClientRemotePlayer (NetworkClient &client, NetworkObject_Client *obj, Vector position); |
95 NetworkClientRemotePlayer (NetworkClient &client, NetworkObjectID obj_id, Vector position); |
79 |
96 |
80 private: |
97 private: |
81 void on_quit (NetworkPacketInput &pkt); |
98 void on_quit (NetworkPacketInput &pkt); |
82 |
99 |
83 }; |
100 }; |
84 |
101 |
85 class NetworkClientProjectile : public NetworkClientObjectHelper, public Projectile { |
102 class NetworkClientProjectile : public NetworkClientObject, public Projectile { |
86 public: |
103 public: |
87 NetworkClientProjectile (NetworkClient &client, NetworkObject_Client *obj, Vector position, Vector velocity, |
104 NetworkClientProjectile (NetworkClient &client, NetworkObjectID obj_id, Vector position, Vector velocity, |
88 float explosionRadius, float radius); |
105 float explosionRadius, float radius); |
89 |
106 |
90 protected: |
107 protected: |
91 virtual void onDestroy (Vector position, bool removeGround); |
108 virtual void onDestroy (Vector position, bool removeGround); |
92 |
109 |