From 4df5eaeee9382cc672519ab4f3978005e9924996 Mon Sep 17 00:00:00 2001 From: Ralph Caraveo Date: Sun, 3 Nov 2024 11:57:03 -0800 Subject: [PATCH] Re-enable background music, removed bgmsNum const which is not necessary since Zig arrays and slices have a known .len --- README.md | 17 +++++++++-------- zsrc/audio.zig | 5 +---- zsrc/res.zig | 6 +++--- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 9bff5b9..1686202 100644 --- a/README.md +++ b/README.md @@ -38,21 +38,22 @@ This is a near exact **Zig port** of the [original DungeonRush `C-based`](https: * To fully eradicate all original C-based files and C-based build scripts. * To port in phases: 1. Phase 1: port the C code almost as-is to minimize bugs introduced - * ✅ Deprecated usage of `c.malloc`/`c.free` in all cases - * ✅ Deprecated use of `c.qsort` with a `callconv(.C)` callback in favor of Zig's sorting. + * ✅ Deprecate usage of `c.malloc`/`c.free` in all cases + * ✅ Deprecate use of `c.qsort` with a `callconv(.C)` callback in favor of Zig's sorting * Deprecate all [*c] style pointers - * ✅ Deprecated C-style multi-pointers - * Find and improve `const` correctness in some cases. + * ✅ Deprecate C-style multi-pointers + * Find and improve `const` correctness where applicable 2. Phase 2: Ziggify * Move away from `c_int` or C specific types - * ✅ Favor slices over multi-pointers, remove any pointer arithmetic. - * Use more of Zig's stdlib for logging, file-io, etc. + * ✅ Favor slices over multi-pointers, remove any pointer arithmetic + * Use more of Zig's stdlib for logging, file-io, etc * Utilize `defer`/`errdefer` for effective cleanup - * Migrate to a Zig-based SDL wrapper, for a nicer SDL experience. + * Migrate to a Zig-based SDL wrapper, for a nicer SDL experience * Ensure all errors are accounted for, utilize `try` * Use build.zig.zon * ✅ Setup Github to build the project regularly 3. Phase 3: Code Clean-up/Refactor + * ✅ Gamepad controller support added * Remove duplicate code * Make code even more idiomatic for Zig * Make the code more maintainable @@ -62,7 +63,7 @@ This is a near exact **Zig port** of the [original DungeonRush `C-based`](https: * ✅ Use some Zig based collections like the `generic` LinkList over the original C ADT style * Bonus: Introduce unit-tests * Get building for other OSes (w/ community contributions) - * Migrated hardcoded textures, music + sound sfx out of the source code and into config files + * Migrate hardcoded textures, music + sound sfx out of the source code and into config files * This will allow the game to be easily skinned, for a whole new experience. 4. Phase 4: ??? * I'd love to port this to Raylib. diff --git a/zsrc/audio.zig b/zsrc/audio.zig index 98cff5f..0c6e366 100644 --- a/zsrc/audio.zig +++ b/zsrc/audio.zig @@ -30,9 +30,6 @@ const BGM_FADE_DURATION = 800; var nowBgmId: c_int = -1; pub fn playBgm(id: c_int) void { - // NOTE: r.c. disabled music bruh. - if (true) return; - if (nowBgmId == id) { return; } @@ -51,7 +48,7 @@ pub fn stopBgm() void { } pub fn randomBgm() void { - playBgm(hlp.randInt(1, res.bgmNums - 1)); + playBgm(hlp.randInt(1, res.bgmsPath.len - 1)); } pub fn playAudio(id: usize) void { diff --git a/zsrc/res.zig b/zsrc/res.zig index 06bacc0..2a12800 100644 --- a/zsrc/res.zig +++ b/zsrc/res.zig @@ -270,7 +270,7 @@ pub const PATH_LEN = 1024; pub const TILESET_SIZE = 1024; pub const TEXTSET_SIZE = 1024; pub const EFFECTS_SIZE = 128; -pub const bgmNums = 4; +// pub const bgmNums = 4; Not needed in Zig port. pub const TEXTURES_SIZE = 1024; pub const nameOfTheGame = "Dungeon Rush: Zig-Edition v1.0 - by @deckarep"; @@ -340,7 +340,7 @@ pub const textList = &[_][*:0]const u8{ "Zig Edition: by @deckarep - (c) 2024", // <-- that's me! }; -const bgmsPath = &[_][]const u8{ +pub const bgmsPath = &[_][]const u8{ "res/audio/main_title.ogg", "res/audio/bg1.ogg", "res/audio/bg2.ogg", @@ -612,7 +612,7 @@ fn loadTileset(path: [:0]const u8, origin: ?*c.SDL_Texture) !bool { } pub fn loadAudio() !bool { - for (0..bgmNums) |i| { + for (0..bgmsPath.len) |i| { const mus = c.Mix_LoadMUS(bgmsPath[i].ptr); if (mus) |mu| { bgms[i] = mu;