mirror of
				https://github.com/KartKrewDev/RingRacers.git
				synced 2025-10-30 08:01:28 +00:00 
			
		
		
		
	Merge branch 'joystick-juggling' into 'master'
Joystick juggling See merge request STJr/SRB2!355
This commit is contained in:
		
						commit
						2c557d668a
					
				
					 3 changed files with 78 additions and 19 deletions
				
			
		
							
								
								
									
										30
									
								
								src/m_menu.c
									
										
									
									
									
								
							
							
						
						
									
										30
									
								
								src/m_menu.c
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -54,6 +54,8 @@
 | 
			
		|||
#include "st_stuff.h"
 | 
			
		||||
#include "i_sound.h"
 | 
			
		||||
 | 
			
		||||
#include "i_joy.h" // for joystick menu controls
 | 
			
		||||
 | 
			
		||||
// Condition Sets
 | 
			
		||||
#include "m_cond.h"
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -2065,6 +2067,7 @@ boolean M_Responder(event_t *ev)
 | 
			
		|||
	INT32 ch = -1;
 | 
			
		||||
//	INT32 i;
 | 
			
		||||
	static tic_t joywait = 0, mousewait = 0;
 | 
			
		||||
	static INT32 pjoyx = 0, pjoyy = 0;
 | 
			
		||||
	static INT32 pmousex = 0, pmousey = 0;
 | 
			
		||||
	static INT32 lastx = 0, lasty = 0;
 | 
			
		||||
	void (*routine)(INT32 choice); // for some casting problem
 | 
			
		||||
| 
						 | 
				
			
			@ -2117,27 +2120,46 @@ boolean M_Responder(event_t *ev)
 | 
			
		|||
	{
 | 
			
		||||
		if (ev->type == ev_joystick  && ev->data1 == 0 && joywait < I_GetTime())
 | 
			
		||||
		{
 | 
			
		||||
			if (ev->data3 == -1)
 | 
			
		||||
			const INT32 jdeadzone = JOYAXISRANGE/4;
 | 
			
		||||
			if (ev->data3 != INT32_MAX)
 | 
			
		||||
			{
 | 
			
		||||
				if (Joystick.bGamepadStyle || abs(ev->data3) > jdeadzone)
 | 
			
		||||
				{
 | 
			
		||||
					if (ev->data3 < 0 && pjoyy >= 0)
 | 
			
		||||
					{
 | 
			
		||||
						ch = KEY_UPARROW;
 | 
			
		||||
						joywait = I_GetTime() + NEWTICRATE/7;
 | 
			
		||||
					}
 | 
			
		||||
			else if (ev->data3 == 1)
 | 
			
		||||
					else if (ev->data3 > 0 && pjoyy <= 0)
 | 
			
		||||
					{
 | 
			
		||||
						ch = KEY_DOWNARROW;
 | 
			
		||||
						joywait = I_GetTime() + NEWTICRATE/7;
 | 
			
		||||
					}
 | 
			
		||||
					pjoyy = ev->data3;
 | 
			
		||||
				}
 | 
			
		||||
				else
 | 
			
		||||
					pjoyy = 0;
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			if (ev->data2 == -1)
 | 
			
		||||
			if (ev->data2 != INT32_MAX)
 | 
			
		||||
			{
 | 
			
		||||
				if (Joystick.bGamepadStyle || abs(ev->data2) > jdeadzone)
 | 
			
		||||
				{
 | 
			
		||||
					if (ev->data2 < 0 && pjoyx >= 0)
 | 
			
		||||
					{
 | 
			
		||||
						ch = KEY_LEFTARROW;
 | 
			
		||||
						joywait = I_GetTime() + NEWTICRATE/17;
 | 
			
		||||
					}
 | 
			
		||||
			else if (ev->data2 == 1)
 | 
			
		||||
					else if (ev->data2 > 0 && pjoyx <= 0)
 | 
			
		||||
					{
 | 
			
		||||
						ch = KEY_RIGHTARROW;
 | 
			
		||||
						joywait = I_GetTime() + NEWTICRATE/17;
 | 
			
		||||
					}
 | 
			
		||||
					pjoyx = ev->data2;
 | 
			
		||||
				}
 | 
			
		||||
				else
 | 
			
		||||
					pjoyx = 0;
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		else if (ev->type == ev_mouse && mousewait < I_GetTime())
 | 
			
		||||
		{
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -894,8 +894,8 @@ void I_GetJoystickEvents(void)
 | 
			
		|||
	UINT64 joyhats = 0;
 | 
			
		||||
#if 0
 | 
			
		||||
	UINT64 joybuttons = 0;
 | 
			
		||||
#endif
 | 
			
		||||
	Sint16 axisx, axisy;
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
	if (!joystick_started) return;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -963,6 +963,7 @@ void I_GetJoystickEvents(void)
 | 
			
		|||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
#if 0
 | 
			
		||||
	// send joystick axis positions
 | 
			
		||||
	event.type = ev_joystick;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -1013,6 +1014,7 @@ void I_GetJoystickEvents(void)
 | 
			
		|||
		}
 | 
			
		||||
		D_PostEvent(&event);
 | 
			
		||||
	}
 | 
			
		||||
#endif
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**	\brief	Open joystick handle
 | 
			
		||||
| 
						 | 
				
			
			@ -1176,8 +1178,8 @@ void I_GetJoystick2Events(void)
 | 
			
		|||
	UINT64 joyhats = 0;
 | 
			
		||||
#if 0
 | 
			
		||||
	INT64 joybuttons = 0;
 | 
			
		||||
#endif
 | 
			
		||||
	INT32 axisx, axisy;
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
	if (!joystick2_started)
 | 
			
		||||
		return;
 | 
			
		||||
| 
						 | 
				
			
			@ -1247,6 +1249,7 @@ void I_GetJoystick2Events(void)
 | 
			
		|||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
#if 0
 | 
			
		||||
	// send joystick axis positions
 | 
			
		||||
	event.type = ev_joystick2;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -1297,7 +1300,7 @@ void I_GetJoystick2Events(void)
 | 
			
		|||
		}
 | 
			
		||||
		D_PostEvent(&event);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**	\brief	Open joystick handle
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -767,6 +767,33 @@ static void Impl_HandleJoystickAxisEvent(SDL_JoyAxisEvent evt)
 | 
			
		|||
	D_PostEvent(&event);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#if 0
 | 
			
		||||
static void Impl_HandleJoystickHatEvent(SDL_JoyHatEvent evt)
 | 
			
		||||
{
 | 
			
		||||
	event_t event;
 | 
			
		||||
	SDL_JoystickID joyid[2];
 | 
			
		||||
 | 
			
		||||
	// Determine the Joystick IDs for each current open joystick
 | 
			
		||||
	joyid[0] = SDL_JoystickInstanceID(JoyInfo.dev);
 | 
			
		||||
	joyid[1] = SDL_JoystickInstanceID(JoyInfo2.dev);
 | 
			
		||||
 | 
			
		||||
	if (evt.hat >= JOYHATS)
 | 
			
		||||
		return; // ignore hats with too high an index
 | 
			
		||||
 | 
			
		||||
	if (evt.which == joyid[0])
 | 
			
		||||
	{
 | 
			
		||||
		event.data1 = KEY_HAT1 + (evt.hat*4);
 | 
			
		||||
	}
 | 
			
		||||
	else if (evt.which == joyid[1])
 | 
			
		||||
	{
 | 
			
		||||
		event.data1 = KEY_2HAT1 + (evt.hat*4);
 | 
			
		||||
	}
 | 
			
		||||
	else return;
 | 
			
		||||
 | 
			
		||||
	// NOTE: UNFINISHED
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
static void Impl_HandleJoystickButtonEvent(SDL_JoyButtonEvent evt, Uint32 type)
 | 
			
		||||
{
 | 
			
		||||
	event_t event;
 | 
			
		||||
| 
						 | 
				
			
			@ -804,6 +831,8 @@ static void Impl_HandleJoystickButtonEvent(SDL_JoyButtonEvent evt, Uint32 type)
 | 
			
		|||
	if (event.type != ev_console) D_PostEvent(&event);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void I_GetEvent(void)
 | 
			
		||||
{
 | 
			
		||||
	SDL_Event evt;
 | 
			
		||||
| 
						 | 
				
			
			@ -844,6 +873,11 @@ void I_GetEvent(void)
 | 
			
		|||
			case SDL_JOYAXISMOTION:
 | 
			
		||||
				Impl_HandleJoystickAxisEvent(evt.jaxis);
 | 
			
		||||
				break;
 | 
			
		||||
#if 0
 | 
			
		||||
			case SDL_JOYHATMOTION:
 | 
			
		||||
				Impl_HandleJoystickHatEvent(evt.jhat)
 | 
			
		||||
				break;
 | 
			
		||||
#endif
 | 
			
		||||
			case SDL_JOYBUTTONUP:
 | 
			
		||||
			case SDL_JOYBUTTONDOWN:
 | 
			
		||||
				Impl_HandleJoystickButtonEvent(evt.jbutton, evt.type);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		
		Reference in a new issue