From: Brendan Hansen Date: Thu, 22 Jun 2023 23:44:20 +0000 (-0500) Subject: updated to new Onyx version X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=32dcbe4676f5fb940861e60eabce1ad670a007e0;p=bar-game.git updated to new Onyx version --- diff --git a/onyx-pkg.ini b/onyx-pkg.ini index fc9cc13..43c7e11 100644 --- a/onyx-pkg.ini +++ b/onyx-pkg.ini @@ -1,24 +1,18 @@ [metadata] name=bar-game description=Bar simulation for MadLads Brewing -url= author=Brendan Hansen version=0.0.1 [config] lib_source_directory=./lib lib_bin_directory=./run_tree/lib -run_cmd= -debug_cmd= -test_cmd= [native_library] -build_cmd= -library= [dependencies] git://onyxlang.io/repo/openal=0.0.3 -git://onyxlang.io/repo/ogre=0.0.19 +git://onyxlang.io/repo/ogre=0.0.20 [dependency_folders] git://onyxlang.io/repo/openal=openal diff --git a/run_tree/run.sh b/run_tree/run.sh index 465d817..c640edc 100755 --- a/run_tree/run.sh +++ b/run_tree/run.sh @@ -5,5 +5,6 @@ case "$1" in check) shift; onyx check -V -I ../src build $@ ;; run) onyx run $dest ;; debug) shift; onyx run -V -I ../src build --debug $@ ;; - *) onyx run -V -I ../src build $@ ;; + watch) shift; onyx watch -I ../src build -o $dest $@ ;; + *) onyx run -V ../src/build $@ ;; esac diff --git a/src/entity/components/collision_mask.onyx b/src/entity/components/collision_mask.onyx index 190c4e4..5d2a825 100644 --- a/src/entity/components/collision_mask.onyx +++ b/src/entity/components/collision_mask.onyx @@ -87,7 +87,7 @@ CollisionMaskComponent :: struct { } if !mask[ty * width + tx] || target_pos == .{tx, ty} { - if array.contains(stack, #(it.pos == .{tx, ty})) do continue; + if slice.contains(stack, [s](s.pos == .{tx, ty})) do continue; g := cast(f32) (math.abs(dx) + math.abs(dy)) + top.g; h := cast(f32) (math.abs(tx - target_pos.x) + math.abs(ty - target_pos.y)) / 2; @@ -107,7 +107,7 @@ CollisionMaskComponent :: struct { } } - array.sort(stack, (n1, n2) => { + slice.sort(stack, (n1, n2) => { if n1.f < n2.f do return 1; if n2.f < n1.f do return -1; return 0; @@ -121,10 +121,10 @@ CollisionMaskComponent :: struct { ~~(path_pos.x * grid_size), ~~(path_pos.y * grid_size), }; - path_pos = visited[path_pos].prev; + path_pos = visited[path_pos]->unwrap().prev; } - array.reverse(*buf); + slice.reverse(*buf); } return found; diff --git a/src/entity/editor.onyx b/src/entity/editor.onyx index e3865b4..ec94adf 100644 --- a/src/entity/editor.onyx +++ b/src/entity/editor.onyx @@ -476,11 +476,7 @@ editor_draw :: () { w := sidebar_width / 2; h := 200.0f; x := ~~ window.width - sidebar_width; - render := render_field_editor; - - if custom_editors[it.type] != null_proc { - render = custom_editors[it.type]; - } + render := custom_editors[it.type] ?? render_field_editor; for it.tags { if it.type == Editor_Custom_Field { diff --git a/src/entity/items.onyx b/src/entity/items.onyx index 69db529..fee289c 100644 --- a/src/entity/items.onyx +++ b/src/entity/items.onyx @@ -91,7 +91,7 @@ item_store_load_items_from_file :: (use this: ^Item_Store, path: str) { } item_store_get_item :: (use this: ^Item_Store, id: str) -> ^Item { - return items[id]; + return items[id]?; } @Entity_Schematic.{"Item_Entity"} diff --git a/src/entity/scene.onyx b/src/entity/scene.onyx index 5361788..b32ec78 100644 --- a/src/entity/scene.onyx +++ b/src/entity/scene.onyx @@ -122,7 +122,7 @@ Entity :: struct { has :: (use this: ^Entity, component_type: type_expr) => components->has(component_type); - get :: (use this: ^Entity, $component_type: type_expr) => cast(^component_type) components[component_type]; + get :: (use this: ^Entity, $component_type: type_expr) => cast(^component_type) components[component_type]->unwrap(); add :: (use this: ^Entity, component: ^Component) => { if components->has(component.type) do return; @@ -263,7 +263,7 @@ scene_make :: (use this: ^Scene) -> ^Entity { } scene_create_from_schematic :: (use this: ^Scene, schematic_name: str) -> ^Entity { - schematic := schematics[schematic_name]; + schematic := schematics[schematic_name] ?? null; if schematic == null do return null; entity := schematic.create(this); @@ -302,7 +302,7 @@ scene_create_component :: (use this: ^Scene, component_type: type_expr) -> ^Comp component_vtables[comp.type] = vtable; } - comp.vtable = component_vtables[comp.type]; + comp.vtable = component_vtables[comp.type] ?? null; if comp.init != null_proc { comp->init(); } @@ -355,7 +355,7 @@ scene_draw :: (use this: ^Scene) { // // This is a rather expensive check. // It could probably be done solely when entities are added/removed. - array.sort(entities, (e1, e2) => { + slice.sort(entities, (e1, e2) => { e1_comp := e1->get(RenderComponent); e2_comp := e2->get(RenderComponent); @@ -381,7 +381,7 @@ scene_draw :: (use this: ^Scene) { } } -scene_get :: (use this: ^Scene, id: Entity_ID) => entity_map[id]; +scene_get :: (use this: ^Scene, id: Entity_ID) => entity_map[id] ?? null; scene_delete :: (use this: ^Scene, ent: ^Entity, delete_from_array := true) { map.delete(^entity_map, ent.id); diff --git a/src/entity/store.onyx b/src/entity/store.onyx index 2c3a27f..74b8dc9 100644 --- a/src/entity/store.onyx +++ b/src/entity/store.onyx @@ -154,14 +154,13 @@ scene_load_from_file :: (use this: ^Scene, filename: str, reset_scene := true) { component_kind := string.advance(line); component_type := get_struct_by_name(component_kind); - if current_entity->has(component_type) { - current_component = current_entity.components[component_type]; - - } else { - current_component = scene->create_component(component_type); + current_component = current_entity.components[component_type] ?? [] { + new_component := scene->create_component(component_type); logf(.Debug, "Adding {} to entity.", component_type); - current_entity->add(current_component); - } + current_entity->add(new_component); + + return new_component; + }; continue; } diff --git a/src/main.onyx b/src/main.onyx index e235f19..92bf33a 100644 --- a/src/main.onyx +++ b/src/main.onyx @@ -1,5 +1,6 @@ // #inject runtime.vars.Onyx_Enable_Operator_Methods :: true +use runtime use core {*} use ogre {*} diff --git a/src/sfx/audio_manager.onyx b/src/sfx/audio_manager.onyx index 8307870..3a71da0 100644 --- a/src/sfx/audio_manager.onyx +++ b/src/sfx/audio_manager.onyx @@ -31,9 +31,9 @@ Audio_Manager :: struct { } get_sound :: (path: str) -> Sound { - if loaded_sounds->has(path) { - return loaded_sounds[path]; - } + loaded_sounds->get(path)->with([sound] { + return sound; + }); wav_file := load_wav_file(path);