From f1c87e4d25c19ecb5f89108e522860950b5436ec Mon Sep 17 00:00:00 2001 From: Raimon Zamora Date: Thu, 13 Oct 2022 18:40:41 +0200 Subject: [PATCH] - [NEW] exit() - [NEW] anykey() - [NEW] ismusicplaying() --- lua.cpp | 19 +++++++++++++++++++ mini.cpp | 19 ++++++++++++++++--- mini.h | 4 ++++ 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/lua.cpp b/lua.cpp index 6eaf26b..43eaa74 100644 --- a/lua.cpp +++ b/lua.cpp @@ -450,6 +450,11 @@ extern "C" { return 1; } + static int cpp_anykey(lua_State *L) { + lua_pushboolean(L, anykey()); + return 1; + } + static int cpp_mousex(lua_State *L) { lua_pushinteger(L, mousex()); return 1; @@ -666,6 +671,16 @@ extern "C" { return 0; } + static int cpp_ismusicplaying(lua_State *L) { + lua_pushboolean(L,ismusicplaying()); + return 1; + } + + static int cpp_exit(lua_State *L) { + exit(); + return 0; + } + } lua_State *L; @@ -722,6 +737,7 @@ void push_lua_funcs() { lua_pushcfunction(L,cpp_map); lua_setglobal(L, "map"); lua_pushcfunction(L,cpp_btn); lua_setglobal(L, "btn"); lua_pushcfunction(L,cpp_btnp); lua_setglobal(L, "btnp"); + lua_pushcfunction(L,cpp_anykey); lua_setglobal(L, "anykey"); lua_pushcfunction(L,cpp_mousex); lua_setglobal(L, "mousex"); lua_pushcfunction(L,cpp_mousey); lua_setglobal(L, "mousey"); lua_pushcfunction(L,cpp_mwheel); lua_setglobal(L, "mwheel"); @@ -765,6 +781,9 @@ void push_lua_funcs() { lua_pushcfunction(L,cpp_pausemusic); lua_setglobal(L, "pausemusic"); lua_pushcfunction(L,cpp_resumemusic); lua_setglobal(L, "resumemusic"); lua_pushcfunction(L,cpp_stopmusic); lua_setglobal(L, "stopmusic"); + lua_pushcfunction(L,cpp_ismusicplaying); lua_setglobal(L, "ismusicplaying"); + + lua_pushcfunction(L,cpp_exit); lua_setglobal(L, "exit"); lua_pushinteger(L, 0); lua_setglobal(L, "KEY_UNKNOWN"); lua_pushinteger(L, 4); lua_setglobal(L, "KEY_A"); diff --git a/mini.cpp b/mini.cpp index df4f299..b6726df 100644 --- a/mini.cpp +++ b/mini.cpp @@ -50,6 +50,7 @@ namespace ds { bool fill_trans = false; } +bool should_exit = false; SDL_Window *mini_win; SDL_Renderer *mini_ren; SDL_Texture *mini_bak; @@ -236,7 +237,7 @@ int main(int argc,char*argv[]){ SDL_RenderSetLogicalSize(mini_ren, screen_width, screen_height); SDL_ShowCursor(show_cursor); mini_bak = SDL_CreateTexture(mini_ren, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, screen_width, screen_height); - bool exit = false; + SDL_Event mini_eve; reinit(); @@ -245,11 +246,11 @@ int main(int argc,char*argv[]){ lua_init(lua_files); lua_call_init(); - while(!exit) { + while(!should_exit) { key_just_pressed = 0; mouse_wheel = 0; while(SDL_PollEvent(&mini_eve)) { - if (mini_eve.type == SDL_QUIT) { exit=true; break; } + if (mini_eve.type == SDL_QUIT) { should_exit=true; break; } if (mini_eve.type == SDL_KEYDOWN) { if (mini_eve.key.keysym.scancode == SDL_SCANCODE_ESCAPE) { if (lua_is_playing()) { @@ -794,6 +795,10 @@ bool btnp(uint8_t i) { return key_just_pressed == i; } +bool anykey() { + return key_just_pressed != 0; +} + int mousex() { return mouse_x; } @@ -998,3 +1003,11 @@ void resumemusic() { void stopmusic() { JA_StopMusic(); } + +bool ismusicplaying() { + return JA_GetMusicState() == JA_MUSIC_PLAYING; +} + +void exit() { + should_exit = true; +} diff --git a/mini.h b/mini.h index 43cce4f..883e393 100644 --- a/mini.h +++ b/mini.h @@ -196,6 +196,7 @@ void map(int celx, int cely, int sx, int sy, uint8_t celw, uint8_t celh, uint8_t bool btn(uint8_t i); bool btnp(uint8_t i); +bool anykey(); int mousex(); int mousey(); @@ -253,3 +254,6 @@ void playmusic(const char *filename, const bool loop = true); void pausemusic(); void resumemusic(); void stopmusic(); +bool ismusicplaying(); + +void exit();