Misc cleanup in session recording

This commit is contained in:
Alexander Bock
2019-05-23 03:03:04 -06:00
parent dfc9ab17f0
commit 9f6733ed72
5 changed files with 278 additions and 305 deletions

View File

@@ -27,18 +27,10 @@
#include <openspace/interaction/externinteraction.h>
#include <openspace/interaction/keyframenavigator.h>
#include <openspace/network/messagestructures.h>
#include <openspace/scripting/lualibrary.h>
#include <ghoul/io/socket/tcpsocket.h>
#include <vector>
#include <fstream>
#include <iomanip>
namespace openspace::interaction {
#define RECORD_BINARY
class KeyframeNavigator;
class SessionRecording : public properties::PropertyOwner {
public:
@@ -57,121 +49,137 @@ public:
using StateChangeCallback = std::function<void()>;
SessionRecording();
~SessionRecording();
/**
* Used to de-initialize the session recording feature. Any recording or playback
* in progress will be stopped, files closed, and keyframes in memory deleted.
*/
* Used to de-initialize the session recording feature. Any recording or playback
* in progress will be stopped, files closed, and keyframes in memory deleted.
*/
void deinitialize();
/**
* This is called with every rendered frame. If in recording state, the camera
* state will be saved to the recording file (if its state has changed since last).
* If in playback state, the next keyframe will be used (if it is time to do so).
*/
* This is called with every rendered frame. If in recording state, the camera
* state will be saved to the recording file (if its state has changed since last).
* If in playback state, the next keyframe will be used (if it is time to do so).
*/
void preSynchronization();
/**
* Starts a recording session, which will save data to the provided filename
* according to the data format specified, and will continue until recording is
* stopped using stopRecording() method.
* \param filename file saved with recorded keyframes.
* \returns true if recording to file starts without errors.
*/
* Starts a recording session, which will save data to the provided filename
* according to the data format specified, and will continue until recording is
* stopped using stopRecording() method.
*
* \param filename file saved with recorded keyframes.
*
* \return \c true if recording to file starts without errors
*/
bool startRecording(const std::string& filename);
/**
* Starts a recording session, which will save data to the provided filename
* in ASCII data format until recording is stopped using stopRecording() method.
* \param filename file saved with recorded keyframes.
* \returns true if recording to file starts without errors.
*/
* Starts a recording session, which will save data to the provided filename
* in ASCII data format until recording is stopped using stopRecording() method.
*
* \param filename file saved with recorded keyframes.
*
* \return \c true if recording to file starts without errors
*/
void setRecordDataFormat(RecordedDataMode dataMode);
/**
* Used to stop a recording in progress. If open, the recording file will be closed,
* and all keyframes deleted from memory.
*/
* Used to stop a recording in progress. If open, the recording file will be closed,
* and all keyframes deleted from memory.
*/
void stopRecording();
/**
* Used to check if a session recording is in progress.
* \returns true if recording is in progress.
*/
* Used to check if a session recording is in progress.
*
* \return true if recording is in progress
*/
bool isRecording() const;
/**
* Starts a playback session, which can run in one of three different time modes.
* \param filename file containing recorded keyframes to play back
* \param timeMode which of the 3 time modes to use for time reference during
* \param forceSimTimeAtStart if true simulation time is forced to that of playback
* playback: recorded time, application time, or simulation time. See the LuaLibrary
* entry for SessionRecording for details on these time modes.
* \returns true if recording to file starts without errors.
*/
* Starts a playback session, which can run in one of three different time modes.
*
* \param filename file containing recorded keyframes to play back
* \param timeMode which of the 3 time modes to use for time reference during
* \param forceSimTimeAtStart if true simulation time is forced to that of playback
* playback: recorded time, application time, or simulation time. See the
* LuaLibrary entry for SessionRecording for details on these time modes
*
* \return \c true if recording to file starts without errors
*/
bool startPlayback(const std::string& filename, KeyframeTimeRef timeMode,
bool forceSimTimeAtStart);
/**
* Used to stop a playback in progress. If open, the playback file will be closed,
* and all keyframes deleted from memory.
*/
* Used to stop a playback in progress. If open, the playback file will be closed,
* and all keyframes deleted from memory.
*/
void stopPlayback();
/**
* Used to check if a session playback is in progress.
* \returns true if playback is in progress.
*/
* Used to check if a session playback is in progress.
*
* \return \c true if playback is in progress
*/
bool isPlayingBack() const;
/**
* Used to obtain the state of idle/recording/playback.
* \returns int value of state as defined by struct SessionState.
*/
* Used to obtain the state of idle/recording/playback.
*
* \return int value of state as defined by struct SessionState
*/
SessionState state() const;
/**
* Used to trigger a save of the camera states (position, rotation, focus node,
* whether it is following the rotation of a node, and timestamp). The data will
* be saved to the recording file only if a recording is currently in progress.
*/
* Used to trigger a save of the camera states (position, rotation, focus node,
* whether it is following the rotation of a node, and timestamp). The data will be
* saved to the recording file only if a recording is currently in progress.
*/
void saveCameraKeyframe();
/**
* Used to trigger a save of the current timing states. The data will be saved
* to the recording file only if a recording is currently in progress.
*/
* Used to trigger a save of the current timing states. The data will be saved to the
* recording file only if a recording is currently in progress.
*/
void saveTimeKeyframe();
/**
* Used to trigger a save of a script to the recording file, but only if a recording
* is currently in progress.
* \param scriptToSave String of the Lua command to be saved.
*/
* Used to trigger a save of a script to the recording file, but only if a recording
* is currently in progress.
*
* \param scriptToSave String of the Lua command to be saved
*/
void saveScriptKeyframe(std::string scriptToSave);
/**
* \return The Lua library that contains all Lua functions available to affect the
* interaction
*/
* \return The Lua library that contains all Lua functions available to affect the
* interaction
*/
static openspace::scripting::LuaLibrary luaLibrary();
/**
* Used to request a callback for notification of playback state change.
* \param cb function handle for callback.
* \returns CallbackHandle value of callback number.
*/
* Used to request a callback for notification of playback state change.
*
* \param cb function handle for callback
*
* \return CallbackHandle value of callback number
*/
CallbackHandle addStateChangeCallback(StateChangeCallback cb);
/**
* Removes the callback for notification of playback state change.
* \param callback function handle for the callback.
*/
*
* \param callback function handle for the callback
*/
void removeStateChangeCallback(CallbackHandle handle);
/**
* Provides list of available playback files.
* \returns vector of filenames in recordings dir.
*
* \return vector of filenames in recordings dir
*/
std::vector<std::string> playbackList() const;
@@ -211,7 +219,6 @@ private:
void saveStringToFile(const std::string& s);
void saveKeyframeToFileBinary(unsigned char* bufferSource, size_t size);
void findFirstCameraKeyframeInTimeline();
std::string readHeaderElement(size_t readLen_chars);
void saveKeyframeToFile(std::string entry);
void addKeyframe(double timestamp,
@@ -226,7 +233,7 @@ private:
bool findNextFutureCameraIndex(double currTime);
bool processCameraKeyframe(double now);
bool processScriptKeyframe();
bool isDataModeBinary();
//bool isDataModeBinary();
unsigned int findIndexOfLastCameraKeyframeInTimeline();
bool doesTimelineEntryContainCamera(unsigned int index) const;
std::vector<std::pair<CallbackHandle, StateChangeCallback>> _stateChangeCallbacks;
@@ -237,13 +244,6 @@ private:
double getPrevTimestamp();
void cleanUpPlayback();
const bool _usingTimeKeyframes = false;
const std::string _fileHeaderTitle = "OpenSpace_record/playback";
static const size_t _fileHeaderVersionLength = 5;
const char _fileHeaderVersion[_fileHeaderVersionLength] = { '0', '0', '.', '8', '5' };
const char dataFormatAsciiTag = 'A';
const char dataFormatBinaryTag = 'B';
RecordedDataMode _recordingDataMode = RecordedDataMode::Binary;
SessionState _state = SessionState::Idle;
SessionState _lastState = SessionState::Idle;
@@ -271,7 +271,7 @@ private:
bool _cleanupNeeded = false;
std::vector < interaction::KeyframeNavigator::CameraPose> _keyframesCamera;
std::vector<interaction::KeyframeNavigator::CameraPose> _keyframesCamera;
std::vector<datamessagestructures::TimeKeyframe> _keyframesTime;
std::vector<std::string> _keyframesScript;
std::vector<timelineEntry> _timeline;

View File

@@ -25,13 +25,13 @@
namespace openspace::interaction {
template <class T>
T nextKeyframeObj(unsigned int index,
const std::vector<T>& keyframeContainer,
T nextKeyframeObj(unsigned int index, const std::vector<T>& keyframeContainer,
std::function<void()> finishedCallback)
{
if (index >= (keyframeContainer.size() - 1)) {
if( index == (keyframeContainer.size() - 1) )
if (index == (keyframeContainer.size() - 1)) {
finishedCallback();
}
return keyframeContainer.back();
} else if (index < keyframeContainer.size()) {
return keyframeContainer[index];
@@ -41,9 +41,7 @@ T nextKeyframeObj(unsigned int index,
}
template <class T>
T prevKeyframeObj(unsigned int index,
const std::vector<T>& keyframeContainer)
{
T prevKeyframeObj(unsigned int index, const std::vector<T>& keyframeContainer) {
if (index >= keyframeContainer.size()) {
return keyframeContainer.back();
} else if (index > 0) {
@@ -53,5 +51,4 @@ T prevKeyframeObj(unsigned int index,
}
}
} // namespace openspace::interaction