From 4afbde805f29a52f762735187a069a70ea5c795a Mon Sep 17 00:00:00 2001 From: gocha Date: Sat, 11 Aug 2012 11:02:13 +0900 Subject: [PATCH] Lua: joypad.get supports movie input from now hope we can use peripherals as well someday. --- cpuexec.cpp | 3 +++ lua-engine.cpp | 15 +++++++++++++++ movie.cpp | 11 +++++++++++ movie.h | 1 + 4 files changed, 30 insertions(+) diff --git a/cpuexec.cpp b/cpuexec.cpp index 2fe420a7..aa057802 100644 --- a/cpuexec.cpp +++ b/cpuexec.cpp @@ -183,6 +183,7 @@ #include "apu/apu.h" #include "fxemu.h" #include "snapshot.h" +#include "movie.h" #include "lua-engine.h" #ifdef DEBUGGER #include "debug.h" @@ -323,6 +324,8 @@ static inline void StartS9xMainLoop (void) pad_read_last = pad_read; pad_read = FALSE; + MovieApplyNextInput(); + #ifdef HAVE_LUA CallRegisteredLuaFunctions(LUACALL_BEFOREEMULATION); #endif diff --git a/lua-engine.cpp b/lua-engine.cpp index 22f45708..08abe3dc 100644 --- a/lua-engine.cpp +++ b/lua-engine.cpp @@ -681,6 +681,7 @@ DEFINE_LUA_FUNCTION(emu_persistglobalvariables, "variabletable") } static const char* deferredGUIIDString = "lazygui"; +static const char* deferredJoySetIDString = "lazyjoy"; // store the most recent C function call from Lua (and all its arguments) // for later evaluation @@ -2293,6 +2294,16 @@ DEFINE_LUA_FUNCTION(joy_set, "[controller=1,]inputtable") luaL_checktype(L, index, LUA_TTABLE); + if (S9xMoviePlaying()) // don't allow tampering with a playing movie's input + return 0; // (although it might be useful sometimes...) + + if (IPPU.InMainLoop) + { + // defer this function until when we are processing input + DeferFunctionCall(L, deferredJoySetIDString); + return 0; + } + uint32 input = 0; uint32 mask = 0; @@ -4233,6 +4244,8 @@ void RunLuaScriptFile(int uid, const char* filenameCStr) // deferred evaluation table lua_newtable(L); lua_setfield(L, LUA_REGISTRYINDEX, deferredGUIIDString); + lua_newtable(L); + lua_setfield(L, LUA_REGISTRYINDEX, deferredJoySetIDString); info.started = true; RefreshScriptStartedStatus(); @@ -4748,6 +4761,8 @@ void CallRegisteredLuaFunctions(LuaCallID calltype) info.guiFuncsNeedDeferring = false; if(calltype == LUACALL_AFTEREMULATIONGUI) CallDeferredFunctions(L, deferredGUIIDString); + if(calltype == LUACALL_BEFOREEMULATION) + CallDeferredFunctions(L, deferredJoySetIDString); lua_settop(L, 0); lua_getfield(L, LUA_REGISTRYINDEX, idstring); diff --git a/movie.cpp b/movie.cpp index 58b1a1dc..3af4f5fd 100644 --- a/movie.cpp +++ b/movie.cpp @@ -1102,6 +1102,17 @@ void S9xMovieUpdateOnReset (void) } } +// apply the next input without changing any movie states +void MovieApplyNextInput(void) +{ + if (Movie.State != MOVIE_STATE_PLAY) + return; + + uint8 *InputBufferPtr = Movie.InputBufferPtr; + read_frame_controller_data(false, NULL); + Movie.InputBufferPtr = InputBufferPtr; +} + void S9xMovieInit (void) { memset(&Movie, 0, sizeof(Movie)); diff --git a/movie.h b/movie.h index 2e4eb46d..7ce31f23 100644 --- a/movie.h +++ b/movie.h @@ -255,5 +255,6 @@ bool MovieGetScope (int, uint8 d[SCOPE_DATA_SIZE]); void MovieSetScope (int, uint8 d[SCOPE_DATA_SIZE]); bool MovieGetJustifier (int, uint8 d[JUSTIFIER_DATA_SIZE]); void MovieSetJustifier (int, uint8 d[JUSTIFIER_DATA_SIZE]); +void MovieApplyNextInput(void); #endif