Modernize the usage of variants
This commit is contained in:
parent
ada320a184
commit
da641df089
|
@ -10,7 +10,7 @@
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
#include "blockingconcurrentqueue.h"
|
#include "blockingconcurrentqueue.h"
|
||||||
|
#include "utils.hpp"
|
||||||
#include "ultra64.h"
|
#include "ultra64.h"
|
||||||
#include "ultramodern.hpp"
|
#include "ultramodern.hpp"
|
||||||
#include "config.hpp"
|
#include "config.hpp"
|
||||||
|
@ -328,8 +328,8 @@ void gfx_thread_func(uint8_t* rdram, moodycamel::LightweightSemaphore* thread_re
|
||||||
// Try to pull an action from the queue
|
// Try to pull an action from the queue
|
||||||
Action action;
|
Action action;
|
||||||
if (events_context.action_queue.wait_dequeue_timed(action, 1ms)) {
|
if (events_context.action_queue.wait_dequeue_timed(action, 1ms)) {
|
||||||
// Determine the action type and act on it
|
match(action,
|
||||||
if (const auto* task_action = std::get_if<SpTaskAction>(&action)) {
|
[&](const SpTaskAction& action){
|
||||||
// Turn on instant present if the game has been started and it hasn't been turned on yet.
|
// Turn on instant present if the game has been started and it hasn't been turned on yet.
|
||||||
if (ultramodern::is_game_started() && !enabled_instant_present) {
|
if (ultramodern::is_game_started() && !enabled_instant_present) {
|
||||||
rt64.enable_instant_present();
|
rt64.enable_instant_present();
|
||||||
|
@ -346,23 +346,26 @@ void gfx_thread_func(uint8_t* rdram, moodycamel::LightweightSemaphore* thread_re
|
||||||
rt64.send_dl(&task_action->task);
|
rt64.send_dl(&task_action->task);
|
||||||
auto rt64_end = std::chrono::high_resolution_clock::now();
|
auto rt64_end = std::chrono::high_resolution_clock::now();
|
||||||
dp_complete();
|
dp_complete();
|
||||||
// printf("RT64 ProcessDList time: %d us\n", static_cast<u32>(std::chrono::duration_cast<std::chrono::microseconds>(rt64_end - rt64_start).count()));
|
},
|
||||||
}
|
[&](const SwapBuffersAction &action)
|
||||||
else if (const auto* swap_action = std::get_if<SwapBuffersAction>(&action)) {
|
{
|
||||||
events_context.vi.current_buffer = events_context.vi.next_buffer;
|
events_context.vi.current_buffer = events_context.vi.next_buffer;
|
||||||
rt64.update_screen(swap_action->origin);
|
rt64.update_screen(swap_action->origin);
|
||||||
display_refresh_rate = rt64.get_display_framerate();
|
display_refresh_rate = rt64.get_display_framerate();
|
||||||
}
|
},
|
||||||
else if (const auto* config_action = std::get_if<UpdateConfigAction>(&action)) {
|
[&](const UpdateConfigAction &action)
|
||||||
|
{
|
||||||
ultramodern::GraphicsConfig new_config = cur_config;
|
ultramodern::GraphicsConfig new_config = cur_config;
|
||||||
if (old_config != new_config) {
|
if (old_config == new_config) return;
|
||||||
|
|
||||||
rt64.update_config(old_config, new_config);
|
rt64.update_config(old_config, new_config);
|
||||||
old_config = new_config;
|
old_config = new_config;
|
||||||
}
|
},
|
||||||
}
|
[&](const LoadShaderCacheAction &action)
|
||||||
else if (const auto* load_shader_cache_action = std::get_if<LoadShaderCacheAction>(&action)) {
|
{
|
||||||
rt64.load_shader_cache(load_shader_cache_action->data);
|
rt64.load_shader_cache(load_shader_cache_action->data);
|
||||||
}
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// TODO move recomp code out of ultramodern.
|
// TODO move recomp code out of ultramodern.
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#include <set>
|
#include <set>
|
||||||
#include "blockingconcurrentqueue.h"
|
#include "blockingconcurrentqueue.h"
|
||||||
|
|
||||||
|
#include "utils.hpp"
|
||||||
#include "ultra64.h"
|
#include "ultra64.h"
|
||||||
#include "ultramodern.hpp"
|
#include "ultramodern.hpp"
|
||||||
|
|
||||||
|
@ -87,12 +88,16 @@ void timer_thread(RDRAM_ARG1) {
|
||||||
|
|
||||||
// Lambda to process a timer action to handle adding and removing timers
|
// Lambda to process a timer action to handle adding and removing timers
|
||||||
auto process_timer_action = [&](const Action& action) {
|
auto process_timer_action = [&](const Action& action) {
|
||||||
// Determine the action type and act on it
|
match(action,
|
||||||
if (const auto* add_action = std::get_if<AddTimerAction>(&action)) {
|
[&active_timers](const AddTimerAction& action)
|
||||||
active_timers.insert(add_action->timer);
|
{
|
||||||
} else if (const auto* remove_action = std::get_if<RemoveTimerAction>(&action)) {
|
active_timers.insert(action->timer);
|
||||||
active_timers.erase(remove_action->timer);
|
},
|
||||||
|
[&active_timers](const RemoveTimerAction& action)
|
||||||
|
{
|
||||||
|
active_timers.erase(action->timer);
|
||||||
}
|
}
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
#include <variant>
|
||||||
|
|
||||||
|
template<class... Ts>
|
||||||
|
struct overloaded : Ts...
|
||||||
|
{
|
||||||
|
using Ts::operator()...;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<class T, class... Ts>
|
||||||
|
auto match(const T& event, Ts&&... args){
|
||||||
|
return std::visit(overloaded{std::forward<Ts>(args)...}, event);
|
||||||
|
}
|
Loading…
Reference in New Issue