mirror of
https://github.com/Llennpie/Saturn.git
synced 2025-01-22 07:32:02 -05:00
Polished free camera system + a few other optimizations
This commit is contained in:
parent
3ce3976dee
commit
2453fa3be4
6 changed files with 79 additions and 67 deletions
|
@ -32,6 +32,8 @@
|
|||
|
||||
#define CBUTTON_MASK (U_CBUTTONS | D_CBUTTONS | L_CBUTTONS | R_CBUTTONS)
|
||||
|
||||
u8 machinimaMode = 0;
|
||||
|
||||
/**
|
||||
* @file camera.c
|
||||
* Implements the camera system, including C-button input, camera modes, camera triggers, and cutscenes.
|
||||
|
@ -2650,7 +2652,8 @@ s32 exit_c_up(struct Camera *c) {
|
|||
*/
|
||||
|
||||
gCameraMovementFlags &= ~(CAM_MOVE_STARTED_EXITING_C_UP | CAM_MOVE_C_UP_MODE);
|
||||
play_sound_cbutton_down();
|
||||
if (machinimaMode == 0)
|
||||
play_sound_cbutton_down();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -3026,7 +3029,7 @@ void update_lakitu(struct Camera *c) {
|
|||
gLakituState.defMode = c->defMode;
|
||||
}
|
||||
#include "engine/math_util.h"
|
||||
u8 P2CamAvtive = 0;
|
||||
|
||||
f32 camVelY = 0.f;
|
||||
s16 yarSpeed = 0;
|
||||
f32 camVelSpeed = 1.f;
|
||||
|
@ -3046,7 +3049,7 @@ void update_camera(struct Camera *c) {
|
|||
&& c->mode != CAMERA_MODE_NEWCAM
|
||||
#endif
|
||||
) {
|
||||
if (gPlayer1Controller->buttonPressed & R_TRIG && !P2CamAvtive) {
|
||||
if (gPlayer1Controller->buttonPressed & R_TRIG && !machinimaMode) {
|
||||
if (set_cam_angle(0) == CAM_ANGLE_LAKITU) {
|
||||
set_cam_angle(CAM_ANGLE_MARIO);
|
||||
} else {
|
||||
|
@ -3146,39 +3149,65 @@ void update_camera(struct Camera *c) {
|
|||
mode_mario_camera(c);
|
||||
}
|
||||
} else {
|
||||
if (P2CamAvtive) {
|
||||
if (machinimaMode) {
|
||||
if (gPlayer1Controller->buttonDown & L_TRIG) {
|
||||
if (gPlayer1Controller->buttonDown & U_CBUTTONS) {
|
||||
camVelY += 10.f * camVelSpeed;
|
||||
camVelY += 5.f * camVelSpeed;
|
||||
}
|
||||
if (gPlayer1Controller->buttonDown & D_CBUTTONS) {
|
||||
camVelY -= 10.f * camVelSpeed;
|
||||
camVelY -= 5.f * camVelSpeed;
|
||||
}
|
||||
} else {
|
||||
} else if (gPlayer1Controller->buttonDown & R_TRIG) {
|
||||
if (gPlayer1Controller->buttonDown & U_CBUTTONS) {
|
||||
c->pos[0] += sins(c->yaw + atan2s(-127, 0)) * 64 * camVelSpeed;
|
||||
c->pos[2] += coss(c->yaw + atan2s(-127, 0)) * 64 * camVelSpeed;
|
||||
c->focus[0] += sins(c->yaw + atan2s(-127, 0)) * 64 * camVelSpeed;
|
||||
c->focus[2] += coss(c->yaw + atan2s(-127, 0)) * 64 * camVelSpeed;
|
||||
c->pos[0] += sins(c->yaw + atan2s(-127, 0)) * 16 * camVelSpeed;
|
||||
c->pos[2] += coss(c->yaw + atan2s(-127, 0)) * 16 * camVelSpeed;
|
||||
c->focus[0] += sins(c->yaw + atan2s(-127, 0)) * 16 * camVelSpeed;
|
||||
c->focus[2] += coss(c->yaw + atan2s(-127, 0)) * 16 * camVelSpeed;
|
||||
}
|
||||
if (gPlayer1Controller->buttonDown & D_CBUTTONS) {
|
||||
c->pos[0] -= sins(c->yaw + atan2s(-127, 0)) * 64 * camVelSpeed;
|
||||
c->pos[2] -= coss(c->yaw + atan2s(-127, 0)) * 64 * camVelSpeed;
|
||||
c->focus[0] -= sins(c->yaw + atan2s(-127, 0)) * 64 * camVelSpeed;
|
||||
c->focus[2] -= coss(c->yaw + atan2s(-127, 0)) * 64 * camVelSpeed;
|
||||
c->pos[0] -= sins(c->yaw + atan2s(-127, 0)) * 16 * camVelSpeed;
|
||||
c->pos[2] -= coss(c->yaw + atan2s(-127, 0)) * 16 * camVelSpeed;
|
||||
c->focus[0] -= sins(c->yaw + atan2s(-127, 0)) * 16 * camVelSpeed;
|
||||
c->focus[2] -= coss(c->yaw + atan2s(-127, 0)) * 16 * camVelSpeed;
|
||||
}
|
||||
if (gPlayer1Controller->buttonDown & R_CBUTTONS) {
|
||||
c->pos[0] += sins(c->yaw + atan2s(0, 127)) * 64 * camVelSpeed;
|
||||
c->pos[2] += coss(c->yaw + atan2s(0, 127)) * 64 * camVelSpeed;
|
||||
c->focus[0] += sins(c->yaw + atan2s(0, 127)) * 64 * camVelSpeed;
|
||||
c->focus[2] += coss(c->yaw + atan2s(0, 127)) * 64 * camVelSpeed;
|
||||
c->pos[0] += sins(c->yaw + atan2s(0, 127)) * 16 * camVelSpeed;
|
||||
c->pos[2] += coss(c->yaw + atan2s(0, 127)) * 16 * camVelSpeed;
|
||||
c->focus[0] += sins(c->yaw + atan2s(0, 127)) * 16 * camVelSpeed;
|
||||
c->focus[2] += coss(c->yaw + atan2s(0, 127)) * 16 * camVelSpeed;
|
||||
}
|
||||
if (gPlayer1Controller->buttonDown & L_CBUTTONS) {
|
||||
c->pos[0] -= sins(c->yaw + atan2s(0, 127)) * 64 * camVelSpeed;
|
||||
c->pos[2] -= coss(c->yaw + atan2s(0, 127)) * 64 * camVelSpeed;
|
||||
c->focus[0] -= sins(c->yaw + atan2s(0, 127)) * 64 * camVelSpeed;
|
||||
c->focus[2] -= coss(c->yaw + atan2s(0, 127)) * 64 * camVelSpeed;
|
||||
c->pos[0] -= sins(c->yaw + atan2s(0, 127)) * 16 * camVelSpeed;
|
||||
c->pos[2] -= coss(c->yaw + atan2s(0, 127)) * 16 * camVelSpeed;
|
||||
c->focus[0] -= sins(c->yaw + atan2s(0, 127)) * 16 * camVelSpeed;
|
||||
c->focus[2] -= coss(c->yaw + atan2s(0, 127)) * 16 * camVelSpeed;
|
||||
}
|
||||
} else {
|
||||
// Zoom in / enter C-Up
|
||||
if (gPlayer1Controller->buttonPressed & U_CBUTTONS) {
|
||||
if (gCameraMovementFlags & CAM_MOVE_ZOOMED_OUT) {
|
||||
gCameraMovementFlags &= ~CAM_MOVE_ZOOMED_OUT;
|
||||
//play_sound_cbutton_up();
|
||||
} else {
|
||||
set_mode_c_up(c);
|
||||
}
|
||||
}
|
||||
// Zoom out
|
||||
if (gPlayer1Controller->buttonPressed & D_CBUTTONS) {
|
||||
if ((gCameraMovementFlags & CAM_MOVE_ZOOMED_OUT) == 0) {
|
||||
exit_c_up(c);
|
||||
//gCameraMovementFlags |= CAM_MOVE_ZOOMED_OUT;
|
||||
//play_sound_cbutton_down();
|
||||
}
|
||||
}
|
||||
|
||||
if (c->mode == CAMERA_MODE_C_UP) {
|
||||
move_mario_head_c_up(c);
|
||||
}
|
||||
|
||||
c->nextYaw = calculate_yaw(gLakituState.focus, gLakituState.pos);
|
||||
c->yaw = gCamera->nextYaw;
|
||||
//gCameraMovementFlags &= ~CAM_MOVE_FIX_IN_PLACE;
|
||||
}
|
||||
|
||||
c->pos[1] += camVelY;
|
||||
|
@ -3186,23 +3215,6 @@ void update_camera(struct Camera *c) {
|
|||
camVelY = approach_f32_symmetric(camVelY, 0.f, 2.f);
|
||||
camVelY = approach_f32_asymptotic(camVelY, 0.f, 0.1f);
|
||||
|
||||
if (gPlayer1Controller->buttonPressed & R_TRIG) {
|
||||
if (c->mode != CAMERA_MODE_C_UP) {
|
||||
set_mode_c_up(c);
|
||||
} else {
|
||||
exit_c_up(c);
|
||||
gCameraMovementFlags &= ~(CAM_MOVE_STARTED_EXITING_C_UP | CAM_MOVE_C_UP_MODE);
|
||||
}
|
||||
}
|
||||
|
||||
if (c->mode == CAMERA_MODE_C_UP) {
|
||||
move_mario_head_c_up(c);
|
||||
}
|
||||
|
||||
if (set_cam_angle(0) == CAM_ANGLE_MARIO) {
|
||||
set_cam_angle(CAM_ANGLE_LAKITU);
|
||||
}
|
||||
|
||||
} else {
|
||||
switch (c->mode) {
|
||||
case CAMERA_MODE_BEHIND_MARIO:
|
||||
|
@ -4009,7 +4021,7 @@ s32 find_c_buttons_pressed(u16 currentState, u16 buttonsPressed, u16 buttonsDown
|
|||
s32 update_camera_hud_status(struct Camera *c) {
|
||||
s16 status = CAM_STATUS_NONE;
|
||||
|
||||
if (c->cutscene != 0
|
||||
if (c->cutscene != 0 || machinimaMode == 1
|
||||
|| ((gPlayer1Controller->buttonDown & R_TRIG) && cam_select_alt_mode(0) == CAM_SELECTION_FIXED)) {
|
||||
status |= CAM_STATUS_FIXED;
|
||||
} else if (set_cam_angle(0) == CAM_ANGLE_MARIO) {
|
||||
|
|
|
@ -775,7 +775,7 @@ void obj_rotate_towards_point(struct Object *o, Vec3f point, s16 pitchOff, s16 y
|
|||
|
||||
Gfx *geo_camera_fov(s32 callContext, struct GraphNode *g, UNUSED void *context);
|
||||
|
||||
extern u8 P2CamAvtive;
|
||||
extern u8 machinimaMode;
|
||||
extern f32 camVelSpeed;
|
||||
|
||||
#endif // CAMERA_H
|
||||
|
|
|
@ -40,6 +40,7 @@
|
|||
#include "gfx_cc.h"
|
||||
#include "gfx_rendering_api.h"
|
||||
|
||||
#include "src/saturn/saturn.h"
|
||||
#include "src/saturn/imgui/saturn_imgui.h"
|
||||
|
||||
#define TEX_CACHE_STEP 512
|
||||
|
@ -646,7 +647,16 @@ static void gfx_opengl_init(void) {
|
|||
static void gfx_opengl_on_resize(void) {
|
||||
}
|
||||
|
||||
u8 frameBreak = 0;
|
||||
|
||||
static void gfx_opengl_start_frame(void) {
|
||||
if (frameBreak == 0) {
|
||||
saturn_update();
|
||||
frameBreak = 1;
|
||||
} else {
|
||||
frameBreak = 0;
|
||||
}
|
||||
|
||||
frame_count++;
|
||||
|
||||
glDisable(GL_SCISSOR_TEST);
|
||||
|
|
|
@ -55,8 +55,6 @@ ImGuiIO io;
|
|||
|
||||
// Variables
|
||||
|
||||
int frameBreak = 0;
|
||||
|
||||
bool showMenu = true;
|
||||
bool showWindowStats = false;
|
||||
bool showWindowMachinima = false;
|
||||
|
@ -131,7 +129,12 @@ void saturn_imgui_handle_events(SDL_Event * event) {
|
|||
case SDL_KEYDOWN:
|
||||
if(event->key.keysym.sym == SDLK_F12)
|
||||
showMenu = !showMenu;
|
||||
break;
|
||||
|
||||
case SDL_CONTROLLERBUTTONDOWN:
|
||||
if(event->cbutton.button == SDL_CONTROLLER_BUTTON_BACK)
|
||||
showMenu = !showMenu;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -245,19 +248,6 @@ void saturn_imgui_update() {
|
|||
//ImGui::ShowDemoWindow();
|
||||
}
|
||||
|
||||
// Attempts to only call saturn_update in 30 FPS
|
||||
// Otherwise, this function is called twice per frame with the 60 FPS patch
|
||||
if (ImGui::GetIO().Framerate > 40) {
|
||||
if (frameBreak == 0) {
|
||||
saturn_update();
|
||||
frameBreak = 1;
|
||||
} else {
|
||||
frameBreak = 0;
|
||||
}
|
||||
} else {
|
||||
saturn_update();
|
||||
}
|
||||
|
||||
ImGui::Render();
|
||||
GLint last_program;
|
||||
glGetIntegerv(GL_CURRENT_PROGRAM, &last_program);
|
||||
|
|
|
@ -58,7 +58,7 @@ void saturn_update() {
|
|||
gCameraMovementFlags &= ~CAM_MOVE_FIX_IN_PLACE;
|
||||
}
|
||||
*/
|
||||
P2CamAvtive = (camera_frozen) ? 1 : 0;
|
||||
machinimaMode = (camera_frozen) ? 1 : 0;
|
||||
|
||||
if (is_anim_playing && is_anim_past_end(gMarioState)) {
|
||||
is_anim_playing = false;
|
||||
|
@ -101,12 +101,6 @@ void saturn_update() {
|
|||
if (gPlayer1Controller->buttonPressed & LOAD_ANIMATION) {
|
||||
saturn_play_animation(selected_animation);
|
||||
}
|
||||
|
||||
// ImGui
|
||||
|
||||
if (gPlayer1Controller->buttonPressed & TOGGLE_MENU) {
|
||||
showMenu = !showMenu;
|
||||
}
|
||||
}
|
||||
|
||||
// Play Animation
|
||||
|
|
|
@ -17,7 +17,13 @@ extern bool enable_dust_particles;
|
|||
extern bool is_anim_playing;
|
||||
extern enum MarioAnimID selected_animation;
|
||||
|
||||
void saturn_update(void);
|
||||
void saturn_play_animation(MarioAnimID);
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
void saturn_update(void);
|
||||
void saturn_play_animation(MarioAnimID);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
Loading…
Reference in a new issue