From 04e322966ad795f8f6d23ff205c3cbd2d04c2c9d Mon Sep 17 00:00:00 2001 From: Angie Date: Wed, 22 May 2024 22:24:13 -0400 Subject: [PATCH] format files --- librecomp/include/recomp_game.h | 50 ++++++------ librecomp/include/recomp_input.h | 65 +++++++-------- librecomp/src/pi.cpp | 2 +- librecomp/src/recomp.cpp | 90 +++++++++++---------- ultramodern/include/ultramodern/recomp_ui.h | 2 +- 5 files changed, 108 insertions(+), 101 deletions(-) diff --git a/librecomp/include/recomp_game.h b/librecomp/include/recomp_game.h index 30a7a34..2aa6719 100644 --- a/librecomp/include/recomp_game.h +++ b/librecomp/include/recomp_game.h @@ -20,30 +20,32 @@ namespace recomp { std::u8string stored_filename() const; }; - enum class RomValidationError { - Good, - FailedToOpen, - NotARom, - IncorrectRom, - NotYet, - IncorrectVersion, - OtherError - }; - bool register_game(const recomp::GameEntry& entry); - void register_patch(const char* patch, std::size_t size); - void check_all_stored_roms(); - bool load_stored_rom(std::u8string& game_id); - RomValidationError select_rom(const std::filesystem::path& rom_path, std::u8string& game_id); - bool is_rom_valid(std::u8string& game_id); - bool is_rom_loaded(); - void set_rom_contents(std::vector&& new_rom); - void do_rom_read(uint8_t* rdram, gpr ram_address, uint32_t physical_addr, size_t num_bytes); - void do_rom_pio(uint8_t* rdram, gpr ram_address, uint32_t physical_addr); - void start(ultramodern::WindowHandle window_handle, const ultramodern::audio_callbacks_t& audio_callbacks, const ultramodern::input_callbacks_t& input_callbacks, const ultramodern::gfx_callbacks_t& gfx_callbacks); - void start_game(std::u8string game_id); - void message_box(const char* message); - std::filesystem::path get_app_folder_path(); - std::u8string current_game_id(); + enum class RomValidationError { + Good, + FailedToOpen, + NotARom, + IncorrectRom, + NotYet, + IncorrectVersion, + OtherError + }; + bool register_game(const recomp::GameEntry& entry); + void register_patch(const char* patch, std::size_t size); + void check_all_stored_roms(); + bool load_stored_rom(std::u8string& game_id); + RomValidationError select_rom(const std::filesystem::path& rom_path, std::u8string& game_id); + bool is_rom_valid(std::u8string& game_id); + bool is_rom_loaded(); + void set_rom_contents(std::vector&& new_rom); + void do_rom_read(uint8_t* rdram, gpr ram_address, uint32_t physical_addr, size_t num_bytes); + void do_rom_pio(uint8_t* rdram, gpr ram_address, uint32_t physical_addr); + void start( + ultramodern::WindowHandle window_handle, const ultramodern::audio_callbacks_t& audio_callbacks, + const ultramodern::input_callbacks_t& input_callbacks, const ultramodern::gfx_callbacks_t& gfx_callbacks); + void start_game(std::u8string game_id); + void message_box(const char* message); + std::filesystem::path get_app_folder_path(); + std::u8string current_game_id(); } // namespace recomp #endif diff --git a/librecomp/include/recomp_input.h b/librecomp/include/recomp_input.h index c494cce..fe03dce 100644 --- a/librecomp/include/recomp_input.h +++ b/librecomp/include/recomp_input.h @@ -12,37 +12,38 @@ #include "json/json.hpp" namespace recomp { - // x-macros to build input enums and arrays. - // First parameter is the enum name, second parameter is the bit field for the input (or 0 if there is no associated one), third is the readable name. - // TODO refactor this to allow projects to rename these, or get rid of the readable name and leave that up to individual projects to map. - #define DEFINE_N64_BUTTON_INPUTS() \ - DEFINE_INPUT(A, 0x8000, "Action") \ - DEFINE_INPUT(B, 0x4000, "Attack/Cancel") \ - DEFINE_INPUT(Z, 0x2000, "Target") \ - DEFINE_INPUT(START, 0x1000, "Start") \ - DEFINE_INPUT(L, 0x0020, "Toggle map") \ - DEFINE_INPUT(R, 0x0010, "Shield") \ - DEFINE_INPUT(C_UP, 0x0008, "Look/Fairy") \ - DEFINE_INPUT(C_LEFT, 0x0002, "Item 1") \ - DEFINE_INPUT(C_DOWN, 0x0004, "Item 2") \ - DEFINE_INPUT(C_RIGHT, 0x0001, "Item 3") \ - DEFINE_INPUT(DPAD_UP, 0x0800, "Special Item 1") \ - DEFINE_INPUT(DPAD_RIGHT, 0x0100, "Special Item 2") \ - DEFINE_INPUT(DPAD_DOWN, 0x0400, "Special Item 3") \ - DEFINE_INPUT(DPAD_LEFT, 0x0200, "Special Item 4") - - #define DEFINE_N64_AXIS_INPUTS() \ - DEFINE_INPUT(Y_AXIS_POS, 0, "Up") \ - DEFINE_INPUT(Y_AXIS_NEG, 0, "Down") \ - DEFINE_INPUT(X_AXIS_NEG, 0, "Left") \ - DEFINE_INPUT(X_AXIS_POS, 0, "Right") \ - - #define DEFINE_ALL_INPUTS() \ - DEFINE_N64_BUTTON_INPUTS() \ - DEFINE_N64_AXIS_INPUTS() - - // Enum containing every recomp input. - #define DEFINE_INPUT(name, value, readable) name, +// x-macros to build input enums and arrays. +// First parameter is the enum name, second parameter is the bit field for the input (or 0 if there is no associated one), third is the +// readable name. +// TODO refactor this to allow projects to rename these, or get rid of the readable name and leave that up to individual projects to map. +#define DEFINE_N64_BUTTON_INPUTS() \ + DEFINE_INPUT(A, 0x8000, "Action") \ + DEFINE_INPUT(B, 0x4000, "Attack/Cancel") \ + DEFINE_INPUT(Z, 0x2000, "Target") \ + DEFINE_INPUT(START, 0x1000, "Start") \ + DEFINE_INPUT(L, 0x0020, "Toggle map") \ + DEFINE_INPUT(R, 0x0010, "Shield") \ + DEFINE_INPUT(C_UP, 0x0008, "Look/Fairy") \ + DEFINE_INPUT(C_LEFT, 0x0002, "Item 1") \ + DEFINE_INPUT(C_DOWN, 0x0004, "Item 2") \ + DEFINE_INPUT(C_RIGHT, 0x0001, "Item 3") \ + DEFINE_INPUT(DPAD_UP, 0x0800, "Special Item 1") \ + DEFINE_INPUT(DPAD_RIGHT, 0x0100, "Special Item 2") \ + DEFINE_INPUT(DPAD_DOWN, 0x0400, "Special Item 3") \ + DEFINE_INPUT(DPAD_LEFT, 0x0200, "Special Item 4") + +#define DEFINE_N64_AXIS_INPUTS() \ + DEFINE_INPUT(Y_AXIS_POS, 0, "Up") \ + DEFINE_INPUT(Y_AXIS_NEG, 0, "Down") \ + DEFINE_INPUT(X_AXIS_NEG, 0, "Left") \ + DEFINE_INPUT(X_AXIS_POS, 0, "Right") + +#define DEFINE_ALL_INPUTS() \ + DEFINE_N64_BUTTON_INPUTS() \ + DEFINE_N64_AXIS_INPUTS() + +// Enum containing every recomp input. +#define DEFINE_INPUT(name, value, readable) name, enum class GameInput { DEFINE_ALL_INPUTS() @@ -52,7 +53,7 @@ namespace recomp { N64_AXIS_START = X_AXIS_NEG, N64_AXIS_COUNT = Y_AXIS_POS - N64_AXIS_START + 1, }; - #undef DEFINE_INPUT +#undef DEFINE_INPUT struct InputField { uint32_t input_type; diff --git a/librecomp/src/pi.cpp b/librecomp/src/pi.cpp index c26e992..ea1a698 100644 --- a/librecomp/src/pi.cpp +++ b/librecomp/src/pi.cpp @@ -96,7 +96,7 @@ struct { } save_context; const std::u8string save_folder = u8"saves"; -const std::u8string save_filename = std::u8string{recomp::current_game_id()} + u8".bin"; +const std::u8string save_filename = std::u8string{ recomp::current_game_id() } + u8".bin"; std::filesystem::path get_save_file_path() { return recomp::get_app_folder_path() / save_folder / save_filename; diff --git a/librecomp/src/recomp.cpp b/librecomp/src/recomp.cpp index c646924..7ab82b3 100644 --- a/librecomp/src/recomp.cpp +++ b/librecomp/src/recomp.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -44,7 +45,7 @@ std::mutex current_game_mutex; // Global variables std::vector patch_data; -std::unordered_map game_roms {}; +std::unordered_map game_roms{}; std::u8string recomp::GameEntry::stored_filename() const { return game_id + u8".z64"; @@ -99,23 +100,23 @@ std::filesystem::path recomp::get_app_folder_path() { #if defined(_WIN32) // Deduce local app data path. - PWSTR known_path = NULL; - HRESULT result = SHGetKnownFolderPath(FOLDERID_LocalAppData, 0, NULL, &known_path); - if (result == S_OK) { - recomp_dir = std::filesystem::path{known_path} / recomp::program_id; - } + PWSTR known_path = NULL; + HRESULT result = SHGetKnownFolderPath(FOLDERID_LocalAppData, 0, NULL, &known_path); + if (result == S_OK) { + recomp_dir = std::filesystem::path{ known_path } / recomp::program_id; + } - CoTaskMemFree(known_path); + CoTaskMemFree(known_path); #elif defined(__linux__) - const char *homedir; + const char* homedir; - if ((homedir = getenv("HOME")) == nullptr) { - homedir = getpwuid(getuid())->pw_dir; - } + if ((homedir = getenv("HOME")) == nullptr) { + homedir = getpwuid(getuid())->pw_dir; + } - if (homedir != nullptr) { - recomp_dir = std::filesystem::path{homedir} / (std::u8string{u8".config/"} + std::u8string{recomp::program_id}); - } + if (homedir != nullptr) { + recomp_dir = std::filesystem::path{ homedir } / (std::u8string{ u8".config/" } + std::u8string{ recomp::program_id }); + } #endif return recomp_dir; @@ -252,12 +253,13 @@ recomp::RomValidationError recomp::select_rom(const std::filesystem::path& rom_p } if (!check_hash(rom_data, game_entry.rom_hash)) { - const std::string_view name{ reinterpret_cast(rom_data.data()) + 0x20, game_entry.internal_name.size()}; + const std::string_view name{ reinterpret_cast(rom_data.data()) + 0x20, game_entry.internal_name.size() }; if (name == game_entry.internal_name) { return recomp::RomValidationError::IncorrectVersion; } else { - if (game_entry.is_enabled && std::string_view{ reinterpret_cast(rom_data.data()) + 0x20, 19 } == game_entry.internal_name) { + if (game_entry.is_enabled && + std::string_view{ reinterpret_cast(rom_data.data()) + 0x20, 19 } == game_entry.internal_name) { return recomp::RomValidationError::NotYet; } else { @@ -453,33 +455,35 @@ void recomp::start( [](ultramodern::WindowHandle window_handle, uint8_t* rdram) { debug_printf("[Recomp] Starting\n"); - game_status.wait(GameStatus::None); - recomp_context context{}; - - switch (game_status.load()) { - // TODO refactor this to allow a project to specify what entrypoint function to run for a give game. - case GameStatus::Running: - if (!recomp::load_stored_rom(current_game.value())) { - recomp::message_box("Error opening stored ROM! Please restart this program."); - } - - auto find_it = game_roms.find(current_game.value()); - const recomp::GameEntry& game_entry = find_it->second; - - ultramodern::load_shader_cache(game_entry.cache_data); - init(rdram, &context); - try { - recomp_entrypoint(rdram, &context); - } catch (ultramodern::thread_terminated& terminated) { - - } - break; - case GameStatus::Quit: - break; - } - - debug_printf("[Recomp] Quitting\n"); - }, window_handle, rdram_buffer.get()}; + game_status.wait(GameStatus::None); + recomp_context context{}; + + switch (game_status.load()) { + // TODO refactor this to allow a project to specify what entrypoint function to run for a give game. + case GameStatus::Running: + if (!recomp::load_stored_rom(current_game.value())) { + recomp::message_box("Error opening stored ROM! Please restart this program."); + } + + auto find_it = game_roms.find(current_game.value()); + const recomp::GameEntry& game_entry = find_it->second; + + ultramodern::load_shader_cache(game_entry.cache_data); + init(rdram, &context); + try { + recomp_entrypoint(rdram, &context); + } catch (ultramodern::thread_terminated& terminated) { + } + break; + case GameStatus::Quit: + break; + } + + debug_printf("[Recomp] Quitting\n"); + }, + window_handle, + rdram_buffer.get(), + }; while (!exited) { ultramodern::sleep_milliseconds(1); diff --git a/ultramodern/include/ultramodern/recomp_ui.h b/ultramodern/include/ultramodern/recomp_ui.h index 7b511fc..9ac4d21 100644 --- a/ultramodern/include/ultramodern/recomp_ui.h +++ b/ultramodern/include/ultramodern/recomp_ui.h @@ -7,6 +7,6 @@ namespace recomp { void destroy_ui(); void update_supported_options(); -} +} // namespace recomp #endif