updated sound engine and fixed rendering on macos

This commit is contained in:
Peter Li 2025-05-09 09:17:15 -07:00
parent 4b259648a1
commit 5ecd94d92f
4 changed files with 16 additions and 9 deletions

View File

@ -26,7 +26,8 @@ pub fn start_module(comptime programSpec: anytype, args: anytype, allocator: std
gSoundLoader.* = soundEngine.SoundLoader.init(gSoundEngine);
assets.gAssetSys.registerLoader(gSoundLoader) catch unreachable;
gSoundEngine.loadSound(core.MakeName("s_test"), "content/sounds/engineTick.wav", .{}) catch unreachable;
var name = core.MakeName("s_test");
gSoundEngine.loadSound(&name, "content/sounds/engineTick.wav", .{}) catch unreachable;
core.engine_logs("sound start_module");
}

View File

@ -27,7 +27,7 @@ pub fn sound_errs(comptime fmt: []const u8) void {
}
pub const SoundLoader = struct {
pub var LoaderInterfaceVTable: assets.AssetLoaderInterface = assets.AssetLoaderInterface.from(core.MakeName("Sound"), @This());
pub var LoaderInterfaceVTable: assets.AssetLoaderInterface = assets.AssetLoaderInterface.from("Sound", @This());
engine: *NeonSoundEngine,
@ -42,16 +42,18 @@ pub const SoundLoader = struct {
}
pub fn destroy(self: *@This(), allocator: std.mem.Allocator) void {
self.engine.deinit();
allocator.destroy(self);
}
// unfortunately this one is blocking
pub fn loadAsset(self: *@This(), assetRef: assets.AssetRef, properties: ?assets.AssetPropertiesBag) assets.AssetLoaderError!void {
core.engine_log("loading sound asset {s}", .{properties.?.path});
self.engine.loadSound(assetRef.name, properties.?.path, .{
var name = assetRef.name;
self.engine.loadSound(&name, properties.?.path, .{
.volume = properties.?.soundVolume,
}) catch {
core.engine_log("unable to load sound {s}", .{assetRef.name.utf8()});
core.engine_log("unable to load sound {s}", .{name.utf8()});
};
}
};
@ -85,12 +87,12 @@ pub const NeonSoundEngine = struct {
}
pub fn shutdown(self: *@This()) void {
ma.ma_engine_uninit(self.engine);
_ = self;
}
pub fn loadSound(
self: *@This(),
soundName: core.Name,
soundName: *core.Name,
fileName: []const u8,
soundParams: struct {
looping: bool = false,
@ -141,7 +143,7 @@ pub const NeonSoundEngine = struct {
self.allocator.destroy(sound.value_ptr.*);
}
self.sounds.deinit(self.allocator);
// ma.ma_engine_uninit(self.engine);
ma.ma_engine_uninit(self.engine);
self.allocator.destroy(self.engine);
self.allocator.destroy(self);
}

View File

@ -788,7 +788,7 @@ pub const Renderer = struct {
pub fn drawPostProcess(self: *@This(), cmd: *gpu.GPUCommandBuffer) void {
const postProcTargetInfo: gpu.GPUColorTargetInfo = std.mem.zeroInit(gpu.GPUColorTargetInfo, .{
.texture = self.state.swapchainTargetTexture.?,
.load_op = .loadopDontCare,
.load_op = .loadopClear,
.store_op = .storeopStore,
});
@ -799,6 +799,10 @@ pub const Renderer = struct {
.{ .sampler = self.blockySampler, .texture = self.state.targetTexture },
.{ .sampler = self.linearSampler, .texture = self.state.emissiveTarget },
}, 2);
postProcPass.bindGPUVertexBuffers(0, &.{ .buffer = self.meshPool.vertexBuffer, .offset = 0 }, 1);
postProcPass.bindGPUIndexBuffer(&.{ .buffer = self.meshPool.indexBuffer, .offset = 0 }, .indexelementsize32bit);
// postProcPass.bindGPUFragmentSamplers(1, &.{ .sampler = self.blockySampler, .texture = self.state.emissiveTarget }, 1);
// post processing + hdr etc...

View File

@ -1,5 +1,4 @@
allocator: std.mem.Allocator,
moveInput: *core.Axis2dBinding = undefined,
cameraSpeed: f32 = 10.0,
@ -365,6 +364,7 @@ pub fn main() anyerror!void {
.enabledModules = .{
.imgui = true,
.physics = true,
.audio = true,
},
});
}