-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsim_entity.cpp
More file actions
72 lines (61 loc) · 2.2 KB
/
sim_entity.cpp
File metadata and controls
72 lines (61 loc) · 2.2 KB
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
#include "sim_entity.h"
sim_entity_*
create_block_entity(game_state_* game_state,
entity_type type,
v2 position,
v2 diagonal,
f32 mass,
f32 orientation,
u32 flags) {
sim_entity_* entity = add_entity(game_state);
phy_body_* body = phy_add_block(&game_state->physics_state,
position,
diagonal,
mass,
orientation);
body->flags = flags;
body->position = position;
body->entity.id = entity->id;
body->entity.type = entity->type = type;
entity->body = body;
return entity;
}
sim_entity_*
create_fillet_block_entity(game_state_* game_state,
entity_type type,
v2 position,
v2 diagonal,
f32 fillet,
f32 mass,
f32 orientation,
u32 flags) {
sim_entity_* entity = add_entity(game_state);
assert_(fillet < diagonal.x / 2.0f);
assert_(fillet < diagonal.y / 2.0f);
phy_body_* body = phy_add_fillet_block(&game_state->physics_state,
position,
diagonal,
fillet,
mass,
orientation);
body->flags = flags;
body->position = position;
body->entity.id = entity->id;
body->entity.type = entity->type = type;
entity->body = body;
return entity;
}
sim_entity_*
add_entity(game_state_* game_state) {
sim_entity_* entity = game_state->entities.acquire();
entity->id = game_state->next_entity_id++;
set_hash_item(&game_state->entity_map, (u64)entity->id, entity);
return entity;
}
void
remove_entity(game_state_* game_state, sim_entity_* entity) {
phy_remove_body(&game_state->physics_state,
entity->body);
remove_hash_item(&game_state->entity_map, (u64)entity->id);
game_state->entities.free(entity);
}