VERSIÓ 1.3.11

- [NEW] surf.loadex()
This commit is contained in:
2025-11-27 11:22:52 +01:00
parent a7cbdea4c5
commit 33d7cc3b6d
6 changed files with 53 additions and 240 deletions

View File

@@ -216,7 +216,7 @@ uint8_t newsurf(int w, int h) {
return i;
}
uint8_t loadsurf(const char* filename) {
uint8_t loadsurf(const char* filename, const bool external) {
// Si el gif ja s'ha carregat en una textura, tornem eixa textura
for (int i=0; i<MAX_TEXTURES; ++i)
if (surfaces[i].name && strcmp(surfaces[i].name, filename)==0) {
@@ -224,12 +224,31 @@ uint8_t loadsurf(const char* filename) {
return i;
}
// Carregar l'arxiu de disc
int size;
uint8_t *buffer;
if (external) {
buffer = (uint8_t*)file_getfilebufferex(filename, size);
} else {
buffer = (uint8_t*)file_getfilebuffer(filename, size);
}
// Si no s'ha pogut, petar
if (!buffer) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error al intentar obrir l'arxiu '%s'\n", filename);
return 255;
}
// Agafar la pròxima textura lliure
int i = 0;
while (i<MAX_TEXTURES && surfaces[i].p != NULL) ++i;
//[TODO] Gestionar el cas en que no queden surfaces lliures
int size;
uint8_t *buffer = (uint8_t*)file_getfilebuffer(filename, size);
// Si no en queden lliures, petar
if (i==MAX_TEXTURES) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error: no queden textures lliures\n");
return 255;
}
surfaces[i].p = LoadGif(buffer, &surfaces[i].w, &surfaces[i].h);
surfaces[i].size = surfaces[i].w*surfaces[i].h;
surfaces[i].name = (char*)malloc(strlen(filename)+1);
@@ -243,13 +262,6 @@ uint8_t loadsurf(const char* filename) {
void savesurf(uint8_t surface, const char* filename, uint8_t *pal, uint8_t colors)
{
gif::write_gif(filename, surfaces[surface].p, surfaces[surface].w, surfaces[surface].h, pal, colors);
/*uint8_t depth=0;
do { colors = colors >> 1; depth++; } while (colors!=0);
printf("pal depth: %i\n", depth);
gif::gif_t *file = gif::create(filename, surfaces[surface].w, surfaces[surface].h, pal, (pal?depth:8), -1, -1);
memcpy(file->frame, surfaces[surface].p, surfaces[surface].w*surfaces[surface].h);
gif::addFrame(file, 0);
gif::close(file);*/
}
void freesurf(uint8_t surface) {