-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathworld.h
47 lines (38 loc) · 1.04 KB
/
world.h
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
#ifndef WORLD_H
#define WORLD_H
#include "unit.h"
#include "projectile.h"
#include "factory.h"
#define WORLD_POOL_SIZE 32
typedef enum { ENTITY_NONE = 0, ENTITY_UNIT, ENTITY_PROJECTILE, ENTITY_FACTORY } EntityType;
typedef struct {
EntityType type;
union {
Unit unit;
Projectile projectile;
Factory factory;
};
} Entity;
typedef struct {
Entity entities[WORLD_POOL_SIZE];
unsigned int entity_count;
Entity * free[WORLD_POOL_SIZE];
unsigned int free_count;
} EntityPool;
typedef struct {
EntityPool ** entity_pools;
unsigned int entity_pool_count;
unsigned int entity_count;
} WorldPool;
typedef struct {
WorldPool units;
WorldPool projectiles;
WorldPool factories;
} World;
void world_initialize(World *);
Entity * world_entity_allocate(World *, EntityType type);
void world_update(World *, float delta);
void world_iterate_entities(World *, void *, void (*)(Entity *, void *));
void world_iterate_entities_of_type(World *, EntityType type, void *, void (*)(Entity *, void *));
void world_deinitialize(World *);
#endif