use shared sdl

This commit is contained in:
2025-03-13 10:54:51 +02:00
parent ab18ed1d4a
commit 2c90324d18
5 changed files with 9 additions and 7 deletions

View File

@@ -10,3 +10,5 @@ add_subdirectory(hiisi)
add_executable(hiisi-run add_executable(hiisi-run
hiisi/main.cpp) hiisi/main.cpp)
target_link_libraries(hiisi-run)

View File

@@ -8,5 +8,4 @@ add_library(hiisi-engine SHARED
set_property(TARGET hiisi-engine PROPERTY POSITION_INDEPENDENT_CODE ON) set_property(TARGET hiisi-engine PROPERTY POSITION_INDEPENDENT_CODE ON)
set_property(TARGET hiisi-engine PROPERTY LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}) set_property(TARGET hiisi-engine PROPERTY LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR})
target_link_libraries(hiisi-engine PRIVATE target_link_libraries(hiisi-engine SDL3::SDL3-shared)
SDL3::SDL3)

View File

@@ -55,7 +55,7 @@ int iterate(EngineData *state)
const float scale = ((float) (((int) (now % 1000)) - 500) / 500.0f) * direction; const float scale = ((float) (((int) (now % 1000)) - 500) / 500.0f) * direction;
/* as you can see from this, rendering draws over whatever was drawn before it. */ /* as you can see from this, rendering draws over whatever was drawn before it. */
SDL_SetRenderDrawColor(renderer, 0, 50, 50, SDL_ALPHA_OPAQUE); /* black, full alpha */ SDL_SetRenderDrawColor(renderer, 0, 0, 0, SDL_ALPHA_OPAQUE); /* black, full alpha */
SDL_RenderClear(renderer); /* start with a blank canvas. */ SDL_RenderClear(renderer); /* start with a blank canvas. */
/* Rectangles are comprised of set of X and Y coordinates, plus width and /* Rectangles are comprised of set of X and Y coordinates, plus width and
@@ -84,7 +84,7 @@ int iterate(EngineData *state)
rects[0].y = 50; rects[0].y = 50;
rects[0].w = 100 + (100 * scale); rects[0].w = 100 + (100 * scale);
rects[0].h = 50 + (50 * scale); rects[0].h = 50 + (50 * scale);
SDL_SetRenderDrawColor(renderer, 0, 0, 255, SDL_ALPHA_OPAQUE); /* blue, full alpha */ SDL_SetRenderDrawColor(renderer, 0, 255, 255, SDL_ALPHA_OPAQUE); /* blue, full alpha */
SDL_RenderFillRect(renderer, &rects[0]); SDL_RenderFillRect(renderer, &rects[0]);

View File

@@ -18,7 +18,7 @@ void reload_signal_handler(int) {
Engine load_hiisi() { Engine load_hiisi() {
const char *name = "build/hiisi/libhiisi-engine.so"; const char *name = "build/hiisi/libhiisi-engine.so";
void *mod = dlopen(name, RTLD_NOW); void *mod = dlopen(name, RTLD_NOW|RTLD_GLOBAL);
Lmid_t list; Lmid_t list;
dlinfo(mod, RTLD_DI_LMID, &list); dlinfo(mod, RTLD_DI_LMID, &list);
@@ -104,9 +104,10 @@ int main(int argc, char **argv) {
while (hiisi.event(&state)) { while (hiisi.event(&state)) {
hiisi.iterate(&state); hiisi.iterate(&state);
if (reload_requested) { if (reload_requested) {
dlclose(hiisi.module); Engine oldEngine = hiisi;
hiisi = load_hiisi(); hiisi = load_hiisi();
reload_requested = false; reload_requested = false;
// dlclose(oldEngine.module);
} }
} }

View File

@@ -3,7 +3,7 @@
echo "Watching changes in hiisi..." echo "Watching changes in hiisi..."
while true; do while true; do
inotifywait -e modify build/hiisi/libhiisi-engine.so inotifywait -e modify build/hiisi/libhiisi-engine.so
echo "$(date \"%H:%M:%S\") - Hiisi changed!" echo "$(date +\"%H:%M:%S\") - Hiisi changed!"
HIISI_PID=$(pgrep -x hiisi-run) HIISI_PID=$(pgrep -x hiisi-run)
kill -USR1 "${HIISI_PID}" && echo "Signal sent!" || echo "Signal send failed!" kill -USR1 "${HIISI_PID}" && echo "Signal sent!" || echo "Signal send failed!"