VERSIÓ 1.4.10:
- [NEW] surface_t.flags - [NEW] F12 per a recàrrega de surfaces en calent
This commit is contained in:
57
mini.cpp
57
mini.cpp
@@ -15,6 +15,10 @@
|
|||||||
#define MAX_SURFACES 100
|
#define MAX_SURFACES 100
|
||||||
#define MAX_FONTS 5
|
#define MAX_FONTS 5
|
||||||
|
|
||||||
|
#define SURF_NOTHING 0
|
||||||
|
#define SURF_EXTERNAL 1
|
||||||
|
#define SURF_GENERATED 2
|
||||||
|
|
||||||
#ifdef MACOS_BUNDLE
|
#ifdef MACOS_BUNDLE
|
||||||
#include <libgen.h>
|
#include <libgen.h>
|
||||||
#endif
|
#endif
|
||||||
@@ -28,6 +32,7 @@ struct surface_t {
|
|||||||
uint8_t *p {nullptr};
|
uint8_t *p {nullptr};
|
||||||
uint16_t w, h;
|
uint16_t w, h;
|
||||||
uint32_t size;
|
uint32_t size;
|
||||||
|
uint8_t flags {SURF_NOTHING};
|
||||||
};
|
};
|
||||||
|
|
||||||
struct char_t {
|
struct char_t {
|
||||||
@@ -282,6 +287,7 @@ 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);
|
||||||
|
surfaces[i].flags = SURF_GENERATED;
|
||||||
log_msg(LOG_INFO, "Surface %i creada.\n", i);
|
log_msg(LOG_INFO, "Surface %i creada.\n", i);
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
@@ -315,11 +321,13 @@ uint8_t loadsurf(const char* filename, const bool external) {
|
|||||||
while (i<MAX_SURFACES && surfaces[i].p != NULL) ++i;
|
while (i<MAX_SURFACES && surfaces[i].p != NULL) ++i;
|
||||||
if (i==MAX_SURFACES) return 255;
|
if (i==MAX_SURFACES) return 255;
|
||||||
|
|
||||||
|
surfaces[i].flags = SURF_NOTHING;
|
||||||
// Carregar l'arxiu de disc
|
// Carregar l'arxiu de disc
|
||||||
int size;
|
int size;
|
||||||
uint8_t *buffer;
|
uint8_t *buffer;
|
||||||
if (external) {
|
if (external) {
|
||||||
buffer = (uint8_t*)file_getfilebufferex(filename, size);
|
buffer = (uint8_t*)file_getfilebufferex(filename, size);
|
||||||
|
surfaces[i].flags |= SURF_EXTERNAL;
|
||||||
} else {
|
} else {
|
||||||
buffer = (uint8_t*)file_getfilebuffer(filename, size);
|
buffer = (uint8_t*)file_getfilebuffer(filename, size);
|
||||||
}
|
}
|
||||||
@@ -341,6 +349,36 @@ uint8_t loadsurf(const char* filename, const bool external) {
|
|||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void reloadsurfs() {
|
||||||
|
for (unsigned int i=0; i<MAX_SURFACES; ++i)
|
||||||
|
if (surfaces[i].name) {
|
||||||
|
if (surfaces[i].flags & SURF_GENERATED) {
|
||||||
|
log_msg(LOG_INFO, "Ignorant surface generada %i.\n", i);
|
||||||
|
} else {
|
||||||
|
log_msg(LOG_INFO, "Recarregant de disc surface %i:'%s'.\n", i, surfaces[i].name);
|
||||||
|
|
||||||
|
int size;
|
||||||
|
uint8_t *buffer;
|
||||||
|
if (surfaces[i].flags & SURF_EXTERNAL) {
|
||||||
|
buffer = (uint8_t*)file_getfilebufferex(surfaces[i].name, size);
|
||||||
|
} else {
|
||||||
|
buffer = (uint8_t*)file_getfilebuffer(surfaces[i].name, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Si no s'ha pogut, petar
|
||||||
|
if (!buffer) {
|
||||||
|
log_msg(LOG_FAIL, "Error al intentar obrir l'arxiu '%s'\n", surfaces[i].name);
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
surfaces[i].p = LoadGif(buffer, &surfaces[i].w, &surfaces[i].h);
|
||||||
|
surfaces[i].size = surfaces[i].w*surfaces[i].h;
|
||||||
|
free(buffer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void savesurf(uint8_t surface, const char* filename, uint8_t *pal, uint8_t colors)
|
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);
|
gif::write_gif(filename, surfaces[surface].p, surfaces[surface].w, surfaces[surface].h, pal, colors);
|
||||||
@@ -354,6 +392,7 @@ void freesurf(uint8_t surface) {
|
|||||||
log_msg(LOG_INFO, "Surface %i alliberada.\n", surface);
|
log_msg(LOG_INFO, "Surface %i alliberada.\n", surface);
|
||||||
}
|
}
|
||||||
surfaces[surface].p = NULL;
|
surfaces[surface].p = NULL;
|
||||||
|
surfaces[surface].flags = SURF_NOTHING;
|
||||||
}
|
}
|
||||||
|
|
||||||
int surfw(uint8_t surface) {
|
int surfw(uint8_t surface) {
|
||||||
@@ -666,7 +705,8 @@ int main(int argc,char*argv[]){
|
|||||||
reinit();
|
reinit();
|
||||||
initaudio();
|
initaudio();
|
||||||
|
|
||||||
loadsurf(default_font_gif, "default_font");
|
uint8_t font_surf = loadsurf(default_font_gif, "default_font");
|
||||||
|
surfaces[font_surf].flags |= SURF_GENERATED;
|
||||||
loadfont_from_buffer((const char*)default_font_fnt, 0, "default_font");
|
loadfont_from_buffer((const char*)default_font_fnt, 0, "default_font");
|
||||||
current_font = &fonts[0];
|
current_font = &fonts[0];
|
||||||
|
|
||||||
@@ -692,13 +732,14 @@ int main(int argc,char*argv[]){
|
|||||||
if (mini_eve.type == SDL_EVENT_KEY_DOWN) {
|
if (mini_eve.type == SDL_EVENT_KEY_DOWN) {
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
if (mini_eve.key.scancode == SDL_SCANCODE_F12) {
|
if (mini_eve.key.scancode == SDL_SCANCODE_F12) {
|
||||||
if (lua_is_playing()) {
|
reloadsurfs();
|
||||||
lua_quit();
|
//if (lua_is_playing()) {
|
||||||
quitaudio();
|
// lua_quit();
|
||||||
reinit();
|
// quitaudio();
|
||||||
} else {
|
// reinit();
|
||||||
should_exit=true;
|
//} else {
|
||||||
}
|
// should_exit=true;
|
||||||
|
//}
|
||||||
} else if (mini_eve.key.scancode == SDL_SCANCODE_F5) {
|
} else if (mini_eve.key.scancode == SDL_SCANCODE_F5) {
|
||||||
should_exit=true;
|
should_exit=true;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user