libspades
Ace of Spades library
gamestate.h
1#ifndef LIBSPADES_GAMESTATE_H
2#define LIBSPADES_GAMESTATE_H
3#ifdef __cplusplus
4extern "C" {
5#endif
6
7#include <enet/enet.h>
8#include "../common/map.h"
9#include "../common/protocol.h"
10
11/* TODO: move objects out of gamestate */
12
13struct Object {
14 uint8_t objectType;
15 uint8_t team;
16 float xPosition;
17 float yPosition;
18 float zPosition;
19
20 float xVelocity;
21 float yVelocity;
22 float zVelocity;
23 float fuse;
24};
25
27 size_t size; /* total storage capacity of the array */
28 size_t elements; /* how many items are in the array */
29 struct Object *contents; /* the actual contents of the array */
30};
31
33struct GameState {
34 ENetHost *host;
35 ENetPeer *peer;
36 struct PacketStateData stateData;
37 struct PacketFogColour fogColor; /* DEPRECATED: no clients actually give a shit. */
38 struct PacketExistingPlayer playerData[MAX_PLAYERS]; /* DEPRECATED: if the playerID field is 255,
39 that
40 player does not exist. */
41 struct PacketWorldUpdate playerTransforms;
42 struct PacketInputData playerInputs[MAX_PLAYERS];
43 struct PacketWeaponInput playerWeaponInputs[MAX_PLAYERS];
44 struct PacketSetColour playerBlockColors[MAX_PLAYERS]; /* DEPRECATED, use playerData's blue,
45 green, and
46 red values instead. */
47 struct LibspadesMapData mapData; /* 64 MiB! */
48 struct PacketSetHP HP; /* the structs are for easy sending or smth! */
49 struct ResizableObjectArray objects;
50 bool playersAlive[MAX_PLAYERS]; /* TODO: make bitmask */
51 bitmask_t connectedPlayers; /* bitmask for every connected player, used to
52 replace the other (terrible) method. Now
53 that i think of it, it wasn't so bad. */
54 uint_fast8_t magazineAmmo;
55 uint_fast8_t reserveAmmo; /* NOTE TODO: maybe add a death counter? or keep track of
56 if player is alive? also to consider is grenades. */
57 uint_fast8_t blocks;
58 uint_fast8_t grenades;
59 bool reloading;
60 bool initialized;
61 bool connected;
62 bool canJoinGame;
63#if EXTENSION_Ed25519_AUTHENTICATION == 1
64 uint8_t publicKey[32];
65 int (*signData)(void *signature,
66 void *data,
67 size_t length); /* Returns 0 on success, and returns a non-zero value on failure. */
68#endif
69 enum ProtocolVersion protocolVersion;
70};
71
72void resize_object_array(size_t newSize, struct ResizableObjectArray *array);
73
74void initialize_object_array(struct ResizableObjectArray *array);
75
76void add_object_array_item(struct Object object, struct ResizableObjectArray *array);
77
78void remove_object_array_item(size_t item, struct ResizableObjectArray *array);
79
80#ifdef __cplusplus
81}
82#endif
83#endif
The main data structure for libspades clients.
Definition gamestate.h:33
Definition map.h:15
Definition gamestate.h:13
Informs the client of in-game players and the server of the joining client player.
Definition protocol.h:257
Changes the colour of the fog.
Definition protocol.h:619
Changes the movement inputs of a player.
Definition protocol.h:127
Changes the block colour of a player.
Definition protocol.h:237
Changes the client player's HP.
Definition protocol.h:170
Contains information about the game's state and the client player's ID.
Definition protocol.h:475
Changes the weapon inputs of a player.
Definition protocol.h:145
Regularly sent packet containing positions and orientations of all players.
Definition protocol.h:117
Definition gamestate.h:26