Add playback/record Lua functions

This commit is contained in:
Brendan Byrd 2018-11-28 22:44:45 -05:00
parent 47c8491114
commit f9f35cbadb
3 changed files with 95 additions and 4 deletions

View File

@ -3098,6 +3098,72 @@ static int movie_replay (lua_State *L) {
return 0;
}
// bool movie.play(string filename, [bool read_only, [int pauseframe]])
//
// Loads and plays a movie.
int movie_playback(lua_State *L) {
int arg_count = lua_gettop(L);
if (arg_count == 0) {
luaL_error(L, "no parameters specified");
return 0;
}
const char *filename = luaL_checkstring(L,1);
if (filename == NULL) {
luaL_error(L, "Filename required");
return 0;
}
bool read_only = arg_count >= 2 ? (lua_toboolean(L,2) == 1) : 0;
int pauseframe = arg_count >= 3 ? lua_tointeger(L,3) : 0;
if (pauseframe < 0) pauseframe = 0;
// Load it!
bool loaded = FCEUI_LoadMovie(filename, read_only, pauseframe);
lua_pushboolean(L, loaded);
return 1;
}
// bool movie.record(string filename, [int save_type, [string author]])
//
// Saves and records a movie.
int movie_record(lua_State *L) {
int arg_count = lua_gettop(L);
if (arg_count == 0) {
luaL_error(L, "no parameters specified");
return 0;
}
const char *filename = luaL_checkstring(L,1);
if (filename == NULL) {
luaL_error(L, "Filename required");
return 0;
}
// No need to use the full functionality of the enum
int save_type = arg_count >= 2 ? lua_tointeger(L, 2) : 0;
EMOVIE_FLAG flags;
if (save_type == 1) flags = MOVIE_FLAG_NONE; // from savestate
else if (save_type == 2) flags = MOVIE_FLAG_FROM_SAVERAM;
else flags = MOVIE_FLAG_FROM_POWERON;
// XXX: Assuming UTF-8 strings in Lua
std::wstring author =
arg_count >= 3 ?
mbstowcs( (std::string)luaL_checkstring(L, 3) ) : L""
;
// Save it!
FCEUI_SaveMovie(filename, flags, author);
lua_pushboolean(L, 1);
return 1;
}
//movie.ispoweron
//
//If movie is recorded from power-on
@ -5759,13 +5825,15 @@ static const struct luaL_reg movielib[] = {
{"readonly", movie_getreadonly},
{"setreadonly", movie_setreadonly},
{"replay", movie_replay},
// {"record", movie_record},
// {"play", movie_playback},
{"record", movie_record},
{"play", movie_playback},
// alternative names
{"close", movie_stop},
{"getname", movie_getname},
// {"playback", movie_playback},
{"load", movie_playback},
{"save", movie_record},
{"playback", movie_playback},
{"playbeginning", movie_replay},
{"getreadonly", movie_getreadonly},
{"ispoweron", movie_ispoweron}, //If movie recorded from power-on

View File

@ -1024,9 +1024,12 @@ bool FCEUI_LoadMovie(const char *fname, bool _read_only, int _pauseframe)
static void openRecordingMovie(const char* fname)
{
osRecordingMovie = FCEUD_UTF8_fstream(fname, "wb");
if(!osRecordingMovie)
if(!osRecordingMovie || osRecordingMovie->fail()) {
FCEU_PrintError("Error opening movie output file: %s",fname);
return;
}
strcpy(curMovieFilename, fname);
#ifdef WIN32
//Add to the recent movie menu
AddRecentMovieFile(fname);
@ -1047,6 +1050,9 @@ void FCEUI_SaveMovie(const char *fname, EMOVIE_FLAG flags, std::wstring author)
openRecordingMovie(fname);
if(!osRecordingMovie || osRecordingMovie->fail())
return;
currFrameCounter = 0;
LagCounterReset();
FCEUMOV_CreateCleanMovie();

View File

@ -485,6 +485,23 @@
<p><span class="rvts37"><br/></span></p>
<p><span class="rvts71">Movie Library</span></p>
<p><span class="rvts37"><br/></span></p>
<p><span class="rvts63">bool movie.play(string filename, [bool read_only, [int pauseframe]])</span></p>
<p><span class="rvts63">bool movie.playback(...)</span></p>
<p><span class="rvts63">bool movie.load(...)</span></p>
<p><span class="rvts37"><br/></span></p>
<p><span class="rvts37">Loads and plays a movie from the directory relative to the Lua script or from the absolute path. If read_only is true, the movie will be loaded in read-only mode. The default is read+write.</span></p>
<p><span class="rvts37"><br/></span></p>
<p><span class="rvts37">A pauseframe can be specified, which controls which frame will auto-pause the movie. By default, this is off. A true value is returned if the movie loaded correctly.</span></p>
<p><span class="rvts37"><br/></span></p>
<p><span class="rvts63">bool movie.record(string filename, [int save_type, [string author]])</span></p>
<p><span class="rvts63">bool movie.save(...)</span></p>
<p><span class="rvts37"><br/></span></p>
<p><span class="rvts37">Starts recording a movie, using the filename, relative to the Lua script.</span></p>
<p><span class="rvts37"><br/></span></p>
<p><span class="rvts37">An optional save_type can be specified. If set to 0 (default), it will record from a power on state, and automatically do so. This is the recommended setting for creating movies. This can also be set to 1 for savestate or 2 for saveram movies.</span></p>
<p><span class="rvts37"><br/></span></p>
<p><span class="rvts37">A third parameter specifies an author string. If included, it will be recorded into the movie file.</span></p>
<p><span class="rvts37"><br/></span></p>
<p><span class="rvts63">bool movie.active()</span></p>
<p><span class="rvts37"><br/></span></p>
<p><span class="rvts37">Returns true if a movie is currently loaded and false otherwise. &nbsp;(This should be used to guard against Lua errors when attempting to retrieve movie information).</span></p>