random changes
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Wed, 2 Mar 2022 17:36:40 +0000 (11:36 -0600)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Wed, 2 Mar 2022 17:36:40 +0000 (11:36 -0600)
.gitignore
.vscode/tasks.json
run_tree/assets/images/spritesheet.png
src/entity/components/patron.onyx
src/entity/editor.onyx
src/game.onyx
src/main.onyx
src/sfx/wav_file.onyx

index 2a82e9b0c4425b685114472e68ca1dee4e2bb812..54f6f035713e14305b70396e2b8908c2c155713a 100644 (file)
@@ -1,4 +1,5 @@
 *.code-workspace
 *.sublime-project
 *.sublime-workspace
-src/config.onyx
\ No newline at end of file
+src/config.onyx
+*.wasm
\ No newline at end of file
index c78e8902580ef4f5645e4e99c342f42f46c67389..1b4ee0bd1db4e1e11e109403b73ca0c2f769a90d 100644 (file)
             "problemMatcher": "$onyx",
             "command": "./run.sh",
             "args": ["build"],
+            "presentation": {
+                "echo": true,
+                "reveal": "silent",
+                "focus": false,
+                "panel": "shared",
+                "showReuseMessage": false,
+                "clear": true,
+            },
             "group": {
                 "kind": "build",
                 "isDefault": true
index 170834d4669f652c03141492415243b6ba6040d3..59a315520caabd435f17fc26a11c88c50cf48897 100644 (file)
Binary files a/run_tree/assets/images/spritesheet.png and b/run_tree/assets/images/spritesheet.png differ
index fd2fb888b005892712ea7c18a9694a2c08987914..6d32f96592d54f2de19d5d25f51fac70c549d2be 100644 (file)
@@ -20,11 +20,7 @@ PatronComponent :: struct {
     consume_timeout: f32;
 
     init :: (use this: ^PatronComponent) {
-        printf("{*}\n", ^item_store.items);
-        items := item_store.items.entries;
-        r := random.between(0, (items.count - 1));
-        order_item = items[r].key;
-        printf("{} {} {}\n", order_item, r, items.count);
+        order_item = random.choice(item_store.items.entries).key;
     }
 
     added :: (use this: ^PatronComponent, entity: ^Entity) {
@@ -35,22 +31,29 @@ PatronComponent :: struct {
         }
     }
 
+    find_available_seat :: (use this: ^PatronComponent) -> bool {
+        seats := scene->query_by_component(.{ 0, 0, 10000, 10000 }, FurnitureComponent);
+        defer memory.free_slice(^seats);
+        if seats.count == 0 do return false;
+
+        while seat == Entity_Nothing {
+            it := random.choice(seats);
+            furniture := it->get(FurnitureComponent);
+            if furniture.furniture_type != .Seat do continue;
+            if furniture->try_take() {
+                seat = it.id;
+                break;
+            }
+        }
+
+        return true;
+    }
+
     update :: (use this: ^PatronComponent, entity: ^Entity, dt: f32) {
         if state == .Walking_To_Seat {
             if seat == Entity_Nothing {
-                seats := scene->query_by_component(.{ 0, 0, 10000, 10000 }, FurnitureComponent);
-                defer memory.free_slice(^seats);
-
-                for seats {
-                    furniture := it->get(FurnitureComponent);
-                    if furniture.furniture_type != .Seat do continue;
-                    if furniture->try_take() {
-                        seat = it.id;
-                        break;
-                    }
-                }
-
-                if seat == Entity_Nothing {
+                found_seat := this->find_available_seat();
+                if !found_seat {
                     state = .Leaving;
                     return;
                 }
index 570f4dd3db6e3b904839485219a5b4f6d80cf91a..b6e85aaa69c14de14d26ff96b4e7f4fb370dcbcb 100644 (file)
@@ -251,13 +251,11 @@ editor_draw :: () {
     }
 
     draw_textbox(.{x, y + 72.0f, w / 2.0f, 36.0f}, ^test);
-
-    #persist dumb := false;
-
-    draw_checkbox(.{x, y + 150, w, 36.0f}, ^dumb, "Testing checkboxes");
 }
 
 #local render_entity_list :: (x, y, w, h: f32) {
+    scrolling_region_start(.{x, y, w, h});
+
     buf: [256] u8;
     for scene.entities {
         msg := conv.format(buf, "{} ({})", it.schematic, cast(u32) it.id);
@@ -266,6 +264,8 @@ editor_draw :: () {
         }
         y += 32;
     }
+
+    scrolling_region_stop();
 }
 
 #local render_entity_fields :: (entity: ^Entity, x, y, w, h: f32) {
index 5a6a959804b580475ac0f46877586d619edb759f..ff76e243173cacf42a8f8bce5eb328c54b9ea753 100644 (file)
@@ -35,6 +35,10 @@ game_init :: () {
     item_store->load_items_from_file("scenes/default.items");
 }
 
+game_deinit :: () {
+    Audio_Manager.deinit();
+}
+
 #local quick_save_file := "scenes/quick_save_new.scene";
 
 game_update :: (dt: f32) {
index c464bb376475bdacbd61bdc34716fccef63dda17..c3c6c20d3523e37a686c23cecb9025bbf2d9ecee 100644 (file)
@@ -39,6 +39,10 @@ init :: () {
     #if DEBUG { debug_font = font_lookup(.{"./assets/fonts/calibri.ttf", 16}); }
 }
 
+deinit :: () {
+    game_deinit();
+}
+
 update :: (dt: f32) {
     input_update();
 
@@ -141,7 +145,7 @@ create_window :: () => {
 }
 
 main :: (args) => {
-    // random.set_seed(os.time());
+    random.set_seed(os.time());
 
     debug_set_level(.Debug);
     if !glfwInit() {
index cfc5fc1f151ef4a9c808fb99e6708025de992171..ec8ed40d54b2f5d2d501fa6c55975c5aaa014696 100644 (file)
@@ -64,67 +64,4 @@ load_wav_file :: (path: str) -> WAV_File {
         defer pos += n;
         return data[pos .. pos+n];
     }
-}
-
-
-#if false {
-main :: (args) => {
-    dev := alcOpenDevice(null);
-    defer alcCloseDevice(dev);
-
-    con := alcCreateContext(dev, null);
-    alcMakeContextCurrent(con);
-    defer {
-        alcMakeContextCurrent(~~ cast(u64) 0);
-        alcDestroyContext(con);
-    }
-
-    alGetError();
-    buf: u32;
-    alGenBuffers(1, ^buf);
-    defer alDeleteBuffers(1, ^buf);
-    if error := alGetError(); error != AL_NO_ERROR {
-        printf("AL ERROR: {}\n", error);
-        return;    
-    }
-
-    sample_rate := 44100;
-
-/*
-    wav_data := memory.make_slice(i16, sample_rate * 5);
-    for i: wav_data.count {
-        sample := math.sin((math.PI * 2.0f * ~~i * 263.2f) / ~~sample_rate) * 32768;
-        sample *= 1 - cast(f32) i / ~~wav_data.count;
-        wav_data[i] = cast(i16) cast(i32) (sample);
-    }
-    */
-
-    wav_file_contents := os.get_contents("/home/brendan/test.wav");
-    wav_data := extract_wav_file_data(wav_file_contents);
-
-    alBufferData(buf, AL_FORMAT_STEREO16, wav_data.data, wav_data.count, sample_rate);
-
-    alListener3f(AL_POSITION, 0, 0, 0);
-    alListener3f(AL_VELOCITY, 0, 0, 0);
-    alListenerfv(AL_ORIENTATION, ~~ f32.[0, 0, 1, 0, 1, 0]);
-
-    source: u32;
-    alGenSources(1, ^source);
-    defer alDeleteSources(1, ^source);
-    alSourcef(source, AL_PITCH, 1);
-    alSourcef(source, AL_GAIN, 0.7);
-    alSource3f(source, AL_POSITION, 0, 0, 0);
-    alSource3f(source, AL_VELOCITY, 0, 0, 0);
-    alSourcei(source, AL_LOOPING, AL_FALSE);
-
-    alSourcei(source, AL_BUFFER, buf);
-    alSourcePlay(source);
-
-    state: i32;
-    while true {
-        os.sleep(1000);
-        alGetSourcei(source, AL_SOURCE_STATE, ^state);
-        if state != AL_PLAYING do break;
-    }
-}
 }
\ No newline at end of file