core: Add read-only mode and separate savestate slots for movies

The read-only mode switch affects how movies interact with savestates after you start a movie playback and load a savestate. When you are in read-only mode, the movie will resume playing from the loaded savestate. When you are in read+write mode however, your input will be recorded over the original movie ('rerecording'). If you wish to start rerecording immediately, you should switch to R+W mode, save a state and then load it.

To make this more user-friendly, I also added a unique ID to the movies, which allows each movie to have an individual set of savestate slots (plus another set for when not doing any movies). This is as recommended by staff at TASVideos.
This commit is contained in:
zhupengfei 2020-06-29 22:32:24 +08:00
parent 2e3834f880
commit ebaa225bcb
No known key found for this signature in database
GPG key ID: DD129E108BD09378
3 changed files with 102 additions and 13 deletions

View file

@ -46,6 +46,18 @@ public:
const std::string& movie_file, std::function<void()> completion_callback = [] {});
void StartRecording(const std::string& movie_file);
/**
* Sets the read-only status.
* When true, movies will be opened in read-only mode. Loading a state will resume playback
* from that state.
* When false, movies will be opened in read/write mode. Loading a state will start recording
* from that state (rerecording). To start rerecording without loading a state, one can save
* and then immediately load while in R/W.
*
* The default is true.
*/
void SetReadOnly(bool read_only);
/// Prepare to override the clock before playing back movies
void PrepareForPlayback(const std::string& movie_file);
@ -58,6 +70,11 @@ public:
u64 GetOverrideInitTime() const;
u64 GetMovieProgramID(const std::string& movie_file) const;
/// Get the current movie's unique ID. Used to provide separate savestate slots for movies.
u64 GetCurrentMovieID() const {
return id;
}
void Shutdown();
/**
@ -133,16 +150,13 @@ private:
u64 init_time;
std::function<void()> playback_completion_callback;
std::size_t current_byte = 0;
u64 id = 0; // ID of the current movie loaded
bool read_only = true;
template <class Archive>
void serialize(Archive& ar, const unsigned int) {
// Only serialize what's needed to make savestates useful for TAS:
u64 _current_byte = static_cast<u64>(current_byte);
ar& _current_byte;
current_byte = static_cast<std::size_t>(_current_byte);
ar& recorded_input;
ar& init_time;
}
void serialize(Archive& ar, const unsigned int file_version);
friend class boost::serialization::access;
};
} // namespace Core
} // namespace Core
BOOST_CLASS_VERSION(Core::Movie, 1)