Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
6d7e9e3
Merge branch 'master' into esefeks
RanPix Mar 22, 2026
f6596ce
play sounds and load them from assets
RanPix Mar 22, 2026
4023a02
convert all bad ogg files to good ogg files and fix memory leak
RanPix Mar 23, 2026
ba74fc8
rename sound setting to audio, add sound volume slider, play multiple…
RanPix Mar 23, 2026
cae0ac4
fix crash while playing multiple sounds
RanPix Mar 23, 2026
986af32
add active sound count to debug menu
RanPix Mar 23, 2026
d364d90
play sound only on actual jump
RanPix Mar 23, 2026
00fa770
fix crash when playing alot of sounds
RanPix Mar 23, 2026
369f237
fixed sound clicking and add volume control for sound type
RanPix Mar 23, 2026
b082e90
oopsie hardcoded path
RanPix Mar 23, 2026
66ea594
change sounds and tweak volume
RanPix Mar 23, 2026
59a71a6
add mono channel support
RanPix Mar 23, 2026
a819070
everything works
RanPix Mar 23, 2026
090cdde
Merge remote-tracking branch 'upstream/master' into esefeks
RanPix Apr 4, 2026
40e76aa
Merge remote-tracking branch 'upstream/master' into esefeks
RanPix Apr 5, 2026
a469cf3
Merge remote-tracking branch 'upstream/master' into esefeks
RanPix Apr 5, 2026
d4ad470
Merge branch 'master' into esefeks
RanPix Jun 21, 2026
4449ef9
back to master
RanPix Jun 21, 2026
7f154fc
cleanup and reorder
RanPix Jun 21, 2026
d7e745b
rename
RanPix Jun 21, 2026
7d8ed9b
add spatial sound
RanPix Jun 21, 2026
731974b
deinit sound map properly
RanPix Jun 24, 2026
70b9356
Merge remote-tracking branch 'origin/master' into esefeks
RanPix Jun 24, 2026
eb74150
improve error message
RanPix Jun 24, 2026
be2f60c
fmt
RanPix Jun 24, 2026
1d8cf49
Merge branch 'master' into esefeks
RanPix Jul 4, 2026
d2da43a
dont process sounds that are too far
RanPix Jul 14, 2026
92fcc3f
Merge branch 'master' into esefeks
RanPix Jul 14, 2026
f0781a4
allow loading audio files explicitly in sound asset files
RanPix Jul 15, 2026
943129d
tiny cleanup
RanPix Jul 15, 2026
22329c6
fmt
RanPix Jul 15, 2026
5a12f1b
add to reset
RanPix Jul 15, 2026
5f209d7
remove fixme
RanPix Jul 15, 2026
0de8631
Merge remote-tracking branch 'origin/master' into esefeks
RanPix Jul 15, 2026
8de387a
rename sounds in settings to audio
RanPix Jul 15, 2026
99ab682
refactor
RanPix Jul 15, 2026
0f6fc28
fmt
RanPix Jul 15, 2026
5c64c2d
remove cast
RanPix Jul 15, 2026
368835a
Merge branch 'smallAudioZigRefactor' into esefeks
RanPix Jul 15, 2026
adf1f8b
oops
RanPix Jul 15, 2026
e108ca9
Merge branch 'smallAudioZigRefactor' into esefeks
RanPix Jul 15, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added assets/cubyz/sounds/audio/block_break.ogg
Binary file not shown.
Binary file added assets/cubyz/sounds/audio/block_hit.ogg
Binary file not shown.
Binary file added assets/cubyz/sounds/audio/jump.ogg
Binary file not shown.
4 changes: 4 additions & 0 deletions assets/cubyz/sounds/block_break.zig.zon
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.{
.audio = "cubyz:block_break",
.volume = 1.25,
}
4 changes: 4 additions & 0 deletions assets/cubyz/sounds/block_hit.zig.zon
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.{
.audio = "cubyz:block_hit",
.volume = 3.5,
}
4 changes: 4 additions & 0 deletions assets/cubyz/sounds/jump.zig.zon
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.{
.audio = "cubyz:jump",
.volume = 1.5,
}
49 changes: 47 additions & 2 deletions src/assets.zig
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const migrations = @import("migrations.zig");
const blueprint = @import("blueprint.zig");
const Blueprint = blueprint.Blueprint;
const particles = @import("particles.zig");
const audio = @import("audio.zig");
const ZonElement = main.ZonElement;
const biomes = main.server.terrain.biomes;
const sbb = main.server.terrain.sbb;
Expand Down Expand Up @@ -42,6 +43,8 @@ pub const Assets = struct {
worldPresets: ZonHashMap,
entityModelDescriptions: ZonHashMap,
entityModelMigrations: ZonHashMap,
audioDatas: main.List([]const u8),
sounds: ZonHashMap,

fn init() Assets {
return .{
Expand All @@ -65,6 +68,8 @@ pub const Assets = struct {
.worldPresets = .{},
.entityModelDescriptions = .{},
.entityModelMigrations = .{},
.audioDatas = .empty,
.sounds = .{},
};
}
fn deinit(self: *Assets, allocator: NeverFailingAllocator) void {
Expand All @@ -88,6 +93,8 @@ pub const Assets = struct {
self.worldPresets.deinit(allocator.allocator);
self.entityModelDescriptions.deinit(allocator.allocator);
self.entityModelMigrations.deinit(allocator.allocator);
self.audioDatas.deinit(allocator);
self.sounds.deinit(allocator.allocator);
}
fn clone(self: Assets, allocator: NeverFailingAllocator) Assets {
return .{
Expand All @@ -111,6 +118,8 @@ pub const Assets = struct {
.worldPresets = .{}, // Not accessible inside the world
.entityModelDescriptions = self.entityModelDescriptions.clone(allocator.allocator) catch unreachable,
.entityModelMigrations = self.entityModelMigrations.clone(allocator.allocator) catch unreachable,
.audioDatas = self.audioDatas.clone(allocator),
.sounds = self.sounds.clone(allocator.allocator) catch unreachable,
};
}
fn read(self: *Assets, allocator: NeverFailingAllocator, assetDir: main.files.Dir, assetPath: []const u8) void {
Expand All @@ -133,12 +142,14 @@ pub const Assets = struct {
addon.readAllZon(allocator, "particles", true, &self.particles, null);
addon.readAllZon(allocator, "world_presets", true, &self.worldPresets, null);
addon.readAllZon(allocator, "entity_models", true, &self.entityModelDescriptions, &self.entityModelMigrations);
addon.readAllAudio(allocator, "sounds/audio", ".ogg", &self.audioDatas);
addon.readAllZon(allocator, "sounds", true, &self.sounds, null);
}
}
fn log(self: *Assets, typ: enum { common, world }) void {
std.log.info(
"Finished {s} assets reading with {} blocks, {} items, {} procedural items, {} biomes, {} cave layers, {} structure tables, {} recipes, {} structure building blocks, {} blueprints, {} particles, {} world presets, block models {}, and {} block model ZONs",
.{@tagName(typ), self.blocks.count(), self.items.count(), self.proceduralItems.count(), self.biomes.count(), self.caveLayers.count(), self.structureTables.count(), self.recipes.count(), self.structureBuildingBlocks.count(), self.blueprints.count(), self.particles.count(), self.worldPresets.count(), self.blockModels.count(), self.blockModelsZon.count()},
"Finished {s} assets reading with {} blocks, {} items, {} procedural items, {} biomes, {} cave layers, {} structure tables, {} recipes, {} structure building blocks, {} blueprints, {} particles, {} world presets, block models {}, {} block model ZONs, {} audio datas, and {} sounds",
.{@tagName(typ), self.blocks.count(), self.items.count(), self.proceduralItems.count(), self.biomes.count(), self.caveLayers.count(), self.structureTables.count(), self.recipes.count(), self.structureBuildingBlocks.count(), self.blueprints.count(), self.particles.count(), self.worldPresets.count(), self.blockModels.count(), self.blockModelsZon.count(), self.audioDatas.items.len, self.sounds.count()},
);
}

Expand Down Expand Up @@ -337,6 +348,30 @@ pub const Assets = struct {
output.put(allocator.allocator, id, string) catch unreachable;
}
}

pub fn readAllAudio(addon: Addon, allocator: NeverFailingAllocator, subPath: []const u8, fileEnding: []const u8, output: *main.List([]const u8)) void {
var assetsDirectory = addon.dir.openIterableDir(subPath) catch |err| {
if (err != error.FileNotFound) {
std.log.err("Could not open addon directory {s}: {s}", .{subPath, @errorName(err)});
}
return;
};
defer assetsDirectory.close();
var walker = assetsDirectory.walk(main.stackAllocator);
defer walker.deinit();

while (walker.next(main.io) catch |err| blk: {
std.log.err("Got error while iterating addon directory {s}: {s}", .{subPath, @errorName(err)});
break :blk null;
}) |entry| {
if (entry.kind != .file) continue;
if (!std.ascii.endsWithIgnoreCase(entry.basename, fileEnding)) continue;

const id = createAssetStringID(allocator, addon.name, "audio", entry.path) catch continue;

output.append(allocator, id);
}
}
};
};

Expand Down Expand Up @@ -709,6 +744,15 @@ pub fn loadWorldAssets(assetFolder: []const u8, blockPalette: *Palette, itemPale
particles.ParticleManager.register(assetFolder, entry.key_ptr.*, entry.value_ptr.*);
}

for (worldAssets.audioDatas.items) |entry| {
audio.registerAudioData(assetFolder, entry);
}

iterator = worldAssets.sounds.iterator();
while (iterator.next()) |entry| {
audio.registerSound(assetFolder, entry.key_ptr.*, entry.value_ptr.*);
}

// Biomes:
var nextBiomeNumericId: u32 = 0;
for (biomePalette.palette.items) |id| {
Expand Down Expand Up @@ -791,6 +835,7 @@ pub fn unloadAssets() void { // MARK: unloadAssets()
main.server.terrain.structures.reset();
main.models.reset();
main.particles.ParticleManager.reset();
main.audio.reset();
main.rotation.reset();
main.Tag.resetTags();
main.entityModel.reset();
Expand Down
Loading
Loading