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
|
#include "gameCommon.h"
#include "entity.h"
#ifndef WORLD_H
#define WORLD_H
#define FINGERPRINT_START_RANGE_MIN 0xf
#define FINGERPRINT_START_RANGE_MAX 0xff
typedef struct World {
Entity * entities;
size_t entitiesCount;
// For getting entity id;
EntityId * lookUp;
size_t lookUpSize;
EntityId * vacantIds;
size_t vacantIdsCount;
Entity * entitiesToAdd;
size_t entitiesToAddCount;
// Used for making fingerprints for entities.
EntityFingerprint currentFingerprint;
} World;
void initWorld(World * world);
void freeWorld(World * world);
#define ENTITY_ID_NONE -1
// ENTITY_ID_NONE on error.
Entity * getEntityFromWorld(World world, EntityId id);
EntityId addEntityToWorld(World * world, Entity entity);
KfError removeEntityFromWorld(World * world, EntityId id);
// Entities can't be added to world during update loop so we schedule the mother fuckers.
KfError scheduleEntityToAdd(World * world, Entity entity);
KfError handleScheduledEntities(World * world);
void updateWorld(World * world, Game * game);
void drawWorld(World * world, Game * game);
// Returns the closest entity that the ray hits or ENTITY_NONE;
// From can be used to stop it from hitting the entity the ray is coming from...
EntityId traceRayToEntityInWorld(World * world, Ray ray, EntityFingerprint from, bool useFrom);
void debugWorld(World * world);
// Used for creating worlds.
typedef struct WorldEntry {
EntityType type;
Vector3 position;
Quaternion rotation;
} WorldEntry;
KfError addEntryToWorld(World * world, Game * game, WorldEntry entry);
KfError addEntriesToWorld(World * world, Game * game, WorldEntry * entries, size_t entriesCount);
#endif
|