Skip to content

Commit

Permalink
Add more mouse functionally and separte mouse define (BETTERCAM_MOUSE)
Browse files Browse the repository at this point in the history
Added mouse control on menu and title screen feature (from sm64pc/sm64ex#406)

Mouse controls for cannons (from sm64pc/sm64ex#409)
  • Loading branch information
AloXado320 committed Jan 21, 2021
1 parent 027fedf commit d3ee22e
Show file tree
Hide file tree
Showing 8 changed files with 139 additions and 29 deletions.
18 changes: 13 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -605,16 +605,24 @@ ifeq ($(TARGET_PORT_CONSOLE),1)
CUSTOM_C_DEFINES += -DTARGET_PORT_CONSOLE
endif

# Check for Discord Rich Presence option
# Use PC-only exclusive defines
ifeq ($(TARGET_PORT_CONSOLE),0)

# Check for Discord Rich Presence option
ifeq ($(DISCORDRPC),1)
CUSTOM_C_DEFINES += -DDISCORDRPC
endif
endif

# Check for PC text save format
ifeq ($(TEXTSAVES),1)
CUSTOM_C_DEFINES += -DTEXTSAVES
endif

# Check for Mouse Puppycam Option
ifeq ($(BETTERCAMERA),1)
CUSTOM_C_DEFINES += -DBETTERCAM_MOUSE
endif

# Check for PC text save format
ifeq ($(TEXTSAVES),1)
CUSTOM_C_DEFINES += -DTEXTSAVES
endif

endif
Expand Down
10 changes: 6 additions & 4 deletions src/extras/bettercamera.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
#include "include/text_strings.h"

#include "pc/configfile.h"
#ifdef BETTERCAM_MOUSE
#include "pc/controller/controller_mouse.h"
#endif

#include "bettercamera.h"

Expand Down Expand Up @@ -110,7 +112,7 @@ s16 newcam_degrade = 1;
s16 newcam_analogue = 0; //Whether to accept inputs from a player 2 joystick, and then disables C button input.
s16 newcam_distance_values[] = {750,1250,2000};
u8 newcam_active = 0; // basically the thing that governs if puppycam is on. If you disable this by hand, you need to set the camera mode to the old modes, too.
#ifndef TARGET_N64
#ifdef BETTERCAM_MOUSE
u8 newcam_mouse = 0;
#endif
u16 newcam_mode;
Expand Down Expand Up @@ -203,7 +205,7 @@ void newcam_init_settings(void) {
newcam_panlevel = newcam_clamp(configCameraPan, 0, 100);
newcam_invertX = (s16)configCameraInvertX;
newcam_invertY = (s16)configCameraInvertY;
#ifndef TARGET_N64
#ifdef BETTERCAM_MOUSE
newcam_mouse = (u8)configCameraMouse;
#endif
newcam_analogue = (s16)configCameraAnalog;
Expand Down Expand Up @@ -394,8 +396,8 @@ static void newcam_rotate_button(void) {
newcam_tilt_acc -= (newcam_tilt_acc*((f32)newcam_degrade/100));
}

#if !defined(TARGET_N64) && !defined(TARGET_PORT_CONSOLE)
if (newcam_mouse == 1) {
#ifdef BETTERCAM_MOUSE
if (newcam_mouse) {
newcam_yaw += ivrt(0) * mouse_x * 16;
newcam_tilt += ivrt(1) * mouse_y * 16;
}
Expand Down
4 changes: 4 additions & 0 deletions src/extras/bettercamera.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ extern u8 newcam_xlu;
extern u16 newcam_mode;
extern s16 newcam_yaw;

#ifdef BETTERCAM_MOUSE
extern u8 newcam_mouse;
#endif

extern void newcam_init(struct Camera *c, u8 dv);
extern void newcam_init_settings(void);
extern void newcam_disable(void);
Expand Down
11 changes: 11 additions & 0 deletions src/game/mario_actions_automatic.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
#include "level_table.h"
#include "rumble_init.h"

#ifdef BETTERCAM_MOUSE
#include "pc/controller/controller_mouse.h"
#include "extras/bettercamera.h"
#endif

#define POLE_NONE 0
#define POLE_TOUCHED_FLOOR 1
#define POLE_FELL_OFF 2
Expand Down Expand Up @@ -710,6 +715,12 @@ s32 act_in_cannon(struct MarioState *m) {
case 2:
m->faceAngle[0] -= (s16)(m->controller->stickY * 10.0f);
marioObj->oMarioCannonInputYaw -= (s16)(m->controller->stickX * 10.0f);
#ifdef BETTERCAM_MOUSE
if (newcam_mouse) {
m->faceAngle[0] -= (s16)(mouse_y * 10.0f);
marioObj->oMarioCannonInputYaw -= (s16)(mouse_x * 10.0f);
}
#endif

if (m->faceAngle[0] > 0x38E3) {
m->faceAngle[0] = 0x38E3;
Expand Down
33 changes: 33 additions & 0 deletions src/goddard/renderer.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@
#include "config.h"
#include "gfx_dimensions.h"

#ifdef BETTERCAM_MOUSE
#include "pc/controller/controller_mouse.h"
#include "pc/configfile.h"

static bool mouseControl = FALSE;
static int oldMouse_x;
static int oldMouse_y;
#endif

#define MAX_GD_DLS 1000
#define OS_MESG_SI_COMPLETE 0x33333333

Expand Down Expand Up @@ -2567,12 +2576,33 @@ void parse_p1_controller(void) {
// deadzone checks
if (ABS(gdctrl->stickX) >= 6) {
gdctrl->csrX += gdctrl->stickX * 0.1;
#ifdef BETTERCAM_MOUSE
mouseControl = FALSE;
#endif
}

if (ABS(gdctrl->stickY) >= 6) {
gdctrl->csrY -= gdctrl->stickY * 0.1;
#ifdef BETTERCAM_MOUSE
mouseControl = FALSE;
#endif
}

#ifdef BETTERCAM_MOUSE
if (mouse_x - oldMouse_x != 0 || mouse_y - oldMouse_y != 0)
mouseControl = true;
if (mouseControl) {
float screenScale = (float) gfx_current_dimensions.height / (float)SCREEN_HEIGHT;
if (configCameraMouse) {
gdctrl->csrX = (mouse_x - (gfx_current_dimensions.width - (screenScale * (float)SCREEN_WIDTH))/ 2)/ screenScale;
gdctrl->csrY = mouse_y / screenScale;
}
}
oldMouse_x = mouse_x;
oldMouse_y = mouse_y;

if (!mouseControl) {
#endif
// clamp cursor position within screen view bounds
if (gdctrl->csrX < sScreenView->parent->upperLeft.x + (16.0f/aspect)) {
gdctrl->csrX = sScreenView->parent->upperLeft.x + (16.0f/aspect);
Expand All @@ -2593,6 +2623,9 @@ void parse_p1_controller(void) {
for (i = 0; i < sizeof(OSContPad); i++) {
((u8 *) prevInputs)[i] = ((u8 *) currInputs)[i];
}
#ifdef BETTERCAM_MOUSE
}
#endif
}

void stub_renderer_4(f32 arg0) {
Expand Down
48 changes: 46 additions & 2 deletions src/menu/file_select.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,17 @@
#include "sm64.h"
#include "text_strings.h"

#ifdef BETTERCAM_MOUSE
#include "pc/controller/controller_mouse.h"
#include "pc/configfile.h"

static bool mouseControl = FALSE;
static int oldMouse_x;
static int oldMouse_y;

extern struct GfxDimensions gfx_current_dimensions;
#endif

#include "eu_translation.h"
#ifdef VERSION_EU
#undef LANGUAGE_FUNCTION
Expand Down Expand Up @@ -115,7 +126,10 @@ static s8 sAllFilesExist = FALSE;

// Defines the value of the save slot selected in the menu.
// Mario A: 1 | Mario B: 2 | Mario C: 3 | Mario D: 4
static s8 sSelectedFileNum = 0;
#ifndef BETTERCAM_MOUSE
static
#endif
s8 sSelectedFileNum = 0;

// Which coin score mode to use when scoring files. 0 for local
// coin high score, 1 for high score across all files.
Expand Down Expand Up @@ -1684,14 +1698,41 @@ void handle_controller_cursor_input(void) {
if (rawStickY > -2 && rawStickY < 2) {
rawStickY = 0;
}
#ifdef BETTERCAM_MOUSE
else
{
mouseControl = 0;
}
#endif
if (rawStickX > -2 && rawStickX < 2) {
rawStickX = 0;
}
#ifdef BETTERCAM_MOUSE
else
{
mouseControl = 0;
}
#endif

// Move cursor
sCursorPos[0] += rawStickX / 8;
sCursorPos[1] += rawStickY / 8;

#ifdef BETTERCAM_MOUSE
static float screenScale;
screenScale = (float) gfx_current_dimensions.height / SCREEN_HEIGHT;
if (mouse_x - oldMouse_x != 0 || mouse_y - oldMouse_y != 0)
mouseControl = 1;
if (mouseControl && configCameraMouse) {
sCursorPos[0] = ((mouse_x - (gfx_current_dimensions.width - (screenScale * 320)) / 2) / screenScale) - 160.0f;
sCursorPos[1] = (mouse_y / screenScale - 120.0f) * -1;
}
oldMouse_x = mouse_x;
oldMouse_y = mouse_y;

if (!mouseControl) {
#endif

// Stop cursor from going offscreen
if (sCursorPos[0] > GFX_DIMENSIONS_FROM_RIGHT_EDGE(188)) {
sCursorPos[0] = GFX_DIMENSIONS_FROM_RIGHT_EDGE(188);
Expand All @@ -1706,6 +1747,9 @@ void handle_controller_cursor_input(void) {
if (sCursorPos[1] < -90.0f) {
sCursorPos[1] = -90.0f;
}
#ifdef BETTERCAM_MOUSE
}
#endif

if (sCursorClickingTimer == 0) {
handle_cursor_button_input();
Expand Down Expand Up @@ -2991,7 +3035,7 @@ static void print_file_select_strings(void) {
* Geo function that prints file select strings and the cursor.
*/
Gfx *geo_file_select_strings_and_menu_cursor(s32 callContext, UNUSED struct GraphNode *node, UNUSED Mat4 mtx) {
if (callContext == GEO_CONTEXT_RENDER) {
if (callContext == GEO_CONTEXT_RENDER && sSelectedFileNum == 0) {
#ifdef TARGET_N3DS
gDPForceFlush(gDisplayListHead++);
gDPSet2d(gDisplayListHead++, 1);
Expand Down
22 changes: 13 additions & 9 deletions src/pc/controller/controller_sdl1.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,12 @@ enum {
MAX_AXES,
};

#ifdef BETTERCAM_MOUSE
int mouse_x;
int mouse_y;

#ifdef BETTERCAMERA
extern u8 newcam_mouse;
#include "extras/bettercamera.h"
extern s8 sSelectedFileNum;
#endif

static bool init_ok;
Expand Down Expand Up @@ -120,8 +121,8 @@ static void controller_sdl_init(void) {
joy_axis_binds[i] = -1;
}

#ifdef BETTERCAMERA
if (newcam_mouse == 1)
#ifdef BETTERCAM_MOUSE
if (newcam_mouse)
SDL_WM_GrabInput(SDL_GRAB_ON);
SDL_GetRelativeMouseState(&mouse_x, &mouse_y);
#endif
Expand All @@ -147,13 +148,16 @@ static inline int16_t get_axis(const int i) {
static void controller_sdl_read(OSContPad *pad) {
if (!init_ok) return;

#ifdef BETTERCAMERA
if (newcam_mouse == 1 && sCurrPlayMode != 2)
#ifdef BETTERCAM_MOUSE
u32 mouse;

if (newcam_mouse && sCurrPlayMode != 2 && sSelectedFileNum != 0) {
SDL_WM_GrabInput(SDL_GRAB_ON);
else
mouse = SDL_GetRelativeMouseState(&mouse_x, &mouse_y);
} else {
SDL_WM_GrabInput(SDL_GRAB_OFF);

u32 mouse = SDL_GetRelativeMouseState(&mouse_x, &mouse_y);
mouse = SDL_GetMouseState(&mouse_x, &mouse_y);
}

for (u32 i = 0; i < num_mouse_binds; ++i)
if (mouse & SDL_BUTTON(mouse_binds[i][0]))
Expand Down
22 changes: 13 additions & 9 deletions src/pc/controller/controller_sdl2.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@
#define MAX_JOYBUTTONS 32 // arbitrary; includes virtual keys for triggers
#define AXIS_THRESHOLD (30 * 256)

#ifdef BETTERCAM_MOUSE
int mouse_x;
int mouse_y;

#ifdef BETTERCAMERA
extern u8 newcam_mouse;
#include "extras/bettercamera.h"
extern s8 sSelectedFileNum;
#endif

static bool init_ok;
Expand Down Expand Up @@ -113,8 +114,8 @@ static void controller_sdl_init(void) {
free(gcdata);
}

#ifdef BETTERCAMERA
if (newcam_mouse == 1)
#ifdef BETTERCAM_MOUSE
if (newcam_mouse)
SDL_SetRelativeMouseMode(SDL_TRUE);
SDL_GetRelativeMouseState(&mouse_x, &mouse_y);
#endif
Expand Down Expand Up @@ -155,13 +156,16 @@ static void controller_sdl_read(OSContPad *pad) {
return;
}

#ifdef BETTERCAMERA
if (newcam_mouse == 1 && sCurrPlayMode != 2)
#ifdef BETTERCAM_MOUSE
u32 mouse;

if (newcam_mouse && sCurrPlayMode != 2 && sSelectedFileNum != 0) {
SDL_SetRelativeMouseMode(SDL_TRUE);
else
mouse = SDL_GetRelativeMouseState(&mouse_x, &mouse_y);
} else {
SDL_SetRelativeMouseMode(SDL_FALSE);

u32 mouse = SDL_GetRelativeMouseState(&mouse_x, &mouse_y);
mouse = SDL_GetMouseState(&mouse_x, &mouse_y);
}

for (u32 i = 0; i < num_mouse_binds; ++i)
if (mouse & SDL_BUTTON(mouse_binds[i][0]))
Expand Down

0 comments on commit d3ee22e

Please sign in to comment.