Skip to content

Commit

Permalink
Load SDL2 symbols at runtime
Browse files Browse the repository at this point in the history
Instead of trying to link SDL2 portably at compile time, which requires
the help of CMake and leads to a bunch of ugly #ifdef gunk, we now look
for a shared library at runtime, and load only the symbols we actually
need.
A mostly gutted set of SDL headers is included, purely to provide a few
types for more ergonomic use of the SDL2 API. This bloats the source
tree by about ~160K unfortunately.
  • Loading branch information
vkoskiv committed Oct 28, 2023
1 parent 3f2fb22 commit 7654115
Show file tree
Hide file tree
Showing 22 changed files with 3,693 additions and 286 deletions.
16 changes: 0 additions & 16 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -95,22 +95,6 @@ if (NO_LOGO)
target_compile_definitions(c-ray PRIVATE -DNO_LOGO)
endif()

if (NOT NO_SDL2)
find_package(SDL2 QUIET)

if (SDL2_FOUND)
message(STATUS "SDL2 found! Enabling UI components.")
target_link_libraries(c-ray PRIVATE ${SDL2_LIBRARY})
target_include_directories(c-ray PRIVATE ${SDL2_INCLUDE_DIR})
target_compile_definitions(c-ray PRIVATE -DCRAY_SDL_ENABLED)
else()
message(STATUS "SDL2 not found! You should install it, it'll be awesome! See README for instructions.")
endif()
else()
message(STATUS "SDL2 explicitly disabled, disabling UI components")
unset(NO_SDL2 CACHE)
endif()

if (TESTING)
message(STATUS "Enabling test suite.")
target_compile_definitions(c-ray PRIVATE -DCRAY_TESTING)
Expand Down
172 changes: 0 additions & 172 deletions cmake/FindSDL2.cmake

This file was deleted.

2 changes: 1 addition & 1 deletion src/renderer/renderer.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ struct texture *renderFrame(struct renderer *r) {

//Gather and maintain this average constantly.
if (!r->state.threadStates[0].paused) {
win_update(r->sdl, r, output);
if (r->sdl) win_update(r->sdl, r, output);
for (int t = 0; t < localThreadCount; ++t) {
avgSampleTime += r->state.threadStates[t].avgSampleTime;
}
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ struct renderer {
struct state state; //Internal state
struct prefs prefs; //User prefs
char *sceneCache; //Packed scene data that can be passed to workers
struct window *sdl; //FIXME: Temporarily here, I guess.
struct sdl_window *sdl; //FIXME: Temporarily here
};

//Initialize a new renderer
Expand Down
Loading

0 comments on commit 7654115

Please sign in to comment.