Mouse Look ported to camera_rebase

With check for settings SDL_SetRelativeMouseMode only if Mouse Look is enabled.

We always send regards to Fastblitters.
This commit is contained in:
IvanDSM 2020-05-09 02:10:56 -03:00
parent 4448d4d9b5
commit 85dbb70e38
3 changed files with 46 additions and 13 deletions

View File

@ -16,6 +16,7 @@
#define NC_OPTION _("OPTIONS")
#define NC_HIGHLIGHT _("O")
#define NC_ANALOGUE _("Analogue Camera")
#define NC_MOUSE _("Mouse Look")
/**
* Global Symbols

View File

@ -97,6 +97,7 @@ u8 newcam_invertY;
u8 newcam_panlevel; //How much the camera sticks out a bit in the direction you're looking.
u8 newcam_aggression; //How much the camera tries to centre itself to Mario's facing and movement.
u8 newcam_analogue; //Wether to accept inputs from a player 2 joystick, and then disables C button input.
u8 newcam_mouse; // Whether to accept mouse input
s16 newcam_distance_values[] = {750,1250,2000};
u8 newcam_active = 1; // basically the thing that governs if newcam is on.
u16 newcam_mode;
@ -109,12 +110,15 @@ f32 newcam_option_timer = 0;
u8 newcam_option_index = 0;
u8 newcam_option_scroll = 0;
u8 newcam_option_scroll_last = 0;
u8 newcam_total = 7; //How many options there are in newcam_uptions.
u8 newcam_total = 8; //How many options there are in newcam_uptions.
u8 newcam_options[][64] = {{NC_ANALOGUE}, {NC_CAMX}, {NC_CAMY}, {NC_INVERTX}, {NC_INVERTY}, {NC_CAMC}, {NC_CAMP}};
u8 newcam_options[][64] = {{NC_ANALOGUE}, {NC_MOUSE}, {NC_CAMX}, {NC_CAMY}, {NC_INVERTX}, {NC_INVERTY}, {NC_CAMC}, {NC_CAMP}};
u8 newcam_flags[][64] = {{NC_DISABLED}, {NC_ENABLED}};
u8 newcam_strings[][64] = {{NC_BUTTON}, {NC_BUTTON2}, {NC_OPTION}, {NC_HIGHLIGHT}};
extern int mouse_x;
extern int mouse_y;
///This is called at every level initialisation.
void newcam_init(struct Camera *c, u8 dv)
{
@ -370,6 +374,12 @@ static void newcam_rotate_button(void)
else
newcam_tilt_acc -= (newcam_tilt_acc*(DEGRADE));
}
if (newcam_mouse == 1)
{
newcam_yaw += mouse_x * 16;
newcam_tilt += mouse_y * 16;
}
}
static void newcam_zoom_button(void)
@ -690,24 +700,27 @@ void newcam_change_setting(u8 toggle)
newcam_analogue ^= 1;
break;
case 1:
newcam_mouse ^= 1;
break;
case 2:
if (newcam_sensitivityX > 10 && newcam_sensitivityX < 250)
newcam_sensitivityX += toggle;
break;
case 2:
case 3:
if (newcam_sensitivityY > 10 && newcam_sensitivityY < 250)
newcam_sensitivityY += toggle;
break;
case 3:
case 4:
newcam_invertX ^= 1;
break;
case 4:
case 5:
newcam_invertY ^= 1;
break;
case 5:
case 6:
if (newcam_aggression > 0 && newcam_aggression < 100)
newcam_aggression += toggle;
break;
case 6:
case 7:
if (newcam_panlevel > 0 && newcam_panlevel < 100)
newcam_panlevel += toggle;
break;
@ -765,24 +778,27 @@ void newcam_display_options()
newcam_text(160,scroll-12,newcam_flags[newcam_analogue],newcam_option_selection-i);
break;
case 1:
newcam_text(160,scroll-12,newcam_flags[newcam_mouse],newcam_option_selection-i);
break;
case 2:
int_to_str(newcam_sensitivityX,newstring);
newcam_text(160,scroll-12,newstring,newcam_option_selection-i);
break;
case 2:
case 3:
int_to_str(newcam_sensitivityY,newstring);
newcam_text(160,scroll-12,newstring,newcam_option_selection-i);
break;
case 3:
case 4:
newcam_text(160,scroll-12,newcam_flags[newcam_invertX],newcam_option_selection-i);
break;
case 4:
case 5:
newcam_text(160,scroll-12,newcam_flags[newcam_invertY],newcam_option_selection-i);
break;
case 5:
case 6:
int_to_str(newcam_aggression,newstring);
newcam_text(160,scroll-12,newstring,newcam_option_selection-i);
break;
case 6:
case 7:
int_to_str(newcam_panlevel,newstring);
newcam_text(160,scroll-12,newstring,newcam_option_selection-i);
break;

View File

@ -14,16 +14,24 @@
extern int16_t rightx;
extern int16_t righty;
int mouse_x;
int mouse_y;
extern u8 newcam_mouse;
static bool init_ok;
static SDL_GameController *sdl_cntrl;
static void controller_sdl_init(void) {
if (SDL_Init(SDL_INIT_GAMECONTROLLER) != 0) {
if (SDL_Init(SDL_INIT_GAMECONTROLLER | SDL_INIT_EVENTS) != 0) {
fprintf(stderr, "SDL init error: %s\n", SDL_GetError());
return;
}
if (newcam_mouse == 1)
SDL_SetRelativeMouseMode(SDL_TRUE);
SDL_GetRelativeMouseState(&mouse_x, &mouse_y);
init_ok = true;
}
@ -32,7 +40,15 @@ static void controller_sdl_read(OSContPad *pad) {
return;
}
if (newcam_mouse == 1)
SDL_SetRelativeMouseMode(SDL_TRUE);
else
SDL_SetRelativeMouseMode(SDL_FALSE);
SDL_GameControllerUpdate();
SDL_GetRelativeMouseState(&mouse_x, &mouse_y);
if (sdl_cntrl != NULL && !SDL_GameControllerGetAttached(sdl_cntrl)) {
SDL_GameControllerClose(sdl_cntrl);