Fix leak, rename and some non working mingw shit

This commit is contained in:
Marc
2023-01-22 22:53:16 +01:00
parent 9f0a8a2692
commit ade88dff84
5 changed files with 30 additions and 8 deletions
+15 -4
View File
@@ -8,15 +8,22 @@ if(CMAKE_BUILD_TYPE MATCHES DEBUG)
add_link_options(-fsanitize=address) add_link_options(-fsanitize=address)
endif() endif()
if(MINGW)
set(CMAKE_C_FLAGS "-Wno-undef --static -windows")
set(CMAKE_C_FLAGS_DEBUG "-g -O0")
set(CMAKE_C_FLAGS_RELEASE "-O2")
else()
set(CMAKE_C_FLAGS "-Wall -Wextra -pedantic -Wcast-qual -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wmaybe-uninitialized -Wno-unused-variable") set(CMAKE_C_FLAGS "-Wall -Wextra -pedantic -Wcast-qual -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wmaybe-uninitialized -Wno-unused-variable")
set(CMAKE_C_FLAGS_DEBUG "-g -Werror -O0") set(CMAKE_C_FLAGS_DEBUG "-g -Werror -O0")
set(CMAKE_C_FLAGS_RELEASE "") set(CMAKE_C_FLAGS_RELEASE "")
endif()
# generate the compile_commands for vscode / clang # generate the compile_commands for vscode / clang
set(CMAKE_EXPORT_COMPILE_COMMANDS ON CACHE INTERNAL "") set(CMAKE_EXPORT_COMPILE_COMMANDS ON CACHE INTERNAL "")
# set the project name # set the project name
project(FLOPPE_FION) project(LEGEND_OF_ADAME)
set(SRC set(SRC
@@ -32,13 +39,17 @@ set(SRC
) )
# add the executable # add the executable
add_executable(FLOPPE_FION ${SRC}) add_executable(LEGEND_OF_ADAME ${SRC})
target_link_libraries(FLOPPE_FION SDL2 SDL2_image SDL2_ttf SDL2_mixer m) target_link_libraries(LEGEND_OF_ADAME SDL2 SDL2_image SDL2_ttf SDL2_mixer m)
set_property(TARGET FLOPPE_FION PROPERTY C_STANDARD 23) set_property(TARGET LEGEND_OF_ADAME PROPERTY C_STANDARD 23)
file(COPY assets DESTINATION ${CMAKE_BINARY_DIR}) file(COPY assets DESTINATION ${CMAKE_BINARY_DIR})
if(MINGW)
target_link_libraries(LEGEND_OF_ADAME ws2_32 windows mingw32 SDLmain SDL)
endif()
+3 -1
View File
@@ -102,7 +102,7 @@ static void playMusic(){
exit(1); exit(1);
} }
if(Mix_PlayMusic(music, 0) != 0){ if(Mix_PlayMusic(music, -1) != 0){
printf("Music sound could not be played!\n" printf("Music sound could not be played!\n"
"SDL_Error: %s\n", Mix_GetError()); "SDL_Error: %s\n", Mix_GetError());
Mix_FreeMusic(music); Mix_FreeMusic(music);
@@ -124,6 +124,7 @@ int game_staticRender(void){
return -1; return -1;
} }
SDL_Surface* gameBackgroundSurface2 = IMG_Load("./assets/img/game_bg.png");
RenderObject_t gameBackground = EMPTY_RENDER_OBJECT; RenderObject_t gameBackground = EMPTY_RENDER_OBJECT;
strcpy(gameBackground.name, "gameBackground"); strcpy(gameBackground.name, "gameBackground");
@@ -132,6 +133,7 @@ int game_staticRender(void){
scaller(gameBackground.surface, 1, &gameBackground.width, &gameBackground.height); scaller(gameBackground.surface, 1, &gameBackground.width, &gameBackground.height);
gameBackground.height = 1; gameBackground.height = 1;
backgrounds[0] = scene_addRenderObject(&gameScene, gameBackground, 0, 0); backgrounds[0] = scene_addRenderObject(&gameScene, gameBackground, 0, 0);
gameBackground.surface = gameBackgroundSurface2;
backgrounds[1] = scene_addRenderObject(&gameScene, gameBackground, gameBackground.width * CAMERA_WIDTH, 0); backgrounds[1] = scene_addRenderObject(&gameScene, gameBackground, gameBackground.width * CAMERA_WIDTH, 0);
backgroundStep = gameBackground.width * CAMERA_WIDTH; backgroundStep = gameBackground.width * CAMERA_WIDTH;
+1
View File
@@ -79,4 +79,5 @@ int main(int argc, char ** argv) {
Mix_CloseAudio(); Mix_CloseAudio();
text_freeFontCache(); text_freeFontCache();
return 0;
} }
+8
View File
@@ -7,6 +7,7 @@
#include <SDL2/SDL_surface.h> #include <SDL2/SDL_surface.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <stdlib.h>
const RenderObject_t EMPTY_RENDER_OBJECT = { 0, 0.f, 0.f, 0.f, 0.f, 0.f, NULL, "Undefined" }; const RenderObject_t EMPTY_RENDER_OBJECT = { 0, 0.f, 0.f, 0.f, 0.f, 0.f, NULL, "Undefined" };
@@ -82,7 +83,11 @@ RenderId_t scene_addRenderObject(Scene_t * scene, RenderObject_t object, int x,
scene->objects[scene->objectCount - 1] = item; scene->objects[scene->objectCount - 1] = item;
//the objects are sorted //the objects are sorted
#ifdef __MINGW32__
qsort(scene->objects, scene->objectCount, sizeof(SceneObject_t), (int (__cdecl *)(const void *,const void *))compartSort);
#else
qsort(scene->objects, scene->objectCount, sizeof(SceneObject_t), (__compar_fn_t)compartSort); qsort(scene->objects, scene->objectCount, sizeof(SceneObject_t), (__compar_fn_t)compartSort);
#endif
return itemId; return itemId;
} }
@@ -121,6 +126,9 @@ void scene_removeRenderObject(Scene_t * scene, RenderId_t id) {
scene->objectCount--; scene->objectCount--;
SDL_DestroyTexture(scene->objects[index].cache);
SDL_FreeSurface(scene->objects[index].renderObj.surface);
for(int i = index; i < scene->objectCount; i++) { for(int i = index; i < scene->objectCount; i++) {
scene->objects[i] = scene->objects[i + 1]; scene->objects[i] = scene->objects[i + 1];
} }