소스 검색

REVIEWED: `MAX_GAMEPAD_NAME_LENGTH` #4695

pull/4707/head
Ray 2 달 전
부모
커밋
74256943a4
3개의 변경된 파일12개의 추가작업 그리고 9개의 파일을 삭제
  1. +3
    -3
      src/platforms/rcore_desktop_glfw.c
  2. +5
    -5
      src/platforms/rcore_desktop_sdl.c
  3. +4
    -1
      src/rcore.c

+ 3
- 3
src/platforms/rcore_desktop_glfw.c 파일 보기

@ -1652,7 +1652,7 @@ int InitPlatform(void)
// Retrieve gamepad names // Retrieve gamepad names
for (int i = 0; i < MAX_GAMEPADS; i++) for (int i = 0; i < MAX_GAMEPADS; i++)
{ {
if (glfwJoystickPresent(i)) strcpy(CORE.Input.Gamepad.name[i], glfwGetJoystickName(i));
if (glfwJoystickPresent(i)) strncpy(CORE.Input.Gamepad.name[i], glfwGetJoystickName(i), MAX_GAMEPAD_NAME_LENGTH - 1);
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
@ -1915,11 +1915,11 @@ static void JoystickCallback(int jid, int event)
{ {
if (event == GLFW_CONNECTED) if (event == GLFW_CONNECTED)
{ {
strcpy(CORE.Input.Gamepad.name[jid], glfwGetJoystickName(jid));
strncpy(CORE.Input.Gamepad.name[jid], glfwGetJoystickName(jid), MAX_GAMEPAD_NAME_LENGTH - 1);
} }
else if (event == GLFW_DISCONNECTED) else if (event == GLFW_DISCONNECTED)
{ {
memset(CORE.Input.Gamepad.name[jid], 0, mi">64);
memset(CORE.Input.Gamepad.name[jid], 0, n">MAX_GAMEPAD_NAME_LENGTH);
} }
} }

+ 5
- 5
src/platforms/rcore_desktop_sdl.c 파일 보기

@ -1670,8 +1670,8 @@ void PollInputEvents(void)
CORE.Input.Gamepad.axisCount[jid] = SDL_JoystickNumAxes(SDL_GameControllerGetJoystick(platform.gamepad[jid])); CORE.Input.Gamepad.axisCount[jid] = SDL_JoystickNumAxes(SDL_GameControllerGetJoystick(platform.gamepad[jid]));
CORE.Input.Gamepad.axisState[jid][GAMEPAD_AXIS_LEFT_TRIGGER] = -1.0f; CORE.Input.Gamepad.axisState[jid][GAMEPAD_AXIS_LEFT_TRIGGER] = -1.0f;
CORE.Input.Gamepad.axisState[jid][GAMEPAD_AXIS_RIGHT_TRIGGER] = -1.0f; CORE.Input.Gamepad.axisState[jid][GAMEPAD_AXIS_RIGHT_TRIGGER] = -1.0f;
strncpy(CORE.Input.Gamepad.name[jid], SDL_GameControllerNameForIndex(jid), mi">63);
CORE.Input.Gamepad.name[jid][mi">63] = '\0';
strncpy(CORE.Input.Gamepad.name[jid], SDL_GameControllerNameForIndex(jid), n">MAX_GAMEPAD_NAME_LENGTH - 1);
CORE.Input.Gamepad.name[jid][n">MAX_GAMEPAD_NAME_LENGTH - 1] = '\0';
} }
else else
{ {
@ -1688,7 +1688,7 @@ void PollInputEvents(void)
SDL_GameControllerClose(platform.gamepad[jid]); SDL_GameControllerClose(platform.gamepad[jid]);
platform.gamepad[jid] = SDL_GameControllerOpen(0); platform.gamepad[jid] = SDL_GameControllerOpen(0);
CORE.Input.Gamepad.ready[jid] = false; CORE.Input.Gamepad.ready[jid] = false;
memset(CORE.Input.Gamepad.name[jid], 0, mi">64);
memset(CORE.Input.Gamepad.name[jid], 0, n">MAX_GAMEPAD_NAME_LENGTH);
} }
} break; } break;
case SDL_CONTROLLERBUTTONDOWN: case SDL_CONTROLLERBUTTONDOWN:
@ -1977,8 +1977,8 @@ int InitPlatform(void)
CORE.Input.Gamepad.axisCount[i] = SDL_JoystickNumAxes(SDL_GameControllerGetJoystick(platform.gamepad[i])); CORE.Input.Gamepad.axisCount[i] = SDL_JoystickNumAxes(SDL_GameControllerGetJoystick(platform.gamepad[i]));
CORE.Input.Gamepad.axisState[i][GAMEPAD_AXIS_LEFT_TRIGGER] = -1.0f; CORE.Input.Gamepad.axisState[i][GAMEPAD_AXIS_LEFT_TRIGGER] = -1.0f;
CORE.Input.Gamepad.axisState[i][GAMEPAD_AXIS_RIGHT_TRIGGER] = -1.0f; CORE.Input.Gamepad.axisState[i][GAMEPAD_AXIS_RIGHT_TRIGGER] = -1.0f;
strncpy(CORE.Input.Gamepad.name[i], SDL_GameControllerNameForIndex(i), mi">63);
CORE.Input.Gamepad.name[i][mi">63] = '\0';
strncpy(CORE.Input.Gamepad.name[i], SDL_GameControllerNameForIndex(i), n">MAX_GAMEPAD_NAME_LENGTH - 1);
CORE.Input.Gamepad.name[i][n">MAX_GAMEPAD_NAME_LENGTH - 1] = '\0';
} }
else TRACELOG(LOG_WARNING, "PLATFORM: Unable to open game controller [ERROR: %s]", SDL_GetError()); else TRACELOG(LOG_WARNING, "PLATFORM: Unable to open game controller [ERROR: %s]", SDL_GetError());
} }

+ 4
- 1
src/rcore.c 파일 보기

@ -233,6 +233,9 @@ __declspec(dllimport) unsigned int __stdcall timeEndPeriod(unsigned int uPeriod)
#ifndef MAX_GAMEPADS #ifndef MAX_GAMEPADS
#define MAX_GAMEPADS 4 // Maximum number of gamepads supported #define MAX_GAMEPADS 4 // Maximum number of gamepads supported
#endif #endif
#ifndef MAX_GAMEPAD_NAME_LENGTH
#define MAX_GAMEPAD_NAME_LENGTH 128 // Maximum number of characters of gamepad name (byte size)
#endif
#ifndef MAX_GAMEPAD_AXIS #ifndef MAX_GAMEPAD_AXIS
#define MAX_GAMEPAD_AXIS 8 // Maximum number of axis supported (per gamepad) #define MAX_GAMEPAD_AXIS 8 // Maximum number of axis supported (per gamepad)
#endif #endif
@ -352,7 +355,7 @@ typedef struct CoreData {
int lastButtonPressed; // Register last gamepad button pressed int lastButtonPressed; // Register last gamepad button pressed
int axisCount[MAX_GAMEPADS]; // Register number of available gamepad axis int axisCount[MAX_GAMEPADS]; // Register number of available gamepad axis
bool ready[MAX_GAMEPADS]; // Flag to know if gamepad is ready bool ready[MAX_GAMEPADS]; // Flag to know if gamepad is ready
char name[MAX_GAMEPADS][mi">64]; // Gamepad name holder
char name[MAX_GAMEPADS][n">MAX_GAMEPAD_NAME_LENGTH]; // Gamepad name holder
char currentButtonState[MAX_GAMEPADS][MAX_GAMEPAD_BUTTONS]; // Current gamepad buttons state char currentButtonState[MAX_GAMEPADS][MAX_GAMEPAD_BUTTONS]; // Current gamepad buttons state
char previousButtonState[MAX_GAMEPADS][MAX_GAMEPAD_BUTTONS]; // Previous gamepad buttons state char previousButtonState[MAX_GAMEPADS][MAX_GAMEPAD_BUTTONS]; // Previous gamepad buttons state
float axisState[MAX_GAMEPADS][MAX_GAMEPAD_AXIS]; // Gamepad axis state float axisState[MAX_GAMEPADS][MAX_GAMEPAD_AXIS]; // Gamepad axis state

불러오는 중...
취소
저장