From 3e15b6dfd09df419bb256469587b52a4efc7a6f4 Mon Sep 17 00:00:00 2001 From: herbglitch Date: Thu, 8 Feb 2024 17:47:32 -0700 Subject: [PATCH] sdl2 now working again I think, but with better cmake --- CMakeLists.txt | 18 +++++++------ cmake/archeus_sdl2.cmake | 35 ++++++++++++++++++-------- include/arc/graphics/sdl/spritesheet.h | 4 +-- include/arc/graphics/sdl/text.h | 4 +-- include/arc/graphics/sdl/window.h | 4 +-- src/graphics/sdl/circle.c | 4 +-- src/graphics/sdl/config.c | 24 +++++++++--------- src/graphics/sdl/line.c | 4 +-- src/graphics/sdl/obround.c | 4 +-- src/graphics/sdl/rectangle.c | 4 +-- src/graphics/sdl/renderer.c | 4 +-- src/graphics/sdl/sprite.c | 4 +-- src/graphics/sdl/spritesheet.c | 5 ++-- src/graphics/sdl/text.c | 5 +++- src/graphics/sdl/view.c | 3 +++ src/graphics/sdl/window.c | 4 +-- 16 files changed, 78 insertions(+), 52 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c4f869a..dfe88b4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,6 +31,14 @@ set_property(CACHE ARCHEUS_STD_GRAPHICS_BACKEND PROPERTY STRINGS NONE SDL2 OPENG set(ARCHEUS_STD_FLAGS "") set(ARCHEUS_STD_LIBRARIES "") +set(ARCHEUS_STD_INCLUDE_DIRECTORIES + PUBLIC $ +) + +set(ARCHEUS_STD_LINK_LIBRARIES + PUBLIC m +) + # ~ ARCHEUS_SOURCES ~ # set(ARCHEUS_STD_SOURCES src/std/config.c @@ -71,7 +79,7 @@ none_check_and_init_needed(ARCHEUS_STD_FLAGS ARCHEUS_STD_SOURCES ${ARCHEUS_STD_W # ~ SDL2 ~ # include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/archeus_sdl2.cmake) -sdl2_check_and_init_needed(ARCHEUS_STD_FLAGS ARCHEUS_STD_SOURCES ${ARCHEUS_STD_WINDOW_BACKEND} ${ARCHEUS_STD_INPUT_BACKEND} ${ARCHEUS_STD_GRAPHICS_BACKEND}) +sdl2_check_and_init_needed(ARCHEUS_STD_FLAGS ARCHEUS_STD_SOURCES ARCHEUS_STD_INCLUDE_DIRECTORIES ARCHEUS_STD_LINK_LIBRARIES ${ARCHEUS_STD_WINDOW_BACKEND} ${ARCHEUS_STD_INPUT_BACKEND} ${ARCHEUS_STD_GRAPHICS_BACKEND}) # ~ OPENGL ~ # include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/archeus_opengl.cmake) @@ -93,13 +101,9 @@ else() add_library(archeus_std SHARED ${ARCHEUS_STD_SOURCES}) endif() -target_include_directories(archeus_std - PUBLIC $ -) +target_include_directories(archeus_std ${ARCHEUS_STD_INCLUDE_DIRECTORIES}) -target_link_libraries(archeus_std - PUBLIC m -) +target_link_libraries(archeus_std ${ARCHEUS_STD_LINK_LIBRARIES}) install(TARGETS archeus_std EXPORT archeus_std_Exports LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} diff --git a/cmake/archeus_sdl2.cmake b/cmake/archeus_sdl2.cmake index f5b076d..d530c9c 100644 --- a/cmake/archeus_sdl2.cmake +++ b/cmake/archeus_sdl2.cmake @@ -1,5 +1,6 @@ set(ARCHEUS_STD_SDL2_WINDOW_SOURCES src/graphics/sdl/window.c + src/graphics/sdl/renderer.c ) set(ARCHEUS_STD_SDL2_INPUT_SOURCES @@ -13,13 +14,12 @@ set(ARCHEUS_STD_SDL2_GRAPHICS_SOURCES src/graphics/sdl/line.c src/graphics/sdl/obround.c src/graphics/sdl/rectangle.c - src/graphics/sdl/renderer.c src/graphics/sdl/sprite.c src/graphics/sdl/spritesheet.c src/graphics/sdl/text.c ) -function(sdl2_check_and_init_needed ARCHEUS_STD_FLAGS ARCHEUS_STD_SOURCES ARCHEUS_STD_WINDOW_BACKEND ARCHEUS_STD_INPUT_BACKEND ARCHEUS_STD_GRAPHICS_BACKEND) +function(sdl2_check_and_init_needed _ARCHEUS_STD_FLAGS _ARCHEUS_STD_SOURCES _ARCHEUS_STD_INCLUDE_DIRECTORIES _ARCHEUS_STD_LINK_LIBRARIES ARCHEUS_STD_WINDOW_BACKEND ARCHEUS_STD_INPUT_BACKEND ARCHEUS_STD_GRAPHICS_BACKEND) #if no backend uses sdl return if(NOT ${ARCHEUS_STD_WINDOW_BACKEND} STREQUAL "SDL2" AND NOT ${ARCHEUS_STD_INPUT_BACKEND} STREQUAL "SDL2" AND NOT ${ARCHEUS_STD_GRAPHICS_BACKEND} STREQUAL "SDL2") return() @@ -28,6 +28,16 @@ function(sdl2_check_and_init_needed ARCHEUS_STD_FLAGS ARCHEUS_STD_SOURCES ARCHEU #get needed libraries for backends find_package(SDL2 REQUIRED) + #add to include directories + list(APPEND ${_ARCHEUS_STD_INCLUDE_DIRECTORIES} + PRIVATE ${SDL2_INCLUDE_DIRS} + ) + + #add to link libraries + list(APPEND ${_ARCHEUS_STD_LINK_LIBRARIES} + PUBLIC ${SDL2_LIBRARIES} + ) + #add matching files for the selected backends if(${ARCHEUS_STD_WINDOW_BACKEND} STREQUAL "SDL2") string(APPEND ${_ARCHEUS_STD_FLAGS} "-DARC_SDL2_WINDOW ") @@ -45,16 +55,21 @@ function(sdl2_check_and_init_needed ARCHEUS_STD_FLAGS ARCHEUS_STD_SOURCES ARCHEU string(APPEND ${_ARCHEUS_STD_FLAGS} "-DARC_SDL2_GRAPHICS ") list(APPEND ${_ARCHEUS_STD_SOURCES} ${ARCHEUS_STD_SDL2_GRAPHICS_SOURCES}) + + #add to include directories + list(APPEND ${_ARCHEUS_STD_INCLUDE_DIRECTORIES} + PRIVATE ${SDL2IMAGE_INCLUDE_DIRS} + ) + + #add to link libraries + list(APPEND ${_ARCHEUS_STD_LINK_LIBRARIES} + PUBLIC SDL2_image::SDL2_image + PUBLIC SDL2_ttf::SDL2_ttf + ) endif() set(${_ARCHEUS_STD_FLAGS} ${${_ARCHEUS_STD_FLAGS}} PARENT_SCOPE) set(${_ARCHEUS_STD_SOURCES} ${${_ARCHEUS_STD_SOURCES}} PARENT_SCOPE) - - - # target_include_directories(archeus_std - # PRIVATE ${SDL2_INCLUDE_DIRS} - # PRIVATE ${SDL2IMAGE_INCLUDE_DIRS} - # ) - - # target_link_libraries(archeus_std PUBLIC ${SDL2_LIBRARIES} SDL2_image::SDL2_image SDL2_ttf::SDL2_ttf) + set(${_ARCHEUS_STD_INCLUDE_DIRECTORIES} ${${_ARCHEUS_STD_INCLUDE_DIRECTORIES}} PARENT_SCOPE) + set(${_ARCHEUS_STD_LINK_LIBRARIES} ${${_ARCHEUS_STD_LINK_LIBRARIES}} PARENT_SCOPE) endfunction() \ No newline at end of file diff --git a/include/arc/graphics/sdl/spritesheet.h b/include/arc/graphics/sdl/spritesheet.h index eb8e449..dfbf6b1 100644 --- a/include/arc/graphics/sdl/spritesheet.h +++ b/include/arc/graphics/sdl/spritesheet.h @@ -1,7 +1,7 @@ #ifndef ARC_SDL_SPRITESHEET_H_ #define ARC_SDL_SPRITESHEET_H_ -#ifdef ARC_SDL +#ifdef ARC_SDL2_GRAPHICS #include "arc/graphics/spritesheet.h" #include @@ -10,6 +10,6 @@ struct ARC_Spritesheet { uint32_t *size; }; -#endif // !ARC_SDL +#endif // !ARC_SDL2_GRPAHCIS #endif // !ARC_SDL_SPRITESHEET_H_ diff --git a/include/arc/graphics/sdl/text.h b/include/arc/graphics/sdl/text.h index 6137f5e..37a6a5c 100644 --- a/include/arc/graphics/sdl/text.h +++ b/include/arc/graphics/sdl/text.h @@ -5,7 +5,7 @@ #include "arc/graphics/color.h" #include "arc/math/rectangle.h" -#ifdef ARC_SDL +#ifdef ARC_SDL2_GRAPHICS #include typedef struct ARC_Text { @@ -18,6 +18,6 @@ typedef struct ARC_Text { ARC_Rect bounds; } ARC_Text; -#endif // !ARC_SDL +#endif // !ARC_SDL2_Graphics #endif // !ARC_SDL_TEXT_H_ diff --git a/include/arc/graphics/sdl/window.h b/include/arc/graphics/sdl/window.h index 4afd1f6..dafe582 100644 --- a/include/arc/graphics/sdl/window.h +++ b/include/arc/graphics/sdl/window.h @@ -1,7 +1,7 @@ #ifndef ARC_SDL_WINDOW_H_ #define ARC_SDL_WINDOW_H_ -#ifdef ARC_SDL +#ifdef ARC_SDL2_GRAPHICS #include "arc/graphics/window.h" #include @@ -21,6 +21,6 @@ struct ARC_WindowInfo { Uint32 flags; }; -#endif // !ARC_SDL +#endif // !ARC_SDL2_GRAPHICS #endif // !ARC_SDL_WINDOW_H_ diff --git a/src/graphics/sdl/circle.c b/src/graphics/sdl/circle.c index 2472404..4df9741 100644 --- a/src/graphics/sdl/circle.c +++ b/src/graphics/sdl/circle.c @@ -1,4 +1,4 @@ -#ifdef ARC_SDL +#ifdef ARC_SDL2_GRAPHICS #include "arc/graphics/circle.h" #include "arc/graphics/sdl/renderer.h" #include @@ -49,4 +49,4 @@ void ARC_Circle_RenderFill(ARC_Circle *circle, ARC_Renderer *renderer, ARC_Color } } -#endif // ARC_SDL \ No newline at end of file +#endif // ARC_SDL2_GRAPHICS \ No newline at end of file diff --git a/src/graphics/sdl/config.c b/src/graphics/sdl/config.c index b92c5e7..633f013 100644 --- a/src/graphics/sdl/config.c +++ b/src/graphics/sdl/config.c @@ -1,4 +1,4 @@ -#ifdef ARC_SDL +#ifdef ARC_SDL2_GRAPHICS #include "arc/graphics/config.h" #include @@ -71,7 +71,7 @@ uint8_t ARC_SDL_Texture_Read(ARC_Config* config, ARC_String *string, void **valu } ARC_String *tempStr, *textureStr; - ARC_String_StripEndsWhitespace(string, &tempStr); + ARC_String_StripEndsWhitespace(&tempStr, string); ARC_String_CopySubstring(&textureStr, tempStr, 1, tempStr->length - 2); ARC_String_Destroy(tempStr); @@ -86,7 +86,7 @@ void ARC_Spritesheet_ReadTexture(ARC_Config *config, ARC_String *string, uint32_ SDL_Texture *texture; ARC_String *tempStr, *textureStr; - ARC_String_StripEndsWhitespace(string, &tempStr); + ARC_String_StripEndsWhitespace(&tempStr, string); //check for reference ARC_Config_Get(config, tempStr, (void **)&texture); @@ -125,11 +125,11 @@ uint8_t ARC_Spritesheet_Read(ARC_Config* config, ARC_String *string, void **valu ARC_String *temp, *textureStr, *sizeStr; ARC_String_CopySubstring(&temp, string, 1, split - 2); - ARC_String_StripEndsWhitespace(temp, &textureStr); + ARC_String_StripEndsWhitespace(&textureStr, temp); ARC_String_Destroy(temp); ARC_String_CopySubstring(&temp, string, split + 1, string->length - (split + 1)); - ARC_String_StripEndsWhitespace(temp, &sizeStr); + ARC_String_StripEndsWhitespace(&sizeStr, temp); ARC_String_Destroy(temp); uint32_t *size; @@ -169,11 +169,11 @@ uint8_t ARC_Sprite_Read(ARC_Config* config, ARC_String *string, void **value){ ARC_String *temp, *spritesheetStr, *framesStr; ARC_String_CopySubstring(&temp, string, 1, split - 2); - ARC_String_StripEndsWhitespace(temp, &spritesheetStr); + ARC_String_StripEndsWhitespace(&spritesheetStr, temp); ARC_String_Destroy(temp); ARC_String_CopySubstring(&temp, string, split + 1, string->length - (split + 2)); - ARC_String_StripEndsWhitespace(temp, &framesStr); + ARC_String_StripEndsWhitespace(&framesStr, temp); ARC_String_Destroy(temp); //spritesheet @@ -253,11 +253,11 @@ void ARC_Spritesheet_Delete(ARC_Config* config, ARC_String *string, void *value) //check if texture and size are references ARC_String *tempStr, *textureStr, *sizeStr; ARC_String_CopySubstring(&tempStr, string, 1, split - 1); - ARC_String_StripEndsWhitespace(tempStr, &textureStr); + ARC_String_StripEndsWhitespace(&textureStr, tempStr); ARC_String_Destroy(tempStr); ARC_String_CopySubstring(&tempStr, string, split + 1, string->length - (split + 1)); - ARC_String_StripEndsWhitespace(tempStr, &sizeStr); + ARC_String_StripEndsWhitespace(&sizeStr, tempStr); ARC_String_Destroy(tempStr); ARC_Config_Get(config, sizeStr, (void **)&temp); @@ -289,11 +289,11 @@ void ARC_Sprite_Delete(ARC_Config* config, ARC_String *string, void *value){ //check if texture and size are references ARC_String *tempStr, *spritesheetStr, *framesStr; ARC_String_CopySubstring(&tempStr, string, 1, split - 1); - ARC_String_StripEndsWhitespace(tempStr, &spritesheetStr); + ARC_String_StripEndsWhitespace(&spritesheetStr, tempStr); ARC_String_Destroy(tempStr); ARC_String_CopySubstring(&tempStr, string, split + 1, string->length - (split + 1)); - ARC_String_StripEndsWhitespace(tempStr, &framesStr); + ARC_String_StripEndsWhitespace(&framesStr, tempStr); ARC_String_Destroy(tempStr); ARC_Config_Get(config, spritesheetStr, (void **)&temp); @@ -311,4 +311,4 @@ void ARC_Sprite_Delete(ARC_Config* config, ARC_String *string, void *value){ free(spriteValue); } -#endif //ARC_SDL \ No newline at end of file +#endif //ARC_SDL2_GRAPHICS \ No newline at end of file diff --git a/src/graphics/sdl/line.c b/src/graphics/sdl/line.c index 4077768..e9a7ccf 100644 --- a/src/graphics/sdl/line.c +++ b/src/graphics/sdl/line.c @@ -1,4 +1,4 @@ -#ifdef ARC_SDL +#ifdef ARC_SDL2_GRAPHICS #include "arc/graphics/line.h" #include "arc/graphics/sdl/renderer.h" #include @@ -8,4 +8,4 @@ void ARC_Line_Render(int32_t *x1, int32_t *y1, int32_t *x2, int32_t *y2, ARC_Ren SDL_RenderDrawLine((SDL_Renderer *)renderer, *x1, *y1, *x2, *y2); } -#endif // ARC_SDL \ No newline at end of file +#endif // ARC_SDL2_GRAPHCIS \ No newline at end of file diff --git a/src/graphics/sdl/obround.c b/src/graphics/sdl/obround.c index 403c573..acabcca 100644 --- a/src/graphics/sdl/obround.c +++ b/src/graphics/sdl/obround.c @@ -1,4 +1,4 @@ -#ifdef ARC_SDL +#ifdef ARC_SDL2_GRAPHICS #include "arc/graphics/obround.h" #include "arc/graphics/sdl/renderer.h" #include @@ -48,4 +48,4 @@ void ARC_FObround_Render(ARC_FObround *obround, ARC_Renderer *renderer, ARC_Colo ARC_Obround_Render(&casted, renderer, color); } -#endif // ARC_SDL \ No newline at end of file +#endif // ARC_SDL2_GRAPHICS \ No newline at end of file diff --git a/src/graphics/sdl/rectangle.c b/src/graphics/sdl/rectangle.c index 636f4d9..2caedfb 100644 --- a/src/graphics/sdl/rectangle.c +++ b/src/graphics/sdl/rectangle.c @@ -1,4 +1,4 @@ -#ifdef ARC_SDL +#ifdef ARC_SDL2_GRAPHICS #include "arc/graphics/rectangle.h" #include "arc/graphics/sdl/renderer.h" #include @@ -23,4 +23,4 @@ void ARC_FRect_RenderFill(ARC_FRect *rect, ARC_Renderer *renderer, ARC_Color *co ARC_Rect_RenderFill(&casted, renderer, color); } -#endif // ARC_SDL \ No newline at end of file +#endif // ARC_SDL2_GRAPHICS \ No newline at end of file diff --git a/src/graphics/sdl/renderer.c b/src/graphics/sdl/renderer.c index 9c065c6..efe9935 100644 --- a/src/graphics/sdl/renderer.c +++ b/src/graphics/sdl/renderer.c @@ -1,4 +1,4 @@ -#ifdef ARC_SDL +#ifdef ARC_SDL2_WINDOW #include "arc/graphics/renderer.h" #include "arc/graphics/sdl/renderer.h" @@ -38,4 +38,4 @@ void ARC_Renderer_Render(ARC_Renderer *renderer){ SDL_RenderPresent((SDL_Renderer *)renderer); } -#endif //ARC_SDL +#endif //ARC_SDL2_WINDOW \ No newline at end of file diff --git a/src/graphics/sdl/sprite.c b/src/graphics/sdl/sprite.c index ace0d0f..d4ce2c4 100644 --- a/src/graphics/sdl/sprite.c +++ b/src/graphics/sdl/sprite.c @@ -1,4 +1,4 @@ -#ifdef ARC_SDL +#ifdef ARC_SDL2_GRAPHICS #include "arc/graphics/sprite.h" #include "arc/graphics/sdl/sprite.h" #include "arc/graphics/sdl/spritesheet.h" @@ -89,4 +89,4 @@ ARC_Array *ARC_Sprite_GetAllBounds(ARC_Sprite *sprite){ return sprite->frames; } -#endif // ARC_SDL \ No newline at end of file +#endif // ARC_SDL2_GRAPHICS \ No newline at end of file diff --git a/src/graphics/sdl/spritesheet.c b/src/graphics/sdl/spritesheet.c index 5f7d2a1..4d456c6 100644 --- a/src/graphics/sdl/spritesheet.c +++ b/src/graphics/sdl/spritesheet.c @@ -1,4 +1,4 @@ -#ifdef ARC_SDL +#ifdef ARC_SDL2_GRAPHICS #include "arc/graphics/spritesheet.h" #include "arc/graphics/sdl/spritesheet.h" #include "arc/graphics/sdl/renderer.h" @@ -18,4 +18,5 @@ ARC_Point ARC_Spritesheet_GetSize(ARC_Spritesheet *spritesheet){ uint32_t *ARC_Spritesheet_GetTileSize(ARC_Spritesheet *spritesheet){ return spritesheet->size; } -#endif //ARC_SDL \ No newline at end of file + +#endif //ARC_SDL2_GRAPHICS \ No newline at end of file diff --git a/src/graphics/sdl/text.c b/src/graphics/sdl/text.c index 9d65ed9..3a0af8d 100644 --- a/src/graphics/sdl/text.c +++ b/src/graphics/sdl/text.c @@ -1,3 +1,4 @@ +#ifdef ARC_SDL2_GRAPHICS #include "arc/graphics/text.h" #include "arc/graphics/sdl/text.h" #include "arc/graphics/color.h" @@ -53,4 +54,6 @@ void ARC_Text_Render(ARC_Text *text, ARC_Renderer *renderer){ void ARC_Text_SetPos(ARC_Text *text, ARC_Point pos){ text->bounds.x = pos.x; text->bounds.y = pos.y; -} \ No newline at end of file +} + +#endif //ARC_SDL2_GRAPHICS \ No newline at end of file diff --git a/src/graphics/sdl/view.c b/src/graphics/sdl/view.c index ffa9483..6ec006a 100644 --- a/src/graphics/sdl/view.c +++ b/src/graphics/sdl/view.c @@ -1,3 +1,4 @@ +#ifdef ARC_SDL2_GRAPHICS #include "arc/graphics/view.h" #include "arc/std/errno.h" @@ -33,3 +34,5 @@ void ARC_View_Render(ARC_View *view, ARC_View_RenderFn renderFn, void *data){ ARC_Rect ARC_View_GetBounds(ARC_View *view){ return view->bounds; } + +#endif //ARC_SDL2_GRAPHICS \ No newline at end of file diff --git a/src/graphics/sdl/window.c b/src/graphics/sdl/window.c index 7921a96..8ae05b9 100644 --- a/src/graphics/sdl/window.c +++ b/src/graphics/sdl/window.c @@ -1,4 +1,4 @@ -#ifdef ARC_SDL +#ifdef ARC_SDL2_WINDOW #include "arc/graphics/window.h" #include "arc/graphics/sdl/window.h" @@ -31,4 +31,4 @@ void ARC_Window_Destroy(ARC_Window *window){ SDL_DestroyWindow((SDL_Window *) window); } -#endif //ARC_SDL +#endif //ARC_SDL2_WINDOW \ No newline at end of file