Skip to content

Commit

Permalink
Re-enable background music, removed bgmsNum const which is not necess…
Browse files Browse the repository at this point in the history
…ary since Zig arrays and slices have a known .len
  • Loading branch information
deckarep committed Nov 3, 2024
1 parent e25bf3b commit 4df5eae
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 15 deletions.
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down
5 changes: 1 addition & 4 deletions zsrc/audio.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions zsrc/res.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 4df5eae

Please sign in to comment.