Skip to content

Commit fe500e3

Browse files
committed
format files
1 parent 40314fd commit fe500e3

5 files changed

Lines changed: 90 additions & 83 deletions

File tree

librecomp/include/recomp_game.h

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -20,34 +20,38 @@ 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();
47-
48-
// TODO: implement both
49-
const std::u8string& get_program_id();
50-
void set_program_id(const std::u8string& program_id);
23+
24+
enum class RomValidationError {
25+
Good,
26+
FailedToOpen,
27+
NotARom,
28+
IncorrectRom,
29+
NotYet,
30+
IncorrectVersion,
31+
OtherError
32+
};
33+
34+
bool register_game(const recomp::GameEntry& entry);
35+
void register_patch(const char* patch, std::size_t size);
36+
void check_all_stored_roms();
37+
bool load_stored_rom(std::u8string& game_id);
38+
RomValidationError select_rom(const std::filesystem::path& rom_path, std::u8string& game_id);
39+
bool is_rom_valid(std::u8string& game_id);
40+
bool is_rom_loaded();
41+
void set_rom_contents(std::vector<uint8_t>&& new_rom);
42+
void do_rom_read(uint8_t* rdram, gpr ram_address, uint32_t physical_addr, size_t num_bytes);
43+
void do_rom_pio(uint8_t* rdram, gpr ram_address, uint32_t physical_addr);
44+
void start(
45+
ultramodern::WindowHandle window_handle, const ultramodern::audio_callbacks_t& audio_callbacks,
46+
const ultramodern::input_callbacks_t& input_callbacks, const ultramodern::gfx_callbacks_t& gfx_callbacks);
47+
void start_game(std::u8string game_id);
48+
void message_box(const char* message);
49+
std::filesystem::path get_app_folder_path();
50+
std::u8string current_game_id();
51+
52+
// TODO: implement both
53+
const std::u8string& get_program_id();
54+
void set_program_id(const std::u8string& program_id);
5155
} // namespace recomp
5256

5357
#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: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <mutex>
99
#include <array>
1010
#include <memory>
11+
#include <mutex>
1112
#include <unordered_map>
1213
#include <unordered_set>
1314

@@ -48,7 +49,7 @@ std::mutex current_game_mutex;
4849

4950
// Global variables
5051
std::vector<char> patch_data;
51-
std::unordered_map<std::u8string, recomp::GameEntry> game_roms {};
52+
std::unordered_map<std::u8string, recomp::GameEntry> game_roms{};
5253

5354
std::u8string recomp::GameEntry::stored_filename() const {
5455
return game_id + u8".z64";
@@ -88,7 +89,7 @@ static std::vector<uint8_t> read_file(const std::filesystem::path& path) {
8889

8990
bool write_file(const std::filesystem::path& path, const std::vector<uint8_t>& data) {
9091
std::ofstream out_file{ path, std::ios::binary };
91-
92+
recomp::g
9293
if (!out_file.good()) {
9394
return false;
9495
}
@@ -103,19 +104,19 @@ std::filesystem::path recomp::get_app_folder_path() {
103104

104105
#if defined(_WIN32)
105106
// Deduce local app data path.
106-
PWSTR known_path = NULL;
107-
HRESULT result = SHGetKnownFolderPath(FOLDERID_LocalAppData, 0, NULL, &known_path);
108-
if (result == S_OK) {
109-
recomp_dir = std::filesystem::path{known_path} / recomp::get_program_id();
110-
}
107+
PWSTR known_path = NULL;
108+
HRESULT result = SHGetKnownFolderPath(FOLDERID_LocalAppData, 0, NULL, &known_path);
109+
if (result == S_OK) {
110+
recomp_dir = std::filesystem::path{known_path} / recomp::get_program_id();
111+
}
111112

112-
CoTaskMemFree(known_path);
113+
CoTaskMemFree(known_path);
113114
#elif defined(__linux__)
114-
const char *homedir;
115+
const char* homedir;
115116

116-
if ((homedir = getenv("HOME")) == nullptr) {
117-
homedir = getpwuid(getuid())->pw_dir;
118-
}
117+
if ((homedir = getenv("HOME")) == nullptr) {
118+
homedir = getpwuid(getuid())->pw_dir;
119+
}
119120

120121
if (homedir != nullptr) {
121122
recomp_dir = std::filesystem::path{homedir} / (std::u8string{u8".config/"} + recomp::get_program_id());
@@ -256,12 +257,13 @@ recomp::RomValidationError recomp::select_rom(const std::filesystem::path& rom_p
256257
}
257258

258259
if (!check_hash(rom_data, game_entry.rom_hash)) {
259-
const std::string_view name{ reinterpret_cast<const char*>(rom_data.data()) + 0x20, game_entry.internal_name.size()};
260+
const std::string_view name{ reinterpret_cast<const char*>(rom_data.data()) + 0x20, game_entry.internal_name.size() };
260261
if (name == game_entry.internal_name) {
261262
return recomp::RomValidationError::IncorrectVersion;
262263
}
263264
else {
264-
if (game_entry.is_enabled && std::string_view{ reinterpret_cast<const char*>(rom_data.data()) + 0x20, 19 } == game_entry.internal_name) {
265+
if (game_entry.is_enabled &&
266+
std::string_view{ reinterpret_cast<const char*>(rom_data.data()) + 0x20, 19 } == game_entry.internal_name) {
265267
return recomp::RomValidationError::NotYet;
266268
}
267269
else {
@@ -460,13 +462,13 @@ void recomp::start(
460462

461463
ultramodern::preinit(rdram, window_handle);
462464

463-
game_status.wait(GameStatus::None);
464-
recomp_context context{};
465+
game_status.wait(GameStatus::None);
466+
recomp_context context{};
465467

466-
switch (game_status.load()) {
467-
// TODO refactor this to allow a project to specify what entrypoint function to run for a give game.
468-
case GameStatus::Running:
469-
{
468+
switch (game_status.load()) {
469+
// TODO refactor this to allow a project to specify what entrypoint function to run for a give game.
470+
case GameStatus::Running:
471+
{
470472
if (!recomp::load_stored_rom(current_game.value())) {
471473
recomp::message_box("Error opening stored ROM! Please restart this program.");
472474
}
@@ -492,7 +494,7 @@ void recomp::start(
492494
}
493495

494496
debug_printf("[Recomp] Quitting\n");
495-
}, window_handle, rdram_buffer.get()};
497+
}, window_handle, rdram_buffer.get(),};
496498

497499
while (!exited) {
498500
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)