From 5a42a80f408c0598d3fb59d7a4213370f362fbb4 Mon Sep 17 00:00:00 2001 From: zhupengfei Date: Tue, 7 Jul 2020 16:38:24 +0800 Subject: [PATCH] core/movie: Allow setting a playback completion callback Instead of specifying it when starting playback. This is necessary as you can end up playing the movie even if you started as Recording (for example, loading a state in R/O mode will switch to Playing mode) --- src/core/movie.cpp | 8 +++++--- src/core/movie.h | 6 +++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/core/movie.cpp b/src/core/movie.cpp index 2be5dfd27..51746e744 100644 --- a/src/core/movie.cpp +++ b/src/core/movie.cpp @@ -486,8 +486,11 @@ void Movie::SaveMovie() { } } -void Movie::StartPlayback(const std::string& movie_file, - std::function completion_callback) { +void Movie::SetPlaybackCompletionCallback(std::function completion_callback) { + playback_completion_callback = completion_callback; +} + +void Movie::StartPlayback(const std::string& movie_file) { LOG_INFO(Movie, "Loading Movie for playback"); FileUtil::IOFile save_record(movie_file, "rb"); const u64 size = save_record.GetSize(); @@ -510,7 +513,6 @@ void Movie::StartPlayback(const std::string& movie_file, current_byte = 0; id = header.id; - playback_completion_callback = completion_callback; LOG_INFO(Movie, "Loaded Movie, ID: {:016X}", id); } diff --git a/src/core/movie.h b/src/core/movie.h index 09912c3f8..dcbe8129b 100644 --- a/src/core/movie.h +++ b/src/core/movie.h @@ -42,8 +42,8 @@ public: return s_instance; } - void StartPlayback(const std::string& movie_file, - std::function completion_callback = [] {}); + void SetPlaybackCompletionCallback(std::function completion_callback); + void StartPlayback(const std::string& movie_file); void StartRecording(const std::string& movie_file, const std::string& author); /** @@ -165,7 +165,7 @@ private: u32 rerecord_count = 1; bool read_only = true; - std::function playback_completion_callback; + std::function playback_completion_callback = [] {}; template void serialize(Archive& ar, const unsigned int file_version);