chore: add FPS counter

This commit is contained in:
Rekai Nyangadzayi Musuka 2022-10-21 05:11:51 -03:00
parent 2cec8d9f70
commit c4c4332485
2 changed files with 11 additions and 1 deletions

View File

@ -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);
}
}

View File

@ -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 => {