mirror of
https://github.com/coop-deluxe/sm64coopdx.git
synced 2026-04-22 10:01:46 +00:00
Bettercam refactor and cleanup (#788)
- `bettercamera` code refactoring, less spaghetti, more consistency - removed unused parts and added comments to the most obscure ones
This commit is contained in:
parent
0d4fd39a00
commit
966d7fc290
8 changed files with 498 additions and 741 deletions
|
|
@ -1,44 +1,51 @@
|
|||
enum newcam_flagvalues
|
||||
{
|
||||
NC_FLAG_XTURN = 0x0001,//If this flag is set, the camera's yaw can be moved by the player.
|
||||
NC_FLAG_YTURN = 0x0002, //If this flag is set, the camera's pitch can be moved by the player.
|
||||
NC_FLAG_ZOOM = 0x0004, //If this flag is set, the camera's distance can be set by the player.
|
||||
NC_FLAG_8D = 0x0008, //If this flag is set, the camera will snap to an 8 directional axis
|
||||
NC_FLAG_4D = 0x0010, //If this flag is set, the camera will snap to a 4 directional axis
|
||||
NC_FLAG_2D = 0x0020, //If this flag is set, the camera will stick to 2D.
|
||||
NC_FLAG_FOCUSX = 0x0040, //If this flag is set, the camera will point towards its focus on the X axis.
|
||||
NC_FLAG_FOCUSY = 0x0080, //If this flag is set, the camera will point towards its focus on the Y axis.
|
||||
NC_FLAG_FOCUSZ = 0x0100, //If this flag is set, the camera will point towards its focus on the Z axis.
|
||||
NC_FLAG_POSX = 0x0200, //If this flag is set, the camera will move along the X axis.
|
||||
NC_FLAG_POSY = 0x0400, //If this flag is set, the camera will move along the Y axis.
|
||||
NC_FLAG_POSZ = 0x0800, //If this flag is set, the camera will move along the Z axis.
|
||||
NC_FLAG_COLLISION = 0x1000, //If this flag is set, the camera will collide and correct itself with terrain.
|
||||
NC_FLAG_SLIDECORRECT = 0x2000, //If this flag is set, the camera will attempt to centre itself behind Mario whenever he's sliding.
|
||||
#ifndef BETTERCAMERA_H
|
||||
#define BETTERCAMERA_H
|
||||
|
||||
NC_MODE_NORMAL = NC_FLAG_XTURN | NC_FLAG_YTURN | NC_FLAG_ZOOM | NC_FLAG_FOCUSX | NC_FLAG_FOCUSY | NC_FLAG_FOCUSZ | NC_FLAG_POSX | NC_FLAG_POSY | NC_FLAG_POSZ | NC_FLAG_COLLISION,
|
||||
NC_MODE_SLIDE = NC_FLAG_XTURN | NC_FLAG_YTURN | NC_FLAG_ZOOM | NC_FLAG_FOCUSX | NC_FLAG_FOCUSY | NC_FLAG_FOCUSZ | NC_FLAG_POSX | NC_FLAG_POSY | NC_FLAG_POSZ | NC_FLAG_COLLISION | NC_FLAG_SLIDECORRECT,
|
||||
NC_MODE_FIXED = NC_FLAG_XTURN | NC_FLAG_YTURN | NC_FLAG_ZOOM | NC_FLAG_FOCUSX | NC_FLAG_FOCUSY | NC_FLAG_FOCUSZ,
|
||||
NC_MODE_2D = NC_FLAG_XTURN | NC_FLAG_YTURN | NC_FLAG_ZOOM | NC_FLAG_FOCUSX | NC_FLAG_FOCUSY | NC_FLAG_FOCUSZ | NC_FLAG_POSX | NC_FLAG_POSY | NC_FLAG_POSZ | NC_FLAG_COLLISION,
|
||||
NC_MODE_8D = NC_FLAG_XTURN | NC_FLAG_YTURN | NC_FLAG_ZOOM | NC_FLAG_8D | NC_FLAG_FOCUSX | NC_FLAG_FOCUSY | NC_FLAG_FOCUSZ | NC_FLAG_POSX | NC_FLAG_POSY | NC_FLAG_POSZ | NC_FLAG_COLLISION,
|
||||
NC_MODE_FIXED_NOMOVE = 0x0000,
|
||||
NC_MODE_NOTURN = NC_FLAG_ZOOM | NC_FLAG_FOCUSX | NC_FLAG_FOCUSY | NC_FLAG_FOCUSZ | NC_FLAG_POSX | NC_FLAG_POSY | NC_FLAG_POSZ | NC_FLAG_COLLISION,
|
||||
NC_MODE_NOROTATE = NC_FLAG_YTURN | NC_FLAG_ZOOM | NC_FLAG_FOCUSX | NC_FLAG_FOCUSY | NC_FLAG_FOCUSZ | NC_FLAG_POSX | NC_FLAG_POSY | NC_FLAG_POSZ | NC_FLAG_COLLISION
|
||||
#include "types.h"
|
||||
|
||||
};
|
||||
typedef struct {
|
||||
|
||||
extern void newcam_init_settings(void);
|
||||
extern void newcam_init_settings_override(bool override);
|
||||
extern void newcam_diagnostics(void);
|
||||
// Status
|
||||
bool isActive; // basically the thing that governs if newcam is on.
|
||||
bool isSlide;
|
||||
Vec3f pos; // Position the camera is in the world
|
||||
Vec3f posTarget; // The position the camera is basing calculations off. *Usually* Mario.
|
||||
Vec3f lookAt; // Position the camera is looking at
|
||||
f32 distance; // The distance the camera stays from the player
|
||||
s32 distanceTargetIndex;
|
||||
s16 yaw; // Z axis rotation
|
||||
s16 yawTarget; // The yaw value the camera tries to set itself to when the centre flag is active. Is set to Mario's face angle.
|
||||
f32 yawAccel;
|
||||
s16 tilt; // Y axis rotation
|
||||
f32 tiltAccel;
|
||||
f32 panX;
|
||||
f32 panZ;
|
||||
s32 framesSinceCButtons[2];
|
||||
bool centering; // The flag that depicts wether the camera's going to try centering.
|
||||
bool directionLocked;
|
||||
s32 turnWait; // The amount of time to wait after landing before allowing the camera to turn again
|
||||
s16 extStick[2];
|
||||
u8 savedMode;
|
||||
u8 savedDefMode;
|
||||
|
||||
extern s16 newcam_sensitivityX; //How quick the camera works.
|
||||
extern s16 newcam_sensitivityY;
|
||||
extern s16 newcam_invertX;
|
||||
extern s16 newcam_invertY;
|
||||
extern s16 newcam_panlevel; //How much the camera sticks out a bit in the direction you're looking.
|
||||
extern s16 newcam_aggression; //How much the camera tries to centre itself to Mario's facing and movement.
|
||||
extern u8 newcam_active; // basically the thing that governs if newcam is on.
|
||||
extern s16 newcam_analogue;
|
||||
extern u16 newcam_intendedmode;
|
||||
// Settings
|
||||
s16 sensitivityX; // How quick the camera works.
|
||||
s16 sensitivityY;
|
||||
s16 panLevel; // How much the camera sticks out a bit in the direction you're looking.
|
||||
s16 aggression; // How much the camera tries to centre itself to Mario's facing and movement.
|
||||
f32 deceleration;
|
||||
bool invertX; // Reverses movement of the camera axis.
|
||||
bool invertY;
|
||||
bool isMouse;
|
||||
bool isAnalogue; // Weither to accept inputs from a player 2 joystick, and then disables C button input.
|
||||
bool useDPad;
|
||||
bool hasCollision;
|
||||
bool LCentering;
|
||||
|
||||
extern u16 newcam_mode;
|
||||
extern s16 newcam_yaw;
|
||||
} NewCamera;
|
||||
|
||||
extern NewCamera gNewCamera;
|
||||
|
||||
void newcam_init_settings(void);
|
||||
|
||||
#endif // BETTERCAMERA_H
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -3235,7 +3235,7 @@ void update_camera(struct Camera *c) {
|
|||
sCButtonsPressed = find_c_buttons_pressed(sCButtonsPressed, gPlayer1Controller->buttonPressed,gPlayer1Controller->buttonDown);
|
||||
}
|
||||
|
||||
if (gMarioStates[0].action == ACT_SHOT_FROM_CANNON && newcam_active) {
|
||||
if (gMarioStates[0].action == ACT_SHOT_FROM_CANNON && gNewCamera.isActive) {
|
||||
gMarioStates[0].area->camera->mode = CAMERA_MODE_NEWCAM;
|
||||
gLakituState.mode = CAMERA_MODE_NEWCAM;
|
||||
}
|
||||
|
|
@ -5794,7 +5794,7 @@ void set_camera_mode_8_directions(struct Camera *c) {
|
|||
s8DirModeYawOffset = 0;
|
||||
}
|
||||
|
||||
if (newcam_active == 1) {
|
||||
if (gNewCamera.isActive) {
|
||||
c->mode = CAMERA_MODE_NEWCAM;
|
||||
}
|
||||
}
|
||||
|
|
@ -5818,7 +5818,7 @@ void set_camera_mode_close_cam(u8 *mode) {
|
|||
*mode = CAMERA_MODE_CLOSE;
|
||||
}
|
||||
|
||||
if (newcam_active == 1) {
|
||||
if (gNewCamera.isActive) {
|
||||
*mode = CAMERA_MODE_NEWCAM;
|
||||
}
|
||||
}
|
||||
|
|
@ -5847,7 +5847,7 @@ void set_camera_mode_radial(struct Camera *c, s16 transitionTime) {
|
|||
sModeOffsetYaw = 0;
|
||||
}
|
||||
|
||||
if (newcam_active == 1) {
|
||||
if (gNewCamera.isActive) {
|
||||
c->mode = CAMERA_MODE_NEWCAM;
|
||||
}
|
||||
}
|
||||
|
|
@ -7306,7 +7306,7 @@ void update_camera_yaw(struct Camera *c) {
|
|||
if (!c) { return; }
|
||||
c->nextYaw = calculate_yaw(c->focus, c->pos);
|
||||
c->yaw = c->nextYaw;
|
||||
newcam_apply_outside_values(c,0);
|
||||
newcam_update_camera_yaw(c, false);
|
||||
}
|
||||
|
||||
void cutscene_reset_spline(void) {
|
||||
|
|
@ -10485,7 +10485,7 @@ BAD_RETURN(s32) cutscene_sliding_doors_follow_mario(struct Camera *c) {
|
|||
BAD_RETURN(s32) cutscene_sliding_doors_open(struct Camera *c) {
|
||||
UNUSED u32 pad[2];
|
||||
|
||||
newcam_apply_outside_values(c,1);
|
||||
newcam_update_camera_yaw(c, true);
|
||||
reset_pan_distance(c);
|
||||
cutscene_event(cutscene_sliding_doors_open_start, c, 0, 8);
|
||||
cutscene_event(cutscene_sliding_doors_open_set_cvars, c, 8, 8);
|
||||
|
|
@ -10698,7 +10698,7 @@ BAD_RETURN(s32) cutscene_unused_exit_focus_mario(struct Camera *c) {
|
|||
*/
|
||||
BAD_RETURN(s32) cutscene_exit_painting_end(struct Camera *c) {
|
||||
if (!c) { return; }
|
||||
if (newcam_active == 1) {
|
||||
if (gNewCamera.isActive) {
|
||||
c->mode = CAMERA_MODE_NEWCAM;
|
||||
} else {
|
||||
c->mode = CAMERA_MODE_CLOSE;
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@
|
|||
#include "save_file.h"
|
||||
#include "print.h"
|
||||
#include "hardcoded.h"
|
||||
#include "bettercamera.h"
|
||||
#include "pc/configfile.h"
|
||||
#include "pc/network/network.h"
|
||||
#include "pc/utils/misc.h"
|
||||
|
|
@ -563,18 +564,11 @@ void render_hud_camera_status(void) {
|
|||
}
|
||||
|
||||
if (gLakituState.mode == CAMERA_MODE_NEWCAM) {
|
||||
extern u8 newcam_direction_locked;
|
||||
extern u8 newcam_distance_index;
|
||||
sCameraHUD.status = newcam_direction_locked ? CAM_STATUS_FIXED : CAM_STATUS_LAKITU;
|
||||
switch (newcam_distance_index) {
|
||||
case 0:
|
||||
sCameraHUD.status |= CAM_STATUS_C_UP;
|
||||
break;
|
||||
case 1:
|
||||
break;
|
||||
case 2:
|
||||
sCameraHUD.status |= CAM_STATUS_C_DOWN;
|
||||
break;
|
||||
sCameraHUD.status = gNewCamera.directionLocked ? CAM_STATUS_FIXED : CAM_STATUS_LAKITU;
|
||||
switch (gNewCamera.distanceTargetIndex) {
|
||||
case 0: sCameraHUD.status |= CAM_STATUS_C_UP; break;
|
||||
case 1: break;
|
||||
case 2: sCameraHUD.status |= CAM_STATUS_C_DOWN; break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1498,7 +1498,7 @@ void update_mario_joystick_inputs(struct MarioState *m) {
|
|||
} else if (get_first_person_enabled()) {
|
||||
m->intendedYaw = atan2s(-controller->stickY, controller->stickX) + gLakituState.yaw;
|
||||
} else {
|
||||
m->intendedYaw = atan2s(-controller->stickY, controller->stickX) - newcam_yaw + 0x4000;
|
||||
m->intendedYaw = atan2s(-controller->stickY, controller->stickX) - gNewCamera.yaw + 0x4000;
|
||||
}
|
||||
m->input |= INPUT_NONZERO_ANALOG;
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -1869,7 +1869,7 @@ s32 act_shot_from_cannon(struct MarioState *m) {
|
|||
set_mario_action(m, ACT_DIVE_SLIDE, 0);
|
||||
m->faceAngle[0] = 0;
|
||||
if (allowCameraChange) {
|
||||
if (newcam_active == 0) {
|
||||
if (!gNewCamera.isActive) {
|
||||
set_camera_mode(m->area->camera, m->area->camera->defMode, 1);
|
||||
} else {
|
||||
m->area->camera->mode = CAMERA_MODE_NEWCAM;
|
||||
|
|
@ -1890,7 +1890,7 @@ s32 act_shot_from_cannon(struct MarioState *m) {
|
|||
set_mario_particle_flags(m, PARTICLE_VERTICAL_STAR, FALSE);
|
||||
set_mario_action(m, ACT_BACKWARD_AIR_KB, 0);
|
||||
if (allowCameraChange) {
|
||||
if (newcam_active == 0) {
|
||||
if (!gNewCamera.isActive) {
|
||||
set_camera_mode(m->area->camera, m->area->camera->defMode, 1);
|
||||
} else {
|
||||
m->area->camera->mode = CAMERA_MODE_NEWCAM;
|
||||
|
|
@ -1927,7 +1927,7 @@ s32 act_flying(struct MarioState *m) {
|
|||
if (m->input & INPUT_Z_PRESSED) {
|
||||
if (m->area->camera->mode == CAMERA_MODE_BEHIND_MARIO) {
|
||||
if (m->playerIndex == 0) {
|
||||
if (newcam_active == 0) {
|
||||
if (!gNewCamera.isActive) {
|
||||
set_camera_mode(m->area->camera, m->area->camera->defMode, 1);
|
||||
} else {
|
||||
m->area->camera->mode = CAMERA_MODE_NEWCAM;
|
||||
|
|
@ -1941,7 +1941,7 @@ s32 act_flying(struct MarioState *m) {
|
|||
if (!(m->flags & MARIO_WING_CAP)) {
|
||||
if (m->area->camera->mode == CAMERA_MODE_BEHIND_MARIO) {
|
||||
if (m->playerIndex == 0) {
|
||||
if (newcam_active == 0) {
|
||||
if (!gNewCamera.isActive) {
|
||||
set_camera_mode(m->area->camera, m->area->camera->defMode, 1);
|
||||
} else {
|
||||
m->area->camera->mode = CAMERA_MODE_NEWCAM;
|
||||
|
|
@ -1954,7 +1954,7 @@ s32 act_flying(struct MarioState *m) {
|
|||
|
||||
if (m->area->camera->mode != CAMERA_MODE_BEHIND_MARIO) {
|
||||
if (m->playerIndex == 0) {
|
||||
if (newcam_active == 0) {
|
||||
if (!gNewCamera.isActive) {
|
||||
set_camera_mode(m->area->camera, CAMERA_MODE_BEHIND_MARIO, 1);
|
||||
// note: EX sets it to the following line instead, but I have
|
||||
// no idea why... possibly copy/paste error?
|
||||
|
|
@ -2007,7 +2007,7 @@ s32 act_flying(struct MarioState *m) {
|
|||
m->faceAngle[0] = 0;
|
||||
|
||||
if (m->playerIndex == 0) {
|
||||
if (newcam_active == 0) {
|
||||
if (!gNewCamera.isActive) {
|
||||
set_camera_mode(m->area->camera, m->area->camera->defMode, 1);
|
||||
} else {
|
||||
m->area->camera->mode = CAMERA_MODE_NEWCAM;
|
||||
|
|
@ -2034,7 +2034,7 @@ s32 act_flying(struct MarioState *m) {
|
|||
set_mario_action(m, ACT_BACKWARD_AIR_KB, 0);
|
||||
|
||||
if (m->playerIndex == 0) {
|
||||
if (newcam_active == 0) {
|
||||
if (!gNewCamera.isActive) {
|
||||
set_camera_mode(m->area->camera, m->area->camera->defMode, 1);
|
||||
} else {
|
||||
m->area->camera->mode = CAMERA_MODE_NEWCAM;
|
||||
|
|
@ -2126,7 +2126,7 @@ s32 act_flying_triple_jump(struct MarioState *m) {
|
|||
#ifndef VERSION_JP
|
||||
if (m->input & (INPUT_B_PRESSED | INPUT_Z_PRESSED)) {
|
||||
if (m->playerIndex == 0 && m->area->camera->mode == CAMERA_MODE_BEHIND_MARIO) {
|
||||
if (newcam_active == 0) {
|
||||
if (!gNewCamera.isActive) {
|
||||
set_camera_mode(m->area->camera, m->area->camera->defMode, 1);
|
||||
} else {
|
||||
m->area->camera->mode = CAMERA_MODE_NEWCAM;
|
||||
|
|
@ -2170,7 +2170,7 @@ s32 act_flying_triple_jump(struct MarioState *m) {
|
|||
|
||||
if (m->vel[1] < 4.0f) {
|
||||
if (m->playerIndex == 0 && m->area->camera->mode != CAMERA_MODE_BEHIND_MARIO) {
|
||||
if (newcam_active == 0) {
|
||||
if (!gNewCamera.isActive) {
|
||||
set_camera_mode(m->area->camera, m->area->camera->defMode, 1);
|
||||
} else {
|
||||
m->area->camera->mode = CAMERA_MODE_NEWCAM;
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@
|
|||
#include "../fs/fs.h"
|
||||
|
||||
#include "game/level_update.h"
|
||||
#include "game/bettercamera.h"
|
||||
|
||||
#include "pc/djui/djui.h"
|
||||
|
||||
|
|
@ -42,8 +43,6 @@ enum {
|
|||
MAX_AXES,
|
||||
};
|
||||
|
||||
extern u8 newcam_mouse;
|
||||
|
||||
static bool init_ok;
|
||||
static SDL_Joystick *sdl_joy;
|
||||
|
||||
|
|
@ -125,7 +124,7 @@ static void controller_sdl_init(void) {
|
|||
joy_axis_binds[i] = -1;
|
||||
}
|
||||
|
||||
if (newcam_mouse == 1 && gMenuMode == -1 && !gDjuiChatBoxFocus && !gDjuiConsoleFocus) {
|
||||
if (gNewCamera.isMouse && gMenuMode == -1 && !gDjuiChatBoxFocus && !gDjuiConsoleFocus) {
|
||||
controller_mouse_enter_relative();
|
||||
}
|
||||
controller_mouse_read_relative();
|
||||
|
|
@ -153,7 +152,7 @@ extern s16 gMenuMode;
|
|||
static void controller_sdl_read(OSContPad *pad) {
|
||||
if (!init_ok) return;
|
||||
|
||||
if (newcam_mouse == 1 && gMenuMode == -1 && !gDjuiChatBoxFocus && !gDjuiConsoleFocus) {
|
||||
if (gNewCamera.isMouse && gMenuMode == -1 && !gDjuiChatBoxFocus && !gDjuiConsoleFocus) {
|
||||
controller_mouse_enter_relative();
|
||||
} else {
|
||||
controller_mouse_leave_relative();
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@
|
|||
|
||||
#include "game/level_update.h"
|
||||
#include "game/first_person_cam.h"
|
||||
#include "game/bettercamera.h"
|
||||
#include "pc/lua/utils/smlua_misc_utils.h"
|
||||
#include "pc/djui/djui.h"
|
||||
#include "pc/djui/djui_panel_pause.h"
|
||||
|
|
@ -33,8 +34,6 @@
|
|||
#define MAX_JOYBUTTONS 32 // arbitrary; includes virtual keys for triggers
|
||||
#define AXIS_THRESHOLD (30 * 256)
|
||||
|
||||
extern u8 newcam_mouse;
|
||||
|
||||
static bool init_ok = false;
|
||||
static bool haptics_enabled = false;
|
||||
static SDL_GameController *sdl_cntrl = NULL;
|
||||
|
|
@ -134,7 +133,7 @@ static void controller_sdl_init(void) {
|
|||
free(gcdata);
|
||||
}
|
||||
|
||||
if (newcam_mouse == 1) { controller_mouse_enter_relative(); }
|
||||
if (gNewCamera.isMouse) { controller_mouse_enter_relative(); }
|
||||
controller_mouse_read_relative();
|
||||
|
||||
controller_sdl_bind();
|
||||
|
|
@ -181,7 +180,7 @@ extern s16 gMenuMode;
|
|||
static void controller_sdl_read(OSContPad *pad) {
|
||||
if (!init_ok) { return; }
|
||||
|
||||
if ((newcam_mouse == 1 || get_first_person_enabled() || gDjuiHudLockMouse) && !is_game_paused() && !gDjuiPanelPauseCreated && !gDjuiInMainMenu && !gDjuiChatBoxFocus && !gDjuiConsoleFocus && WAPI.has_focus()) {
|
||||
if ((gNewCamera.isMouse || get_first_person_enabled() || gDjuiHudLockMouse) && !is_game_paused() && !gDjuiPanelPauseCreated && !gDjuiInMainMenu && !gDjuiChatBoxFocus && !gDjuiConsoleFocus && WAPI.has_focus()) {
|
||||
controller_mouse_enter_relative();
|
||||
} else {
|
||||
controller_mouse_leave_relative();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue