mirror of
https://github.com/Zelda64Recomp/Zelda64Recomp
synced 2026-06-05 11:19:10 -04:00
3c34fa63c1
* Added analog cam and camera inversion options to menu, initial implementation of analog cam * Automatically suppress inputs on the right stick while analog cam is active * Return to automatic camera mode when pressing target * Add aiming inversion options * Add analog camera inversion options
169 lines
5.6 KiB
C++
169 lines
5.6 KiB
C++
#include <cmath>
|
|
|
|
#include "recomp.h"
|
|
#include "recomp_overlays.h"
|
|
#include "recomp_config.h"
|
|
#include "recomp_input.h"
|
|
#include "recomp_ui.h"
|
|
#include "recomp_sound.h"
|
|
#include "recomp_helpers.h"
|
|
#include "rt64_layer.h"
|
|
#include "../patches/input.h"
|
|
#include "../patches/graphics.h"
|
|
#include "../patches/sound.h"
|
|
#include "../ultramodern/ultramodern.hpp"
|
|
#include "../ultramodern/config.hpp"
|
|
|
|
extern "C" void recomp_update_inputs(uint8_t* rdram, recomp_context* ctx) {
|
|
recomp::poll_inputs();
|
|
}
|
|
|
|
extern "C" void recomp_puts(uint8_t* rdram, recomp_context* ctx) {
|
|
PTR(char) cur_str = _arg<0, PTR(char)>(rdram, ctx);
|
|
u32 length = _arg<1, u32>(rdram, ctx);
|
|
|
|
for (u32 i = 0; i < length; i++) {
|
|
fputc(MEM_B(i, (gpr)cur_str), stdout);
|
|
}
|
|
}
|
|
|
|
extern "C" void recomp_exit(uint8_t* rdram, recomp_context* ctx) {
|
|
ultramodern::quit();
|
|
}
|
|
|
|
extern "C" void recomp_get_gyro_deltas(uint8_t* rdram, recomp_context* ctx) {
|
|
float* x_out = _arg<0, float*>(rdram, ctx);
|
|
float* y_out = _arg<1, float*>(rdram, ctx);
|
|
|
|
recomp::get_gyro_deltas(x_out, y_out);
|
|
}
|
|
|
|
extern "C" void recomp_get_mouse_deltas(uint8_t* rdram, recomp_context* ctx) {
|
|
float* x_out = _arg<0, float*>(rdram, ctx);
|
|
float* y_out = _arg<1, float*>(rdram, ctx);
|
|
|
|
recomp::get_mouse_deltas(x_out, y_out);
|
|
}
|
|
|
|
extern "C" void recomp_powf(uint8_t* rdram, recomp_context* ctx) {
|
|
float a = _arg<0, float>(rdram, ctx);
|
|
float b = ctx->f14.fl; //_arg<1, float>(rdram, ctx);
|
|
|
|
_return(ctx, std::pow(a, b));
|
|
}
|
|
|
|
extern "C" void recomp_get_target_framerate(uint8_t* rdram, recomp_context* ctx) {
|
|
int frame_divisor = _arg<0, u32>(rdram, ctx);
|
|
|
|
_return(ctx, ultramodern::get_target_framerate(60 / frame_divisor));
|
|
}
|
|
|
|
extern "C" void recomp_get_aspect_ratio(uint8_t* rdram, recomp_context* ctx) {
|
|
ultramodern::GraphicsConfig graphics_config = ultramodern::get_graphics_config();
|
|
float original = _arg<0, float>(rdram, ctx);
|
|
int width, height;
|
|
recomp::get_window_size(width, height);
|
|
|
|
switch (graphics_config.ar_option) {
|
|
case RT64::UserConfiguration::AspectRatio::Original:
|
|
default:
|
|
_return(ctx, original);
|
|
return;
|
|
case RT64::UserConfiguration::AspectRatio::Expand:
|
|
_return(ctx, std::max(static_cast<float>(width) / height, original));
|
|
return;
|
|
}
|
|
}
|
|
|
|
extern "C" void recomp_get_targeting_mode(uint8_t* rdram, recomp_context* ctx) {
|
|
_return(ctx, static_cast<int>(recomp::get_targeting_mode()));
|
|
}
|
|
|
|
extern "C" void recomp_get_bgm_volume(uint8_t* rdram, recomp_context* ctx) {
|
|
_return(ctx, recomp::get_bgm_volume() / 100.0f);
|
|
}
|
|
|
|
extern "C" void recomp_get_low_health_beeps_enabled(uint8_t* rdram, recomp_context* ctx) {
|
|
_return(ctx, static_cast<u32>(recomp::get_low_health_beeps_enabled()));
|
|
}
|
|
|
|
extern "C" void recomp_time_us(uint8_t* rdram, recomp_context* ctx) {
|
|
_return(ctx, static_cast<u32>(std::chrono::duration_cast<std::chrono::microseconds>(ultramodern::time_since_start()).count()));
|
|
}
|
|
|
|
extern "C" void recomp_autosave_enabled(uint8_t* rdram, recomp_context* ctx) {
|
|
_return(ctx, static_cast<s32>(recomp::get_autosave_mode() == recomp::AutosaveMode::On));
|
|
}
|
|
|
|
extern "C" void recomp_load_overlays(uint8_t * rdram, recomp_context * ctx) {
|
|
u32 rom = _arg<0, u32>(rdram, ctx);
|
|
PTR(void) ram = _arg<1, PTR(void)>(rdram, ctx);
|
|
u32 size = _arg<2, u32>(rdram, ctx);
|
|
|
|
load_overlays(rom, ram, size);
|
|
}
|
|
|
|
extern "C" void recomp_high_precision_fb_enabled(uint8_t * rdram, recomp_context * ctx) {
|
|
_return(ctx, static_cast<s32>(ultramodern::RT64HighPrecisionFBEnabled()));
|
|
}
|
|
|
|
extern "C" void recomp_get_resolution_scale(uint8_t* rdram, recomp_context* ctx) {
|
|
_return(ctx, ultramodern::get_resolution_scale());
|
|
}
|
|
|
|
extern "C" void recomp_get_inverted_axes(uint8_t* rdram, recomp_context* ctx) {
|
|
s32* x_out = _arg<0, s32*>(rdram, ctx);
|
|
s32* y_out = _arg<1, s32*>(rdram, ctx);
|
|
|
|
recomp::CameraInvertMode mode = recomp::get_camera_invert_mode();
|
|
|
|
*x_out = (mode == recomp::CameraInvertMode::InvertX || mode == recomp::CameraInvertMode::InvertBoth);
|
|
*y_out = (mode == recomp::CameraInvertMode::InvertY || mode == recomp::CameraInvertMode::InvertBoth);
|
|
}
|
|
|
|
extern "C" void recomp_get_analog_inverted_axes(uint8_t* rdram, recomp_context* ctx) {
|
|
s32* x_out = _arg<0, s32*>(rdram, ctx);
|
|
s32* y_out = _arg<1, s32*>(rdram, ctx);
|
|
|
|
recomp::CameraInvertMode mode = recomp::get_analog_camera_invert_mode();
|
|
|
|
*x_out = (mode == recomp::CameraInvertMode::InvertX || mode == recomp::CameraInvertMode::InvertBoth);
|
|
*y_out = (mode == recomp::CameraInvertMode::InvertY || mode == recomp::CameraInvertMode::InvertBoth);
|
|
}
|
|
|
|
extern "C" void recomp_analog_cam_enabled(uint8_t* rdram, recomp_context* ctx) {
|
|
_return<s32>(ctx, recomp::get_analog_cam_mode() == recomp::AnalogCamMode::On);
|
|
}
|
|
|
|
extern "C" void recomp_get_camera_inputs(uint8_t* rdram, recomp_context* ctx) {
|
|
float* x_out = _arg<0, float*>(rdram, ctx);
|
|
float* y_out = _arg<1, float*>(rdram, ctx);
|
|
|
|
// TODO expose this in the menu
|
|
constexpr float radial_deadzone = 0.05f;
|
|
|
|
float x, y;
|
|
|
|
recomp::get_right_analog(&x, &y);
|
|
|
|
float magnitude = sqrtf(x * x + y * y);
|
|
|
|
if (magnitude < radial_deadzone) {
|
|
*x_out = 0.0f;
|
|
*y_out = 0.0f;
|
|
}
|
|
else {
|
|
float x_normalized = x / magnitude;
|
|
float y_normalized = y / magnitude;
|
|
|
|
*x_out = x_normalized * ((magnitude - radial_deadzone) / (1 - radial_deadzone));
|
|
*y_out = y_normalized * ((magnitude - radial_deadzone) / (1 - radial_deadzone));
|
|
}
|
|
}
|
|
|
|
extern "C" void recomp_set_right_analog_suppressed(uint8_t* rdram, recomp_context* ctx) {
|
|
s32 suppressed = _arg<0, s32>(rdram, ctx);
|
|
|
|
recomp::set_right_analog_suppressed(suppressed);
|
|
}
|