mirror of
https://github.com/raysan5/raylib.git
synced 2025-09-27 05:28:30 +00:00
Merge branch 'master' of https://github.com/raysan5/raylib
This commit is contained in:
@@ -7,6 +7,8 @@ if(POLICY CMP0072)
|
|||||||
cmake_policy(SET CMP0072 NEW)
|
cmake_policy(SET CMP0072 NEW)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
set(RAYLIB_DEPENDENCIES "include(CMakeFindDependencyMacro)")
|
||||||
|
|
||||||
if (${PLATFORM} MATCHES "Desktop")
|
if (${PLATFORM} MATCHES "Desktop")
|
||||||
set(PLATFORM_CPP "PLATFORM_DESKTOP")
|
set(PLATFORM_CPP "PLATFORM_DESKTOP")
|
||||||
|
|
||||||
@@ -120,15 +122,17 @@ elseif ("${PLATFORM}" MATCHES "SDL")
|
|||||||
find_package(SDL3 QUIET)
|
find_package(SDL3 QUIET)
|
||||||
if(SDL3_FOUND)
|
if(SDL3_FOUND)
|
||||||
message(STATUS "Found SDL3 via find_package()")
|
message(STATUS "Found SDL3 via find_package()")
|
||||||
|
set(LIBS_PUBLIC SDL3::SDL3)
|
||||||
|
set(RAYLIB_DEPENDENCIES "${RAYLIB_DEPENDENCIES}\nfind_dependency(SDL3 REQUIRED)")
|
||||||
set(PLATFORM_CPP "PLATFORM_DESKTOP_SDL")
|
set(PLATFORM_CPP "PLATFORM_DESKTOP_SDL")
|
||||||
set(LIBS_PRIVATE SDL3::SDL3)
|
|
||||||
add_compile_definitions(USING_SDL3_PACKAGE)
|
add_compile_definitions(USING_SDL3_PACKAGE)
|
||||||
else()
|
else()
|
||||||
# Fallback to SDL2
|
# Fallback to SDL2
|
||||||
find_package(SDL2 REQUIRED)
|
find_package(SDL2 REQUIRED)
|
||||||
message(STATUS "Found SDL2 via find_package()")
|
message(STATUS "Found SDL2 via find_package()")
|
||||||
set(PLATFORM_CPP "PLATFORM_DESKTOP_SDL")
|
set(PLATFORM_CPP "PLATFORM_DESKTOP_SDL")
|
||||||
set(LIBS_PRIVATE SDL2::SDL2)
|
set(LIBS_PUBLIC SDL2::SDL2)
|
||||||
|
set(RAYLIB_DEPENDENCIES "${RAYLIB_DEPENDENCIES}\nfind_dependency(SDL3 REQUIRED)")
|
||||||
add_compile_definitions(USING_SDL2_PACKAGE)
|
add_compile_definitions(USING_SDL2_PACKAGE)
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
@@ -1,2 +1,4 @@
|
|||||||
@PACKAGE_INIT@
|
@PACKAGE_INIT@
|
||||||
|
@RAYLIB_DEPENDENCIES@
|
||||||
|
|
||||||
include("${CMAKE_CURRENT_LIST_DIR}/raylib-targets.cmake")
|
include("${CMAKE_CURRENT_LIST_DIR}/raylib-targets.cmake")
|
||||||
|
@@ -92,6 +92,7 @@ if (BUILD_SHARED_LIBS)
|
|||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
target_link_libraries(raylib PRIVATE $<BUILD_INTERFACE:${LIBS_PRIVATE}>)
|
target_link_libraries(raylib PRIVATE $<BUILD_INTERFACE:${LIBS_PRIVATE}>)
|
||||||
|
target_link_libraries(raylib PUBLIC ${LIBS_PUBLIC})
|
||||||
|
|
||||||
# Sets some compile time definitions for the pre-processor
|
# Sets some compile time definitions for the pre-processor
|
||||||
# If CUSTOMIZE_BUILD option is on you will not use config.h by default
|
# If CUSTOMIZE_BUILD option is on you will not use config.h by default
|
||||||
|
@@ -98,7 +98,7 @@ typedef struct {
|
|||||||
SDL_GLContext glContext;
|
SDL_GLContext glContext;
|
||||||
|
|
||||||
SDL_GameController *gamepad[MAX_GAMEPADS];
|
SDL_GameController *gamepad[MAX_GAMEPADS];
|
||||||
SDL_JoystickID gamepadId[MAX_GAMEPADS]; // Joystick instance ids
|
SDL_JoystickID gamepadId[MAX_GAMEPADS]; // Joystick instance ids, they do not start from 0
|
||||||
SDL_Cursor *cursor;
|
SDL_Cursor *cursor;
|
||||||
bool cursorRelative;
|
bool cursorRelative;
|
||||||
} PlatformData;
|
} PlatformData;
|
||||||
@@ -1706,19 +1706,34 @@ void PollInputEvents(void)
|
|||||||
{
|
{
|
||||||
int jid = event.jdevice.which; // Joystick device index
|
int jid = event.jdevice.which; // Joystick device index
|
||||||
|
|
||||||
if (CORE.Input.Gamepad.ready[jid] && (jid < MAX_GAMEPADS))
|
// check if already added at InitPlatform
|
||||||
|
for (int i = 0; i < MAX_GAMEPADS; ++i)
|
||||||
{
|
{
|
||||||
platform.gamepad[jid] = SDL_GameControllerOpen(jid);
|
if (jid == platform.gamepadId[i])
|
||||||
platform.gamepadId[jid] = SDL_JoystickInstanceID(SDL_GameControllerGetJoystick(platform.gamepad[jid]));
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (platform.gamepad[jid])
|
int nextAvailableSlot = 0;
|
||||||
|
while (nextAvailableSlot < MAX_GAMEPADS && CORE.Input.Gamepad.ready[nextAvailableSlot])
|
||||||
{
|
{
|
||||||
CORE.Input.Gamepad.ready[jid] = true;
|
++nextAvailableSlot;
|
||||||
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_RIGHT_TRIGGER] = -1.0f;
|
if ((nextAvailableSlot < MAX_GAMEPADS) && !CORE.Input.Gamepad.ready[nextAvailableSlot])
|
||||||
memset(CORE.Input.Gamepad.name[jid], 0, MAX_GAMEPAD_NAME_LENGTH);
|
{
|
||||||
strncpy(CORE.Input.Gamepad.name[jid], SDL_GameControllerNameForIndex(jid), MAX_GAMEPAD_NAME_LENGTH - 1);
|
platform.gamepad[nextAvailableSlot] = SDL_GameControllerOpen(jid);
|
||||||
|
platform.gamepadId[nextAvailableSlot] = SDL_JoystickInstanceID(SDL_GameControllerGetJoystick(platform.gamepad[nextAvailableSlot]));
|
||||||
|
|
||||||
|
if (platform.gamepad[nextAvailableSlot])
|
||||||
|
{
|
||||||
|
CORE.Input.Gamepad.ready[nextAvailableSlot] = true;
|
||||||
|
CORE.Input.Gamepad.axisCount[nextAvailableSlot] = SDL_JoystickNumAxes(SDL_GameControllerGetJoystick(platform.gamepad[nextAvailableSlot]));
|
||||||
|
CORE.Input.Gamepad.axisState[nextAvailableSlot][GAMEPAD_AXIS_LEFT_TRIGGER] = -1.0f;
|
||||||
|
CORE.Input.Gamepad.axisState[nextAvailableSlot][GAMEPAD_AXIS_RIGHT_TRIGGER] = -1.0f;
|
||||||
|
memset(CORE.Input.Gamepad.name[nextAvailableSlot], 0, MAX_GAMEPAD_NAME_LENGTH);
|
||||||
|
strncpy(CORE.Input.Gamepad.name[nextAvailableSlot], SDL_GameControllerNameForIndex(nextAvailableSlot), MAX_GAMEPAD_NAME_LENGTH - 1);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -1746,7 +1761,7 @@ void PollInputEvents(void)
|
|||||||
{
|
{
|
||||||
int button = -1;
|
int button = -1;
|
||||||
|
|
||||||
switch (event.jbutton.button)
|
switch (event.gbutton.button)
|
||||||
{
|
{
|
||||||
case SDL_CONTROLLER_BUTTON_Y: button = GAMEPAD_BUTTON_RIGHT_FACE_UP; break;
|
case SDL_CONTROLLER_BUTTON_Y: button = GAMEPAD_BUTTON_RIGHT_FACE_UP; break;
|
||||||
case SDL_CONTROLLER_BUTTON_B: button = GAMEPAD_BUTTON_RIGHT_FACE_RIGHT; break;
|
case SDL_CONTROLLER_BUTTON_B: button = GAMEPAD_BUTTON_RIGHT_FACE_RIGHT; break;
|
||||||
@@ -1774,7 +1789,7 @@ void PollInputEvents(void)
|
|||||||
{
|
{
|
||||||
for (int i = 0; i < MAX_GAMEPADS; i++)
|
for (int i = 0; i < MAX_GAMEPADS; i++)
|
||||||
{
|
{
|
||||||
if (platform.gamepadId[i] == event.jbutton.which)
|
if (platform.gamepadId[i] == event.gbutton.which)
|
||||||
{
|
{
|
||||||
CORE.Input.Gamepad.currentButtonState[i][button] = 1;
|
CORE.Input.Gamepad.currentButtonState[i][button] = 1;
|
||||||
CORE.Input.Gamepad.lastButtonPressed = button;
|
CORE.Input.Gamepad.lastButtonPressed = button;
|
||||||
@@ -1787,7 +1802,7 @@ void PollInputEvents(void)
|
|||||||
{
|
{
|
||||||
int button = -1;
|
int button = -1;
|
||||||
|
|
||||||
switch (event.jbutton.button)
|
switch (event.gbutton.button)
|
||||||
{
|
{
|
||||||
case SDL_CONTROLLER_BUTTON_Y: button = GAMEPAD_BUTTON_RIGHT_FACE_UP; break;
|
case SDL_CONTROLLER_BUTTON_Y: button = GAMEPAD_BUTTON_RIGHT_FACE_UP; break;
|
||||||
case SDL_CONTROLLER_BUTTON_B: button = GAMEPAD_BUTTON_RIGHT_FACE_RIGHT; break;
|
case SDL_CONTROLLER_BUTTON_B: button = GAMEPAD_BUTTON_RIGHT_FACE_RIGHT; break;
|
||||||
@@ -1815,7 +1830,7 @@ void PollInputEvents(void)
|
|||||||
{
|
{
|
||||||
for (int i = 0; i < MAX_GAMEPADS; i++)
|
for (int i = 0; i < MAX_GAMEPADS; i++)
|
||||||
{
|
{
|
||||||
if (platform.gamepadId[i] == event.jbutton.which)
|
if (platform.gamepadId[i] == event.gbutton.which)
|
||||||
{
|
{
|
||||||
CORE.Input.Gamepad.currentButtonState[i][button] = 0;
|
CORE.Input.Gamepad.currentButtonState[i][button] = 0;
|
||||||
if (CORE.Input.Gamepad.lastButtonPressed == button) CORE.Input.Gamepad.lastButtonPressed = 0;
|
if (CORE.Input.Gamepad.lastButtonPressed == button) CORE.Input.Gamepad.lastButtonPressed = 0;
|
||||||
@@ -2044,9 +2059,14 @@ int InitPlatform(void)
|
|||||||
platform.gamepadId[i] = -1; // Set all gamepad initial instance ids as invalid to not conflict with instance id zero
|
platform.gamepadId[i] = -1; // Set all gamepad initial instance ids as invalid to not conflict with instance id zero
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; (i < SDL_NumJoysticks()) && (i < MAX_GAMEPADS); i++)
|
int numJoysticks = 0;
|
||||||
|
SDL_JoystickID *joysticks = SDL_GetJoysticks(&numJoysticks); // array of joystick IDs, they do not start from 0
|
||||||
|
|
||||||
|
if (joysticks)
|
||||||
{
|
{
|
||||||
platform.gamepad[i] = SDL_GameControllerOpen(i);
|
for (int i = 0; (i < numJoysticks) && (i < MAX_GAMEPADS); i++)
|
||||||
|
{
|
||||||
|
platform.gamepad[i] = SDL_GameControllerOpen(joysticks[i]);
|
||||||
platform.gamepadId[i] = SDL_JoystickInstanceID(SDL_GameControllerGetJoystick(platform.gamepad[i]));
|
platform.gamepadId[i] = SDL_JoystickInstanceID(SDL_GameControllerGetJoystick(platform.gamepad[i]));
|
||||||
|
|
||||||
if (platform.gamepad[i])
|
if (platform.gamepad[i])
|
||||||
@@ -2060,6 +2080,8 @@ int InitPlatform(void)
|
|||||||
}
|
}
|
||||||
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());
|
||||||
}
|
}
|
||||||
|
SDL_free(joysticks);
|
||||||
|
}
|
||||||
|
|
||||||
// Disable mouse events being interpreted as touch events
|
// Disable mouse events being interpreted as touch events
|
||||||
// NOTE: This is wanted because there are SDL_FINGER* events available which provide unique data
|
// NOTE: This is wanted because there are SDL_FINGER* events available which provide unique data
|
||||||
|
Reference in New Issue
Block a user