Core/Movie: Refactor to class, move to System.

A bit of global state remains (the `header` in `BeginRecordingInput()`) due to unclear lifetime requirements.
This commit is contained in:
Admiral H. Curtiss
2024-01-13 13:14:48 +01:00
parent c76dee7807
commit 95cba6be2b
32 changed files with 717 additions and 609 deletions

View File

@ -277,7 +277,7 @@ MainWindow::MainWindow(std::unique_ptr<BootParameters> boot_parameters,
if (!movie_path.empty())
{
std::optional<std::string> savestate_path;
if (Movie::PlayInput(movie_path, &savestate_path))
if (Core::System::GetInstance().GetMovie().PlayInput(movie_path, &savestate_path))
{
m_pending_boot->boot_session_data.SetSavestateData(std::move(savestate_path),
DeleteSavestateAfterBoot::No);
@ -646,8 +646,9 @@ void MainWindow::ConnectHotkeys()
connect(m_hotkey_scheduler, &HotkeyScheduler::ConnectWiiRemote, this,
&MainWindow::OnConnectWiiRemote);
connect(m_hotkey_scheduler, &HotkeyScheduler::ToggleReadOnlyMode, [this] {
bool read_only = !Movie::IsReadOnly();
Movie::SetReadOnly(read_only);
auto& movie = Core::System::GetInstance().GetMovie();
bool read_only = !movie.IsReadOnly();
movie.SetReadOnly(read_only);
emit ReadOnlyModeChanged(read_only);
});
@ -1011,9 +1012,10 @@ void MainWindow::ForceStop()
void MainWindow::Reset()
{
if (Movie::IsRecordingInput())
Movie::SetReset(true);
auto& system = Core::System::GetInstance();
auto& movie = system.GetMovie();
if (movie.IsRecordingInput())
movie.SetReset(true);
system.GetProcessorInterface().ResetButton_Tap();
}
@ -1853,15 +1855,16 @@ void MainWindow::OnPlayRecording()
if (dtm_file.isEmpty())
return;
if (!Movie::IsReadOnly())
auto& movie = Core::System::GetInstance().GetMovie();
if (!movie.IsReadOnly())
{
// let's make the read-only flag consistent at the start of a movie.
Movie::SetReadOnly(true);
movie.SetReadOnly(true);
emit ReadOnlyModeChanged(true);
}
std::optional<std::string> savestate_path;
if (Movie::PlayInput(dtm_file.toStdString(), &savestate_path))
if (movie.PlayInput(dtm_file.toStdString(), &savestate_path))
{
emit RecordingStatusChanged(true);
@ -1871,14 +1874,17 @@ void MainWindow::OnPlayRecording()
void MainWindow::OnStartRecording()
{
if ((!Core::IsRunningAndStarted() && Core::IsRunning()) || Movie::IsRecordingInput() ||
Movie::IsPlayingInput())
auto& movie = Core::System::GetInstance().GetMovie();
if ((!Core::IsRunningAndStarted() && Core::IsRunning()) || movie.IsRecordingInput() ||
movie.IsPlayingInput())
{
return;
}
if (Movie::IsReadOnly())
if (movie.IsReadOnly())
{
// The user just chose to record a movie, so that should take precedence
Movie::SetReadOnly(false);
movie.SetReadOnly(false);
emit ReadOnlyModeChanged(true);
}
@ -1897,7 +1903,7 @@ void MainWindow::OnStartRecording()
wiimotes[i] = Config::Get(Config::GetInfoForWiimoteSource(i)) != WiimoteSource::None;
}
if (Movie::BeginRecordingInput(controllers, wiimotes))
if (movie.BeginRecordingInput(controllers, wiimotes))
{
emit RecordingStatusChanged(true);
@ -1908,10 +1914,11 @@ void MainWindow::OnStartRecording()
void MainWindow::OnStopRecording()
{
if (Movie::IsRecordingInput())
auto& movie = Core::System::GetInstance().GetMovie();
if (movie.IsRecordingInput())
OnExportRecording();
if (Movie::IsMovieActive())
Movie::EndPlayInput(false);
if (movie.IsMovieActive())
movie.EndPlayInput(false);
emit RecordingStatusChanged(false);
}
@ -1921,7 +1928,7 @@ void MainWindow::OnExportRecording()
QString dtm_file = DolphinFileDialog::getSaveFileName(
this, tr("Save Recording File As"), QString(), tr("Dolphin TAS Movies (*.dtm)"));
if (!dtm_file.isEmpty())
Movie::SaveRecording(dtm_file.toStdString());
Core::System::GetInstance().GetMovie().SaveRecording(dtm_file.toStdString());
});
}