From c4c433248594e04a0b260afe05ebe79a7c73f1eb Mon Sep 17 00:00:00 2001 From: Rekai Musuka Date: Fri, 21 Oct 2022 05:11:51 -0300 Subject: [PATCH] chore: add FPS counter --- src/main.zig | 10 ++++++++++ src/scheduler.zig | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main.zig b/src/main.zig index 0a5a83c..abe4e02 100644 --- a/src/main.zig +++ b/src/main.zig @@ -6,6 +6,8 @@ const Bus = @import("Bus.zig"); const Arm7tdmi = @import("cpu.zig").Arm7tdmi; const Scheduler = @import("scheduler.zig").Scheduler; +const Timer = std.time.Timer; + const buf_pitch = @import("ppu.zig").buf_pitch; pub fn main() anyerror!void { @@ -59,6 +61,10 @@ pub fn main() anyerror!void { const texture = SDL.SDL_CreateTexture(renderer, SDL.SDL_PIXELFORMAT_BGR555, SDL.SDL_TEXTUREACCESS_STREAMING, 240, 160) orelse sdlPanic(); defer SDL.SDL_DestroyTexture(texture); + // Init FPS Timer + var timer = Timer.start() catch unreachable; + var title_buf: [0x30]u8 = [_]u8{0x00} ** 0x30; + emu_loop: while (true) { emu.runFrame(&scheduler, &cpu, &bus); @@ -74,6 +80,10 @@ pub fn main() anyerror!void { _ = SDL.SDL_UpdateTexture(texture, null, buf_ptr, buf_pitch); _ = SDL.SDL_RenderCopy(renderer, texture, null, null); SDL.SDL_RenderPresent(renderer); + + const fps = std.time.ns_per_s / timer.lap(); + const title = std.fmt.bufPrint(&title_buf, "Gameboy Advance Emulator FPS: {d}", .{fps}) catch unreachable; + SDL.SDL_SetWindowTitle(window, title.ptr); } } diff --git a/src/scheduler.zig b/src/scheduler.zig index 6e91fb5..0247dc5 100644 --- a/src/scheduler.zig +++ b/src/scheduler.zig @@ -29,7 +29,7 @@ pub const Scheduler = struct { if (should_handle) { const event = self.queue.remove(); - std.log.info("[Scheduler] Handle {} at {} ticks", .{ event.kind, self.tick }); + // std.log.info("[Scheduler] Handle {} at {} ticks", .{ event.kind, self.tick }); switch (event.kind) { .HeatDeath => {