Skip to content

Commit

Permalink
recording improvements
Browse files Browse the repository at this point in the history
remove 'r' record shortcut
add tpt.record function. Still gives the user a confirm prompt
recordings now go into recordings/<timestamp>/, where timestamp is the time the recording was started. <timestamp> is returned by the tpt.record function. Each new recording starts the filenames over at 0 again.

you probably still need a lua script to use the recording feature, this should make it easier for those
  • Loading branch information
jacob1 committed Sep 4, 2017
1 parent e4089a2 commit 6bd0687
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 21 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -18,6 +18,7 @@ Saves/*
scripts/*
generated/*
includes/*
recordings/
font/*
generate
Makefile.me
Expand Down
5 changes: 5 additions & 0 deletions src/gui/game/GameController.cpp
Expand Up @@ -1571,6 +1571,11 @@ std::string GameController::WallName(int type)
return "";
}

int GameController::Record(bool record)
{
return gameView->Record(record);
}

void GameController::NotifyAuthUserChanged(Client * sender)
{
User newUser = sender->GetAuthUser();
Expand Down
1 change: 1 addition & 0 deletions src/gui/game/GameController.h
Expand Up @@ -149,6 +149,7 @@ class GameController: public ClientListener
std::string ElementResolve(int type, int ctype);
bool IsValidElement(int type);
std::string WallName(int type);
int Record(bool record);

void ResetAir();
void ResetSpark();
Expand Down
41 changes: 22 additions & 19 deletions src/gui/game/GameView.cpp
Expand Up @@ -186,8 +186,9 @@ GameView::GameView():
introTextMessage(introTextData),

doScreenshot(false),
recording(false),
screenshotIndex(0),
recording(false),
recordingFolder(0),
recordingIndex(0),
currentPoint(ui::Point(0, 0)),
lastPoint(ui::Point(0, 0)),
Expand Down Expand Up @@ -1044,28 +1045,31 @@ void GameView::screenshot()
doScreenshot = true;
}

void GameView::record()
int GameView::Record(bool record)
{
if(recording)
if (!record)
{
recording = false;
recordingIndex = 0;
recordingFolder = 0;
}
else
else if (!recording)
{
class RecordingConfirmation: public ConfirmDialogueCallback {
public:
GameView * v;
RecordingConfirmation(GameView * v): v(v) {}
virtual void ConfirmCallback(ConfirmPrompt::DialogueResult result) {
if (result == ConfirmPrompt::ResultOkay)
{
v->recording = true;
}
}
virtual ~RecordingConfirmation() { }
};
new ConfirmPrompt("Recording", "You're about to start recording all drawn frames. This may use a load of hard disk space.", new RecordingConfirmation(this));
// block so that the return value is correct
bool record = ConfirmPrompt::Blocking("Recording", "You're about to start recording all drawn frames. This will use a load of disk space.");
if (record)
{
time_t startTime = time(NULL);
recordingFolder = startTime;
std::stringstream recordingDir;
recordingDir << "recordings" << PATH_SEP << recordingFolder;
Client::Ref().MakeDirectory("recordings");
Client::Ref().MakeDirectory(recordingDir.str().c_str());
recording = true;
recordingIndex = 0;
}
}
return recordingFolder;
}

void GameView::updateToolButtonScroll()
Expand Down Expand Up @@ -1496,8 +1500,6 @@ void GameView::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool
case 'r':
if (ctrl)
c->ReloadSim();
else
record();
break;
case 'e':
c->OpenElementSearch();
Expand Down Expand Up @@ -2233,6 +2235,7 @@ void GameView::OnDraw()
std::vector<char> data = format::VideoBufferToPPM(screenshot);

std::stringstream filename;
filename << "recordings" << PATH_SEP << recordingFolder << PATH_SEP;
filename << "frame_";
filename << std::setfill('0') << std::setw(6) << (recordingIndex++);
filename << ".ppm";
Expand Down
5 changes: 3 additions & 2 deletions src/gui/game/GameView.h
Expand Up @@ -66,8 +66,9 @@ class GameView: public ui::Window
std::string introTextMessage;

bool doScreenshot;
bool recording;
int screenshotIndex;
bool recording;
int recordingFolder;
int recordingIndex;

ui::Point currentPoint, lastPoint;
Expand Down Expand Up @@ -117,7 +118,6 @@ class GameView: public ui::Window
void SetSaveButtonTooltips();

void screenshot();
void record();

void enableShiftBehaviour();
void disableShiftBehaviour();
Expand Down Expand Up @@ -147,6 +147,7 @@ class GameView: public ui::Window
void ExitPrompt();
SelectMode GetSelectMode() { return selectMode; }
void BeginStampSelection();
int Record(bool record);

//all of these are only here for one debug lines
bool GetMouseDown() { return isMouseDown; }
Expand Down
10 changes: 10 additions & 0 deletions src/lua/LegacyLuaAPI.cpp
Expand Up @@ -2032,4 +2032,14 @@ int luatpt_screenshot(lua_State* l)
return 1;
}

int luatpt_record(lua_State* l)
{
if (!lua_isboolean(l, -1))
return luaL_typerror(l, 1, lua_typename(l, LUA_TBOOLEAN));
bool record = lua_toboolean(l, -1);
int recordingFolder = luacon_controller->Record(record);
lua_pushinteger(l, recordingFolder);
return 1;
}

#endif
1 change: 1 addition & 0 deletions src/lua/LuaScriptHelper.h
Expand Up @@ -131,6 +131,7 @@ int luatpt_getscript(lua_State* l);
int luatpt_setwindowsize(lua_State* l);

int luatpt_screenshot(lua_State* l);
int luatpt_record(lua_State* l);


#endif /* LUASCRIPTHELPER_H_ */
1 change: 1 addition & 0 deletions src/lua/LuaScriptInterface.cpp
Expand Up @@ -202,6 +202,7 @@ LuaScriptInterface::LuaScriptInterface(GameController * c, GameModel * m):
{"setwindowsize",&luatpt_setwindowsize},
{"watertest",&luatpt_togglewater},
{"screenshot",&luatpt_screenshot},
{"record",&luatpt_record},
{"element",&luatpt_getelement},
{"element_func",&luatpt_element_func},
{"graphics_func",&luatpt_graphics_func},
Expand Down

0 comments on commit 6bd0687

Please sign in to comment.