From 3e5c51d8380332695c54d8398576ec8b9e3a9679 Mon Sep 17 00:00:00 2001 From: Rokas Puzonas Date: Sun, 21 Jan 2024 17:41:04 +0200 Subject: [PATCH] pause audio when settings are open --- src/main-scene.zig | 8 ++++++-- src/raylib-chip.zig | 4 ++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main-scene.zig b/src/main-scene.zig index 8a73b0f..cabc286 100644 --- a/src/main-scene.zig +++ b/src/main-scene.zig @@ -97,7 +97,10 @@ pub fn reset_rom(self: *Self) void { pub fn update(self: *Self, dt: f32) void { if (!self.is_gui_open) { + rl.ResumeSound(self.chip_sound); self.raylib_chip.update(dt); + } else { + rl.PauseSound(self.chip_sound); } } @@ -210,8 +213,7 @@ pub fn drawGui(self: *Self, allocator: Allocator) !void { var window_layout = GUILayout.init(); defer window_layout.deinit(); - const screen_width: f32 = @floatFromInt(rl.GetScreenWidth()); - const screen_height: f32 = @floatFromInt(rl.GetScreenHeight()); + // Draw overlay, to indicate that emulator is paused rl.DrawRectangle(0, 0, rl.GetScreenWidth(), rl.GetScreenHeight(), .{ .r = 22, .g = 22, @@ -221,6 +223,8 @@ pub fn drawGui(self: *Self, allocator: Allocator) !void { const window_width: f32 = 400; const window_height: f32 = 200; + const screen_width: f32 = @floatFromInt(rl.GetScreenWidth()); + const screen_height: f32 = @floatFromInt(rl.GetScreenHeight()); const window = rl.Rectangle{ .x = @trunc((screen_width-window_width)/2), .y = @trunc((screen_height-window_height)/2), diff --git a/src/raylib-chip.zig b/src/raylib-chip.zig index c710b74..7ed32e2 100644 --- a/src/raylib-chip.zig +++ b/src/raylib-chip.zig @@ -64,6 +64,10 @@ pub fn update(self: *Self, dt: f32) void { self.tick_time -= 1/self.tick_speed; } + self.update_timers(dt); +} + +pub fn update_timers(self: *Self, dt: f32) void { self.timer_time += dt; while (self.timer_time > 1/self.timer_speed) { self.chip.update_timer();