:Door
entity.id = 13
-entity.flags = 7
+entity.flags = 3
entity.pos.x = 352.0000
entity.pos.y = 320.0000
entity.size.x = 160.0000
selected_entity_id = Entity_Nothing;
for scene.entities {
- get_rect := scene.entity_types[it.type].get_rect;
- if get_rect == null_proc do continue;
-
- if get_rect(it) |> Rect.contains(mouse_pos) {
- selected_entity_id = it.id;
- break;
+ if get_rect := ENT_INFO(it).get_rect; get_rect != null_proc {
+ if get_rect(it) |> Rect.contains(mouse_pos) {
+ selected_entity_id = it.id;
+ break;
+ }
}
}
new_top_left.x = editor_grid_size * math.floor(new_top_left.x / editor_grid_size);
new_top_left.y = editor_grid_size * math.floor(new_top_left.y / editor_grid_size);
- rect := scene.entity_types[selected_entity.type].get_rect(selected_entity);
+ rect := ENT_INFO(selected_entity).get_rect(selected_entity);
new_rect := Rect.{ new_top_left.x, new_top_left.y, rect.w, rect.h };
selected_entity.pos = Rect.center(new_rect);
if resizing {
if editor_grid_shown {
- E :: macro (e: ^Entity) => scene.entity_types[e.type];
-
- rect := E(selected_entity).get_rect(selected_entity);
+ rect := ENT_INFO(selected_entity).get_rect(selected_entity);
new_size := mouse_get_position_vector() - Rect.top_left(rect);
new_size.x = editor_grid_size * math.floor(new_size.x / editor_grid_size);
new_size.y = editor_grid_size * math.floor(new_size.y / editor_grid_size);
if selected_entity_id != Entity_Nothing {
selected_entity := scene->get(selected_entity_id);
- get_rect := scene.entity_types[selected_entity.type].get_rect;
+ get_rect := ENT_INFO(selected_entity).get_rect;
r := get_rect(selected_entity);
immediate_set_color(.{1,1,0,0.5});
save_to_file :: entity_manager_save_to_file;
}
+// This assumes that the main entity manager is called "scene".
+ENT_INFO :: macro (e: ^Entity) => {
+ @CompilerBug // Why does the following line break the program?
+ // It's like its declaring a new null scene...?
+ // scene :: scene;
+
+ return ^scene.entity_types[e.type];
+}
+
entity_manager_create :: () -> Entity_Manager {
em: Entity_Manager;
em.entity_allocator = context.allocator; @TODO // Replace the allocator here.
if holding != Entity_Nothing {
holding_object := scene->get(holding);
holding_object.flags |= .Carryable;
- vtable := ^scene.entity_types[holding_object.type];
- if vtable.get_rect != null_proc {
- r := vtable.get_rect(holding_object);
+ obj_get_rect := ENT_INFO(holding_object).get_rect;
+ if obj_get_rect != null_proc {
+ r := get_rect(holding_object);
d := Vector2.{(size.x + r.w) / 2 + 4, (size.y + r.h) / 2 + 4};
holding_object.pos = pos + facing_to_direction_vector(facing) * d;
defer memory.free_slice(^objects);
for objects {
- vtable := ^scene.entity_types[it.type];
- if vtable.interact == null_proc do continue;
- vtable.interact(it, this);
+ if interact := ENT_INFO(it).interact; interact != null_proc {
+ interact(it, this);
+ }
}
}
//
if holding != Entity_Nothing {
holding_object := scene->get(holding);
- vtable := ^scene.entity_types[holding_object.type];
- if vtable.get_rect != null_proc {
- r := vtable.get_rect(holding_object);
+ obj_get_rect := ENT_INFO(holding_object).get_rect;
+ if obj_get_rect != null_proc {
+ r := obj_get_rect(holding_object);
holding_object.pos = pos - .{0, (size.y + r.h) / 2};
}
}
if it == this do continue;
if it.id == this.holding do continue;
- vtable := ^scene.entity_types[it.type];
- if Rect.intersects(ent_rect, vtable.get_rect(~~ it)) {
+ vtable := ENT_INFO(it);
+ if Rect.intersects(ent_rect, vtable.get_rect(it)) {
pos -= delta;
break;
}
this.flags |= .Interactable;
this.flags |= .Solid;
- this.flags |= .Carryable;
}
get_rect :: (use this: ^Door) => {