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
+3 -1
View File
@@ -102,7 +102,7 @@ static void playMusic(){
exit(1);
}
if(Mix_PlayMusic(music, 0) != 0){
if(Mix_PlayMusic(music, -1) != 0){
printf("Music sound could not be played!\n"
"SDL_Error: %s\n", Mix_GetError());
Mix_FreeMusic(music);
@@ -124,6 +124,7 @@ int game_staticRender(void){
return -1;
}
SDL_Surface* gameBackgroundSurface2 = IMG_Load("./assets/img/game_bg.png");
RenderObject_t gameBackground = EMPTY_RENDER_OBJECT;
strcpy(gameBackground.name, "gameBackground");
@@ -132,6 +133,7 @@ int game_staticRender(void){
scaller(gameBackground.surface, 1, &gameBackground.width, &gameBackground.height);
gameBackground.height = 1;
backgrounds[0] = scene_addRenderObject(&gameScene, gameBackground, 0, 0);
gameBackground.surface = gameBackgroundSurface2;
backgrounds[1] = scene_addRenderObject(&gameScene, gameBackground, gameBackground.width * CAMERA_WIDTH, 0);
backgroundStep = gameBackground.width * CAMERA_WIDTH;
+1
View File
@@ -79,4 +79,5 @@ int main(int argc, char ** argv) {
Mix_CloseAudio();
text_freeFontCache();
return 0;
}
+8
View File
@@ -7,6 +7,7 @@
#include <SDL2/SDL_surface.h>
#include <stdio.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" };
@@ -82,7 +83,11 @@ RenderId_t scene_addRenderObject(Scene_t * scene, RenderObject_t object, int x,
scene->objects[scene->objectCount - 1] = item;
//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);
#endif
return itemId;
}
@@ -121,6 +126,9 @@ void scene_removeRenderObject(Scene_t * scene, RenderId_t id) {
scene->objectCount--;
SDL_DestroyTexture(scene->objects[index].cache);
SDL_FreeSurface(scene->objects[index].renderObj.surface);
for(int i = index; i < scene->objectCount; i++) {
scene->objects[i] = scene->objects[i + 1];
}