From 63eaaa857eaa2ad89addba10ba06d5c3e1709325 Mon Sep 17 00:00:00 2001 From: Raimon Zamora Date: Tue, 28 Nov 2023 19:03:13 +0100 Subject: [PATCH] =?UTF-8?q?-=20Es=20pot=20canviar=20la=20resoluci=C3=B3=20?= =?UTF-8?q?des=20del=20programa=20abm=20res(w,h)=20-=20La=20finestra=20es?= =?UTF-8?q?=20resizable=20-=20Es=20permet=20arrancar=20des=20d'un=20arxiu?= =?UTF-8?q?=20.lua=20passat=20com=20a=20par=C3=A0metre.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lua.cpp | 12 ++++++++++-- lua.h | 2 +- mini.cpp | 41 +++++++++++++++++++++++++++++++---------- mini.h | 1 + version.h | 2 +- 5 files changed, 44 insertions(+), 14 deletions(-) diff --git a/lua.cpp b/lua.cpp index 893dc79..d08d934 100644 --- a/lua.cpp +++ b/lua.cpp @@ -825,6 +825,13 @@ extern "C" { } } + static int cpp_res(lua_State *L) { + const int w = luaL_optinteger(L, 1, 160); + const int h = luaL_optinteger(L, 2, 120); + setres(w, h); + return 0; + } + static int cpp_getconf(lua_State *L) { const char* key = luaL_checkstring(L, 1); const char* value = getconfig(key); @@ -991,6 +998,7 @@ void push_lua_funcs() { lua_pushcfunction(L,cpp_zoom); lua_setglobal(L, "zoom"); lua_pushcfunction(L,cpp_fullscreen); lua_setglobal(L, "fullscreen"); lua_pushcfunction(L,cpp_cursor); lua_setglobal(L, "cursor"); + lua_pushcfunction(L,cpp_res); lua_setglobal(L, "res"); lua_pushcfunction(L,cpp_getconf); lua_setglobal(L, "getconf"); lua_pushcfunction(L,cpp_setconf); lua_setglobal(L, "setconf"); @@ -1154,7 +1162,7 @@ int MiniLoader(lua_State *L) { return 1; } -void lua_init() { +void lua_init(const char *main_lua_file) { L = luaL_newstate(); luaL_openlibs(L); push_lua_funcs(); @@ -1162,7 +1170,7 @@ void lua_init() { luaL_dostring(L, "table.insert(package.searchers,2,mini_loader)\n"); int size; - char* buffer = file_getfilebuffer("main.lua", size); + char* buffer = file_getfilebuffer(main_lua_file, size); if (luaL_loadbuffer(L, buffer, size, "main")) { debug("LOADING ERROR: "); debug("%s\n",lua_tostring(L, -1)); diff --git a/lua.h b/lua.h index f991050..5ffa159 100644 --- a/lua.h +++ b/lua.h @@ -1,7 +1,7 @@ #pragma once bool lua_is_playing(); -void lua_init(); +void lua_init(const char* main_lua_file = "main.lua"); void lua_call_init(); void lua_call_update(); void lua_quit(); diff --git a/mini.cpp b/mini.cpp index 79a86c6..15b5035 100644 --- a/mini.cpp +++ b/mini.cpp @@ -41,6 +41,8 @@ FILE *file = NULL; //uint8_t file_mode = 0; bool file_ignore_comma=true; +char main_lua_file[200] = "main.lua"; +bool override_ini = false; //char lua_files[1024]; #define DEST(x, y) dest_surface->p[x+y*dest_surface->w] @@ -229,7 +231,7 @@ void createDisplay() { if (screen_zoom <= 0) screen_zoom = 1; while (screen_width*screen_zoom > desktop_width || screen_height*screen_zoom > desktop_height) screen_zoom--; - mini_win = SDL_CreateWindow(window_title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, screen_width*screen_zoom, screen_height*screen_zoom, screen_fullscreen?SDL_WINDOW_FULLSCREEN_DESKTOP:SDL_WINDOW_SHOWN); + mini_win = SDL_CreateWindow(window_title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, screen_width*screen_zoom, screen_height*screen_zoom, screen_fullscreen?SDL_WINDOW_FULLSCREEN_DESKTOP:SDL_WINDOW_RESIZABLE); windowID = SDL_GetWindowID(mini_win); mini_ren = SDL_CreateRenderer(mini_win, -1, 0); //SDL_CreateWindowAndRenderer(512,512,0,&mini_win,&mini_ren); @@ -262,6 +264,15 @@ void initGamePad() { int main(int argc,char*argv[]){ + if (argc>1) + { + file_setresourcefolder("./"); + file_setsource(SOURCE_FOLDER); + strcpy(main_lua_file, argv[1]); + strcpy(window_title, argv[1]); + override_ini = true; + } + while (!should_quit) { should_exit=false; @@ -279,14 +290,17 @@ int main(int argc,char*argv[]){ strcat(res_file, "/../Resources/data.jrf"); file_setresourcefilename(res_file); #endif - read_ini(); - file_setconfigfolder(config_folder); - const char *zoom = file_getconfigvalue("zoom"); - if (zoom) screen_zoom=atoi(zoom); - const char *fullscreen = file_getconfigvalue("fullscreen"); - if (fullscreen) screen_fullscreen=strcmp(fullscreen, "true")==0?true:false; - const char *cursor = file_getconfigvalue("cursor"); - if (cursor) screen_cursor=strcmp(cursor, "true")?true:false; + if (!override_ini) + { + read_ini(); + file_setconfigfolder(config_folder); + const char *zoom = file_getconfigvalue("zoom"); + if (zoom) screen_zoom=atoi(zoom); + const char *fullscreen = file_getconfigvalue("fullscreen"); + if (fullscreen) screen_fullscreen=strcmp(fullscreen, "true")==0?true:false; + const char *cursor = file_getconfigvalue("cursor"); + if (cursor) screen_cursor=strcmp(cursor, "true")?true:false; + } setdest(newsurf(screen_width, screen_height)); @@ -314,7 +328,7 @@ int main(int argc,char*argv[]){ #ifdef DEBUG debug("MINI v%s\n",MINI_VERSION); #endif - lua_init(); + lua_init(main_lua_file); lua_call_init(); Uint32 dt=SDL_GetTicks(); @@ -1270,6 +1284,13 @@ void setzoom(const int value) { file_setconfigvalue("zoom", SDL_itoa(screen_zoom, strzoom, 10)); } +void setres(const int w, const int h) { + screen_width = w; + screen_height = h; + destroyDisplay(); + createDisplay(); +} + bool getfullscreen() { return screen_fullscreen; } diff --git a/mini.h b/mini.h index 5d88880..e99ca36 100644 --- a/mini.h +++ b/mini.h @@ -285,6 +285,7 @@ void stopsound(int soundchannel); int getzoom(); void setzoom(const int value); +void setres(const int w, const int h); bool getfullscreen(); void setfullscreen(const bool value); bool getcursor(); diff --git a/version.h b/version.h index f65a2cd..f2fb791 100644 --- a/version.h +++ b/version.h @@ -1,3 +1,3 @@ #pragma once -#define MINI_VERSION "0.9.82d" +#define MINI_VERSION "0.9.86d"