- Es pot canviar la resolució des del programa abm res(w,h)
- La finestra es resizable - Es permet arrancar des d'un arxiu .lua passat com a paràmetre.
This commit is contained in:
12
lua.cpp
12
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));
|
||||
|
||||
2
lua.h
2
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();
|
||||
|
||||
41
mini.cpp
41
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;
|
||||
}
|
||||
|
||||
1
mini.h
1
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();
|
||||
|
||||
Reference in New Issue
Block a user