updating to newer version of onyx
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Sat, 3 Sep 2022 04:29:24 +0000 (23:29 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Sat, 3 Sep 2022 04:29:24 +0000 (23:29 -0500)
run_tree/run.sh
src/entity/components/collision_mask.onyx
src/entity/components/dispenser.onyx
src/entity/components/patron.onyx
src/entity/scene.onyx
src/game.onyx
src/main.onyx
src/sfx/audio_manager.onyx

index 90450efd138c699cd0a2b1a9ab8ed36fccd625ae..d7d7b85d31c99cf416c2affabeada9c8b2d76d83 100755 (executable)
@@ -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
index ba1afff559dd9199a09c6819723dbefa19d323af..e42b1c2966ea9c9a40b2dc5bf306925ecde02e4a 100644 (file)
@@ -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;
index 61835b2464b7a9637a2b4bdeabb79f9f0b1e63ff..ecc60b0a8704fc2d72326506e60871e9639c48e0 100644 (file)
@@ -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 {
index 273ca4775d3e130a98fa4609f9769443f36ea6d0..48f7e7c7a7fc69c75a3749a9b55650554a25dfa4 100644 (file)
@@ -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;
                     }
index cee5a5f92a06a787c3ab97a02b26aa825b05da51..d7042fcf112e5abb5cd5194bffbdfbeaa6a4295a 100644 (file)
@@ -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;
index b76760e283375b0e997b641c634d408f63b4a047..7ee8441d6d91b03c03ea57f88af3ab96df7fa5de 100644 (file)
@@ -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});
index 4155973538bb786225455c701485444df6890f7b..e63f333da0fb3f16b837a6265a497c3900325811 100644 (file)
@@ -116,7 +116,7 @@ run :: () {
             frame_count = 0;
         }
 
-        update(cast(f32) dt);
+        update(~~ dt);
         draw();
     }
 }
index 159c25dec38f0bcedb20579ee051f5c38e40f8da..970ec857a5e387828ad2e3b392bd2e632fa3dc32 100644 (file)
@@ -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];