| author | saiam |
| Thu, 20 Nov 2008 22:45:10 +0000 | |
| changeset 86 | ed31ece6f340 |
| parent 66 | 1415a2d45686 |
| child 89 | 825c4613e087 |
| permissions | -rw-r--r-- |
| 5 | 1 |
#ifndef NETWORK_HH |
2 |
#define NETWORK_HH |
|
3 |
||
| 21 | 4 |
#include "NetworkConfig.hh" |
5 |
#include "GameState.hh" |
|
6 |
||
| 13 | 7 |
#include <ClanLib/network.h> |
| 5 | 8 |
|
| 66 | 9 |
const int32_t COORDINATE_MAX = 1 << 30; |
10 |
||
| 21 | 11 |
class NetworkCore {
|
| 24 | 12 |
protected: |
13 |
GameState &state; |
|
| 5 | 14 |
|
| 24 | 15 |
CL_SlotContainer slots; |
|
22
b70d30e1b0fe
all the network code is now there, although it doesn't quite work
terom
parents:
21
diff
changeset
|
16 |
|
| 24 | 17 |
CL_NetSession netsession; |
18 |
||
19 |
CL_NetObject_Controller netobjs; |
|
20 |
||
21 |
// constructor |
|
22 |
NetworkCore (GameState &state) : state(state), netsession(NETWORK_APP_NAME), netobjs(&netsession, NETWORK_NETOBJ_CHAN) { }
|
|
| 66 | 23 |
|
24 |
||
|
22
b70d30e1b0fe
all the network code is now there, although it doesn't quite work
terom
parents:
21
diff
changeset
|
25 |
}; |
|
b70d30e1b0fe
all the network code is now there, although it doesn't quite work
terom
parents:
21
diff
changeset
|
26 |
|
| 66 | 27 |
// XXX: util methods |
28 |
void writeVector (CL_NetPacket &pkt, const Vector &vec); |
|
29 |
Vector readVector (CL_NetPacket &pkt); |
|
30 |
||
|
22
b70d30e1b0fe
all the network code is now there, although it doesn't quite work
terom
parents:
21
diff
changeset
|
31 |
enum NetworkMessage {
|
| 24 | 32 |
NETMSG_PACKET_INVALID = 0x00, |
|
22
b70d30e1b0fe
all the network code is now there, although it doesn't quite work
terom
parents:
21
diff
changeset
|
33 |
|
| 24 | 34 |
/* |
35 |
* You have joined the game: |
|
36 |
* |
|
| 66 | 37 |
* Vector initial_position |
| 24 | 38 |
*/ |
39 |
NETMSG_SERVER_HELLO = 0x0100, |
|
|
22
b70d30e1b0fe
all the network code is now there, although it doesn't quite work
terom
parents:
21
diff
changeset
|
40 |
|
| 24 | 41 |
/* |
42 |
* New client has connected to server: |
|
| 66 | 43 |
* |
44 |
* Vector initial_position |
|
| 24 | 45 |
*/ |
46 |
NETMSG_PLAYER_JOIN = 0x0101, |
|
|
22
b70d30e1b0fe
all the network code is now there, although it doesn't quite work
terom
parents:
21
diff
changeset
|
47 |
|
| 24 | 48 |
/* |
49 |
* Client has left server: |
|
50 |
* |
|
51 |
*/ |
|
52 |
NETMSG_PLAYER_QUIT = 0x0102, |
|
53 |
||
54 |
/* |
|
55 |
* Client has moved |
|
56 |
* |
|
| 66 | 57 |
* Vector impulse_force |
58 |
* uint16_t impulse_ms |
|
| 24 | 59 |
*/ |
60 |
NETMSG_CLIENT_MOVE = 0x0201, |
|
61 |
||
62 |
/* |
|
63 |
* Initial player info |
|
64 |
* |
|
| 66 | 65 |
* Vector initial_position |
| 24 | 66 |
*/ |
67 |
NETMSG_PLAYER_INFO = 0x0300, |
|
68 |
||
69 |
/* |
|
70 |
* Player position update |
|
71 |
* |
|
| 66 | 72 |
* Vector position |
73 |
* Vector velocity |
|
| 24 | 74 |
*/ |
75 |
NETMSG_PLAYER_POSITION = 0x0301, |
|
| 5 | 76 |
}; |
77 |
||
78 |
#endif |