mirror of
https://github.com/N64Recomp/N64ModernRuntime.git
synced 2026-05-11 03:12:15 +00:00
Remove UserCallbacks in favor of threads_callbacks_t
This commit is contained in:
parent
d582b9e6fa
commit
048a3172d7
5 changed files with 26 additions and 63 deletions
|
|
@ -23,7 +23,6 @@ add_library(ultramodern STATIC
|
|||
"${CMAKE_CURRENT_SOURCE_DIR}/src/threads.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/src/timer.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/src/ultrainit.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/src/user_callbacks.cpp"
|
||||
)
|
||||
|
||||
target_include_directories(ultramodern PUBLIC
|
||||
|
|
|
|||
|
|
@ -146,7 +146,7 @@ struct input_callbacks_t {
|
|||
set_rumble_t* set_rumble;
|
||||
};
|
||||
|
||||
// TODO: This really isn't used by ultramodern. Should we move it to librecomp instead?
|
||||
// TODO: Most of the members of this struct are not used by ultramodern. Should we move them to librecomp instead?
|
||||
struct gfx_callbacks_t {
|
||||
using gfx_data_t = void*;
|
||||
using create_gfx_t = gfx_data_t();
|
||||
|
|
@ -163,6 +163,21 @@ struct gfx_callbacks_t {
|
|||
destroy_ui_t* destroy_ui;
|
||||
};
|
||||
|
||||
struct threads_callbacks_t {
|
||||
using vi_callback_t = void();
|
||||
using gfx_init_callback_t = void();
|
||||
|
||||
/**
|
||||
* Called in each VI.
|
||||
*/
|
||||
vi_callback_t* vi_callback;
|
||||
|
||||
/**
|
||||
* Called before entering the gfx main loop.
|
||||
*/
|
||||
gfx_init_callback_t* gfx_init_callback;
|
||||
};
|
||||
|
||||
bool is_game_started();
|
||||
void quit();
|
||||
void join_event_threads();
|
||||
|
|
|
|||
|
|
@ -1,29 +0,0 @@
|
|||
#ifndef __USER_CALLBACKS_HPP__
|
||||
#define __USER_CALLBACKS_HPP__
|
||||
|
||||
#include "rsp_stuff.hpp"
|
||||
#include "ultra64.h"
|
||||
|
||||
namespace ultramodern {
|
||||
struct UserCallbacks {
|
||||
// TODO: Do we want those functions to take a generic `void *arg` for user data?
|
||||
|
||||
// TODO: Consider renaming some functions to something more general,
|
||||
// like `update_rumble` -> `update_controller`
|
||||
|
||||
void (*update_rumble)();
|
||||
void (*update_supported_options)();
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
void register_user_callbacks(UserCallbacks& callbacks);
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
const UserCallbacks& get_user_callbacks();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -15,9 +15,14 @@
|
|||
#include "ultramodern.hpp"
|
||||
#include "config.hpp"
|
||||
#include "rt64_layer.h"
|
||||
#include "user_callbacks.hpp"
|
||||
#include "rsp_stuff.hpp"
|
||||
|
||||
static ultramodern::threads_callbacks_t threads_callbacks{};
|
||||
|
||||
void set_threads_callbacks(const ultramodern::threads_callbacks_t& callbacks) {
|
||||
threads_callbacks = callbacks;
|
||||
}
|
||||
|
||||
struct SpTaskAction {
|
||||
OSTask task;
|
||||
};
|
||||
|
|
@ -115,7 +120,6 @@ void vi_thread_func() {
|
|||
using namespace std::chrono_literals;
|
||||
|
||||
int remaining_retraces = events_context.vi.retrace_count;
|
||||
auto& user_callbacks = ultramodern::get_user_callbacks();
|
||||
|
||||
while (!exited) {
|
||||
// Determine the next VI time (more accurate than adding 16ms each VI interrupt)
|
||||
|
|
@ -175,8 +179,8 @@ void vi_thread_func() {
|
|||
}
|
||||
}
|
||||
|
||||
if (user_callbacks.update_rumble != nullptr) {
|
||||
user_callbacks.update_rumble();
|
||||
if (threads_callbacks.vi_callback != nullptr) {
|
||||
threads_callbacks.vi_callback();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -274,8 +278,6 @@ void gfx_thread_func(uint8_t* rdram, moodycamel::LightweightSemaphore* thread_re
|
|||
|
||||
ultramodern::RT64Context rt64{rdram, window_handle, cur_config.load().developer_mode};
|
||||
|
||||
auto& user_callbacks = ultramodern::get_user_callbacks();
|
||||
|
||||
if (!rt64.valid()) {
|
||||
// TODO move recomp code out of ultramodern.
|
||||
rt64_setup_result.store(rt64.get_setup_result());
|
||||
|
|
@ -284,8 +286,8 @@ void gfx_thread_func(uint8_t* rdram, moodycamel::LightweightSemaphore* thread_re
|
|||
return;
|
||||
}
|
||||
|
||||
if (user_callbacks.update_supported_options != nullptr) {
|
||||
user_callbacks.update_supported_options();
|
||||
if (threads_callbacks.gfx_init_callback != nullptr) {
|
||||
threads_callbacks.gfx_init_callback();
|
||||
}
|
||||
|
||||
ultramodern::rsp::constants_init();
|
||||
|
|
|
|||
|
|
@ -1,24 +0,0 @@
|
|||
#include <cassert>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
|
||||
#include "ultramodern/user_callbacks.hpp"
|
||||
|
||||
static ultramodern::UserCallbacks s_user_callbacks {};
|
||||
static bool s_callbacks_initialized = false;
|
||||
|
||||
void ultramodern::register_user_callbacks(UserCallbacks& callbacks) {
|
||||
s_user_callbacks = callbacks;
|
||||
|
||||
s_callbacks_initialized = true;
|
||||
}
|
||||
|
||||
const ultramodern::UserCallbacks& ultramodern::get_user_callbacks() {
|
||||
if (!s_callbacks_initialized) {
|
||||
fprintf(stderr, "%s: User callbacks have not been initialized.\n", __func__);
|
||||
assert(false);
|
||||
std::quick_exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
return s_user_callbacks;
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue