From 4fc9c2ef302d8c3f63c1e18ac21c629e6a4bc5b5 Mon Sep 17 00:00:00 2001 From: Yves Rizoud Date: Sat, 18 Dec 2010 20:03:59 +0000 Subject: [PATCH] Lua: changed sleep() to wait() and waitbreak() that are now in seconds, and the last one returns early with a value of 1 if user hit esc. They allow delay of zero if you only want to poll keyboard/mouse and update mouse position. Added updatescreen(): It must be followed by wait() or waitbreak(), because of the double-buffer screen system. See the Sierpinski scripts for example usage. git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@1662 416bcca6-2ee7-4201-b75f-2eb2f807beb1 --- src/factory.c | 68 +++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 61 insertions(+), 7 deletions(-) diff --git a/src/factory.c b/src/factory.c index e0e9f7b9..cb695cd1 100644 --- a/src/factory.c +++ b/src/factory.c @@ -949,21 +949,74 @@ int L_MessageBox(lua_State* L) return 0; } -int L_Sleep(lua_State* L) +int L_Wait(lua_State* L) { - int delay; + float delay; Uint32 end; int nb_args=lua_gettop(L); - LUA_ARG_LIMIT (1, "sleep"); - LUA_ARG_NUMBER(1, "sleep", delay, 0, 10000); + LUA_ARG_LIMIT (1, "wait"); + LUA_ARG_NUMBER(1, "wait", delay, 0.0, 10.0); - end = SDL_GetTicks()+delay; + // Simple 'yield' + if (delay == 0.0) + { + Get_input(0); + return 0; + } + // Wait specified time + end = SDL_GetTicks()+(int)(delay*1000.0); do { Get_input(20); } while (SDL_GetTicks()