Skip to content

Commit

Permalink
review
Browse files Browse the repository at this point in the history
  • Loading branch information
AngheloAlf committed May 30, 2024
1 parent 7bdafc6 commit d57405e
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 30 deletions.
2 changes: 1 addition & 1 deletion librecomp/include/rsp.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ namespace recomp {

void constants_init();

bool run_microcode(uint8_t* rdram, const OSTask* task);
bool run_task(uint8_t* rdram, const OSTask* task);
}
}

Expand Down
14 changes: 5 additions & 9 deletions librecomp/src/recomp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -430,10 +430,12 @@ void recomp::start(ultramodern::WindowHandle window_handle, const recomp::rsp::c

recomp::rsp::set_callbacks(rsp_callbacks);

ultramodern::set_callbacks(ultramodern::rsp::callbacks_t {
static const ultramodern::rsp::callbacks_t ultramodern_rsp_callbacks {
.init = recomp::rsp::constants_init,
.run_microcode = recomp::rsp::run_microcode,
}, audio_callbacks, input_callbacks, gfx_callbacks_, thread_callbacks_, error_handling_callbacks_);
.run_task = recomp::rsp::run_task,
};

ultramodern::set_callbacks(ultramodern_rsp_callbacks, audio_callbacks, input_callbacks, gfx_callbacks_, thread_callbacks_, error_handling_callbacks_);

set_input_callbacks(input_callbacks);

Expand Down Expand Up @@ -506,12 +508,6 @@ void recomp::start(ultramodern::WindowHandle window_handle, const recomp::rsp::c
}
}

// moved from ultarmodern/src/events.cpp/gfx_thread_func
// TODO: is it fine to have it here?
if (gfx_callbacks.destroy_ui != nullptr) {
gfx_callbacks.destroy_ui();
}

game_thread.join();
ultramodern::join_event_threads();
ultramodern::join_thread_cleaner_thread();
Expand Down
3 changes: 2 additions & 1 deletion librecomp/src/rsp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,12 @@ void recomp::rsp::constants_init() {
}

// Runs a recompiled RSP microcode
bool recomp::rsp::run_microcode(uint8_t* rdram, const OSTask* task) {
bool recomp::rsp::run_task(uint8_t* rdram, const OSTask* task) {
assert(rsp_callbacks.get_rsp_microcode != nullptr);
RspUcodeFunc* ucode_func = rsp_callbacks.get_rsp_microcode(task);

if (ucode_func == nullptr) {
fprintf(stderr, "No registered RSP ucode for %" PRIu32 " (returned `nullptr`)\n", task->t.type);
return false;
}

Expand Down
4 changes: 2 additions & 2 deletions ultramodern/include/ultramodern/rsp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ namespace ultramodern {
*
* Returns true if task was executed successfully.
*/
run_microcode_t* run_microcode;
run_microcode_t* run_task;
};

void set_callbacks(const callbacks_t& callbacks);

void init();
bool run_microcode(RDRAM_ARG const OSTask* task);
bool run_task(RDRAM_ARG const OSTask* task);
};
} // namespace ultramodern

Expand Down
7 changes: 1 addition & 6 deletions ultramodern/include/ultramodern/ultramodern.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ struct audio_callbacks_t {
set_frequency_t* set_frequency;
};

// TODO: This really isn't used by ultramodern. Should we move it to librecomp instead?
// TODO: These functions are currently called by librecomp, but will get called by ultramodern in the future
// Input
struct input_callbacks_t {
using poll_input_t = void(void);
Expand All @@ -153,15 +153,10 @@ struct gfx_callbacks_t {
using create_gfx_t = gfx_data_t();
using create_window_t = WindowHandle(gfx_data_t);
using update_gfx_t = void(gfx_data_t);
using destroy_ui_t = void();

create_gfx_t* create_gfx;
create_window_t* create_window;
update_gfx_t* update_gfx;

// TODO: Since we have a destroy_ui we could provide an init_ui?
// void (*init_ui)();
destroy_ui_t* destroy_ui;
};

bool is_game_started();
Expand Down
2 changes: 1 addition & 1 deletion ultramodern/src/error_handling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ void ultramodern::error_handling::set_callbacks(const ultramodern::error_handlin

void ultramodern::error_handling::message_box(const char* msg) {
// We print the message to stderr since the user may not have provided a message_box callback
// TODO: is fprintf ok? or do we prefer using something more C++'ish?

fprintf(stderr, "%s\n", msg);

if (error_handling_callbacks.message_box != nullptr) {
Expand Down
14 changes: 7 additions & 7 deletions ultramodern/src/events.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
#include "rt64_layer.h"
#include "ultramodern/rsp.hpp"

static ultramodern::events::callbacks_t threads_callbacks{};
static ultramodern::events::callbacks_t events_callbacks{};

void ultramodern::events::set_callbacks(const ultramodern::events::callbacks_t& callbacks) {
threads_callbacks = callbacks;
events_callbacks = callbacks;
}

struct SpTaskAction {
Expand Down Expand Up @@ -179,8 +179,8 @@ void vi_thread_func() {
}
}

if (threads_callbacks.vi_callback != nullptr) {
threads_callbacks.vi_callback();
if (events_callbacks.vi_callback != nullptr) {
events_callbacks.vi_callback();
}
}
}
Expand Down Expand Up @@ -214,7 +214,7 @@ void task_thread_func(uint8_t* rdram, moodycamel::LightweightSemaphore* thread_r
}


if (!ultramodern::rsp::run_microcode(PASS_RDRAM task)) {
if (!ultramodern::rsp::run_task(PASS_RDRAM task)) {
fprintf(stderr, "Failed to execute task type: %" PRIu32 "\n", task->t.type);
assert(false);
std::quick_exit(EXIT_FAILURE);
Expand Down Expand Up @@ -281,8 +281,8 @@ void gfx_thread_func(uint8_t* rdram, moodycamel::LightweightSemaphore* thread_re
return;
}

if (threads_callbacks.gfx_init_callback != nullptr) {
threads_callbacks.gfx_init_callback();
if (events_callbacks.gfx_init_callback != nullptr) {
events_callbacks.gfx_init_callback();
}

ultramodern::rsp::init();
Expand Down
6 changes: 3 additions & 3 deletions ultramodern/src/rsp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ void ultramodern::rsp::init() {
}
}

bool ultramodern::rsp::run_microcode(RDRAM_ARG const OSTask* task) {
assert(rsp_callbacks.run_microcode != nullptr);
bool ultramodern::rsp::run_task(RDRAM_ARG const OSTask* task) {
assert(rsp_callbacks.run_task != nullptr);

return rsp_callbacks.run_microcode(PASS_RDRAM task);
return rsp_callbacks.run_task(PASS_RDRAM task);
}

0 comments on commit d57405e

Please sign in to comment.