summaryrefslogtreecommitdiff
path: root/src/include/data_network.h
blob: 9725cd51d01490642fb8e65d1f47aab3b45b7790 (plain)
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
#ifndef DATA_NETWORK_H
#define DATA_NETWORK_H

#include "SDL/SDL_net.h"

#include "data_types.h"
#include "data_lemming.h"
#include "events.h"

// All necessary stuff to ensure that client node on the network can synchronize each other

#define DEFAULT_LISTEN_PORT 9999


enum gameState { gameNew, gameRunning, gameEnded };

typedef struct {
	enum gameState state;
	int startTime_ms;
	int clientCount;
	struct _client_t **clients; // FIXME: il y a toujours la boucle ?
} game_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;
	// Everything in this game for network syncing is based on events (a valid action of a local or remote player at one tick
	eventList_t elist;
	client_t local, net; //TODO : reprendre un peu, bcp de champs dupliqués pour rien
} netGame_t;

#endif /* DATA_NETWORK_H */