Migrate to SDL3. Update imgui. Fork soloud for support of SDL3 static

This commit is contained in:
yaz0r 2025-04-15 23:23:35 -07:00
parent 5b9cee04b6
commit b305a4a44c
14 changed files with 60 additions and 81 deletions

2
.gitmodules vendored
View File

@ -6,7 +6,7 @@
url = https://github.com/ocornut/imgui.git url = https://github.com/ocornut/imgui.git
[submodule "ThirdParty/soloud"] [submodule "ThirdParty/soloud"]
path = ThirdParty/soloud.cmake/soloud path = ThirdParty/soloud.cmake/soloud
url = https://github.com/jarikomppa/soloud.git url = https://github.com/yaz0r/soloud.git
[submodule "ThirdParty/bgfx.cmake"] [submodule "ThirdParty/bgfx.cmake"]
path = ThirdParty/bgfx.cmake path = ThirdParty/bgfx.cmake
url = https://github.com/bkaradzic/bgfx.cmake.git url = https://github.com/bkaradzic/bgfx.cmake.git

View File

@ -10,7 +10,7 @@ add_subdirectory( ${THIRD_PARTY}/bgfx.cmake )
add_subdirectory( ${THIRD_PARTY}/soloud.cmake ) add_subdirectory( ${THIRD_PARTY}/soloud.cmake )
set(SDL_SHARED OFF CACHE BOOL "" FORCE) set(SDL_SHARED OFF CACHE BOOL "" FORCE)
set(LIBC ON CACHE BOOL "" FORCE) set(SDL_STATIC ON CACHE BOOL "" FORCE)
add_subdirectory( ${THIRD_PARTY}/SDL ) add_subdirectory( ${THIRD_PARTY}/SDL )
set(SKIP_INSTALL_ALL on) set(SKIP_INSTALL_ALL on)

View File

@ -36,7 +36,7 @@ set( CMAKE_EXE_LINKER_FLAGS_SHIPPING "${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO} /
add_executable (Fitd ${SOURCES}) add_executable (Fitd ${SOURCES})
TARGET_LINK_LIBRARIES(Fitd SDL2main SDL2-static soloud FitdLib bgfx zlibstatic ${EXTRA_LIBS}) TARGET_LINK_LIBRARIES(Fitd SDL3-static soloud FitdLib bgfx zlibstatic ${EXTRA_LIBS})
set_target_properties(Fitd PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/data/AITD1_CD") set_target_properties(Fitd PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/data/AITD1_CD")
set_target_properties(Fitd PROPERTIES WIN32_EXECUTABLE FALSE) set_target_properties(Fitd PROPERTIES WIN32_EXECUTABLE FALSE)

View File

@ -2,6 +2,7 @@ cmake_minimum_required(VERSION 3.9)
include_directories( include_directories(
"." "."
"${THIRD_PARTY}/SDL/include/SDL3"
"${THIRD_PARTY}/SDL/include" "${THIRD_PARTY}/SDL/include"
"${THIRD_PARTY}/imgui" "${THIRD_PARTY}/imgui"
"${THIRD_PARTY}/soloud.cmake/soloud/include" "${THIRD_PARTY}/soloud.cmake/soloud/include"
@ -32,7 +33,7 @@ set(SOURCES
"${THIRD_PARTY}/imgui/imgui_draw.cpp" "${THIRD_PARTY}/imgui/imgui_draw.cpp"
"${THIRD_PARTY}/imgui/imgui_tables.cpp" "${THIRD_PARTY}/imgui/imgui_tables.cpp"
"${THIRD_PARTY}/imgui/imgui_widgets.cpp" "${THIRD_PARTY}/imgui/imgui_widgets.cpp"
"${THIRD_PARTY}/imgui/backends/imgui_impl_sdl.cpp" "${THIRD_PARTY}/imgui/backends/imgui_impl_sdl3.cpp"
) )
function(assign_source_group) function(assign_source_group)

View File

@ -1,14 +1,16 @@
#include <SDL.h> #include <SDL.h>
#include <SDL_syswm.h>
#include <bgfx/bgfx.h> #include <bgfx/bgfx.h>
#include <bx/platform.h> #include <bx/platform.h>
#include <backends/imgui_impl_sdl.h> #include <backends/imgui_impl_sdl3.h>
#include "imguiBGFX.h" #include "imguiBGFX.h"
#include "SDL3/SDL.h"
#if BX_PLATFORM_OSX #if BX_PLATFORM_OSX
extern "C" { extern "C" {
void* cbSetupMetalLayer(void*); void* cbSetupMetalLayer(void*);
} }
#elif BX_PLATFORM_WINDOWS
#include <windows.h>
#endif #endif
@ -61,7 +63,7 @@ void StartFrame()
} }
// Pull the input from SDL2 instead // Pull the input from SDL2 instead
ImGui_ImplSDL2_NewFrame(gWindowBGFX); ImGui_ImplSDL3_NewFrame();
imguiBeginFrame(0, 0, 0, 0, outputResolution[0], outputResolution[1], -1); imguiBeginFrame(0, 0, 0, 0, outputResolution[0], outputResolution[1], -1);
if (ImGui::BeginMainMenuBar()) if (ImGui::BeginMainMenuBar())
@ -83,7 +85,7 @@ void StartFrame()
extern bool debuggerVar_debugMenuDisplayed; extern bool debuggerVar_debugMenuDisplayed;
void EndFrame() void EndFrame()
{ {
if (ImGui::GetIO().KeysDown[SDL_SCANCODE_GRAVE] && (ImGui::GetIO().KeysDownDuration[SDL_SCANCODE_GRAVE] == 0.f)) if (ImGui::IsKeyPressed(ImGuiKey_GraveAccent, false))
{ {
debuggerVar_debugMenuDisplayed = !debuggerVar_debugMenuDisplayed; debuggerVar_debugMenuDisplayed = !debuggerVar_debugMenuDisplayed;
} }
@ -95,7 +97,7 @@ void EndFrame()
else else
{ {
ImGui::Render(); ImGui::Render();
} }
bgfx::frame(); bgfx::frame();
{ {
@ -119,31 +121,31 @@ bgfx::Init initparam;
void createBgfxInitParams() void createBgfxInitParams()
{ {
SDL_SysWMinfo wmi; #if BX_PLATFORM_LINUX
SDL_VERSION(&wmi.version); if (SDL_strcmp(SDL_GetCurrentVideoDriver(), "x11") == 0)
if (!SDL_GetWindowWMInfo(gWindowBGFX, &wmi)) { {
return; initparam.platformData.ndt = (Display*)SDL_GetPointerProperty(SDL_GetWindowProperties(window), SDL_PROP_WINDOW_X11_DISPLAY_POINTER, NULL);
initparam.platformData.nwh = (Window)SDL_GetNumberProperty(SDL_GetWindowProperties(window), SDL_PROP_WINDOW_X11_WINDOW_NUMBER, 0);
}
else if (SDL_strcmp(SDL_GetCurrentVideoDriver(), "wayland") == 0)
{
/*struct wl_display *display*/ initparam.platformData.ndt = (struct wl_display*)SDL_GetPointerProperty(SDL_GetWindowProperties(window), SDL_PROP_WINDOW_WAYLAND_DISPLAY_POINTER, NULL);
/*struct wl_surface *surface*/ initparam.platformData.nwh = (struct wl_surface*)SDL_GetPointerProperty(SDL_GetWindowProperties(window), SDL_PROP_WINDOW_WAYLAND_SURFACE_POINTER, NULL);
} }
#if BX_PLATFORM_LINUX || BX_PLATFORM_BSD
initparam.platformData.ndt = wmi.info.x11.display;
initparam.platformData.nwh = (void*)(uintptr_t)wmi.info.x11.window;
#elif BX_PLATFORM_OSX #elif BX_PLATFORM_OSX
initparam.platformData.ndt = NULL; initparam.platformData.ndt = NULL;
initparam.platformData.nwh = cbSetupMetalLayer(wmi.info.cocoa.window); initparam.platformData.nwh = cbSetupMetalLayer(wmi.info.cocoa.window);
#elif BX_PLATFORM_WINDOWS #elif BX_PLATFORM_WINDOWS
initparam.platformData.ndt = NULL; initparam.platformData.ndt = NULL;
initparam.platformData.nwh = wmi.info.win.window; initparam.platformData.nwh = (HWND)SDL_GetPointerProperty(SDL_GetWindowProperties(gWindowBGFX), SDL_PROP_WINDOW_WIN32_HWND_POINTER, NULL);
#elif BX_PLATFORM_STEAMLINK
initparam.platformData.ndt = wmi.info.vivante.display;
initparam.platformData.nwh = wmi.info.vivante.window;
#endif // BX_PLATFORM_ #endif // BX_PLATFORM_
} }
int initBgfxGlue(int argc, char* argv[]) int initBgfxGlue(int argc, char* argv[])
{ {
createBgfxInitParams();
//initparam.type = bgfx::RendererType::OpenGL; //initparam.type = bgfx::RendererType::OpenGL;
//initparam.type = bgfx::RendererType::Vulkan; initparam.type = bgfx::RendererType::Vulkan;
bgfx::init(initparam); bgfx::init(initparam);
imguiCreate(); imguiCreate();
@ -152,11 +154,11 @@ int initBgfxGlue(int argc, char* argv[])
//io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; //io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable;
#if BX_PLATFORM_WINDOWS #if BX_PLATFORM_WINDOWS
ImGui_ImplSDL2_InitForD3D(gWindowBGFX); ImGui_ImplSDL3_InitForD3D(gWindowBGFX);
#elif BX_PLATFORM_OSX #elif BX_PLATFORM_OSX
ImGui_ImplSDL2_InitForMetal(gWindowBGFX); ImGui_ImplSDL3_InitForMetal(gWindowBGFX);
#else #else
ImGui_ImplSDL2_InitForVulkan(gWindowBGFX); ImGui_ImplSDL3_InitForVulkan(gWindowBGFX);
#endif #endif
return true; return true;

View File

@ -2,7 +2,6 @@
#include <SDL.h> #include <SDL.h>
void createBgfxInitParams();
int initBgfxGlue(int argc, char* argv[]); int initBgfxGlue(int argc, char* argv[]);
void deleteBgfxGlue(); void deleteBgfxGlue();

View File

@ -3,6 +3,10 @@
* License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause
*/ */
#ifndef IMGUI_DEFINE_MATH_OPERATORS
#define IMGUI_DEFINE_MATH_OPERATORS
#endif
#include <bgfx/bgfx.h> #include <bgfx/bgfx.h>
#include <bgfx/embedded_shader.h> #include <bgfx/embedded_shader.h>
#include <bx/allocator.h> #include <bx/allocator.h>
@ -18,9 +22,7 @@
//#include "ImGuizmo.h" //#include "ImGuizmo.h"
#ifndef IMGUI_DEFINE_MATH_OPERATORS
#define IMGUI_DEFINE_MATH_OPERATORS
#endif
#include <imgui_internal.h> #include <imgui_internal.h>
#include <../3rdparty/dear-imgui/widgets/dock.inl> #include <../3rdparty/dear-imgui/widgets/dock.inl>
//#include <../3rdparty/dear-imgui/widgets/gizmo.inl> //#include <../3rdparty/dear-imgui/widgets/gizmo.inl>

View File

@ -88,7 +88,7 @@ namespace ImGui
, const ImVec4& _tintCol = ImVec4(1.0f, 1.0f, 1.0f, 1.0f) , const ImVec4& _tintCol = ImVec4(1.0f, 1.0f, 1.0f, 1.0f)
) )
{ {
return ImageButton(toId(_handle, _flags, _mip), _size, _uv0, _uv1, _framePadding, _bgCol, _tintCol); return ImageButton("image", toId(_handle, _flags, _mip), _size, _uv0, _uv1, _bgCol, _tintCol);
} }
// Helper function for passing bgfx::TextureHandle to ImGui::ImageButton. // Helper function for passing bgfx::TextureHandle to ImGui::ImageButton.

View File

@ -1,5 +1,6 @@
#include "common.h" #include "common.h"
#include <SDL.h> #include <SDL.h>
#include <backends/imgui_impl_sdl3.h>
extern float nearVal; extern float nearVal;
extern float farVal; extern float farVal;
@ -10,7 +11,7 @@ extern bool debuggerVar_debugMenuDisplayed;
void handleKeyDown(SDL_Event& event) void handleKeyDown(SDL_Event& event)
{ {
switch (event.key.keysym.scancode) switch (event.key.key)
{ {
case SDL_SCANCODE_GRAVE: case SDL_SCANCODE_GRAVE:
debuggerVar_debugMenuDisplayed ^= 1; debuggerVar_debugMenuDisplayed ^= 1;
@ -23,7 +24,7 @@ void readKeyboard(void)
SDL_Event event; SDL_Event event;
int size; int size;
int j; int j;
const unsigned char *keyboard; const bool *keyboard;
JoyD = 0; JoyD = 0;
Click = 0; Click = 0;
@ -31,11 +32,13 @@ void readKeyboard(void)
while (SDL_PollEvent(&event)) { while (SDL_PollEvent(&event)) {
ImGui_ImplSDL3_ProcessEvent(&event);
switch (event.type) { switch (event.type) {
case SDL_KEYDOWN: case SDL_EVENT_KEY_DOWN:
handleKeyDown(event); handleKeyDown(event);
break; break;
case SDL_QUIT: case SDL_EVENT_QUIT:
cleanupAndExit(); cleanupAndExit();
break; break;
} }

View File

@ -20,9 +20,10 @@ email : yaz0r@yaz0r.net
#include "bgfxGlue.h" #include "bgfxGlue.h"
#include <SDL.h> #include <SDL.h>
#include <SDL_thread.h> #include <SDL_thread.h>
#include <SDL_mutex.h>
#include "osystem.h" #include "osystem.h"
#include "osystemAL.h" #include "osystemAL.h"
#include <backends/imgui_impl_sdl.h> #include <backends/imgui_impl_sdl3.h>
void detectGame(void); void detectGame(void);
void renderGameWindow(); void renderGameWindow();
@ -75,8 +76,8 @@ extern "C" {
int FitdMain(void* unkused); int FitdMain(void* unkused);
} }
SDL_semaphore* startOfRender = NULL; SDL_Semaphore* startOfRender = NULL;
SDL_semaphore* endOfRender = NULL; SDL_Semaphore* endOfRender = NULL;
//SDL_sem* emptyCount = NULL; //SDL_sem* emptyCount = NULL;
//SDL_sem* fullCount = NULL; //SDL_sem* fullCount = NULL;
@ -93,14 +94,9 @@ int FitdInit(int argc, char* argv[])
osystem_init(); osystem_init();
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_JOYSTICK) != 0)
{
assert(false);
}
unsigned int flags = 0; unsigned int flags = 0;
flags |= SDL_WINDOW_RESIZABLE; flags |= SDL_WINDOW_RESIZABLE;
flags |= SDL_WINDOW_ALLOW_HIGHDPI; //flags |= SDL_WINDOW_ALLOW_HIGHDPI;
#ifdef __IPHONEOS__ #ifdef __IPHONEOS__
flags |= SDL_WINDOW_FULLSCREEN; flags |= SDL_WINDOW_FULLSCREEN;
@ -111,7 +107,7 @@ int FitdInit(int argc, char* argv[])
int scale = 4; int scale = 4;
int resolution[2] = { 320 * scale, 240 * scale }; int resolution[2] = { 320 * scale, 240 * scale };
gWindowBGFX = SDL_CreateWindow("FITD", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, resolution[0], resolution[1], flags); gWindowBGFX = SDL_CreateWindow("FITD", resolution[0], resolution[1], flags);
char version[256]; char version[256];
@ -120,9 +116,7 @@ int FitdInit(int argc, char* argv[])
printf(version); printf(version);
detectGame(); detectGame();
createBgfxInitParams();
SDL_CreateThread(FitdMain, "FitdMainThread", NULL); SDL_CreateThread(FitdMain, "FitdMainThread", NULL);
unsigned long int t_start = SDL_GetTicks(); unsigned long int t_start = SDL_GetTicks();
@ -159,8 +153,6 @@ int FitdInit(int argc, char* argv[])
t_lastUpdate = t_sinceStart; t_lastUpdate = t_sinceStart;
} }
readKeyboard();
osystemAL_udpate(); osystemAL_udpate();
SDL_PumpEvents(); SDL_PumpEvents();
@ -170,28 +162,15 @@ int FitdInit(int argc, char* argv[])
// Don't process events on first frame to avoid race condition with the init code // Don't process events on first frame to avoid race condition with the init code
if(!bFirstFrame) if(!bFirstFrame)
{ {
SDL_Event event; readKeyboard();
while (SDL_PollEvent(&event))
{
ImGui_ImplSDL2_ProcessEvent(&event);
switch (event.type)
{
case SDL_QUIT:
gCloseApp = true;
break;
default:
break;
}
}
} }
else { else {
bFirstFrame = false; bFirstFrame = false;
} }
SDL_SemPost(startOfRender); SDL_SignalSemaphore(startOfRender);
SDL_SemWait(endOfRender); SDL_WaitSemaphore(endOfRender);
//SDL_RenderPresent(SDL_GetRenderer(gWindowBGFX)); //SDL_RenderPresent(SDL_GetRenderer(gWindowBGFX));
} }
@ -205,7 +184,7 @@ u32 lastFrameTime = 0;
u32 osystem_startOfFrame() u32 osystem_startOfFrame()
{ {
SDL_SemWait(startOfRender); SDL_WaitSemaphore(startOfRender);
StartFrame(); StartFrame();
osystem_startFrame(); osystem_startFrame();
@ -257,7 +236,7 @@ void osystem_endOfFrame()
if (bFirst) if (bFirst)
bFirst = false; bFirst = false;
SDL_SemPost(endOfRender); SDL_SignalSemaphore(endOfRender);
//SDL_SemPost(emptyCount); //SDL_SemPost(emptyCount);
} }
@ -279,10 +258,7 @@ int fileExists(const char* name)
void osystem_init() // that's the constructor of the system dependent void osystem_init() // that's the constructor of the system dependent
// object used for the SDL port // object used for the SDL port
{ {
const unsigned char *keyboard; if (SDL_Init(SDL_INIT_VIDEO) < 0)
int size;
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) < 0)
{ {
fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError()); fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
assert(0); assert(0);
@ -294,10 +270,6 @@ void osystem_init() // that's the constructor of the system dependent
SDL_PumpEvents(); SDL_PumpEvents();
keyboard = SDL_GetKeyboardState(&size);
//keyboard[SDLK_RETURN] = 0;
int screen_width = 800; int screen_width = 800;
int screen_height = 600; int screen_height = 600;

2
ThirdParty/SDL vendored

@ -1 +1 @@
Subproject commit 4f7f72c257165ecd30654f80d8b45fcc02d608da Subproject commit 877399b2b2cf21e67554ed9046410f268ce1d1b2

2
ThirdParty/imgui vendored

@ -1 +1 @@
Subproject commit 14466a6d19ca97f4dcf07688ebe4411aeb51958a Subproject commit f5befd2d29e66809cd1110a152e375a7f1981f06

View File

@ -15,11 +15,11 @@ file(GLOB_RECURSE SOLOUD_HEADERS ${soloud_SOURCE_DIR}/soloud/include/*.h)
file(GLOB_RECURSE SOLOUD_SOURCES file(GLOB_RECURSE SOLOUD_SOURCES
${soloud_SOURCE_DIR}/soloud/src/core/*.cpp ${soloud_SOURCE_DIR}/soloud/src/core/*.cpp
${soloud_SOURCE_DIR}/soloud/src/audiosource/wav/*.c* ${soloud_SOURCE_DIR}/soloud/src/audiosource/wav/*.c*
${soloud_SOURCE_DIR}/soloud/src/backend/sdl2_static/*.cpp ${soloud_SOURCE_DIR}/soloud/src/backend/sdl3_static/*.cpp
${soloud_SOURCE_DIR}/soloud/src/backend/null/*.cpp ${soloud_SOURCE_DIR}/soloud/src/backend/null/*.cpp
) )
include_directories(${soloud_SOURCE_DIR}/soloud/include "${THIRD_PARTY}/SDL/include") include_directories(${soloud_SOURCE_DIR}/soloud/include "${THIRD_PARTY}/SDL/include" "${THIRD_PARTY}/SDL/include/SDL3")
set(SOLOUD_SOURCES set(SOLOUD_SOURCES
${SOLOUD_HEADERS} ${SOLOUD_HEADERS}
@ -32,5 +32,5 @@ set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
IF(${CMAKE_SYSTEM_NAME} STREQUAL watchOS) IF(${CMAKE_SYSTEM_NAME} STREQUAL watchOS)
target_compile_definitions(${SOLOUD_LIB_NAME} PRIVATE WITH_NULL=1) target_compile_definitions(${SOLOUD_LIB_NAME} PRIVATE WITH_NULL=1)
ELSE() ELSE()
target_compile_definitions(${SOLOUD_LIB_NAME} PRIVATE WITH_SDL2_STATIC=1) target_compile_definitions(${SOLOUD_LIB_NAME} PRIVATE WITH_SDL3_STATIC=1)
ENDIF() ENDIF()

@ -1 +1 @@
Subproject commit b3468d366ed9342cfa731475d267d1e2e7a3e81e Subproject commit 467259ef305251b43b26ad91229189f659240c91