From: Brendan Hansen Date: Wed, 2 Mar 2022 17:36:40 +0000 (-0600) Subject: random changes X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=3f85af5b634130036c202342afe4d2d6f0553d75;p=bar-game.git random changes --- diff --git a/.gitignore b/.gitignore index 2a82e9b..54f6f03 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/.vscode/tasks.json b/.vscode/tasks.json index c78e890..1b4ee0b 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -12,6 +12,14 @@ "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 diff --git a/run_tree/assets/images/spritesheet.png b/run_tree/assets/images/spritesheet.png index 170834d..59a3155 100644 Binary files a/run_tree/assets/images/spritesheet.png and b/run_tree/assets/images/spritesheet.png differ diff --git a/src/entity/components/patron.onyx b/src/entity/components/patron.onyx index fd2fb88..6d32f96 100644 --- a/src/entity/components/patron.onyx +++ b/src/entity/components/patron.onyx @@ -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; } diff --git a/src/entity/editor.onyx b/src/entity/editor.onyx index 570f4dd..b6e85aa 100644 --- a/src/entity/editor.onyx +++ b/src/entity/editor.onyx @@ -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) { diff --git a/src/game.onyx b/src/game.onyx index 5a6a959..ff76e24 100644 --- a/src/game.onyx +++ b/src/game.onyx @@ -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) { diff --git a/src/main.onyx b/src/main.onyx index c464bb3..c3c6c20 100644 --- a/src/main.onyx +++ b/src/main.onyx @@ -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() { diff --git a/src/sfx/wav_file.onyx b/src/sfx/wav_file.onyx index cfc5fc1..ec8ed40 100644 --- a/src/sfx/wav_file.onyx +++ b/src/sfx/wav_file.onyx @@ -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