more movie cleanup. Removes the remaining globals that didn't need to be global, rearranges some code to make more sense, and removes some redundant code.

This commit is contained in:
rog 2012-10-21 17:48:45 -04:00
parent 9070e7ff8c
commit aece5310f3
5 changed files with 55 additions and 42 deletions

View File

@ -124,7 +124,7 @@ bool BootCore(const std::string& _rFilename)
StartUp.bDSPHLE = Movie::IsDSPHLE(); StartUp.bDSPHLE = Movie::IsDSPHLE();
StartUp.bProgressive = Movie::IsProgressive(); StartUp.bProgressive = Movie::IsProgressive();
StartUp.bFastDiscSpeed = Movie::IsFastDiscSpeed(); StartUp.bFastDiscSpeed = Movie::IsFastDiscSpeed();
if (Movie::g_bMemcard && Movie::g_bBlankMC) if (Movie::IsUsingMemcard() && Movie::IsBlankMemcard())
{ {
if (File::Exists("Movie.raw")) if (File::Exists("Movie.raw"))
File::Delete("Movie.raw"); File::Delete("Movie.raw");

View File

@ -434,7 +434,7 @@ void EmuThread()
CBoot::BootUp(); CBoot::BootUp();
// Setup our core, but can't use dynarec if we are compare server // Setup our core, but can't use dynarec if we are compare server
if (Movie::g_CPUCore && (!_CoreParameter.bRunCompareServer || if (Movie::GetCPUMode() && (!_CoreParameter.bRunCompareServer ||
_CoreParameter.bRunCompareClient)) _CoreParameter.bRunCompareClient))
PowerPC::SetMode(PowerPC::MODE_JIT); PowerPC::SetMode(PowerPC::MODE_JIT);
else else

View File

@ -52,7 +52,7 @@ CEXIMemoryCard::CEXIMemoryCard(const int index)
, m_bDirty(false) , m_bDirty(false)
{ {
m_strFilename = (card_index == 0) ? SConfig::GetInstance().m_strMemoryCardA : SConfig::GetInstance().m_strMemoryCardB; m_strFilename = (card_index == 0) ? SConfig::GetInstance().m_strMemoryCardA : SConfig::GetInstance().m_strMemoryCardB;
if (Movie::g_bMemcard && Movie::IsPlayingInput() && Movie::IsConfigSaved() && Movie::g_bBlankMC) if (Movie::IsUsingMemcard() && Movie::IsPlayingInput() && Movie::IsConfigSaved() && Movie::IsBlankMemcard())
m_strFilename = "Movie.raw"; m_strFilename = "Movie.raw";
// we're potentially leaking events here, since there's no UnregisterEvent until emu shutdown, but I guess it's inconsequential // we're potentially leaking events here, since there's no UnregisterEvent until emu shutdown, but I guess it's inconsequential

View File

@ -66,10 +66,10 @@ bool bDualCore = false;
bool bProgressive = false; bool bProgressive = false;
bool bDSPHLE = false; bool bDSPHLE = false;
bool bFastDiscSpeed = false; bool bFastDiscSpeed = false;
std::string g_videoBackend = "opengl"; std::string videoBackend = "opengl";
int g_CPUCore = 1; int iCPUCore = 1;
bool g_bMemcard; bool bMemcard;
bool g_bBlankMC = false; bool bBlankMC = false;
bool g_bDiscChange = false; bool g_bDiscChange = false;
std::string g_discChange = ""; std::string g_discChange = "";
std::string author = ""; std::string author = "";
@ -138,7 +138,7 @@ void Init()
} }
g_frameSkipCounter = g_framesToSkip; g_frameSkipCounter = g_framesToSkip;
memset(&g_padState, 0, sizeof(g_padState)); memset(&g_padState, 0, sizeof(g_padState));
if (!tmpHeader.bFromSaveState) if (!tmpHeader.bFromSaveState || !IsPlayingInput())
Core::SetStateFileName(""); Core::SetStateFileName("");
for (int i = 0; i < 8; ++i) for (int i = 0; i < 8; ++i)
g_InputDisplay[i].clear(); g_InputDisplay[i].clear();
@ -245,7 +245,7 @@ bool IsJustStartingRecordingInputFromSaveState()
bool IsJustStartingPlayingInputFromSaveState() bool IsJustStartingPlayingInputFromSaveState()
{ {
return tmpHeader.bFromSaveState && g_currentFrame == 1; return IsRecordingInputFromSaveState() && g_currentFrame == 1 && IsPlayingInput();
} }
bool IsPlayingInput() bool IsPlayingInput()
@ -304,7 +304,17 @@ bool IsFastDiscSpeed()
int GetCPUMode() int GetCPUMode()
{ {
return g_CPUCore; return iCPUCore;
}
bool IsBlankMemcard()
{
return bBlankMC;
}
bool IsUsingMemcard()
{
return bMemcard;
} }
void ChangePads(bool instantly) void ChangePads(bool instantly)
@ -374,8 +384,9 @@ bool BeginRecordingInput(int controllers)
bProgressive = SConfig::GetInstance().m_LocalCoreStartupParameter.bProgressive; bProgressive = SConfig::GetInstance().m_LocalCoreStartupParameter.bProgressive;
bDSPHLE = SConfig::GetInstance().m_LocalCoreStartupParameter.bDSPHLE; bDSPHLE = SConfig::GetInstance().m_LocalCoreStartupParameter.bDSPHLE;
bFastDiscSpeed = SConfig::GetInstance().m_LocalCoreStartupParameter.bFastDiscSpeed; bFastDiscSpeed = SConfig::GetInstance().m_LocalCoreStartupParameter.bFastDiscSpeed;
g_videoBackend = SConfig::GetInstance().m_LocalCoreStartupParameter.m_strVideoBackend; videoBackend = SConfig::GetInstance().m_LocalCoreStartupParameter.m_strVideoBackend;
g_CPUCore = SConfig::GetInstance().m_LocalCoreStartupParameter.iCPUCore; iCPUCore = SConfig::GetInstance().m_LocalCoreStartupParameter.iCPUCore;
bBlankMC = !File::Exists(SConfig::GetInstance().m_strMemoryCardA);
delete [] tmpInput; delete [] tmpInput;
tmpInput = new u8[MAX_DTM_LENGTH]; tmpInput = new u8[MAX_DTM_LENGTH];
@ -604,7 +615,7 @@ void ReadHeader()
{ {
g_numPads = tmpHeader.numControllers; g_numPads = tmpHeader.numControllers;
g_recordingStartTime = tmpHeader.recordingStartTime; g_recordingStartTime = tmpHeader.recordingStartTime;
if (g_rerecords < tmpHeader.numRerecords); if (g_rerecords < tmpHeader.numRerecords)
g_rerecords = tmpHeader.numRerecords; g_rerecords = tmpHeader.numRerecords;
if (tmpHeader.bSaveConfig) if (tmpHeader.bSaveConfig)
@ -615,24 +626,26 @@ void ReadHeader()
bProgressive = tmpHeader.bProgressive; bProgressive = tmpHeader.bProgressive;
bDSPHLE = tmpHeader.bDSPHLE; bDSPHLE = tmpHeader.bDSPHLE;
bFastDiscSpeed = tmpHeader.bFastDiscSpeed; bFastDiscSpeed = tmpHeader.bFastDiscSpeed;
g_CPUCore = tmpHeader.CPUCore; iCPUCore = tmpHeader.CPUCore;
bBlankMC = tmpHeader.bBlankMC;
} }
else else
{ {
bSaveConfig = true; bSaveConfig = false;
bSkipIdle = SConfig::GetInstance().m_LocalCoreStartupParameter.bSkipIdle; bSkipIdle = SConfig::GetInstance().m_LocalCoreStartupParameter.bSkipIdle;
bDualCore = SConfig::GetInstance().m_LocalCoreStartupParameter.bCPUThread; bDualCore = SConfig::GetInstance().m_LocalCoreStartupParameter.bCPUThread;
bProgressive = SConfig::GetInstance().m_LocalCoreStartupParameter.bProgressive; bProgressive = SConfig::GetInstance().m_LocalCoreStartupParameter.bProgressive;
bDSPHLE = SConfig::GetInstance().m_LocalCoreStartupParameter.bDSPHLE; bDSPHLE = SConfig::GetInstance().m_LocalCoreStartupParameter.bDSPHLE;
bFastDiscSpeed = SConfig::GetInstance().m_LocalCoreStartupParameter.bFastDiscSpeed; bFastDiscSpeed = SConfig::GetInstance().m_LocalCoreStartupParameter.bFastDiscSpeed;
g_videoBackend = SConfig::GetInstance().m_LocalCoreStartupParameter.m_strVideoBackend; videoBackend = SConfig::GetInstance().m_LocalCoreStartupParameter.m_strVideoBackend;
bBlankMC = !File::Exists(SConfig::GetInstance().m_strMemoryCardA);
} }
g_videoBackend.resize(ARRAYSIZE(tmpHeader.videoBackend)); videoBackend.resize(ARRAYSIZE(tmpHeader.videoBackend));
for (int i = 0; i < ARRAYSIZE(tmpHeader.videoBackend);i++) for (int i = 0; i < ARRAYSIZE(tmpHeader.videoBackend);i++)
{ {
g_videoBackend[i] = tmpHeader.videoBackend[i]; videoBackend[i] = tmpHeader.videoBackend[i];
} }
g_discChange.resize(ARRAYSIZE(tmpHeader.discChange)); g_discChange.resize(ARRAYSIZE(tmpHeader.discChange));
@ -655,19 +668,19 @@ bool PlayInput(const char *filename)
if(!File::Exists(filename)) if(!File::Exists(filename))
return false; return false;
File::IOFile g_recordfd; File::IOFile g_recordfd;
if (!g_recordfd.Open(filename, "rb")) if (!g_recordfd.Open(filename, "rb"))
return false; return false;
g_recordfd.ReadArray(&tmpHeader, 1); g_recordfd.ReadArray(&tmpHeader, 1);
if(tmpHeader.filetype[0] != 'D' || tmpHeader.filetype[1] != 'T' || tmpHeader.filetype[2] != 'M' || tmpHeader.filetype[3] != 0x1A) { if(tmpHeader.filetype[0] != 'D' || tmpHeader.filetype[1] != 'T' || tmpHeader.filetype[2] != 'M' || tmpHeader.filetype[3] != 0x1A) {
PanicAlertT("Invalid recording file"); PanicAlertT("Invalid recording file");
goto cleanup; goto cleanup;
} }
// Load savestate (and skip to frame data) // Load savestate (and skip to frame data)
if(tmpHeader.bFromSaveState) if(tmpHeader.bFromSaveState)
{ {
@ -676,16 +689,15 @@ bool PlayInput(const char *filename)
Core::SetStateFileName(stateFilename); Core::SetStateFileName(stateFilename);
g_bRecordingFromSaveState = true; g_bRecordingFromSaveState = true;
Movie::LoadInput(filename); Movie::LoadInput(filename);
g_currentFrame = 0;
} }
/* TODO: Put this verification somewhere we have the gameID of the played game /* TODO: Put this verification somewhere we have the gameID of the played game
// TODO: Replace with Unique ID // TODO: Replace with Unique ID
if(tmpHeader.uniqueID != 0) { if(tmpHeader.uniqueID != 0) {
PanicAlert("Recording Unique ID Verification Failed"); PanicAlert("Recording Unique ID Verification Failed");
goto cleanup; goto cleanup;
} }
if(strncmp((char *)tmpHeader.gameID, Core::g_CoreStartupParameter.GetUniqueID().c_str(), 6)) { if(strncmp((char *)tmpHeader.gameID, Core::g_CoreStartupParameter.GetUniqueID().c_str(), 6)) {
PanicAlert("The recorded game (%s) is not the same as the selected game (%s)", header.gameID, Core::g_CoreStartupParameter.GetUniqueID().c_str()); PanicAlert("The recorded game (%s) is not the same as the selected game (%s)", header.gameID, Core::g_CoreStartupParameter.GetUniqueID().c_str());
goto cleanup; goto cleanup;
@ -708,9 +720,9 @@ bool PlayInput(const char *filename)
g_recordfd.ReadArray(tmpInput, (size_t)g_totalBytes); g_recordfd.ReadArray(tmpInput, (size_t)g_totalBytes);
g_currentByte = 0; g_currentByte = 0;
g_recordfd.Close(); g_recordfd.Close();
return true; return true;
cleanup: cleanup:
g_recordfd.Close(); g_recordfd.Close();
return false; return false;
@ -736,7 +748,7 @@ void LoadInput(const char *filename)
File::IOFile t_record(filename, "r+b"); File::IOFile t_record(filename, "r+b");
t_record.ReadArray(&tmpHeader, 1); t_record.ReadArray(&tmpHeader, 1);
if(tmpHeader.filetype[0] != 'D' || tmpHeader.filetype[1] != 'T' || tmpHeader.filetype[2] != 'M' || tmpHeader.filetype[3] != 0x1A) if(tmpHeader.filetype[0] != 'D' || tmpHeader.filetype[1] != 'T' || tmpHeader.filetype[2] != 'M' || tmpHeader.filetype[3] != 0x1A)
{ {
PanicAlertT("Savestate movie %s is corrupted, movie recording stopping...", filename); PanicAlertT("Savestate movie %s is corrupted, movie recording stopping...", filename);
@ -871,7 +883,12 @@ static void CheckInputEnd()
void PlayController(SPADStatus *PadStatus, int controllerID) void PlayController(SPADStatus *PadStatus, int controllerID)
{ {
if (IsPlayingInput() && IsConfigSaved()) // Correct playback is entirely dependent on the emulator polling the controllers
// in the same order done during recording
if (!IsPlayingInput() || !IsUsingPad(controllerID) || tmpInput == NULL)
return;
if (IsConfigSaved())
{ {
SetGraphicsConfig(); SetGraphicsConfig();
} }
@ -886,10 +903,6 @@ void PlayController(SPADStatus *PadStatus, int controllerID)
ExpansionInterface::ChangeDevice(0, EXIDEVICE_NONE, 0); ExpansionInterface::ChangeDevice(0, EXIDEVICE_NONE, 0);
} }
} }
// Correct playback is entirely dependent on the emulator polling the controllers
// in the same order done during recording
if (!IsPlayingInput() || !IsUsingPad(controllerID) || tmpInput == NULL)
return;
if (g_currentByte + 8 > g_totalBytes) if (g_currentByte + 8 > g_totalBytes)
{ {
@ -1044,7 +1057,7 @@ void EndPlayInput(bool cont)
g_currentByte = 0; g_currentByte = 0;
g_playMode = MODE_NONE; g_playMode = MODE_NONE;
Core::DisplayMessage("Movie End.", 2000); Core::DisplayMessage("Movie End.", 2000);
tmpHeader.bFromSaveState = 0; g_bRecordingFromSaveState = 0;
// we don't clear these things because otherwise we can't resume playback if we load a movie state later // we don't clear these things because otherwise we can't resume playback if we load a movie state later
//g_totalFrames = g_totalBytes = 0; //g_totalFrames = g_totalBytes = 0;
//delete tmpInput; //delete tmpInput;
@ -1077,8 +1090,8 @@ void SaveRecording(const char *filename)
header.bProgressive = bProgressive; header.bProgressive = bProgressive;
header.bDSPHLE = bDSPHLE; header.bDSPHLE = bDSPHLE;
header.bFastDiscSpeed = bFastDiscSpeed; header.bFastDiscSpeed = bFastDiscSpeed;
strncpy((char *)header.videoBackend, g_videoBackend.c_str(),ARRAYSIZE(header.videoBackend)); strncpy((char *)header.videoBackend, videoBackend.c_str(),ARRAYSIZE(header.videoBackend));
header.CPUCore = g_CPUCore; header.CPUCore = iCPUCore;
header.bEFBAccessEnable = g_ActiveConfig.bEFBAccessEnable; header.bEFBAccessEnable = g_ActiveConfig.bEFBAccessEnable;
header.bEFBCopyEnable = g_ActiveConfig.bEFBCopyEnable; header.bEFBCopyEnable = g_ActiveConfig.bEFBCopyEnable;
header.bCopyEFBToTexture = g_ActiveConfig.bCopyEFBToTexture; header.bCopyEFBToTexture = g_ActiveConfig.bCopyEFBToTexture;
@ -1086,8 +1099,8 @@ void SaveRecording(const char *filename)
header.bEFBEmulateFormatChanges = g_ActiveConfig.bEFBEmulateFormatChanges; header.bEFBEmulateFormatChanges = g_ActiveConfig.bEFBEmulateFormatChanges;
header.bUseXFB = g_ActiveConfig.bUseXFB; header.bUseXFB = g_ActiveConfig.bUseXFB;
header.bUseRealXFB = g_ActiveConfig.bUseRealXFB; header.bUseRealXFB = g_ActiveConfig.bUseRealXFB;
header.bMemcard = g_bMemcard; header.bMemcard = bMemcard;
header.bBlankMC = g_bBlankMC; header.bBlankMC = bBlankMC;
strncpy((char *)header.discChange, g_discChange.c_str(),ARRAYSIZE(header.discChange)); strncpy((char *)header.discChange, g_discChange.c_str(),ARRAYSIZE(header.discChange));
strncpy((char *)header.author, author.c_str(),ARRAYSIZE(header.author)); strncpy((char *)header.author, author.c_str(),ARRAYSIZE(header.author));

View File

@ -57,11 +57,11 @@ struct ControllerState {
u8 CStickX, CStickY; // Sub-Stick, 16 bits u8 CStickX, CStickY; // Sub-Stick, 16 bits
}; // Total: 60 + 4 = 64 bits per frame }; // Total: 60 + 4 = 64 bits per frame
static_assert(sizeof(ControllerState) == 8, "ControllerState should be 8 bytes");
#pragma pack(pop) #pragma pack(pop)
// Global declarations // Global declarations
extern bool g_bFrameStep, g_bPolled, g_bReadOnly, g_bDiscChange; extern bool g_bFrameStep, g_bPolled, g_bReadOnly, g_bDiscChange;
extern bool g_bMemcard, g_bBlankMC;
extern PlayMode g_playMode; extern PlayMode g_playMode;
extern u32 g_framesToSkip, g_frameSkipCounter; extern u32 g_framesToSkip, g_frameSkipCounter;
@ -75,8 +75,6 @@ extern u64 g_currentByte, g_totalBytes;
extern u64 g_currentFrame, g_totalFrames; extern u64 g_currentFrame, g_totalFrames;
extern u64 g_currentLagCount, g_totalLagCount; extern u64 g_currentLagCount, g_totalLagCount;
extern u64 g_currentInputCount, g_totalInputCount; extern u64 g_currentInputCount, g_totalInputCount;
extern std::string g_videoBackend;
extern int g_CPUCore;
extern std::string g_discChange; extern std::string g_discChange;
extern u32 g_rerecords; extern u32 g_rerecords;
@ -120,7 +118,7 @@ struct DTMHeader {
bool bUseRealXFB; bool bUseRealXFB;
bool bMemcard; bool bMemcard;
bool bBlankMC; // Create a new memory card when playing back a movie if true bool bBlankMC; // Create a new memory card when playing back a movie if true
u8 reserved[16]; u8 reserved[16]; // Padding for any new config options
u8 discChange[40]; // Name of iso file to switch to, for two disc games. u8 discChange[40]; // Name of iso file to switch to, for two disc games.
u8 reserved2[47]; // Make heading 256 bytes, just because we can u8 reserved2[47]; // Make heading 256 bytes, just because we can
}; };
@ -150,6 +148,8 @@ bool IsSkipIdle();
bool IsDSPHLE(); bool IsDSPHLE();
bool IsFastDiscSpeed(); bool IsFastDiscSpeed();
int GetCPUMode(); int GetCPUMode();
bool IsBlankMemcard();
bool IsUsingMemcard();
void SetGraphicsConfig(); void SetGraphicsConfig();
bool IsUsingPad(int controller); bool IsUsingPad(int controller);