Skip to content

Commit 63965b3

Browse files
committed
start on sdl input
1 parent 3bf3412 commit 63965b3

File tree

5 files changed

+41
-1
lines changed

5 files changed

+41
-1
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "Encore/thirdparty/sdl"]
2+
path = Encore/thirdparty/sdl
3+
url = https://github.com/libsdl-org/SDL

Encore/CMakeLists.txt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,12 @@ if (NOT json_FOUND)
4141
FetchContent_MakeAvailable(json)
4242
endif()
4343
endif()
44+
4445
option(JSON_Diagnostics "" ON)
4546

4647
option(SUPPORT_FILEFORMAT_JPG "Support loading JPG as textures" ON)
48+
49+
add_subdirectory(thirdparty/sdl EXCLUDE_FROM_ALL)
4750
# Add all subdirectories of src
4851

4952
file(GLOB_RECURSE SRC_FILES "src/*.cpp" "include/*.cpp" "include/*.c")
@@ -77,6 +80,8 @@ if(WIN32)
7780
find_library(BASSOPUS NAMES bassopus PATHS "lib/bass/windows/x64/")
7881
file(COPY "lib/bass/windows/x64/bassopus.dll" DESTINATION ${CMAKE_BINARY_DIR}/Encore)
7982
endif()
83+
target_compile_definitions(${PROJECT_NAME} PRIVATE
84+
"-DGLFW_EXPOSE_NATIVE_WIN32")
8085
endif()
8186
if(UNIX AND NOT APPLE)
8287
if (CMAKE_SIZEOF_VOID_P EQUAL 8)
@@ -88,6 +93,10 @@ if(UNIX AND NOT APPLE)
8893
file(COPY "lib/bass/linux/x86_64/libbassopus.so" DESTINATION ${CMAKE_BINARY_DIR}/Encore)
8994
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath='$ORIGIN'")
9095
endif()
96+
target_compile_definitions(${PROJECT_NAME} PRIVATE
97+
"-DGLFW_EXPOSE_NATIVE_X11")
98+
target_compile_definitions(${PROJECT_NAME} PRIVATE
99+
"-DGLFW_EXPOSE_NATIVE_WAYLAND")
91100
endif()
92101
if(APPLE)
93102
find_library(DISCORD_GAME_SDK NAMES discord_game_sdk PATHS "lib/discord-rpc/macos")
@@ -135,5 +144,5 @@ set_property(TARGET Encore PROPERTY CXX_STANDARD 20)
135144

136145

137146

138-
target_link_libraries(Encore raylib nlohmann_json::nlohmann_json ${BASS} ${BASSOPUS} ${DISCORD_GAME_SDK})
147+
target_link_libraries(Encore raylib nlohmann_json::nlohmann_json ${BASS} ${BASSOPUS} ${DISCORD_GAME_SDK} SDL3::SDL3)
139148

Encore/src/gameplay/inputCallbacks.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ void keyCallback(GLFWwindow *wind, int key, int scancode, int action, int mods)
3636
TheMenuManager.ActiveMenu->KeyboardInputCallback(key, scancode, action, mods);
3737
}
3838

39+
void
40+
3941
void gamepadStateCallback(int joypadID, GLFWgamepadstate state) {
4042
//Encore::EncoreLog(
4143
// LOG_DEBUG,

Encore/src/main.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
#include <cassert>
1313

14+
#include "SDL3/SDL.h"
15+
1416
#include "settings/keybinds.h"
1517
#include "song/cacheload.h"
1618
#define assertm(exp, msg) assert((void(msg), exp))
@@ -253,6 +255,13 @@ int main(int argc, char *argv[]) {
253255
}
254256

255257

258+
SDL_SetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, "1");
259+
if (!SDL_Init(SDL_INIT_GAMEPAD | SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_EVENTS)) {
260+
SDL_Log("Unable to initialize SDL: %s", SDL_GetError());
261+
return 0;
262+
}
263+
Encore::EncoreLog(LOG_INFO, TextFormat("SDL Initialzed: revision %s", SDL_GetRevision()));
264+
256265
if (TheGameSettings.Framerate > 0)
257266
Encore::EncoreLog(
258267
LOG_INFO, TextFormat("Target FPS: %d", TheGameSettings.Framerate)
@@ -266,6 +275,22 @@ int main(int argc, char *argv[]) {
266275
glfwSwapInterval(TheGameSettings.VerticalSync ? 1 : 0);
267276
u.calcUnits();
268277

278+
279+
SDL_Event event;
280+
while (SDL_PollEvent(&event)) {
281+
Encore::EncoreLog(LOG_INFO, TextFormat("SDL event %i", event.type));
282+
switch (event.type) {
283+
case SDL_EVENT_GAMEPAD_ADDED:
284+
SDL_OpenGamepad(event.gdevice.which);
285+
break;
286+
case SDL_EVENT_GAMEPAD_BUTTON_DOWN:
287+
Encore::EncoreLog(LOG_INFO, TextFormat("SDL button press %i", event.gbutton.button));
288+
break;
289+
case SDL_EVENT_QUIT:
290+
return 0;
291+
}
292+
}
293+
269294
if (GetRenderWidth() < minWidth) {
270295
if (GetRenderHeight() < minHeight)
271296
SetWindowSize(minWidth, minHeight);

Encore/thirdparty/sdl

Submodule sdl added at 49a8b42

0 commit comments

Comments
 (0)