diff --git a/lua.cpp b/lua.cpp index 53f2f3c..2ea2c62 100644 --- a/lua.cpp +++ b/lua.cpp @@ -16,19 +16,34 @@ extern "C" { static int cpp_surf_new(lua_State *L) { int w = luaL_checknumber(L, 1); int h = luaL_checknumber(L, 2); - lua_pushinteger(L, newsurf(w, h)); + uint8_t s = newsurf(w, h); + if (s==255) { + luaL_error(L, "Error while creating new surface: Max surfaces reached"); + return 0; + } + lua_pushinteger(L, s); return 1; } static int cpp_surf_load(lua_State *L) { const char* str = luaL_checkstring(L, 1); - lua_pushinteger(L, loadsurf(str)); + uint8_t s = loadsurf(str); + if (s==255) { + luaL_error(L, "Error while loading surface: Max surfaces reached"); + return 0; + } + lua_pushinteger(L, s); return 1; } static int cpp_surf_loadex(lua_State *L) { const char* str = luaL_checkstring(L, 1); - lua_pushinteger(L, loadsurf(str, true)); + uint8_t s = loadsurf(str, true); + if (s==255) { + luaL_error(L, "Error while loading surface: Max surfaces reached"); + return 0; + } + lua_pushinteger(L, s); return 1; } @@ -472,9 +487,13 @@ extern "C" { } static int cpp_draw_pattern(lua_State *L) { - uint16_t pat = luaL_checkinteger(L, 1); - bool transparent = lua_toboolean(L, 2); - fillp(pat, transparent); + if (lua_gettop(L) == 0) { + fillp(0xffff); + } else { + uint16_t pat = luaL_checkinteger(L, 1); + bool transparent = lua_toboolean(L, 2); + fillp(pat, transparent); + } return 0; } diff --git a/mini.cpp b/mini.cpp index 1f029d7..e6d0a5e 100644 --- a/mini.cpp +++ b/mini.cpp @@ -6,10 +6,10 @@ #include "gifenc.h" #include "jail_audio.h" #include "jshader.h" -#include +//#include #include "log.h" -//#define MAX_TEXTURES 100 +#define MAX_SURFACES 100 #ifdef MACOS_BUNDLE #include @@ -47,9 +47,9 @@ bool screen_cursor = true; int desktop_width = 0; int desktop_height = 0; -std::vector surfaces; -surface_t *screen_surface = NULL; //&surfaces[0]; -surface_t *dest_surface = NULL; //screen_surface; +surface_t surfaces[MAX_SURFACES]; +surface_t *screen_surface = &surfaces[0]; +surface_t *dest_surface = screen_surface; surface_t *source_surface = NULL; surface_t *map_surface = NULL; @@ -136,8 +136,8 @@ void read_ini() { int size; FILE *f = file_getfilepointer("game.ini", size); // fopen("game.ini", "r"); char line[1024]; - if (f == NULL) { log_msg(LOG_FAIL, "No s'ha pogut obrir 'game.ini'"); exit(-1); } - log_msg(LOG_OK, "'game.ini' carregat"); + if (f == NULL) { log_msg(LOG_FAIL, "No s'ha pogut obrir 'game.ini'\n"); exit(-1); } + log_msg(LOG_OK, "'game.ini' carregat\n"); while (fgets(line, sizeof(line), f)) { char *value = get_value_from_line(line); if (value != NULL) { @@ -183,13 +183,14 @@ void reinit() { ds::trans=0; ds::fill_pattern = 0b1111111111111111; ds::fill_trans = false; - for (unsigned int i=1; i