Initial Setup

This commit is contained in:
Sonic Dreamcaster
2025-10-22 21:04:47 -03:00
parent 7e0f928de0
commit b0e5376ba7
236 changed files with 46212 additions and 7 deletions
+10
View File
@@ -0,0 +1,10 @@
#ifndef __OVERLOADED_H__
#define __OVERLOADED_H__
// Helper for std::visit
template<class... Ts>
struct overloaded : Ts... { using Ts::operator()...; };
template<class... Ts>
overloaded(Ts...) -> overloaded<Ts...>;
#endif
+9
View File
@@ -0,0 +1,9 @@
#ifndef __OVL_PATCHES_HPP__
#define __OVL_PATCHES_HPP__
namespace zelda64 {
void register_overlays();
void register_patches();
}
#endif
File diff suppressed because it is too large Load Diff
+11
View File
@@ -0,0 +1,11 @@
#ifndef __RECOMP_DATA_H__
#define __RECOMP_DATA_H__
namespace recomputil {
// void init_extended_actor_data();
void reset_actor_data();
void register_data_api_exports();
}
#endif
+14
View File
@@ -0,0 +1,14 @@
#ifndef __RECOMP_FILES_H__
#define __RECOMP_FILES_H__
#include <filesystem>
#include <fstream>
namespace recomp {
std::ifstream open_input_file_with_backup(const std::filesystem::path& filepath, std::ios_base::openmode mode = std::ios_base::in);
std::ifstream open_input_backup_file(const std::filesystem::path& filepath, std::ios_base::openmode mode = std::ios_base::in);
std::ofstream open_output_file_with_backup(const std::filesystem::path& filepath, std::ios_base::openmode mode = std::ios_base::out);
bool finalize_output_file_with_backup(const std::filesystem::path& filepath);
};
#endif
+201
View File
@@ -0,0 +1,201 @@
#ifndef __RECOMP_INPUT_H__
#define __RECOMP_INPUT_H__
#include <cstdint>
#include <variant>
#include <vector>
#include <type_traits>
#include <span>
#include <string>
#include <string_view>
#include "ultramodern/input.hpp"
#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, "A") \
DEFINE_INPUT(B, 0x4000, "B") \
DEFINE_INPUT(Z, 0x2000, "Z") \
DEFINE_INPUT(R, 0x0010, "R") \
DEFINE_INPUT(START, 0x1000, "START") \
DEFINE_INPUT(L, 0x0020, "L") \
DEFINE_INPUT(C_UP, 0x0008, "C UP") \
DEFINE_INPUT(C_LEFT, 0x0002, "C LEFT") \
DEFINE_INPUT(C_DOWN, 0x0004, "C DOWN") \
DEFINE_INPUT(C_RIGHT, 0x0001, "C RIGHT") \
DEFINE_INPUT(DPAD_UP, 0x0800, "Menu Up") \
DEFINE_INPUT(DPAD_RIGHT, 0x0100, "Menu Right") \
DEFINE_INPUT(DPAD_DOWN, 0x0400, "Menu Down") \
DEFINE_INPUT(DPAD_LEFT, 0x0200, "Menu Left")
#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_RECOMP_UI_INPUTS() \
DEFINE_INPUT(TOGGLE_MENU, 0, "Toggle Menu") \
DEFINE_INPUT(ACCEPT_MENU, 0, "Accept (Menu)") \
DEFINE_INPUT(APPLY_MENU, 0, "Apply (Menu)")
#define DEFINE_ALL_INPUTS() \
DEFINE_N64_BUTTON_INPUTS() \
DEFINE_N64_AXIS_INPUTS() \
DEFINE_RECOMP_UI_INPUTS()
// Enum containing every recomp input.
#define DEFINE_INPUT(name, value, readable) name,
enum class GameInput {
DEFINE_ALL_INPUTS()
COUNT,
N64_BUTTON_START = A,
N64_BUTTON_COUNT = C_RIGHT - N64_BUTTON_START + 1,
N64_AXIS_START = X_AXIS_NEG,
N64_AXIS_COUNT = Y_AXIS_POS - N64_AXIS_START + 1,
};
#undef DEFINE_INPUT
struct InputField {
uint32_t input_type;
int32_t input_id;
std::string to_string() const;
auto operator<=>(const InputField& rhs) const = default;
};
void poll_inputs();
float get_input_analog(const InputField& field);
float get_input_analog(const std::span<const recomp::InputField> fields);
bool get_input_digital(const InputField& field);
bool get_input_digital(const std::span<const recomp::InputField> fields);
void get_gyro_deltas(float* x, float* y);
void get_mouse_deltas(float* x, float* y);
void get_right_analog(float* x, float* y);
enum class InputDevice {
Controller,
Keyboard,
COUNT
};
void start_scanning_input(InputDevice device);
void stop_scanning_input();
void finish_scanning_input(InputField scanned_field);
void cancel_scanning_input();
void config_menu_set_cont_or_kb(bool cont_interacted);
InputField get_scanned_input();
int get_scanned_input_index();
struct DefaultN64Mappings {
std::vector<InputField> a;
std::vector<InputField> b;
std::vector<InputField> l;
std::vector<InputField> r;
std::vector<InputField> z;
std::vector<InputField> start;
std::vector<InputField> c_left;
std::vector<InputField> c_right;
std::vector<InputField> c_up;
std::vector<InputField> c_down;
std::vector<InputField> dpad_left;
std::vector<InputField> dpad_right;
std::vector<InputField> dpad_up;
std::vector<InputField> dpad_down;
std::vector<InputField> analog_left;
std::vector<InputField> analog_right;
std::vector<InputField> analog_up;
std::vector<InputField> analog_down;
std::vector<InputField> toggle_menu;
std::vector<InputField> accept_menu;
std::vector<InputField> apply_menu;
};
constexpr const std::vector<InputField>& get_default_mapping_for_input(const DefaultN64Mappings& defaults, const GameInput input) {
switch (input) {
case GameInput::A: return defaults.a;
case GameInput::B: return defaults.b;
case GameInput::L: return defaults.l;
case GameInput::R: return defaults.r;
case GameInput::Z: return defaults.z;
case GameInput::START: return defaults.start;
case GameInput::C_LEFT: return defaults.c_left;
case GameInput::C_RIGHT: return defaults.c_right;
case GameInput::C_UP: return defaults.c_up;
case GameInput::C_DOWN: return defaults.c_down;
case GameInput::DPAD_LEFT: return defaults.dpad_left;
case GameInput::DPAD_RIGHT: return defaults.dpad_right;
case GameInput::DPAD_UP: return defaults.dpad_up;
case GameInput::DPAD_DOWN: return defaults.dpad_down;
case GameInput::X_AXIS_NEG: return defaults.analog_left;
case GameInput::X_AXIS_POS: return defaults.analog_right;
case GameInput::Y_AXIS_POS: return defaults.analog_up;
case GameInput::Y_AXIS_NEG: return defaults.analog_down;
case GameInput::TOGGLE_MENU: return defaults.toggle_menu;
case GameInput::ACCEPT_MENU: return defaults.accept_menu;
case GameInput::APPLY_MENU: return defaults.apply_menu;
default: return std::vector<InputField>();
}
}
extern const DefaultN64Mappings default_n64_keyboard_mappings;
extern const DefaultN64Mappings default_n64_controller_mappings;
constexpr size_t bindings_per_input = 2;
size_t get_num_inputs();
const std::string& get_input_name(GameInput input);
const std::string& get_input_enum_name(GameInput input);
GameInput get_input_from_enum_name(const std::string_view name);
InputField& get_input_binding(GameInput input, size_t binding_index, InputDevice device);
void set_input_binding(GameInput input, size_t binding_index, InputDevice device, InputField value);
bool get_n64_input(int controller_num, uint16_t* buttons_out, float* x_out, float* y_out);
void set_rumble(int controller_num, bool);
void update_rumble();
void handle_events();
ultramodern::input::connected_device_info_t get_connected_device_info(int controller_num);
// Rumble strength ranges from 0 to 100.
int get_rumble_strength();
void set_rumble_strength(int strength);
// Gyro and mouse sensitivities range from 0 to 100.
int get_gyro_sensitivity();
int get_mouse_sensitivity();
int get_joystick_deadzone();
void set_gyro_sensitivity(int strength);
void set_mouse_sensitivity(int strength);
void set_joystick_deadzone(int strength);
void apply_joystick_deadzone(float x_in, float y_in, float* x_out, float* y_out);
void set_right_analog_suppressed(bool suppressed);
enum class BackgroundInputMode {
On,
Off,
OptionCount
};
NLOHMANN_JSON_SERIALIZE_ENUM(recomp::BackgroundInputMode, {
{recomp::BackgroundInputMode::On, "On"},
{recomp::BackgroundInputMode::Off, "Off"}
});
BackgroundInputMode get_background_input_mode();
void set_background_input_mode(BackgroundInputMode mode);
bool game_input_disabled();
bool all_input_disabled();
}
#endif
+146
View File
@@ -0,0 +1,146 @@
#ifndef __RECOMP_UI__
#define __RECOMP_UI__
#include <memory>
#include <string>
#include <string_view>
#include <list>
// TODO move this file into src/ui
#include "SDL.h"
#include "RmlUi/Core.h"
#include "../src/ui/util/hsv.h"
#include "../src/ui/util/bem.h"
#include "../src/ui/core/ui_context.h"
namespace Rml {
class ElementDocument;
class EventListenerInstancer;
class Context;
class Event;
}
namespace recompui {
class UiEventListenerInstancer;
// TODO remove this once the UI has been ported over to the new system.
class MenuController {
public:
virtual ~MenuController() {}
virtual void load_document() = 0;
virtual void register_events(UiEventListenerInstancer& listener) = 0;
virtual void make_bindings(Rml::Context* context) = 0;
};
std::unique_ptr<MenuController> create_launcher_menu();
std::unique_ptr<MenuController> create_config_menu();
using event_handler_t = void(const std::string& param, Rml::Event&);
void queue_event(const SDL_Event& event);
bool try_deque_event(SDL_Event& out);
std::unique_ptr<UiEventListenerInstancer> make_event_listener_instancer();
void register_event(UiEventListenerInstancer& listener, const std::string& name, event_handler_t* handler);
void show_context(ContextId context, std::string_view param);
void hide_context(ContextId context);
void hide_all_contexts();
bool is_context_shown(ContextId context);
bool is_context_capturing_input();
bool is_context_capturing_mouse();
bool is_any_context_shown();
ContextId try_close_current_context();
ContextId get_launcher_context_id();
ContextId get_config_context_id();
ContextId get_config_sub_menu_context_id();
enum class ConfigTab {
General,
Controls,
Graphics,
Sound,
Mods,
Debug,
};
void set_config_tab(ConfigTab tab);
int config_tab_to_index(ConfigTab tab);
Rml::ElementTabSet* get_config_tabset();
Rml::Element* get_mod_tab();
void set_config_tabset_mod_nav();
void focus_mod_configure_button();
enum class ButtonVariant {
Primary,
Secondary,
Tertiary,
Success,
Error,
Warning,
NumVariants,
};
void init_styling(const std::filesystem::path& rcss_file);
void init_prompt_context();
void open_choice_prompt(
const std::string& header_text,
const std::string& content_text,
const std::string& confirm_label_text,
const std::string& cancel_label_text,
std::function<void()> confirm_action,
std::function<void()> cancel_action,
ButtonVariant confirm_variant = ButtonVariant::Success,
ButtonVariant cancel_variant = ButtonVariant::Error,
bool focus_on_cancel = true,
const std::string& return_element_id = ""
);
void open_info_prompt(
const std::string& header_text,
const std::string& content_text,
const std::string& okay_label_text,
std::function<void()> okay_action,
ButtonVariant okay_variant = ButtonVariant::Error,
const std::string& return_element_id = ""
);
void open_notification(
const std::string& header_text,
const std::string& content_text,
const std::string& return_element_id = ""
);
void close_prompt();
bool is_prompt_open();
void update_mod_list(bool scan_mods = true);
void process_game_started();
void apply_color_hack();
void get_window_size(int& width, int& height);
void set_cursor_visible(bool visible);
void update_supported_options();
void toggle_fullscreen();
bool get_cont_active(void);
void set_cont_active(bool active);
void activate_mouse();
void message_box(const char* msg);
void set_render_hooks();
Rml::ElementPtr create_custom_element(Rml::Element* parent, std::string tag);
Rml::ElementDocument* load_document(const std::filesystem::path& path);
Rml::ElementDocument* create_empty_document();
Rml::Element* get_child_by_tag(Rml::Element* parent, const std::string& tag);
void queue_image_from_bytes_rgba32(const std::string &src, const std::vector<char> &bytes, uint32_t width, uint32_t height);
void queue_image_from_bytes_file(const std::string &src, const std::vector<char> &bytes);
void release_image(const std::string &src);
void drop_files(const std::list<std::filesystem::path> &file_list);
}
#endif
+93
View File
@@ -0,0 +1,93 @@
#ifndef __ZELDA_CONFIG_H__
#define __ZELDA_CONFIG_H__
#include <filesystem>
#include <string_view>
#include "ultramodern/config.hpp"
#include "recomp_input.h"
namespace zelda64 {
constexpr std::u8string_view program_id = u8"MarioKart64Recompiled";
constexpr std::string_view program_name = "MarioKart 64: Recompiled";
// TODO: Move loading configs to the runtime once we have a way to allow per-project customization.
void load_config();
void save_config();
void reset_input_bindings();
void reset_cont_input_bindings();
void reset_kb_input_bindings();
void reset_single_input_binding(recomp::InputDevice device, recomp::GameInput input);
std::filesystem::path get_app_folder_path();
bool get_debug_mode_enabled();
void set_debug_mode_enabled(bool enabled);
enum class AutosaveMode {
On,
Off,
OptionCount
};
NLOHMANN_JSON_SERIALIZE_ENUM(zelda64::AutosaveMode, {
{zelda64::AutosaveMode::On, "On"},
{zelda64::AutosaveMode::Off, "Off"}
});
enum class TargetingMode {
Switch,
Hold,
OptionCount
};
NLOHMANN_JSON_SERIALIZE_ENUM(zelda64::TargetingMode, {
{zelda64::TargetingMode::Switch, "Switch"},
{zelda64::TargetingMode::Hold, "Hold"}
});
TargetingMode get_targeting_mode();
void set_targeting_mode(TargetingMode mode);
enum class CameraInvertMode {
InvertNone,
InvertX,
InvertY,
InvertBoth,
OptionCount
};
NLOHMANN_JSON_SERIALIZE_ENUM(zelda64::CameraInvertMode, {
{zelda64::CameraInvertMode::InvertNone, "InvertNone"},
{zelda64::CameraInvertMode::InvertX, "InvertX"},
{zelda64::CameraInvertMode::InvertY, "InvertY"},
{zelda64::CameraInvertMode::InvertBoth, "InvertBoth"}
});
CameraInvertMode get_camera_invert_mode();
void set_camera_invert_mode(CameraInvertMode mode);
CameraInvertMode get_analog_camera_invert_mode();
void set_analog_camera_invert_mode(CameraInvertMode mode);
enum class AnalogCamMode {
On,
Off,
OptionCount
};
NLOHMANN_JSON_SERIALIZE_ENUM(zelda64::AnalogCamMode, {
{zelda64::AnalogCamMode::On, "On"},
{zelda64::AnalogCamMode::Off, "Off"}
});
AutosaveMode get_autosave_mode();
void set_autosave_mode(AutosaveMode mode);
AnalogCamMode get_analog_cam_mode();
void set_analog_cam_mode(AnalogCamMode mode);
void open_quit_game_prompt();
};
#endif
+25
View File
@@ -0,0 +1,25 @@
#ifndef __ZELDA_DEBUG_H__
#define __ZELDA_DEBUG_H__
#include <vector>
#include <string>
namespace zelda64 {
struct SceneWarps {
int index;
std::string name;
std::vector<std::string> entrances;
};
struct AreaWarps {
std::string name;
std::vector<SceneWarps> scenes;
};
extern std::vector<AreaWarps> game_warps;
void do_warp(int area, int scene, int entrance);
void set_time(uint8_t day, uint8_t hour, uint8_t minute);
}
#endif
+9
View File
@@ -0,0 +1,9 @@
#ifndef __ZELDA_GAME_H__
#define __ZELDA_GAME_H__
namespace zelda64 {
void quicksave_save();
void quicksave_load();
};
#endif
+61
View File
@@ -0,0 +1,61 @@
#ifndef __ZELDA_RENDER_H__
#define __ZELDA_RENDER_H__
#include <unordered_set>
#include <filesystem>
#include "common/rt64_user_configuration.h"
#include "ultramodern/renderer_context.hpp"
#include "librecomp/mods.hpp"
namespace RT64 {
struct Application;
}
namespace zelda64 {
namespace renderer {
inline const std::string special_option_texture_pack_enabled = "_recomp_texture_pack_enabled";
class RT64Context final : public ultramodern::renderer::RendererContext {
public:
~RT64Context() override;
RT64Context(uint8_t *rdram, ultramodern::renderer::WindowHandle window_handle, bool developer_mode);
bool valid() override { return static_cast<bool>(app); }
bool update_config(const ultramodern::renderer::GraphicsConfig &old_config, const ultramodern::renderer::GraphicsConfig &new_config) override;
void enable_instant_present() override;
void send_dl(const OSTask *task) override;
void update_screen() override;
void shutdown() override;
uint32_t get_display_framerate() const override;
float get_resolution_scale() const override;
private:
std::unique_ptr<RT64::Application> app;
std::unordered_set<std::string> enabled_texture_packs;
std::unordered_set<std::string> secondary_disabled_texture_packs;
void check_texture_pack_actions();
};
std::unique_ptr<ultramodern::renderer::RendererContext> create_render_context(uint8_t *rdram, ultramodern::renderer::WindowHandle window_handle, bool developer_mode);
RT64::UserConfiguration::Antialiasing RT64MaxMSAA();
bool RT64SamplePositionsSupported();
bool RT64HighPrecisionFBEnabled();
void trigger_texture_pack_update();
void enable_texture_pack(const recomp::mods::ModContext& context, const recomp::mods::ModHandle& mod);
void disable_texture_pack(const recomp::mods::ModHandle& mod);
void secondary_enable_texture_pack(const std::string& mod_id);
void secondary_disable_texture_pack(const std::string& mod_id);
// Texture pack enable option. Must be an enum with two options.
// The first option is treated as disabled and the second option is treated as enabled.
bool is_texture_pack_enable_config_option(const recomp::mods::ConfigOption& option, bool show_errors);
}
}
#endif
+18
View File
@@ -0,0 +1,18 @@
#ifndef __ZELDA_SOUND_H__
#define __ZELDA_SOUND_H__
namespace zelda64 {
void reset_sound_settings();
void set_main_volume(int volume);
int get_main_volume();
void set_bgm_volume(int volume);
void set_sfx_volume(int volume);
void set_env_volume(int volume);
int get_bgm_volume();
int get_sfx_volume();
int get_env_volume();
void set_low_health_beeps_enabled(bool enabled);
bool get_low_health_beeps_enabled();
}
#endif
+26
View File
@@ -0,0 +1,26 @@
#ifndef __ZELDA_SUPPORT_H__
#define __ZELDA_SUPPORT_H__
#include <functional>
#include <filesystem>
#include <vector>
#include <optional>
#include <list>
namespace zelda64 {
std::filesystem::path get_program_path();
std::filesystem::path get_asset_path(const char* asset);
void open_file_dialog(std::function<void(bool success, const std::filesystem::path& path)> callback);
void open_file_dialog_multiple(std::function<void(bool success, const std::list<std::filesystem::path>& paths)> callback);
void show_error_message_box(const char *title, const char *message);
// Apple specific methods that usually require Objective-C. Implemented in support_apple.mm.
#ifdef __APPLE__
void dispatch_on_ui_thread(std::function<void()> func);
std::optional<std::filesystem::path> get_application_support_directory();
std::filesystem::path get_bundle_resource_directory();
std::filesystem::path get_bundle_directory();
#endif
}
#endif