Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reonucam and camera collision defines #778

Open
wants to merge 22 commits into
base: develop/3.0.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ Thanks to Frame#5375 and AloXado320 for also helping with silhouette stuff
- Removed course-specific camera processing *
- Ability to set Mario's movement speed when hanging from a ceiling *
- Tighter hanging controls (Mario will face the direction of the analog stick directly while hanging from a ceiling) *
- reonucam3: custom camera by Reonu. This is included as a .patch file in the enhancements folder, you need to apply it if you want this camera.
This video shows a rundown of the features: https://youtu.be/TQNkznX9Z3k
- Reonucam: Custom camera by Reonu. Now included as a define in config_camera.h.
- Ability to disable Mario getting suck in snow or sand

**Hacker QOL:**
Expand Down
20 changes: 12 additions & 8 deletions include/config/config_camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,25 @@
#define FAST_VERTICAL_CAMERA_MOVEMENT

/**
* Enables "parallel lakitu camera" or "aglab cam" which lets you move the camera smoothly with the D-pad.
* Enables camera collision for 8 direction camera and, by extension, to Parallel Lakitu cam or Reonucam if enabled.
* If you enable it, please consider using surface types with the SURFACE_FLAG_NO_CAM_COLLISION flag for small obstacles,
* such as fences, pillars, signs, etc, in order to make your game more enjoyable and not let the camera get in the way of gameplay.
*/
#define PARALLEL_LAKITU_CAM
#define EIGHT_DIR_CAMERA_COLLISION

/**
* Enables Puppy Camera 2, a rewritten camera that can be freely configured and modified.
* Enables "parallel lakitu camera" or "aglab cam" which lets you move the camera smoothly with the D-pad. Will be disabled if Reonucam is enabled.
*/
// #define PUPPYCAM
#define PARALLEL_LAKITU_CAM

// Enables Reonucam, a custom camera that aims to be a more feature-rich "aglabcam" that doesn't use a single button more than the vanilla camera.
// An explanation the features can be seen here: https://www.youtube.com/watch?v=TQNkznX9Z3k (please note that the analog feature shown at the end is no longer present)
Comment on lines +54 to +55
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missed this last time, but this should use a block comment rather than line comments like the rest of the file.

//#define REONUCAM
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: // #define REONUCAM (the space)


/**
* Note: Reonucam is available, but because we had no time to test it properly, it's included as a patch rather than being in the code by default.
* Run this command to apply the patch if you want to use it:
* tools/apply_patch.sh enhancements/reonucam.patch
* Consider it a beta, but it should work fine. Please report any bugs with it. Applying the patch will simply add a define here, so you can still turn it off even after patching.
* Enables Puppy Camera 2, a rewritten camera that can be freely configured and modified.
*/
//#define PUPPYCAM
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably should have been a bit more clear; the commented defines in the other files do use a space here. Space is also better because it's consistent with VSCode's commenting shortcut (Ctrl + /).


/**********************************/
/***** Vanilla config options *****/
Expand Down
21 changes: 21 additions & 0 deletions include/config/config_safeguards.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,27 @@
#define FLYING_CAMERA_MODE CAMERA_MODE_BEHIND_MARIO
#endif // !FLYING_CAMERA_MODE

// Reonucam overrides
#ifdef REONUCAM
// Use course default mode
#ifndef USE_COURSE_DEFAULT_MODE
#define USE_COURSE_DEFAULT_MODE
#endif
Comment on lines +145 to +147
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: #undef here instead


// Force camera mode to 8 Dir
#ifdef FORCED_CAMERA_MODE
#undef FORCED_CAMERA_MODE
#endif
#define FORCED_CAMERA_MODE CAMERA_MODE_8_DIRECTIONS

// Disable vanilla cam processing
#undef ENABLE_VANILLA_CAM_PROCESSING

// Disable aglab cam
#undef PARALLEL_LAKITU_CAM
#endif



/*****************
* config_game.h
Expand Down
166 changes: 164 additions & 2 deletions src/game/camera.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@
*
*/

#ifdef REONUCAM
struct ReonucamState gReonucamState = { 2, FALSE, FALSE, FALSE, 0, 0, };
#endif

// BSS
/**
* Stores Lakitu's position from the last frame, used for transitioning in next_lakitu_state()
Expand Down Expand Up @@ -875,6 +879,25 @@ s32 update_8_directions_camera(struct Camera *c, Vec3f focus, Vec3f pos) {
f32 yOff = 125.f;
f32 baseDist = 1000.f;

#ifdef REONUCAM
if (gMarioState->action & ACT_FLAG_SWIMMING) {
yOff = -125.f;
} else if (gMarioState->action & ACT_FLAG_SWIMMING_OR_FLYING) {
yOff = 325.f;
} else {
yOff = 125.f;
}

if ((gPlayer1Controller->buttonDown & R_TRIG) && (gPlayer1Controller->buttonDown & U_CBUTTONS)) {
gReonucamState.keepCliffCam = 1;
pitch = DEGREES(60);
} else if (((gPlayer1Controller->buttonDown & U_CBUTTONS) || (gPlayer1Controller->buttonDown & R_TRIG)) && gReonucamState.keepCliffCam) {
pitch = DEGREES(60);
} else {
gReonucamState.keepCliffCam = 0;
}
#endif

sAreaYaw = camYaw;
calc_y_to_curr_floor(&posY, 1.f, 200.f, &focusY, 0.9f, 200.f);
focus_on_mario(focus, pos, posY + yOff, focusY + yOff, sLakituDist + baseDist, pitch, camYaw);
Expand Down Expand Up @@ -1116,13 +1139,117 @@ s32 snap_to_45_degrees(s16 angle) {
return angle;
}

#ifdef EIGHT_DIR_CAMERA_COLLISION

#define MIN_CAMERA_DISTANCE 300.0f // Minimum distance between Mario and the camera.
#define VERTICAL_RAY_OFFSET 300.0f // The ray is cast from 300 units above Mario in order to prevent small obstacles from constantly snapping the camera

void eight_dir_collision_handler(struct Camera *c) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would like some lines of spacing between parts of the code in this function and the below function, its a little hard to read

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mark it as resolved if you think it's ok now

struct Surface *surf;

Vec3f camdir;
Vec3f origin;
Vec3f thick;
Vec3f hitpos;

vec3f_copy(origin,gMarioState->pos);

origin[1] += VERTICAL_RAY_OFFSET;
camdir[0] = c->pos[0] - origin[0];
camdir[1] = c->pos[1] - origin[1];
camdir[2] = c->pos[2] - origin[2];

find_surface_on_ray(origin, camdir, &surf, hitpos, (RAYCAST_FIND_FLOOR | RAYCAST_FIND_WALL | RAYCAST_FIND_CEIL));

if (surf) {
f32 distFromSurf = 100.0f;
f32 dist;
f32 yDist = 0;
Vec3f camToMario;
vec3f_diff(camToMario, gMarioState->pos, hitpos);
s16 yaw = atan2s(camToMario[2], camToMario[0]);
vec3f_get_lateral_dist(hitpos,gMarioState->pos, &dist);
if (dist < MIN_CAMERA_DISTANCE) {
distFromSurf += (dist - MIN_CAMERA_DISTANCE); // If Mario runs right up to the screen, the camera pull back slightly...
yDist = MIN_CAMERA_DISTANCE - CLAMP(dist, 0, MIN_CAMERA_DISTANCE); // ...and also up slightly.
}
thick[0] = sins(yaw) * distFromSurf;
thick[1] = yDist;
thick[2] = coss(yaw) * distFromSurf;
vec3f_add(hitpos,thick);
vec3f_copy(c->pos,hitpos);
}

c->yaw = atan2s(c->pos[2] - gMarioState->pos[2], c->pos[0] - gMarioState->pos[0]);

}
#endif

#ifdef REONUCAM
f32 cameraSpeeds[] = {0.5f, 1.f, 1.5f, 2.f, 3.5f}; // The camera speed settings, from slowest to fastest.
#define R_DOUBLE_TAP_WINDOW 5 // How many frames the player has to double tap R in order to ender Mario cam mode.

void reonucam_handler(void) {
// Get the camera speed based on the user's setting
f32 cameraSpeed = cameraSpeeds[gReonucamState.speed];

//45º rotations
if ((gPlayer1Controller->buttonPressed & L_CBUTTONS) && !(gPlayer1Controller->buttonDown & R_TRIG)) {
s8DirModeBaseYaw = snap_to_45_degrees(s8DirModeBaseYaw - DEGREES(45));
} else if ((gPlayer1Controller->buttonPressed & R_CBUTTONS) && !(gPlayer1Controller->buttonDown & R_TRIG)) {
s8DirModeBaseYaw = snap_to_45_degrees(s8DirModeBaseYaw + DEGREES(45));
}

//Smooth rotation
if (gPlayer1Controller->buttonDown & R_TRIG) {
if (gPlayer1Controller->buttonDown & L_CBUTTONS) {
s8DirModeBaseYaw -= DEGREES(cameraSpeed);
} else if (gPlayer1Controller->buttonDown & R_CBUTTONS) {
s8DirModeBaseYaw += DEGREES(cameraSpeed);
}
if (gReonucamState.rButtonCounter++ > 100) { // This increses whenever R is held.
gReonucamState.rButtonCounter = 100;
}
} else {
if (gReonucamState.rButtonCounter > 0 && gReonucamState.rButtonCounter <= R_DOUBLE_TAP_WINDOW && !((gPlayer1Controller->buttonDown & L_CBUTTONS) || (gPlayer1Controller->buttonDown & R_CBUTTONS) || (gMarioState->action & ACT_FLAG_SWIMMING_OR_FLYING))) {
// This centers the camera behind mario. It triggers when you let go of R in less than 5 frames.
s8DirModeYawOffset = 0;
s8DirModeBaseYaw = gMarioState->faceAngle[1]-0x8000;
gMarioState->area->camera->yaw = s8DirModeBaseYaw;
play_sound_rbutton_changed();
}
gReonucamState.rButtonCounter = 0;
}

if (gPlayer1Controller->buttonPressed & R_TRIG) {
if (gReonucamState.rButtonCounter2 <= R_DOUBLE_TAP_WINDOW) {
set_cam_angle(CAM_ANGLE_MARIO); // Enter mario cam if R is pressed 2 times in less than 5 frames
gReonucamState.rButtonCounter2 = R_DOUBLE_TAP_WINDOW + 1;
} else {
gReonucamState.rButtonCounter2 = 0;
}
} else {
if (gReonucamState.rButtonCounter2++ > 100) {
gReonucamState.rButtonCounter2 = 100;
}
}

print_text_fmt_int(20, 40, "R %d", gReonucamState.rButtonCounter);
print_text_fmt_int(20, 20, "R %d", gReonucamState.rButtonCounter2);

}
#endif

/**
* A mode that only has 8 camera angles, 45 degrees apart
*/
void mode_8_directions_camera(struct Camera *c) {
Vec3f pos;
s16 oldAreaYaw = sAreaYaw;

#ifdef REONUCAM
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for this function i think it might be better if reonucam_handler was expanded to include the other parts of this function and then it would be a replacement for this function rather than being full of ifdefs

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense, will look into it tomorrow

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still havent done this smh

reonucam_handler();
radial_camera_input(c);
#else
radial_camera_input(c);

if (gPlayer1Controller->buttonPressed & R_CBUTTONS) {
Expand All @@ -1149,13 +1276,21 @@ void mode_8_directions_camera(struct Camera *c) {
s8DirModeYawOffset = snap_to_45_degrees(s8DirModeYawOffset);
}
#endif

#endif
lakitu_zoom(400.f, 0x900);
c->nextYaw = update_8_directions_camera(c, c->focus, pos);
#ifdef REONUCAM
set_camera_height(c, pos[1]);
#endif
c->pos[0] = pos[0];
c->pos[2] = pos[2];
sAreaYawChange = sAreaYaw - oldAreaYaw;
#ifdef EIGHT_DIR_CAMERA_COLLISION
eight_dir_collision_handler(c);
#endif
#ifndef REONUCAM
set_camera_height(c, pos[1]);
#endif
}

/**
Expand Down Expand Up @@ -2751,6 +2886,9 @@ void set_camera_mode(struct Camera *c, s16 mode, s16 frames) {
#ifndef ENABLE_VANILLA_CAM_PROCESSING
if (mode == CAMERA_MODE_8_DIRECTIONS) {
// Helps transition from any camera mode to 8dir
#ifdef REONUCAM
s8DirModeBaseYaw = 0;
#endif
s8DirModeYawOffset = snap_to_45_degrees(c->yaw);
}
#endif
Expand Down Expand Up @@ -2882,14 +3020,23 @@ void update_camera(struct Camera *c) {
// Only process R_TRIG if 'fixed' is not selected in the menu
if (cam_select_alt_mode(CAM_SELECTION_NONE) == CAM_SELECTION_MARIO) {
if (gPlayer1Controller->buttonPressed & R_TRIG) {
#ifdef REONUCAM
if (set_cam_angle(0) == CAM_ANGLE_MARIO) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be in the cam handler not here

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unless thats not possible with how the cam angle stuff works idk

s8DirModeBaseYaw = snap_to_45_degrees(s8DirModeBaseYaw);
set_cam_angle(CAM_ANGLE_LAKITU);
}
#else
if (set_cam_angle(0) == CAM_ANGLE_LAKITU) {
set_cam_angle(CAM_ANGLE_MARIO);
} else {
set_cam_angle(CAM_ANGLE_LAKITU);
}
#endif
}
}
#ifndef REONUCAM
play_sound_if_cam_switched_to_lakitu_or_mario();
#endif
}

// Initialize the camera
Expand Down Expand Up @@ -4545,15 +4692,21 @@ void play_camera_buzz_if_c_sideways(void) {
}

void play_sound_cbutton_up(void) {
#ifndef REONUCAM
play_sound(SOUND_MENU_CAMERA_ZOOM_IN, gGlobalSoundSource);
#endif
}

void play_sound_cbutton_down(void) {
#ifndef REONUCAM
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cleaner (both codewise and optimization wise) to ifdef this whole block and then if reonucam is defined instead do #define play_sound_cbutton_up()

play_sound(SOUND_MENU_CAMERA_ZOOM_OUT, gGlobalSoundSource);
#endif
}

void play_sound_cbutton_side(void) {
#ifndef REONUCAM
play_sound(SOUND_MENU_CAMERA_TURN, gGlobalSoundSource);
#endif
}

void play_sound_button_change_blocked(void) {
Expand Down Expand Up @@ -4652,7 +4805,11 @@ void radial_camera_input(struct Camera *c) {
}

// Zoom in / enter C-Up
#ifdef REONUCAM
if ((gPlayer1Controller->buttonPressed & U_CBUTTONS) && !(gPlayer1Controller->buttonDown & R_TRIG)) {
#else
if (gPlayer1Controller->buttonPressed & U_CBUTTONS) {
#endif
if (gCameraMovementFlags & CAM_MOVE_ZOOMED_OUT) {
gCameraMovementFlags &= ~CAM_MOVE_ZOOMED_OUT;
play_sound_cbutton_up();
Expand Down Expand Up @@ -4741,6 +4898,7 @@ void handle_c_button_movement(struct Camera *c) {
}
}


Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get this formatting change outta here!!!!!!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think arceveti took over my pc

/**
* Zero the 10 cvars.
*/
Expand Down Expand Up @@ -5210,7 +5368,11 @@ void set_camera_mode_8_directions(struct Camera *c) {
if (c->mode != CAMERA_MODE_8_DIRECTIONS) {
c->mode = CAMERA_MODE_8_DIRECTIONS;
sStatusFlags &= ~CAM_FLAG_SMOOTH_MOVEMENT;
#ifdef REONUCAM
s8DirModeBaseYaw = snap_to_45_degrees(s8DirModeBaseYaw);
#else
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems weird, how do you know what s8DirModeBaseYaw is here? that variable is not used outside of 8 direction camera afaik so i don't know if this has the effect you think it does

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you're right and this is completely unnecessary

s8DirModeBaseYaw = 0;
#endif
s8DirModeYawOffset = 0;
}
}
Expand Down
12 changes: 12 additions & 0 deletions src/game/camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,18 @@
#define CAM_MODE_LAKITU_WAS_ZOOMED_OUT 0x02
#define CAM_MODE_MARIO_SELECTED 0x04

#ifdef REONUCAM
struct ReonucamState {
s8 speed;
u8 waterCamOverride;
u8 flyingCamOverride;
u8 keepCliffCam;
u16 rButtonCounter;
u16 rButtonCounter2;
};
extern struct ReonucamState gReonucamState;
#endif

enum CameraSelection {
CAM_SELECTION_NONE,
CAM_SELECTION_MARIO,
Expand Down
4 changes: 4 additions & 0 deletions src/game/game_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "vc_ultra.h"
#include "profiling.h"
#include "emutest.h"
#include "camera.h"

// Emulators that the Instant Input patch should not be applied to
#define INSTANT_INPUT_BLACKLIST (EMU_CONSOLE | EMU_WIIVC | EMU_ARES | EMU_SIMPLE64 | EMU_CEN64)
Expand Down Expand Up @@ -785,6 +786,9 @@ void thread5_game_loop(UNUSED void *arg) {

play_music(SEQ_PLAYER_SFX, SEQUENCE_ARGS(0, SEQ_SOUND_PLAYER), 0);
set_sound_mode(save_file_get_sound_mode());
#ifdef REONUCAM
gReonucamState.speed = save_file_get_camera_speed();
#endif
#ifdef WIDE
gConfig.widescreen = save_file_get_widescreen_mode();
#endif
Expand Down
Loading