From 39f031adb528972f5e695b3a1607a5832042c10a Mon Sep 17 00:00:00 2001 From: Matthew Berry Date: Wed, 21 Jul 2021 22:13:10 -0700 Subject: [PATCH] add scheduler debug window --- .../frontend/controllers/gba_controller.cr | 20 +++++++++++++++++++ src/crab/common/scheduler.cr | 2 +- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/crab/common/frontend/controllers/gba_controller.cr b/src/crab/common/frontend/controllers/gba_controller.cr index 0940e36..d32040d 100644 --- a/src/crab/common/frontend/controllers/gba_controller.cr +++ b/src/crab/common/frontend/controllers/gba_controller.cr @@ -7,6 +7,7 @@ class GBAController < Controller getter height : Int32 = 160 @debug_window = false + @scheduler_window = false def initialize(bios : String?, rom : String) @emu = GBA::GBA.new(bios || gba_bios, rom) @@ -23,6 +24,7 @@ class GBAController < Controller def render_debug_items : Nil ImGui.menu_item("Video", "", pointerof(@debug_window)) + ImGui.menu_item("Scheduler", "", pointerof(@scheduler_window)) end def render_windows : Nil @@ -34,6 +36,24 @@ class GBAController < Controller end ImGui.end end + if @scheduler_window + cycles = @emu.scheduler.cycles + ImGui.begin("Scheduler", pointerof(@scheduler_window)) + ImGui.text("Total cycles: #{cycles}") + ImGui.begin_table("Table", 2) + ImGui.table_setup_column("Cycles") + ImGui.table_setup_column("Type") + ImGui.table_headers_row + @emu.scheduler.events.each do |event| + ImGui.table_next_row + ImGui.table_set_column_index 0 + ImGui.text_unformatted (event.cycles - cycles).to_s + ImGui.table_set_column_index 1 + ImGui.text_unformatted event.type.to_s + end + ImGui.end_table + ImGui.end + end end private def render_palettes_tab_item : Nil diff --git a/src/crab/common/scheduler.cr b/src/crab/common/scheduler.cr index b7f2821..a1fd194 100644 --- a/src/crab/common/scheduler.cr +++ b/src/crab/common/scheduler.cr @@ -19,7 +19,7 @@ class Scheduler private record Event, cycles : UInt64, proc : Proc(Nil), type : EventType - @events : Deque(Event) = Deque(Event).new 10 + getter events : Deque(Event) = Deque(Event).new 10 getter cycles : UInt64 = 0 @next_event : UInt64 = UInt64::MAX