1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
#ifndef GAME_H
#define GAME_H
#define DEFAULT_LISTEN_PORT 9999
#define TICK_DURATION_MS 30
#include "SDL/SDL_net.h"
typedef int tick_t;
typedef unsigned int id_t;
typedef struct {
unsigned int x,y;
} pos_t;
enum eventType_t { eReady, eTimeSync, eLemAction };
typedef struct {
unsigned int dead : 1;
unsigned int side : 1;
unsigned int flotter : 1;
unsigned int climber : 1;
unsigned int remainCount: 4;
unsigned int currRole: 4;
unsigned int animState: 4;
pos_t pos;
} stateLem_t;
enum gameState { gameNew, gameRunning, gameEnded };
typedef struct {
enum gameState state;
int startTime_ms;
int clientCount;
struct _client_t **clients;
} game_t;
typedef struct _event_t {
id_t playerId;
tick_t eventTick;
tick_t serverTick;
enum eventType_t type;
id_t lemId;
unsigned int newRole: 4;
struct _event_t *prev, *next;
} event_t;
typedef struct {
event_t *first, *last;
SDL_mutex *lock;
} eventList_t;
enum clientState { clientNew, clientReady };
typedef struct _client_t {
int numClient;
enum clientState state;
TCPsocket sockClient;
eventList_t events;
SDL_sem *semEventAvailable;
SDL_sem *semGameStart;
int lastEventSendTime_ms;
game_t *game;
stateLem_t *lems;
} client_t;
typedef struct {
id_t lemCount;
eventList_t elist;
client_t local, net; //TODO : reprendre un peu, bcp de champs dupliqué pour rien
} netGame_t;
tick_t getGameCurrentTick(Uint32 startTime_ms);
int initNetGame(netGame_t *ng, id_t lemCount);
void freeNetGame(netGame_t *ng);
int sendEvent(TCPsocket sockDest, const event_t *e);
int receiveEvent(client_t *c, event_t *e);
int init();
void play(int tick);
#endif //GAME_H
|