Skip to content

Commit 04e3229

Browse files
committed
format files
1 parent 6f92e64 commit 04e3229

File tree

5 files changed

+108
-101
lines changed

5 files changed

+108
-101
lines changed

librecomp/include/recomp_game.h

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,30 +20,32 @@ namespace recomp {
2020

2121
std::u8string stored_filename() const;
2222
};
23-
enum class RomValidationError {
24-
Good,
25-
FailedToOpen,
26-
NotARom,
27-
IncorrectRom,
28-
NotYet,
29-
IncorrectVersion,
30-
OtherError
31-
};
32-
bool register_game(const recomp::GameEntry& entry);
33-
void register_patch(const char* patch, std::size_t size);
34-
void check_all_stored_roms();
35-
bool load_stored_rom(std::u8string& game_id);
36-
RomValidationError select_rom(const std::filesystem::path& rom_path, std::u8string& game_id);
37-
bool is_rom_valid(std::u8string& game_id);
38-
bool is_rom_loaded();
39-
void set_rom_contents(std::vector<uint8_t>&& new_rom);
40-
void do_rom_read(uint8_t* rdram, gpr ram_address, uint32_t physical_addr, size_t num_bytes);
41-
void do_rom_pio(uint8_t* rdram, gpr ram_address, uint32_t physical_addr);
42-
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);
43-
void start_game(std::u8string game_id);
44-
void message_box(const char* message);
45-
std::filesystem::path get_app_folder_path();
46-
std::u8string current_game_id();
23+
enum class RomValidationError {
24+
Good,
25+
FailedToOpen,
26+
NotARom,
27+
IncorrectRom,
28+
NotYet,
29+
IncorrectVersion,
30+
OtherError
31+
};
32+
bool register_game(const recomp::GameEntry& entry);
33+
void register_patch(const char* patch, std::size_t size);
34+
void check_all_stored_roms();
35+
bool load_stored_rom(std::u8string& game_id);
36+
RomValidationError select_rom(const std::filesystem::path& rom_path, std::u8string& game_id);
37+
bool is_rom_valid(std::u8string& game_id);
38+
bool is_rom_loaded();
39+
void set_rom_contents(std::vector<uint8_t>&& new_rom);
40+
void do_rom_read(uint8_t* rdram, gpr ram_address, uint32_t physical_addr, size_t num_bytes);
41+
void do_rom_pio(uint8_t* rdram, gpr ram_address, uint32_t physical_addr);
42+
void start(
43+
ultramodern::WindowHandle window_handle, const ultramodern::audio_callbacks_t& audio_callbacks,
44+
const ultramodern::input_callbacks_t& input_callbacks, const ultramodern::gfx_callbacks_t& gfx_callbacks);
45+
void start_game(std::u8string game_id);
46+
void message_box(const char* message);
47+
std::filesystem::path get_app_folder_path();
48+
std::u8string current_game_id();
4749
} // namespace recomp
4850

4951
#endif

librecomp/include/recomp_input.h

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -12,37 +12,38 @@
1212
#include "json/json.hpp"
1313

1414
namespace recomp {
15-
// x-macros to build input enums and arrays.
16-
// 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.
17-
// 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.
18-
#define DEFINE_N64_BUTTON_INPUTS() \
19-
DEFINE_INPUT(A, 0x8000, "Action") \
20-
DEFINE_INPUT(B, 0x4000, "Attack/Cancel") \
21-
DEFINE_INPUT(Z, 0x2000, "Target") \
22-
DEFINE_INPUT(START, 0x1000, "Start") \
23-
DEFINE_INPUT(L, 0x0020, "Toggle map") \
24-
DEFINE_INPUT(R, 0x0010, "Shield") \
25-
DEFINE_INPUT(C_UP, 0x0008, "Look/Fairy") \
26-
DEFINE_INPUT(C_LEFT, 0x0002, "Item 1") \
27-
DEFINE_INPUT(C_DOWN, 0x0004, "Item 2") \
28-
DEFINE_INPUT(C_RIGHT, 0x0001, "Item 3") \
29-
DEFINE_INPUT(DPAD_UP, 0x0800, "Special Item 1") \
30-
DEFINE_INPUT(DPAD_RIGHT, 0x0100, "Special Item 2") \
31-
DEFINE_INPUT(DPAD_DOWN, 0x0400, "Special Item 3") \
32-
DEFINE_INPUT(DPAD_LEFT, 0x0200, "Special Item 4")
33-
34-
#define DEFINE_N64_AXIS_INPUTS() \
35-
DEFINE_INPUT(Y_AXIS_POS, 0, "Up") \
36-
DEFINE_INPUT(Y_AXIS_NEG, 0, "Down") \
37-
DEFINE_INPUT(X_AXIS_NEG, 0, "Left") \
38-
DEFINE_INPUT(X_AXIS_POS, 0, "Right") \
39-
40-
#define DEFINE_ALL_INPUTS() \
41-
DEFINE_N64_BUTTON_INPUTS() \
42-
DEFINE_N64_AXIS_INPUTS()
43-
44-
// Enum containing every recomp input.
45-
#define DEFINE_INPUT(name, value, readable) name,
15+
// x-macros to build input enums and arrays.
16+
// 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
17+
// readable name.
18+
// 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.
19+
#define DEFINE_N64_BUTTON_INPUTS() \
20+
DEFINE_INPUT(A, 0x8000, "Action") \
21+
DEFINE_INPUT(B, 0x4000, "Attack/Cancel") \
22+
DEFINE_INPUT(Z, 0x2000, "Target") \
23+
DEFINE_INPUT(START, 0x1000, "Start") \
24+
DEFINE_INPUT(L, 0x0020, "Toggle map") \
25+
DEFINE_INPUT(R, 0x0010, "Shield") \
26+
DEFINE_INPUT(C_UP, 0x0008, "Look/Fairy") \
27+
DEFINE_INPUT(C_LEFT, 0x0002, "Item 1") \
28+
DEFINE_INPUT(C_DOWN, 0x0004, "Item 2") \
29+
DEFINE_INPUT(C_RIGHT, 0x0001, "Item 3") \
30+
DEFINE_INPUT(DPAD_UP, 0x0800, "Special Item 1") \
31+
DEFINE_INPUT(DPAD_RIGHT, 0x0100, "Special Item 2") \
32+
DEFINE_INPUT(DPAD_DOWN, 0x0400, "Special Item 3") \
33+
DEFINE_INPUT(DPAD_LEFT, 0x0200, "Special Item 4")
34+
35+
#define DEFINE_N64_AXIS_INPUTS() \
36+
DEFINE_INPUT(Y_AXIS_POS, 0, "Up") \
37+
DEFINE_INPUT(Y_AXIS_NEG, 0, "Down") \
38+
DEFINE_INPUT(X_AXIS_NEG, 0, "Left") \
39+
DEFINE_INPUT(X_AXIS_POS, 0, "Right")
40+
41+
#define DEFINE_ALL_INPUTS() \
42+
DEFINE_N64_BUTTON_INPUTS() \
43+
DEFINE_N64_AXIS_INPUTS()
44+
45+
// Enum containing every recomp input.
46+
#define DEFINE_INPUT(name, value, readable) name,
4647
enum class GameInput {
4748
DEFINE_ALL_INPUTS()
4849

@@ -52,7 +53,7 @@ namespace recomp {
5253
N64_AXIS_START = X_AXIS_NEG,
5354
N64_AXIS_COUNT = Y_AXIS_POS - N64_AXIS_START + 1,
5455
};
55-
#undef DEFINE_INPUT
56+
#undef DEFINE_INPUT
5657

5758
struct InputField {
5859
uint32_t input_type;

librecomp/src/pi.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ struct {
9696
} save_context;
9797

9898
const std::u8string save_folder = u8"saves";
99-
const std::u8string save_filename = std::u8string{recomp::current_game_id()} + u8".bin";
99+
const std::u8string save_filename = std::u8string{ recomp::current_game_id() } + u8".bin";
100100

101101
std::filesystem::path get_save_file_path() {
102102
return recomp::get_app_folder_path() / save_folder / save_filename;

librecomp/src/recomp.cpp

Lines changed: 47 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <fstream>
66
#include <iostream>
77
#include <memory>
8+
#include <mutex>
89
#include <unordered_map>
910
#include <unordered_set>
1011

@@ -44,7 +45,7 @@ std::mutex current_game_mutex;
4445

4546
// Global variables
4647
std::vector<char> patch_data;
47-
std::unordered_map<std::u8string, recomp::GameEntry> game_roms {};
48+
std::unordered_map<std::u8string, recomp::GameEntry> game_roms{};
4849

4950
std::u8string recomp::GameEntry::stored_filename() const {
5051
return game_id + u8".z64";
@@ -99,23 +100,23 @@ std::filesystem::path recomp::get_app_folder_path() {
99100

100101
#if defined(_WIN32)
101102
// Deduce local app data path.
102-
PWSTR known_path = NULL;
103-
HRESULT result = SHGetKnownFolderPath(FOLDERID_LocalAppData, 0, NULL, &known_path);
104-
if (result == S_OK) {
105-
recomp_dir = std::filesystem::path{known_path} / recomp::program_id;
106-
}
103+
PWSTR known_path = NULL;
104+
HRESULT result = SHGetKnownFolderPath(FOLDERID_LocalAppData, 0, NULL, &known_path);
105+
if (result == S_OK) {
106+
recomp_dir = std::filesystem::path{ known_path } / recomp::program_id;
107+
}
107108

108-
CoTaskMemFree(known_path);
109+
CoTaskMemFree(known_path);
109110
#elif defined(__linux__)
110-
const char *homedir;
111+
const char* homedir;
111112

112-
if ((homedir = getenv("HOME")) == nullptr) {
113-
homedir = getpwuid(getuid())->pw_dir;
114-
}
113+
if ((homedir = getenv("HOME")) == nullptr) {
114+
homedir = getpwuid(getuid())->pw_dir;
115+
}
115116

116-
if (homedir != nullptr) {
117-
recomp_dir = std::filesystem::path{homedir} / (std::u8string{u8".config/"} + std::u8string{recomp::program_id});
118-
}
117+
if (homedir != nullptr) {
118+
recomp_dir = std::filesystem::path{ homedir } / (std::u8string{ u8".config/" } + std::u8string{ recomp::program_id });
119+
}
119120
#endif
120121

121122
return recomp_dir;
@@ -252,12 +253,13 @@ recomp::RomValidationError recomp::select_rom(const std::filesystem::path& rom_p
252253
}
253254

254255
if (!check_hash(rom_data, game_entry.rom_hash)) {
255-
const std::string_view name{ reinterpret_cast<const char*>(rom_data.data()) + 0x20, game_entry.internal_name.size()};
256+
const std::string_view name{ reinterpret_cast<const char*>(rom_data.data()) + 0x20, game_entry.internal_name.size() };
256257
if (name == game_entry.internal_name) {
257258
return recomp::RomValidationError::IncorrectVersion;
258259
}
259260
else {
260-
if (game_entry.is_enabled && std::string_view{ reinterpret_cast<const char*>(rom_data.data()) + 0x20, 19 } == game_entry.internal_name) {
261+
if (game_entry.is_enabled &&
262+
std::string_view{ reinterpret_cast<const char*>(rom_data.data()) + 0x20, 19 } == game_entry.internal_name) {
261263
return recomp::RomValidationError::NotYet;
262264
}
263265
else {
@@ -453,33 +455,35 @@ void recomp::start(
453455
[](ultramodern::WindowHandle window_handle, uint8_t* rdram) {
454456
debug_printf("[Recomp] Starting\n");
455457

456-
game_status.wait(GameStatus::None);
457-
recomp_context context{};
458-
459-
switch (game_status.load()) {
460-
// TODO refactor this to allow a project to specify what entrypoint function to run for a give game.
461-
case GameStatus::Running:
462-
if (!recomp::load_stored_rom(current_game.value())) {
463-
recomp::message_box("Error opening stored ROM! Please restart this program.");
464-
}
465-
466-
auto find_it = game_roms.find(current_game.value());
467-
const recomp::GameEntry& game_entry = find_it->second;
468-
469-
ultramodern::load_shader_cache(game_entry.cache_data);
470-
init(rdram, &context);
471-
try {
472-
recomp_entrypoint(rdram, &context);
473-
} catch (ultramodern::thread_terminated& terminated) {
474-
475-
}
476-
break;
477-
case GameStatus::Quit:
478-
break;
479-
}
480-
481-
debug_printf("[Recomp] Quitting\n");
482-
}, window_handle, rdram_buffer.get()};
458+
game_status.wait(GameStatus::None);
459+
recomp_context context{};
460+
461+
switch (game_status.load()) {
462+
// TODO refactor this to allow a project to specify what entrypoint function to run for a give game.
463+
case GameStatus::Running:
464+
if (!recomp::load_stored_rom(current_game.value())) {
465+
recomp::message_box("Error opening stored ROM! Please restart this program.");
466+
}
467+
468+
auto find_it = game_roms.find(current_game.value());
469+
const recomp::GameEntry& game_entry = find_it->second;
470+
471+
ultramodern::load_shader_cache(game_entry.cache_data);
472+
init(rdram, &context);
473+
try {
474+
recomp_entrypoint(rdram, &context);
475+
} catch (ultramodern::thread_terminated& terminated) {
476+
}
477+
break;
478+
case GameStatus::Quit:
479+
break;
480+
}
481+
482+
debug_printf("[Recomp] Quitting\n");
483+
},
484+
window_handle,
485+
rdram_buffer.get(),
486+
};
483487

484488
while (!exited) {
485489
ultramodern::sleep_milliseconds(1);

ultramodern/include/ultramodern/recomp_ui.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ namespace recomp {
77

88
void destroy_ui();
99
void update_supported_options();
10-
}
10+
} // namespace recomp
1111

1212
#endif

0 commit comments

Comments
 (0)