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_FONTS 5
|
||||
|
||||
#define SURF_NOTHING 0
|
||||
#define SURF_EXTERNAL 1
|
||||
#define SURF_GENERATED 2
|
||||
|
||||
#ifdef MACOS_BUNDLE
|
||||
#include <libgen.h>
|
||||
#endif
|
||||
@@ -28,6 +32,7 @@ struct surface_t {
|
||||
uint8_t *p {nullptr};
|
||||
uint16_t w, h;
|
||||
uint32_t size;
|
||||
uint8_t flags {SURF_NOTHING};
|
||||
};
|
||||
|
||||
struct char_t {
|
||||
@@ -282,6 +287,7 @@ uint8_t newsurf(int w, int h) {
|
||||
surfaces[i].h = h;
|
||||
surfaces[i].size = w*h;
|
||||
surfaces[i].p = (uint8_t*)calloc(surfaces[i].size,1);
|
||||
surfaces[i].flags = SURF_GENERATED;
|
||||
log_msg(LOG_INFO, "Surface %i creada.\n", 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;
|
||||
if (i==MAX_SURFACES) return 255;
|
||||
|
||||
surfaces[i].flags = SURF_NOTHING;
|
||||
// Carregar l'arxiu de disc
|
||||
int size;
|
||||
uint8_t *buffer;
|
||||
if (external) {
|
||||
buffer = (uint8_t*)file_getfilebufferex(filename, size);
|
||||
surfaces[i].flags |= SURF_EXTERNAL;
|
||||
} else {
|
||||
buffer = (uint8_t*)file_getfilebuffer(filename, size);
|
||||
}
|
||||
@@ -341,6 +349,36 @@ uint8_t loadsurf(const char* filename, const bool external) {
|
||||
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)
|
||||
{
|
||||
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);
|
||||
}
|
||||
surfaces[surface].p = NULL;
|
||||
surfaces[surface].flags = SURF_NOTHING;
|
||||
}
|
||||
|
||||
int surfw(uint8_t surface) {
|
||||
@@ -666,7 +705,8 @@ int main(int argc,char*argv[]){
|
||||
reinit();
|
||||
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");
|
||||
current_font = &fonts[0];
|
||||
|
||||
@@ -692,13 +732,14 @@ int main(int argc,char*argv[]){
|
||||
if (mini_eve.type == SDL_EVENT_KEY_DOWN) {
|
||||
#ifdef DEBUG
|
||||
if (mini_eve.key.scancode == SDL_SCANCODE_F12) {
|
||||
if (lua_is_playing()) {
|
||||
lua_quit();
|
||||
quitaudio();
|
||||
reinit();
|
||||
} else {
|
||||
should_exit=true;
|
||||
}
|
||||
reloadsurfs();
|
||||
//if (lua_is_playing()) {
|
||||
// lua_quit();
|
||||
// quitaudio();
|
||||
// reinit();
|
||||
//} else {
|
||||
// should_exit=true;
|
||||
//}
|
||||
} else if (mini_eve.key.scancode == SDL_SCANCODE_F5) {
|
||||
should_exit=true;
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user