VERSIÓ 1.0 RC3

- [FIX] Funció "view.local()" canviada a "view.tolocal()", per a evitar problemes.
- [FIX] Si una surface no s'ha creat, no hi ha res que alliberar.
- [NEW] Afegit log de creació i destrucció de surfaces.
This commit is contained in:
2025-06-03 13:26:11 +02:00
parent adcc44ddab
commit 4bda9cbd39
3 changed files with 15 additions and 6 deletions

View File

@@ -323,7 +323,7 @@ extern "C" {
} }
} }
static int cpp_viewport_local(lua_State *L) { static int cpp_viewport_tolocal(lua_State *L) {
int x = luaL_checknumber(L, 1); int x = luaL_checknumber(L, 1);
int y = luaL_checknumber(L, 2); int y = luaL_checknumber(L, 2);
lua_pushinteger(L, x+camx()); lua_pushinteger(L, x+camx());
@@ -834,7 +834,7 @@ void push_lua_funcs() {
lua_newtable(L); lua_newtable(L);
lua_pushcfunction(L,cpp_viewport_clip); lua_setfield(L, -2, "clip"); lua_pushcfunction(L,cpp_viewport_clip); lua_setfield(L, -2, "clip");
lua_pushcfunction(L,cpp_viewport_origin); lua_setfield(L, -2, "origin"); lua_pushcfunction(L,cpp_viewport_origin); lua_setfield(L, -2, "origin");
lua_pushcfunction(L,cpp_viewport_local); lua_setfield(L, -2, "local"); lua_pushcfunction(L,cpp_viewport_tolocal); lua_setfield(L, -2, "tolocal");
lua_setglobal(L, "view"); lua_setglobal(L, "view");
lua_newtable(L); lua_newtable(L);

View File

@@ -210,12 +210,17 @@ uint8_t newsurf(int w, int h) {
surfaces[i].h = h; surfaces[i].h = h;
surfaces[i].size = w*h; surfaces[i].size = w*h;
surfaces[i].p = (uint8_t*)calloc(surfaces[i].size,1); surfaces[i].p = (uint8_t*)calloc(surfaces[i].size,1);
SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "Surface %i creada.\n", i);
return i; return i;
} }
uint8_t loadsurf(const char* filename) { uint8_t loadsurf(const char* filename) {
// Si el gif ja s'ha carregat en una textura, tornem eixa textura // Si el gif ja s'ha carregat en una textura, tornem eixa textura
for (int i=0; i<MAX_TEXTURES; ++i) if (strcmp(surfaces[i].name, filename)==0) return i; for (int i=0; i<MAX_TEXTURES; ++i)
if (surfaces[i].name && strcmp(surfaces[i].name, filename)==0) {
SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "Carrega de '%s' abortada: Reusant: %i.\n", filename, i);
return i;
}
int i = 0; int i = 0;
while (i<MAX_TEXTURES && surfaces[i].p != NULL) ++i; while (i<MAX_TEXTURES && surfaces[i].p != NULL) ++i;
@@ -229,6 +234,7 @@ uint8_t loadsurf(const char* filename) {
strcpy(surfaces[i].name, filename); strcpy(surfaces[i].name, filename);
free(buffer); free(buffer);
SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "Carregat '%s': Surface: %i.\n", filename, i);
return i; return i;
} }
@@ -243,10 +249,13 @@ void savesurf(uint8_t surface, const char* filename, uint8_t *pal, uint8_t color
} }
void freesurf(uint8_t surface) { void freesurf(uint8_t surface) {
if (surfaces[surface].p != NULL) free(surfaces[surface].p);
surfaces[surface].p = NULL;
if (surfaces[surface].name != NULL) free(surfaces[surface].name); if (surfaces[surface].name != NULL) free(surfaces[surface].name);
surfaces[surface].name = NULL; surfaces[surface].name = NULL;
if (surfaces[surface].p != NULL) {
free(surfaces[surface].p);
SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "Surface %i alliberada.\n", surface);
}
surfaces[surface].p = NULL;
} }
int surfw(uint8_t surface) { int surfw(uint8_t surface) {

View File

@@ -1,3 +1,3 @@
#pragma once #pragma once
#define MINI_VERSION "1.0 RC2" #define MINI_VERSION "1.0 RC3"