mirror of
https://github.com/N64Recomp/N64ModernRuntime.git
synced 2026-05-10 19:01:53 +00:00
Implement renderer creation callback
This commit is contained in:
parent
98faa24800
commit
0af92b76f1
6 changed files with 42 additions and 8 deletions
|
|
@ -16,6 +16,7 @@ add_library(ultramodern STATIC
|
|||
"${CMAKE_CURRENT_SOURCE_DIR}/src/input.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/src/mesgqueue.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/src/misc_ultra.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/src/renderer_wrapper.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/src/rsp.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/src/scheduling.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/src/task_win32.cpp"
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
#ifndef __ERROR_HANDLING_HPP__
|
||||
#define __ERROR_HANDLING_HPP__
|
||||
|
||||
#include <cstdlib>
|
||||
|
||||
namespace ultramodern {
|
||||
namespace error_handling {
|
||||
struct callbacks_t {
|
||||
|
|
@ -17,6 +19,8 @@ namespace ultramodern {
|
|||
void set_callbacks(const callbacks_t& callbacks);
|
||||
|
||||
void message_box(const char* msg);
|
||||
|
||||
[[noreturn]] void quick_exit(const char* filename, int line, const char *func, int exit_status = EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -43,7 +43,13 @@ namespace ultramodern {
|
|||
SetupResult setup_result;
|
||||
};
|
||||
|
||||
// TODO: register function
|
||||
struct callbacks_t {
|
||||
using create_render_context_t = std::unique_ptr<RendererContext>(uint8_t* rdram, WindowHandle window_handle, bool developer_mode);
|
||||
|
||||
create_render_context_t *create_render_context;
|
||||
};
|
||||
|
||||
void set_callbacks(const callbacks_t& callbacks);
|
||||
|
||||
std::unique_ptr<RendererContext> create_render_context(uint8_t* rdram, WindowHandle window_handle, bool developer_mode);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,3 +17,13 @@ void ultramodern::error_handling::message_box(const char* msg) {
|
|||
error_handling_callbacks.message_box(msg);
|
||||
}
|
||||
}
|
||||
|
||||
void ultramodern::error_handling::quick_exit(const char* filename, int line, const char *func, int exit_status) {
|
||||
fprintf(stderr, "Exiting with exit status '%i'. Function %s, at file %s:%i, ", exit_status, func, filename, line);
|
||||
|
||||
#ifdef __APPLE__
|
||||
std::_Exit(exit_status);
|
||||
#else
|
||||
std::quick_exit(exit_status);
|
||||
#endif
|
||||
}
|
||||
|
|
|
|||
|
|
@ -214,15 +214,9 @@ void task_thread_func(uint8_t* rdram, moodycamel::LightweightSemaphore* thread_r
|
|||
return;
|
||||
}
|
||||
|
||||
|
||||
if (!ultramodern::rsp::run_task(PASS_RDRAM task)) {
|
||||
fprintf(stderr, "Failed to execute task type: %" PRIu32 "\n", task->t.type);
|
||||
assert(false);
|
||||
# ifdef __APPLE__
|
||||
std::_Exit(EXIT_FAILURE);
|
||||
# else
|
||||
std::quick_exit(EXIT_FAILURE);
|
||||
# endif
|
||||
ultramodern::error_handling::quick_exit(__FILE__, __LINE__, __func__);
|
||||
}
|
||||
|
||||
// Tell the game that the RSP has completed
|
||||
|
|
|
|||
19
ultramodern/src/renderer_wrapper.cpp
Normal file
19
ultramodern/src/renderer_wrapper.cpp
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
#include "ultramodern/renderer_wrapper.hpp"
|
||||
#include "ultramodern/ultramodern.hpp"
|
||||
|
||||
static ultramodern::renderer::callbacks_t render_callbacks{};
|
||||
|
||||
void set_callbacks(const ultramodern::renderer::callbacks_t& callbacks) {
|
||||
render_callbacks = callbacks;
|
||||
}
|
||||
|
||||
|
||||
std::unique_ptr<ultramodern::renderer::RendererContext> ultramodern::renderer::create_render_context(uint8_t* rdram, WindowHandle window_handle, bool developer_mode) {
|
||||
if (render_callbacks.create_render_context == nullptr) {
|
||||
error_handling::message_box("[Error] The render callback `create_render_context` was not registered");
|
||||
// TODO: should we make a macro for this?
|
||||
error_handling::quick_exit(__FILE__, __LINE__, __func__);
|
||||
}
|
||||
|
||||
return render_callbacks.create_render_context(rdram, window_handle, developer_mode);
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue