From 3abe07210d68145f6126ffac8b3c1238f7df9301 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9lestin=20Matte?= Date: Sat, 18 Oct 2025 17:30:47 +0200 Subject: [PATCH 1/4] lua: add movie.getMarker() This paves the road towards more movie control in lua --- docs/guides/lua.md | 6 ++++++ src/program/Context.h | 4 ++++ src/program/GameLoop.cpp | 1 + src/program/lua/Movie.cpp | 13 +++++++++++++ src/program/lua/Movie.h | 4 ++++ 5 files changed, 28 insertions(+) diff --git a/docs/guides/lua.md b/docs/guides/lua.md index 1bebe5af..a1e19e89 100644 --- a/docs/guides/lua.md +++ b/docs/guides/lua.md @@ -299,6 +299,12 @@ Returns the current rerecord count of the movie, or -1 if no movie is loaded Returns 1 of the current frame is a draw frame, or 0 if not. +#### movie.getMarker + + String movie.getMarker() + +Returns the marker at current frame if there is one, none instead. + ### Runtime functions Runtime functions must be performed in callback `onFrame()` to be effective on diff --git a/src/program/Context.h b/src/program/Context.h index e07f7804..dcbe37dd 100644 --- a/src/program/Context.h +++ b/src/program/Context.h @@ -23,6 +23,7 @@ #include "Config.h" #include "ConcurrentQueue.h" #include "KeyMapping.h" +#include "movie/MovieFile.h" #ifdef __unix__ #include @@ -142,6 +143,9 @@ struct Context { /* PID of the appimage process that mounts the appimage structure */ pid_t appimage_pid = 0; + + /* Link to the movie */ + MovieFile* movie; }; #endif diff --git a/src/program/GameLoop.cpp b/src/program/GameLoop.cpp index 0d0da792..c23e35a3 100644 --- a/src/program/GameLoop.cpp +++ b/src/program/GameLoop.cpp @@ -67,6 +67,7 @@ GameLoop::GameLoop(Context* c) : movie(MovieFile(c)), context(c) #elif defined(__APPLE__) && defined(__MACH__) gameEvents = new GameEventsQuartz(c, &movie); #endif + c->movie = &movie; } void GameLoop::start() diff --git a/src/program/lua/Movie.cpp b/src/program/lua/Movie.cpp index b2d9c772..377c249c 100644 --- a/src/program/lua/Movie.cpp +++ b/src/program/lua/Movie.cpp @@ -38,6 +38,7 @@ static const luaL_Reg movie_functions[] = { "time", Lua::Movie::time}, { "rerecords", Lua::Movie::rerecords}, { "isDraw", Lua::Movie::isDraw}, + { "getMarker", Lua::Movie::getMarker}, { NULL, NULL } }; @@ -90,3 +91,15 @@ int Lua::Movie::isDraw(lua_State *L) lua_pushinteger(L, static_cast(context->draw_frame)); return 1; } + +int Lua::Movie::getMarker(lua_State *L) +{ + std::string marker; + try { + marker = context->movie->editor->markers.at(context->framecount); + } catch (const std::out_of_range&) { + return 0; + } + lua_pushstring(L, marker.c_str()); + return 1; +} diff --git a/src/program/lua/Movie.h b/src/program/lua/Movie.h index 15ec310e..b6e067f0 100644 --- a/src/program/lua/Movie.h +++ b/src/program/lua/Movie.h @@ -24,6 +24,8 @@ extern "C" { #include } +#include + struct Context; namespace Lua { @@ -51,6 +53,8 @@ namespace Movie { /* Returns if the current frame is a draw frame */ int isDraw(lua_State *L); + /* Get marker at current frame if there is one */ + int getMarker(lua_State *L); } } From 809a7f8a7dea9620f1f7a14f0b4b3f606e90f2f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9lestin=20Matte?= Date: Sun, 19 Oct 2025 10:25:24 +0200 Subject: [PATCH 2/4] lua: add movie.setMarker() --- docs/guides/lua.md | 6 ++++++ src/program/lua/Movie.cpp | 8 ++++++++ src/program/lua/Movie.h | 3 +++ 3 files changed, 17 insertions(+) diff --git a/docs/guides/lua.md b/docs/guides/lua.md index a1e19e89..2743e7f8 100644 --- a/docs/guides/lua.md +++ b/docs/guides/lua.md @@ -305,6 +305,12 @@ Returns 1 of the current frame is a draw frame, or 0 if not. Returns the marker at current frame if there is one, none instead. +#### movie.setMarker + + none movie.setMarker(String text) + +Edit marker at current frame with the text given as parameter. + ### Runtime functions Runtime functions must be performed in callback `onFrame()` to be effective on diff --git a/src/program/lua/Movie.cpp b/src/program/lua/Movie.cpp index 377c249c..51f19eca 100644 --- a/src/program/lua/Movie.cpp +++ b/src/program/lua/Movie.cpp @@ -39,6 +39,7 @@ static const luaL_Reg movie_functions[] = { "rerecords", Lua::Movie::rerecords}, { "isDraw", Lua::Movie::isDraw}, { "getMarker", Lua::Movie::getMarker}, + { "setMarker", Lua::Movie::setMarker}, { NULL, NULL } }; @@ -103,3 +104,10 @@ int Lua::Movie::getMarker(lua_State *L) lua_pushstring(L, marker.c_str()); return 1; } + +int Lua::Movie::setMarker(lua_State *L) +{ + const char* marker = lua_tostring(L, 1); + context->movie->editor->markers[context->framecount] = marker; + return 0; +} diff --git a/src/program/lua/Movie.h b/src/program/lua/Movie.h index b6e067f0..0538bd3d 100644 --- a/src/program/lua/Movie.h +++ b/src/program/lua/Movie.h @@ -55,6 +55,9 @@ namespace Movie { /* Get marker at current frame if there is one */ int getMarker(lua_State *L); + + /* Set marker at current frame */ + int setMarker(lua_State *L); } } From b00e46e932f541669ceb972f1e264f763d1ae978 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9lestin=20Matte?= Date: Tue, 4 Nov 2025 21:46:29 +0100 Subject: [PATCH 3/4] get/setMarkers(): register movie similarly to inputs instead of adding it to context --- src/program/Context.h | 3 --- src/program/GameLoop.cpp | 4 +++- src/program/lua/Movie.cpp | 10 ++++++++-- src/program/lua/Movie.h | 5 +++++ 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/program/Context.h b/src/program/Context.h index dcbe37dd..dab97d98 100644 --- a/src/program/Context.h +++ b/src/program/Context.h @@ -143,9 +143,6 @@ struct Context { /* PID of the appimage process that mounts the appimage structure */ pid_t appimage_pid = 0; - - /* Link to the movie */ - MovieFile* movie; }; #endif diff --git a/src/program/GameLoop.cpp b/src/program/GameLoop.cpp index c23e35a3..40f8cb0f 100644 --- a/src/program/GameLoop.cpp +++ b/src/program/GameLoop.cpp @@ -37,6 +37,7 @@ #include "SaveStateList.h" #include "lua/Input.h" #include "lua/Callbacks.h" +#include "lua/Movie.h" #include "lua/NamedLuaFunction.h" #include "ramsearch/MemAccess.h" #include "ramsearch/BaseAddresses.h" @@ -67,7 +68,8 @@ GameLoop::GameLoop(Context* c) : movie(MovieFile(c)), context(c) #elif defined(__APPLE__) && defined(__MACH__) gameEvents = new GameEventsQuartz(c, &movie); #endif - c->movie = &movie; + /* Register Movie so that lua scripts can modify it */ + Lua::Movie::registerMovie(&movie); } void GameLoop::start() diff --git a/src/program/lua/Movie.cpp b/src/program/lua/Movie.cpp index 51f19eca..effdc458 100644 --- a/src/program/lua/Movie.cpp +++ b/src/program/lua/Movie.cpp @@ -28,6 +28,7 @@ extern "C" { } static Context* context; +static MovieFile* movie; /* List of functions to register */ static const luaL_Reg movie_functions[] = @@ -50,6 +51,11 @@ void Lua::Movie::registerFunctions(lua_State *L, Context* c) lua_setglobal(L, "movie"); } +void Lua::Movie::registerMovie(MovieFile* frame_movie) +{ + movie = frame_movie; +} + int Lua::Movie::currentFrame(lua_State *L) { lua_pushinteger(L, static_cast(context->framecount)); @@ -97,7 +103,7 @@ int Lua::Movie::getMarker(lua_State *L) { std::string marker; try { - marker = context->movie->editor->markers.at(context->framecount); + marker = movie->editor->markers.at(context->framecount); } catch (const std::out_of_range&) { return 0; } @@ -108,6 +114,6 @@ int Lua::Movie::getMarker(lua_State *L) int Lua::Movie::setMarker(lua_State *L) { const char* marker = lua_tostring(L, 1); - context->movie->editor->markers[context->framecount] = marker; + movie->editor->markers[context->framecount] = marker; return 0; } diff --git a/src/program/lua/Movie.h b/src/program/lua/Movie.h index 0538bd3d..2fb090bf 100644 --- a/src/program/lua/Movie.h +++ b/src/program/lua/Movie.h @@ -28,6 +28,8 @@ extern "C" { struct Context; +class MovieFile; + namespace Lua { namespace Movie { @@ -35,6 +37,9 @@ namespace Movie { /* Register all functions */ void registerFunctions(lua_State *L, Context* c); + /* Pass the current MovieFile object to be used by lua functions */ + void registerMovie(MovieFile* frame_movie); + /* Get the current framecount */ int currentFrame(lua_State *L); From d21d0ba34a83a3f5449e07d9a441cad667e5777e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9lestin=20Matte?= Date: Tue, 4 Nov 2025 22:45:45 +0100 Subject: [PATCH 4/4] lua: add movie.insertFrame() and movie.insertFrames() --- docs/guides/lua.md | 12 ++++++++++++ src/program/lua/Movie.cpp | 19 +++++++++++++++++++ src/program/lua/Movie.h | 6 ++++++ 3 files changed, 37 insertions(+) diff --git a/docs/guides/lua.md b/docs/guides/lua.md index 2743e7f8..f8556713 100644 --- a/docs/guides/lua.md +++ b/docs/guides/lua.md @@ -311,6 +311,18 @@ Returns the marker at current frame if there is one, none instead. Edit marker at current frame with the text given as parameter. +#### movie.insertFrame + + none movie.insertFrame() + +Insert frame at current position + +#### movie.insertFrames + + none movie.insertFrames(Number nb_frames) + +Insert `nb_frame` frames at current position + ### Runtime functions Runtime functions must be performed in callback `onFrame()` to be effective on diff --git a/src/program/lua/Movie.cpp b/src/program/lua/Movie.cpp index effdc458..780ab5ae 100644 --- a/src/program/lua/Movie.cpp +++ b/src/program/lua/Movie.cpp @@ -21,6 +21,8 @@ #include "Context.h" +#include "../movie/MovieActionInsertFrames.h" + #include extern "C" { #include @@ -41,6 +43,8 @@ static const luaL_Reg movie_functions[] = { "isDraw", Lua::Movie::isDraw}, { "getMarker", Lua::Movie::getMarker}, { "setMarker", Lua::Movie::setMarker}, + { "insertFrame", Lua::Movie::insertFrame}, + { "insertFrames", Lua::Movie::insertFrames}, { NULL, NULL } }; @@ -117,3 +121,18 @@ int Lua::Movie::setMarker(lua_State *L) movie->editor->markers[context->framecount] = marker; return 0; } + +int Lua::Movie::insertFrame(lua_State *L) +{ + MovieActionInsertFrames action(context->framecount, 1, movie->inputs); + action.redo(); + return 0; +} + +int Lua::Movie::insertFrames(lua_State *L) +{ + unsigned int n = static_cast(lua_tointeger(L, 1)); + MovieActionInsertFrames action(context->framecount, n, movie->inputs); + action.redo(); + return 0; +} diff --git a/src/program/lua/Movie.h b/src/program/lua/Movie.h index 2fb090bf..5e256e3d 100644 --- a/src/program/lua/Movie.h +++ b/src/program/lua/Movie.h @@ -63,6 +63,12 @@ namespace Movie { /* Set marker at current frame */ int setMarker(lua_State *L); + + /* Insert frame at current position */ + int insertFrame(lua_State *L); + + /* Insert n frames at current position */ + int insertFrames(lua_State *L); } }