From 5ee5ff04bfe342f602b30fd1c08361108025a526 Mon Sep 17 00:00:00 2001 From: Brendan Hansen Date: Tue, 1 Mar 2022 15:15:07 -0600 Subject: [PATCH] renamed 'Entity_Manager' to 'Scene' --- src/entity/entities.onyx | 4 +- src/entity/{manager.onyx => scene.onyx} | 68 ++++++++++++------------- src/entity/schematics/furniture.onyx | 2 +- src/entity/schematics/patron.onyx | 2 +- src/entity/schematics/player.onyx | 4 +- src/entity/schematics/tap.onyx | 2 +- src/entity/store.onyx | 4 +- src/game.onyx | 4 +- 8 files changed, 45 insertions(+), 45 deletions(-) rename src/entity/{manager.onyx => scene.onyx} (82%) diff --git a/src/entity/entities.onyx b/src/entity/entities.onyx index 1af81b2..f5c5234 100644 --- a/src/entity/entities.onyx +++ b/src/entity/entities.onyx @@ -14,7 +14,7 @@ use package glfw3 } } -wall_create :: (scene: ^Entity_Manager, pos, size: Vector2) -> ^Entity { +wall_create :: (scene: ^Scene, pos, size: Vector2) -> ^Entity { this := scene->make(); this.pos = pos; this.size = size; @@ -72,7 +72,7 @@ DoorComponent :: struct { } } -door_create :: (scene: ^Entity_Manager, pos, size: Vector2) -> ^Entity { +door_create :: (scene: ^Scene, pos, size: Vector2) -> ^Entity { this := scene->make(); this.pos = pos; this.size = size; diff --git a/src/entity/manager.onyx b/src/entity/scene.onyx similarity index 82% rename from src/entity/manager.onyx rename to src/entity/scene.onyx index ce42d97..968afba 100644 --- a/src/entity/manager.onyx +++ b/src/entity/scene.onyx @@ -119,11 +119,11 @@ Entity_Flags :: enum #flags { } Entity_Schematic :: struct { - create: (^Entity_Manager) -> ^Entity; + create: (^Scene) -> ^Entity; type := void; // This will be filled out at runtime. } -Entity_Manager :: struct { +Scene :: struct { entity_allocator: Allocator; // Hmmm... Do they need to be stored in both ways? @@ -135,29 +135,29 @@ Entity_Manager :: struct { next_entity_id: Entity_ID; - add :: entity_manager_add; - make :: entity_manager_make; - update :: entity_manager_update; - draw :: entity_manager_draw; - get :: entity_manager_get; - delete :: entity_manager_delete; - query :: entity_manager_query; - query_by_flags :: entity_manager_query_by_flags; + add :: scene_add; + make :: scene_make; + update :: scene_update; + draw :: scene_draw; + get :: scene_get; + delete :: scene_delete; + query :: scene_query; + query_by_flags :: scene_query_by_flags; - count_by_component :: entity_manager_count_by_component; + count_by_component :: scene_count_by_component; - query_by_component :: entity_manager_query_by_component; - create_component :: entity_manager_create_component; - create_and_add :: entity_manager_create_and_add; + query_by_component :: scene_query_by_component; + create_component :: scene_create_component; + create_and_add :: scene_create_and_add; - create_from_schematic :: entity_manager_create_from_schematic; + create_from_schematic :: scene_create_from_schematic; - load_from_file :: entity_manager_load_from_file; - save_to_file :: entity_manager_save_to_file; + load_from_file :: scene_load_from_file; + save_to_file :: scene_save_to_file; } -entity_manager_create :: () -> Entity_Manager { - em: Entity_Manager; +scene_create :: () -> Scene { + em: Scene; em.entity_allocator = context.allocator; @TODO // Replace the allocator here. array.init(^em.entities, 4); @@ -165,11 +165,11 @@ entity_manager_create :: () -> Entity_Manager { // Entity ID 0 is reserved as a "empty / null" entity em.next_entity_id = 1; - entity_manager_load_schematics(^em); + scene_load_schematics(^em); return em; } -#local entity_manager_load_schematics :: (use this: ^Entity_Manager) { +#local scene_load_schematics :: (use this: ^Scene) { use type_info; index := 0; @@ -207,7 +207,7 @@ entity_manager_create :: () -> Entity_Manager { } } -entity_manager_add :: (use this: ^Entity_Manager, entity: ^Entity) -> Entity_ID { +scene_add :: (use this: ^Scene, entity: ^Entity) -> Entity_ID { // Automatically assign an id if the entity does not have one. // This will not be used when loading the entity from a file. if entity.id == 0 { @@ -222,13 +222,13 @@ entity_manager_add :: (use this: ^Entity_Manager, entity: ^Entity) -> Entity_ID return entity.id; } -entity_manager_make :: (use this: ^Entity_Manager) -> ^Entity { +scene_make :: (use this: ^Scene) -> ^Entity { entity := new(Entity, allocator=entity_allocator); map.init(^entity.components); return entity; } -entity_manager_create_from_schematic :: (use this: ^Entity_Manager, schematic_name: str) -> ^Entity { +scene_create_from_schematic :: (use this: ^Scene, schematic_name: str) -> ^Entity { schematic := schematics[schematic_name]; if schematic == null do return null; @@ -237,7 +237,7 @@ entity_manager_create_from_schematic :: (use this: ^Entity_Manager, schematic_na return entity; } -entity_manager_create_component :: (use this: ^Entity_Manager, component_type: type_expr) -> ^Component { +scene_create_component :: (use this: ^Scene, component_type: type_expr) -> ^Component { comp := cast(^Component) new(component_type, allocator=entity_allocator); comp.type = component_type; @@ -255,7 +255,7 @@ entity_manager_create_component :: (use this: ^Entity_Manager, component_type: t return comp; } -entity_manager_create_and_add :: macro (this: ^Entity_Manager, entity: ^Entity, $component_type: type_expr, init_block: Code) where IsComponent(^component_type) { +scene_create_and_add :: macro (this: ^Scene, entity: ^Entity, $component_type: type_expr, init_block: Code) where IsComponent(^component_type) { use package core.intrinsics.onyx {__initialize} comp := cast(^component_type) this->create_component(component_type); @@ -270,7 +270,7 @@ entity_manager_create_and_add :: macro (this: ^Entity_Manager, entity: ^Entity, entity->add(comp); } -entity_manager_update :: (use this: ^Entity_Manager, dt: f32) { +scene_update :: (use this: ^Scene, dt: f32) { for entities { for^ entry: it.components.entries { comp := entry.value; @@ -290,7 +290,7 @@ entity_manager_update :: (use this: ^Entity_Manager, dt: f32) { } } -entity_manager_draw :: (use this: ^Entity_Manager) { +scene_draw :: (use this: ^Scene) { // // This is a rather expensive check. @@ -321,9 +321,9 @@ entity_manager_draw :: (use this: ^Entity_Manager) { } } -entity_manager_get :: (use this: ^Entity_Manager, id: Entity_ID) => entity_map[id]; +scene_get :: (use this: ^Scene, id: Entity_ID) => entity_map[id]; -entity_manager_delete :: (use this: ^Entity_Manager, ent: ^Entity, delete_from_array := true) { +scene_delete :: (use this: ^Scene, ent: ^Entity, delete_from_array := true) { map.delete(^entity_map, ent.id); // @@ -342,7 +342,7 @@ entity_manager_delete :: (use this: ^Entity_Manager, ent: ^Entity, delete_from_a raw_free(entity_allocator, ent); } -entity_manager_count_by_component :: (use this: ^Entity_Manager, comp_type: type_expr) -> u32 { +scene_count_by_component :: (use this: ^Scene, comp_type: type_expr) -> u32 { count := 0; for entities { if it->has(comp_type) { @@ -353,7 +353,7 @@ entity_manager_count_by_component :: (use this: ^Entity_Manager, comp_type: type return count; } -entity_manager_query :: (use this: ^Entity_Manager, area: Rect) -> [] ^Entity { +scene_query :: (use this: ^Scene, area: Rect) -> [] ^Entity { ents: [..] ^Entity; for entities { if Rect.intersects(Entity.get_rect(it), area) { @@ -364,7 +364,7 @@ entity_manager_query :: (use this: ^Entity_Manager, area: Rect) -> [] ^Entity { return ents; } -entity_manager_query_by_component :: (use this: ^Entity_Manager, area: Rect, comp_type: type_expr) -> [] ^Entity { +scene_query_by_component :: (use this: ^Scene, area: Rect, comp_type: type_expr) -> [] ^Entity { ents: [..] ^Entity; for entities { if !it.components->has(comp_type) do continue; @@ -377,7 +377,7 @@ entity_manager_query_by_component :: (use this: ^Entity_Manager, area: Rect, com return ents; } -entity_manager_query_by_flags :: (use this: ^Entity_Manager, area: Rect, flags: Entity_Flags) -> [] ^Entity { +scene_query_by_flags :: (use this: ^Scene, area: Rect, flags: Entity_Flags) -> [] ^Entity { ents: [..] ^Entity; // Currently, enum #flags are not the greatest and & doesn't do what you want it to here. diff --git a/src/entity/schematics/furniture.onyx b/src/entity/schematics/furniture.onyx index 058692f..c21ca84 100644 --- a/src/entity/schematics/furniture.onyx +++ b/src/entity/schematics/furniture.onyx @@ -6,7 +6,7 @@ Furniture :: struct { (scene) => Furniture.create(scene, .{0, 0}) } - create :: (scene: ^Entity_Manager, pos: Vector2) -> ^Entity { + create :: (scene: ^Scene, pos: Vector2) -> ^Entity { this := scene->make(); this.pos = pos; this.size = .{16, 16}; diff --git a/src/entity/schematics/patron.onyx b/src/entity/schematics/patron.onyx index fd0dffd..1281629 100644 --- a/src/entity/schematics/patron.onyx +++ b/src/entity/schematics/patron.onyx @@ -6,7 +6,7 @@ Patron :: struct { (scene) => Patron.create(scene, .{0,0}) } - create :: (scene: ^Entity_Manager, pos: Vector2) -> ^Entity { + create :: (scene: ^Scene, pos: Vector2) -> ^Entity { this := scene->make(); this.pos = pos; this.size = .{32, 32}; diff --git a/src/entity/schematics/player.onyx b/src/entity/schematics/player.onyx index 3d51622..d5ea2d5 100644 --- a/src/entity/schematics/player.onyx +++ b/src/entity/schematics/player.onyx @@ -32,10 +32,10 @@ player_2_controls :: Player_Controls.{ Player :: struct { #struct_tag Entity_Schematic.{ - (scene: ^Entity_Manager) => Player.create(scene, .{0,0}) + (scene: ^Scene) => Player.create(scene, .{0,0}) } - create :: (scene: ^Entity_Manager, pos: Vector2, controls := player_1_controls) -> ^Entity { + create :: (scene: ^Scene, pos: Vector2, controls := player_1_controls) -> ^Entity { this := scene->make(); this.pos = pos; this.size = .{32, 32}; diff --git a/src/entity/schematics/tap.onyx b/src/entity/schematics/tap.onyx index 4c00be0..8db88e8 100644 --- a/src/entity/schematics/tap.onyx +++ b/src/entity/schematics/tap.onyx @@ -4,7 +4,7 @@ Tap :: struct { (scene) => Tap.create(scene, .{0,0}, .{0,0}) } - create :: (scene: ^Entity_Manager, pos: Vector2, size: Vector2) -> ^Entity { + create :: (scene: ^Scene, pos: Vector2, size: Vector2) -> ^Entity { this := scene->make(); this.pos = pos; this.size = size; diff --git a/src/entity/store.onyx b/src/entity/store.onyx index 77be0bb..c9eb05c 100644 --- a/src/entity/store.onyx +++ b/src/entity/store.onyx @@ -7,7 +7,7 @@ Entity_Store :: enum { Skip; } -entity_manager_save_to_file :: (use this: ^Entity_Manager, filename: str) { +scene_save_to_file :: (use this: ^Scene, filename: str) { err, output_file := os.open(filename, .Write); defer os.close(^output_file); writer_ := io.writer_make(^output_file); @@ -83,7 +83,7 @@ entity_manager_save_to_file :: (use this: ^Entity_Manager, filename: str) { } } -entity_manager_load_from_file :: (use this: ^Entity_Manager, filename: str) { +scene_load_from_file :: (use this: ^Scene, filename: str) { err, input_file := os.open(filename, .Read); if err != .None { debug_log(.Error, "Failed to open file: {}", filename); diff --git a/src/game.onyx b/src/game.onyx index fb5f832..3099419 100644 --- a/src/game.onyx +++ b/src/game.onyx @@ -7,7 +7,7 @@ use package opengles // Game Global Variables // -scene: Entity_Manager; +scene: Scene; item_store: Item_Store; scene_render_offset: Vector2; @@ -26,7 +26,7 @@ game_init :: () { load_assets(); - scene = entity_manager_create(); + scene = scene_create(); scene->load_from_file(quick_save_file); item_store = item_store_make(); -- 2.25.1