From: Brendan Hansen Date: Sat, 3 Sep 2022 04:29:24 +0000 (-0500) Subject: updating to newer version of onyx X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=2808d738a3155e78ca321c2555cadace8dd69b1d;p=bar-game.git updating to newer version of onyx --- diff --git a/run_tree/run.sh b/run_tree/run.sh index 90450ef..d7d7b85 100755 --- a/run_tree/run.sh +++ b/run_tree/run.sh @@ -3,5 +3,6 @@ dest=game.wasm case "$1" in build) shift; onyx -V -I ../src build -o $dest $@ ;; run) onyx-run $dest ;; + debug) onyx-run --debug $dest ;; *) onyx run -V -I ../src build $@ ;; esac \ No newline at end of file diff --git a/src/entity/components/collision_mask.onyx b/src/entity/components/collision_mask.onyx index ba1afff..e42b1c2 100644 --- a/src/entity/components/collision_mask.onyx +++ b/src/entity/components/collision_mask.onyx @@ -23,18 +23,18 @@ CollisionMaskComponent :: struct { update :: (use this: ^CollisionMaskComponent, entity: ^Entity, dt: f32) { if mask.data == null { memory.alloc_slice(^mask, width * height); - } - for y: height { - for x: width { - mask[y * width + x] = false; - area := Rect.{ ~~(x * grid_size), ~~(y * grid_size), ~~grid_size, ~~grid_size }; + for y: height { + for x: width { + mask[y * width + x] = false; + area := Rect.{ ~~(x * grid_size), ~~(y * grid_size), ~~grid_size, ~~grid_size }; - for scene.entities { - if it.flags & .Solid { - if Rect.intersects(Entity.get_rect(it), area) { - mask[y * width + x] = true; - continue continue; + for scene.entities { + if it.flags & .Solid { + if Rect.intersects(Entity.get_rect(it), area) { + mask[y * width + x] = true; + continue continue; + } } } } @@ -50,24 +50,12 @@ CollisionMaskComponent :: struct { } get_path :: (use this: ^CollisionMaskComponent, start: Vector2, target: Vector2, buf: ^[..] Vector2) -> bool { - Node :: struct { - pos: Vector2i; - g: f32 = 0; - h: f32 = 0; - } - - Visited_Node :: struct { - prev: Vector2i; - cost: f32; - } - start_pos := Vector2i.{ ~~start.x / grid_size, ~~start.y / grid_size }; target_pos := Vector2i.{ ~~target.x / grid_size, ~~target.y / grid_size }; - stack: [..] Node; - stack << .{ start_pos }; + stack := array.make(.[ .{ pos=start_pos, g=0.0f, h=0.0f } ]); - visited: Map(Vector2i, Visited_Node); + visited: Map(Vector2i, #type struct{ prev: Vector2i; cost: f32 }); found := false; while stack.count != 0 { @@ -111,7 +99,7 @@ CollisionMaskComponent :: struct { } } - array.quicksort(stack, (n1: ^Node, n2: typeof n1) => { + array.quicksort(stack, (n1, n2) => { f1 := n1.g + n1.h; f2 := n2.g + n2.h; if f1 < f2 do return 1; diff --git a/src/entity/components/dispenser.onyx b/src/entity/components/dispenser.onyx index 61835b2..ecc60b0 100644 --- a/src/entity/components/dispenser.onyx +++ b/src/entity/components/dispenser.onyx @@ -44,7 +44,7 @@ DispenserComponent :: struct { item_info := item_store->get_item(dispenser_comp.item); money_comp := scene->first_component(MoneyComponent); - if !money_comp->withdraw(item_info.production_cost) do return; + if !(money_comp->withdraw(item_info.production_cost)) do return; item := scene->create_from_schematic("Item_Entity"); if item == null { diff --git a/src/entity/components/patron.onyx b/src/entity/components/patron.onyx index 273ca47..48f7e7c 100644 --- a/src/entity/components/patron.onyx +++ b/src/entity/components/patron.onyx @@ -136,7 +136,7 @@ PatronComponent :: struct { if path.count == 0 { array.clear(^path); collision_mask := scene->first_component(CollisionMaskComponent); - if !collision_mask->get_path(entity.pos, target_location, ^path) { + if !(collision_mask->get_path(entity.pos, target_location, ^path)) { debug_log(.Warning, "No path for patron."); return; } diff --git a/src/entity/scene.onyx b/src/entity/scene.onyx index cee5a5f..d7042fc 100644 --- a/src/entity/scene.onyx +++ b/src/entity/scene.onyx @@ -230,7 +230,7 @@ scene_create :: (width, height: f32) -> Scene { debug_log(.Debug, "Discovered component: '{}'", s_info.name); comp_type := cast(type_expr) index; - if !component_vtables->has(comp_type) { + if !(component_vtables->has(comp_type)) { vtable := new(Component_Vtable, allocator=entity_allocator); runtime.info.populate_struct_vtable(vtable, comp_type, safe=false); component_vtables[comp_type] = vtable; @@ -294,7 +294,7 @@ scene_create_component :: (use this: ^Scene, component_type: type_expr) -> ^Comp comp := cast(^Component) new(component_type, allocator=entity_allocator); comp.type = component_type; - if !component_vtables->has(comp.type) { + if !(component_vtables->has(comp.type)) { vtable := new(Component_Vtable, allocator=entity_allocator); type_info.populate_struct_vtable(vtable, component_type, safe=false); component_vtables[comp.type] = vtable; @@ -312,8 +312,8 @@ scene_modify_component :: macro (this: ^Scene, entity: ^Entity, $component_type: use core.intrinsics.onyx {__initialize} comp: ^component_type; - if !entity->has(component_type) { - comp = cast(^component_type) this->create_component(component_type); + if !(entity->has(component_type)) { + comp = cast(^component_type) (this->create_component(component_type)); // The 'create_component' function does not initailize the component, as it is not // a compile time known parameter and therefore cannot know how to initialize it. @@ -425,7 +425,7 @@ scene_query :: (use this: ^Scene, area: Rect) -> [] ^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; + if !(it.components->has(comp_type)) do continue; if Rect.intersects(Entity.get_rect(it), area) { ents << it; diff --git a/src/game.onyx b/src/game.onyx index b76760e..7ee8441 100644 --- a/src/game.onyx +++ b/src/game.onyx @@ -22,6 +22,7 @@ distortion_shader: Shader; game_init :: () { Audio_Manager.init(); + Audio_Manager.set_volume(0.1); distortion_shader = shader_make("./assets/shaders/crt.glsl"); shader_link_window_matrix_block(distortion_shader); @@ -72,7 +73,7 @@ game_update :: (dt: f32) { game_draw :: () { @REMOVE @DEBUG - Spritesheet', _ := texture_lookup(#cstr "./assets/images/spritesheet.png"); + // Spritesheet', _ := texture_lookup(#cstr "./assets/images/spritesheet.png"); canvas_use(^scene_canvas); immediate_clear(.{0.15, 0.15, 0.2}); diff --git a/src/main.onyx b/src/main.onyx index 4155973..e63f333 100644 --- a/src/main.onyx +++ b/src/main.onyx @@ -116,7 +116,7 @@ run :: () { frame_count = 0; } - update(cast(f32) dt); + update(~~ dt); draw(); } } diff --git a/src/sfx/audio_manager.onyx b/src/sfx/audio_manager.onyx index 159c25d..970ec85 100644 --- a/src/sfx/audio_manager.onyx +++ b/src/sfx/audio_manager.onyx @@ -26,6 +26,10 @@ Audio_Manager :: struct { alcCloseDevice(device); } + set_volume :: (volume: f32) { + alListenerf(AL_GAIN, volume); + } + get_sound :: (path: str) -> Sound { if loaded_sounds->has(path) { return loaded_sounds[path];