From 347572d9df9233fee9ad30c206d5020ba6fecce2 Mon Sep 17 00:00:00 2001 From: water111 <48171810+water111@users.noreply.github.com> Date: Sat, 30 Apr 2022 14:55:13 -0400 Subject: [PATCH] support non-debug-mode (#1347) --- game/graphics/opengl_renderer/debug_gui.cpp | 5 ++++ game/graphics/opengl_renderer/debug_gui.h | 1 + game/graphics/pipelines/opengl.cpp | 12 +++++++-- game/kernel/kboot.cpp | 8 +++--- game/kernel/kboot.h | 9 ++++++- game/kernel/klisten.cpp | 5 ++-- game/kernel/kmachine.cpp | 13 ++++++---- game/main.cpp | 27 +++++++++++++++++++-- game/runtime.cpp | 8 +++--- game/runtime.h | 7 ++++-- goal_src/engine/draw/process-drawable.gc | 2 +- goal_src/engine/game/main-h.gc | 2 +- goal_src/engine/game/main.gc | 2 +- goal_src/pc/subtitle.gc | 20 +++++++++------ 14 files changed, 88 insertions(+), 33 deletions(-) diff --git a/game/graphics/opengl_renderer/debug_gui.cpp b/game/graphics/opengl_renderer/debug_gui.cpp index 12f757dfc..da5091d3c 100644 --- a/game/graphics/opengl_renderer/debug_gui.cpp +++ b/game/graphics/opengl_renderer/debug_gui.cpp @@ -122,6 +122,11 @@ void OpenGlDebugGui::draw(const DmaStats& dma_stats) { ImGui::MenuItem("Dump to file", nullptr, &dump_events); ImGui::EndMenu(); } + + if (ImGui::BeginMenu("Reboot in Debug Mode")) { + want_reboot_in_debug = true; + ImGui::EndMenu(); + } } ImGui::EndMainMenuBar(); diff --git a/game/graphics/opengl_renderer/debug_gui.h b/game/graphics/opengl_renderer/debug_gui.h index 92837a599..0ff186d6b 100644 --- a/game/graphics/opengl_renderer/debug_gui.h +++ b/game/graphics/opengl_renderer/debug_gui.h @@ -66,6 +66,7 @@ class OpenGlDebugGui { bool small_profiler = false; bool record_events = false; bool dump_events = false; + bool want_reboot_in_debug = false; private: FrameTimeRecorder m_frame_timer; diff --git a/game/graphics/pipelines/opengl.cpp b/game/graphics/pipelines/opengl.cpp index 30bf6705d..705b712de 100644 --- a/game/graphics/pipelines/opengl.cpp +++ b/game/graphics/pipelines/opengl.cpp @@ -463,10 +463,16 @@ static void gl_render_display(GfxDisplay* display) { g_gfx_data->sync_cv.notify_all(); } + // reboot whole game, if requested + if (g_gfx_data->debug_gui.want_reboot_in_debug) { + g_gfx_data->debug_gui.want_reboot_in_debug = false; + MasterExit = RuntimeExitStatus::RESTART_IN_DEBUG; + } + // exit if display window was closed if (glfwWindowShouldClose(window)) { std::unique_lock lock(g_gfx_data->sync_mutex); - MasterExit = 2; + MasterExit = RuntimeExitStatus::EXIT; g_gfx_data->sync_cv.notify_all(); } } @@ -481,7 +487,9 @@ u32 gl_vsync() { } std::unique_lock lock(g_gfx_data->sync_mutex); auto init_frame = g_gfx_data->frame_idx_of_input_data; - g_gfx_data->sync_cv.wait(lock, [=] { return MasterExit || g_gfx_data->frame_idx > init_frame; }); + g_gfx_data->sync_cv.wait(lock, [=] { + return (MasterExit != RuntimeExitStatus::RUNNING) || g_gfx_data->frame_idx > init_frame; + }); return g_gfx_data->frame_idx & 1; } diff --git a/game/kernel/kboot.cpp b/game/kernel/kboot.cpp index ef65bef02..25c57693f 100644 --- a/game/kernel/kboot.cpp +++ b/game/kernel/kboot.cpp @@ -40,7 +40,7 @@ char DebugBootMessage[64]; MasterConfig masterConfig; // Set to 1 to kill GOAL kernel -u32 MasterExit; +RuntimeExitStatus MasterExit; // Set to 1 to enable debug heap u32 MasterDebug; @@ -57,7 +57,7 @@ void kboot_init_globals() { strcpy(DebugBootLevel, "#f"); // no specified level strcpy(DebugBootMessage, "play"); // play mode, the default retail mode - MasterExit = 0; + MasterExit = RuntimeExitStatus::RUNNING; MasterDebug = 1; MasterUseKernel = 1; DebugSegment = 1; @@ -144,7 +144,7 @@ s32 goal_main(int argc, const char* const* argv) { void KernelCheckAndDispatch() { u64 goal_stack = u64(g_ee_main_mem) + EE_MAIN_MEM_SIZE - 8; - while (!MasterExit) { + while (MasterExit == RuntimeExitStatus::RUNNING) { // try to get a message from the listener, and process it if needed Ptr new_message = WaitForMessageAndAck(); if (new_message.offset) { @@ -198,5 +198,5 @@ void KernelCheckAndDispatch() { * DONE, EXACT */ void KernelShutdown() { - MasterExit = 2; // GOAL Kernel Dispatch loop will stop now. + MasterExit = RuntimeExitStatus::EXIT; // GOAL Kernel Dispatch loop will stop now. } diff --git a/game/kernel/kboot.h b/game/kernel/kboot.h index 2f652b612..368ed2b0a 100644 --- a/game/kernel/kboot.h +++ b/game/kernel/kboot.h @@ -22,6 +22,13 @@ struct MasterConfig { u16 territory; // added. this is normally burnt onto the disc executable. }; +enum class RuntimeExitStatus { + RUNNING = 0, + RESTART_RUNTIME = 1, + EXIT = 2, + RESTART_IN_DEBUG = 3, +}; + // Level to load on boot extern char DebugBootLevel[64]; @@ -29,7 +36,7 @@ extern char DebugBootLevel[64]; extern char DebugBootMessage[64]; // Set to 1 to kill GOAL kernel -extern u32 MasterExit; +extern RuntimeExitStatus MasterExit; // Set to 1 to enable debug heap extern u32 MasterDebug; diff --git a/game/kernel/klisten.cpp b/game/kernel/klisten.cpp index 1aa2199d4..ce28328af 100644 --- a/game/kernel/klisten.cpp +++ b/game/kernel/klisten.cpp @@ -66,6 +66,7 @@ void ClearPending() { if (size > 0) { printf("%s", PrintBufArea.cast().c() + sizeof(ListenerMessageHeader)); } + clear_print(); } } else { if (ListenerStatus) { @@ -134,10 +135,10 @@ void ProcessListenerMessage(Ptr msg) { printf("[ERROR] unsupported message kind LTT_MSG_PRINT_SYMBOLS (NYI)\n"); break; case LTT_MSG_RESET: - MasterExit = 1; + MasterExit = RuntimeExitStatus::RESTART_RUNTIME; break; case LTT_MSG_SHUTDOWN: - MasterExit = 2; + MasterExit = RuntimeExitStatus::EXIT; break; case LTT_MSG_CODE: { auto buffer = kmalloc(kdebugheap, MessCount, 0, "listener-link-block"); diff --git a/game/kernel/kmachine.cpp b/game/kernel/kmachine.cpp index ebf5a394f..f1af9078d 100644 --- a/game/kernel/kmachine.cpp +++ b/game/kernel/kmachine.cpp @@ -67,7 +67,7 @@ Timer ee_clock_timer; u32 vif1_interrupt_handler = 0; void kmachine_init_globals() { - isodrv = iso_cd; + isodrv = fakeiso; // changed. fakeiso is the only one that works in opengoal. modsrc = 1; reboot = 1; memset(pad_dma_buf, 0, sizeof(pad_dma_buf)); @@ -88,6 +88,8 @@ void InitParms(int argc, const char* const* argv) { isodrv = fakeiso; modsrc = 0; reboot = 0; + DebugSegment = 0; + MasterDebug = 0; } for (int i = 1; i < argc; i++) { @@ -367,9 +369,10 @@ int InitMachine() { // MsgErr("dkernel: !init pad\n"); // } - if (MasterDebug) { // connect to GOAL compiler - InitGoalProto(); - } + // do this always + // if (MasterDebug) { // connect to GOAL compiler + InitGoalProto(); + //} lg::info("InitSound"); InitSound(); // do nothing! @@ -983,7 +986,7 @@ void InitMachine_PCPort() { void vif_interrupt_callback() { // added for the PC port for faking VIF interrupts from the graphics system. - if (vif1_interrupt_handler && MasterExit == 0) { + if (vif1_interrupt_handler && MasterExit == RuntimeExitStatus::RUNNING) { call_goal(Ptr(vif1_interrupt_handler), 0, 0, 0, s7.offset, g_ee_main_mem); } } diff --git a/game/main.cpp b/game/main.cpp index 481961272..744f239bb 100644 --- a/game/main.cpp +++ b/game/main.cpp @@ -94,12 +94,35 @@ int main(int argc, char** argv) { setup_logging(verbose); + bool force_debug_next_time = false; while (true) { + std::vector args; + for (int i = 0; i < argc; i++) { + args.push_back(argv[i]); + } + if (force_debug_next_time) { + args.push_back("-boot"); + args.push_back("-debug"); + force_debug_next_time = false; + } + std::vector ptrs; + for (auto& str : args) { + ptrs.push_back(str.data()); + } + // run the runtime in a loop so we can reset the game and have it restart cleanly lg::info("OpenGOAL Runtime {}.{}", versions::GOAL_VERSION_MAJOR, versions::GOAL_VERSION_MINOR); + auto exit_status = exec_runtime(ptrs.size(), ptrs.data()); - if (exec_runtime(argc, argv) == 2) { - return 0; + switch (exit_status) { + case RuntimeExitStatus::EXIT: + return 0; + case RuntimeExitStatus::RESTART_RUNTIME: + case RuntimeExitStatus::RUNNING: + break; + case RuntimeExitStatus::RESTART_IN_DEBUG: + force_debug_next_time = true; + break; } } return 0; diff --git a/game/runtime.cpp b/game/runtime.cpp index bcd433ecc..574759409 100644 --- a/game/runtime.cpp +++ b/game/runtime.cpp @@ -273,7 +273,7 @@ void dmac_runner(SystemThreadInterface& iface) { * Main function to launch the runtime. * GOAL kernel arguments are currently ignored. */ -u32 exec_runtime(int argc, char** argv) { +RuntimeExitStatus exec_runtime(int argc, char** argv) { g_argc = argc; g_argv = argv; g_main_thread_id = std::this_thread::get_id(); @@ -315,17 +315,17 @@ u32 exec_runtime(int argc, char** argv) { // step 3: start the EE! iop_thread.start(iop_runner); ee_thread.start(ee_runner); + deci_thread.start(deci2_runner); + if (VM::use) { vm_dmac_thread.start(dmac_runner); - } else { - vm_dmac_thread.start(null_runner); } // step 4: wait for EE to signal a shutdown. meanwhile, run video loop on main thread. // TODO relegate this to its own function if (enable_display) { - Gfx::Loop([]() { return !MasterExit; }); + Gfx::Loop([]() { return MasterExit == RuntimeExitStatus::RUNNING; }); Gfx::Exit(); } diff --git a/game/runtime.h b/game/runtime.h index 329637972..9799bc302 100644 --- a/game/runtime.h +++ b/game/runtime.h @@ -5,10 +5,13 @@ * Setup and launcher for the runtime. */ -#include "common/common_types.h" #include +#include "common/common_types.h" +#include "game/kernel/kboot.h" + extern u8* g_ee_main_mem; -u32 exec_runtime(int argc, char** argv); + +RuntimeExitStatus exec_runtime(int argc, char** argv); extern std::thread::id g_main_thread_id; diff --git a/goal_src/engine/draw/process-drawable.gc b/goal_src/engine/draw/process-drawable.gc index 14b70b8ba..e71eac76a 100644 --- a/goal_src/engine/draw/process-drawable.gc +++ b/goal_src/engine/draw/process-drawable.gc @@ -270,7 +270,7 @@ (defun execute-math-engine () (#when PC_PORT - (with-dma-buffer-add-bucket ((debug-buf (-> (current-frame) debug-buf)) + (with-dma-buffer-add-bucket ((debug-buf (-> (current-frame) global-buf)) (bucket-id debug-no-zbuf)) (when (-> *pc-settings* display-actor-counts) (draw-string-xy (string-format "M: ~D/~D A: ~D" (-> *matrix-engine* length) MATRIX_ENGINE_AMOUNT (process-count *active-pool*)) debug-buf 8 (- 224 18) (font-color default) (font-flags shadow kerning)) diff --git a/goal_src/engine/game/main-h.gc b/goal_src/engine/game/main-h.gc index 419b02bd3..b97d5eee8 100644 --- a/goal_src/engine/game/main-h.gc +++ b/goal_src/engine/game/main-h.gc @@ -119,7 +119,7 @@ ;; function to call in the main loop to run the debug menu (declare-type debug-menu-context basic) -(define-extern *menu-hook* (function debug-menu-context)) +(define *menu-hook* (the (function debug-menu-context) nothing)) ;; function to call in the main loop to run the progress menu (define *progress-hook* nothing) diff --git a/goal_src/engine/game/main.gc b/goal_src/engine/game/main.gc index 0a1669f62..6f6c8ffcf 100644 --- a/goal_src/engine/game/main.gc +++ b/goal_src/engine/game/main.gc @@ -671,7 +671,7 @@ (with-profiler "menu" (with-pc - (if (-> *pc-settings* display-sha) + (if (and (-> *pc-settings* display-sha) *debug-segment*) (draw-build-revision))) (*menu-hook*) diff --git a/goal_src/pc/subtitle.gc b/goal_src/pc/subtitle.gc index c5b37f37e..28b1ca867 100644 --- a/goal_src/pc/subtitle.gc +++ b/goal_src/pc/subtitle.gc @@ -568,9 +568,11 @@ (set! (-> self spool-name) (-> *art-control* active-stream)) (set! (-> self cur-channel) (pc-subtitle-channel movie)) (with-proc ((handle->process (-> *art-control* spool-lock))) - (format *stdcon* "movie spool detected:~%~3L~A~0L~%current spool frame is ~3L~D~0L~%" - (-> *art-control* active-stream) (the int (ja-aframe-num 0))) - ) + (if *debug-segment* + (format *stdcon* "movie spool detected:~%~3L~A~0L~%current spool frame is ~3L~D~0L~%" + (-> *art-control* active-stream) (the int (ja-aframe-num 0))) + ) + ) ) (*hint-semaphore* ;; there's a hint playing @@ -581,11 +583,13 @@ (set! (-> self cur-channel) (if (-> self spool-name) (pc-subtitle-channel hint-named) (pc-subtitle-channel hint))) - (format *stdcon* "hint detected!~%~3L~A~0L/~3L#x~X~0L~%current str pos is ~D (~3L~D~0L)~%" - (-> self spool-name) (-> self text-id) - (current-str-pos (-> *hint-semaphore* 0 sound-id)) - (subtitle-str-adjust (current-str-pos (-> *hint-semaphore* 0 sound-id)))) - ) + (if *debug-segment* + (format *stdcon* "hint detected!~%~3L~A~0L/~3L#x~X~0L~%current str pos is ~D (~3L~D~0L)~%" + (-> self spool-name) (-> self text-id) + (current-str-pos (-> *hint-semaphore* 0 sound-id)) + (subtitle-str-adjust (current-str-pos (-> *hint-semaphore* 0 sound-id)))) + ) + ) ) ;; do subtitles