Skip to content

Commit

Permalink
format files
Browse files Browse the repository at this point in the history
  • Loading branch information
AngheloAlf committed May 23, 2024
1 parent 6f92e64 commit 04e3229
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 101 deletions.
50 changes: 26 additions & 24 deletions librecomp/include/recomp_game.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint8_t>&& 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<uint8_t>&& 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
65 changes: 33 additions & 32 deletions librecomp/include/recomp_input.h
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion librecomp/src/pi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
90 changes: 47 additions & 43 deletions librecomp/src/recomp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <fstream>
#include <iostream>
#include <memory>
#include <mutex>
#include <unordered_map>
#include <unordered_set>

Expand Down Expand Up @@ -44,7 +45,7 @@ std::mutex current_game_mutex;

// Global variables
std::vector<char> patch_data;
std::unordered_map<std::u8string, recomp::GameEntry> game_roms {};
std::unordered_map<std::u8string, recomp::GameEntry> game_roms{};

std::u8string recomp::GameEntry::stored_filename() const {
return game_id + u8".z64";
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<const char*>(rom_data.data()) + 0x20, game_entry.internal_name.size()};
const std::string_view name{ reinterpret_cast<const char*>(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<const char*>(rom_data.data()) + 0x20, 19 } == game_entry.internal_name) {
if (game_entry.is_enabled &&
std::string_view{ reinterpret_cast<const char*>(rom_data.data()) + 0x20, 19 } == game_entry.internal_name) {
return recomp::RomValidationError::NotYet;
}
else {
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion ultramodern/include/ultramodern/recomp_ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ namespace recomp {

void destroy_ui();
void update_supported_options();
}
} // namespace recomp

#endif

0 comments on commit 04e3229

Please sign in to comment.