From 396ae89e5c636433b2960dc421b70db5797fa4ec Mon Sep 17 00:00:00 2001 From: Lioncash Date: Tue, 28 Jun 2016 22:25:22 -0400 Subject: [PATCH] FifoDataFile: Convert FifoFrameInfo's fifoData member into a vector --- Source/Core/Core/FifoPlayer/FifoAnalyzer.cpp | 10 +++++----- Source/Core/Core/FifoPlayer/FifoAnalyzer.h | 8 ++++---- Source/Core/Core/FifoPlayer/FifoDataFile.cpp | 15 +++++---------- Source/Core/Core/FifoPlayer/FifoDataFile.h | 3 +-- .../Core/Core/FifoPlayer/FifoPlaybackAnalyzer.cpp | 6 +++--- Source/Core/Core/FifoPlayer/FifoPlayer.cpp | 8 ++++---- Source/Core/Core/FifoPlayer/FifoPlayer.h | 2 +- .../Core/Core/FifoPlayer/FifoRecordAnalyzer.cpp | 2 +- Source/Core/Core/FifoPlayer/FifoRecordAnalyzer.h | 2 +- Source/Core/Core/FifoPlayer/FifoRecorder.cpp | 5 +---- Source/Core/DolphinWX/FifoPlayerDlg.cpp | 2 +- 11 files changed, 27 insertions(+), 36 deletions(-) diff --git a/Source/Core/Core/FifoPlayer/FifoAnalyzer.cpp b/Source/Core/Core/FifoPlayer/FifoAnalyzer.cpp index 22358fb501..c5d91cca2c 100644 --- a/Source/Core/Core/FifoPlayer/FifoAnalyzer.cpp +++ b/Source/Core/Core/FifoPlayer/FifoAnalyzer.cpp @@ -27,30 +27,30 @@ void Init() VertexLoader_Normal::Init(); } -u8 ReadFifo8(u8*& data) +u8 ReadFifo8(const u8*& data) { u8 value = data[0]; data += 1; return value; } -u16 ReadFifo16(u8*& data) +u16 ReadFifo16(const u8*& data) { u16 value = Common::swap16(data); data += 2; return value; } -u32 ReadFifo32(u8*& data) +u32 ReadFifo32(const u8*& data) { u32 value = Common::swap32(data); data += 4; return value; } -u32 AnalyzeCommand(u8* data, DecodeMode mode) +u32 AnalyzeCommand(const u8* data, DecodeMode mode) { - u8* dataStart = data; + const u8* dataStart = data; int cmd = ReadFifo8(data); diff --git a/Source/Core/Core/FifoPlayer/FifoAnalyzer.h b/Source/Core/Core/FifoPlayer/FifoAnalyzer.h index 162d1b0b74..1184b5ec00 100644 --- a/Source/Core/Core/FifoPlayer/FifoAnalyzer.h +++ b/Source/Core/Core/FifoPlayer/FifoAnalyzer.h @@ -13,9 +13,9 @@ namespace FifoAnalyzer { void Init(); -u8 ReadFifo8(u8*& data); -u16 ReadFifo16(u8*& data); -u32 ReadFifo32(u8*& data); +u8 ReadFifo8(const u8*& data); +u16 ReadFifo16(const u8*& data); +u32 ReadFifo32(const u8*& data); enum DecodeMode { @@ -23,7 +23,7 @@ enum DecodeMode DECODE_PLAYBACK, }; -u32 AnalyzeCommand(u8* data, DecodeMode mode); +u32 AnalyzeCommand(const u8* data, DecodeMode mode); struct CPMemory { diff --git a/Source/Core/Core/FifoPlayer/FifoDataFile.cpp b/Source/Core/Core/FifoPlayer/FifoDataFile.cpp index d7796056d3..92e3769327 100644 --- a/Source/Core/Core/FifoPlayer/FifoDataFile.cpp +++ b/Source/Core/Core/FifoPlayer/FifoDataFile.cpp @@ -18,10 +18,6 @@ FifoDataFile::FifoDataFile() : m_Flags(0) FifoDataFile::~FifoDataFile() { - for (auto& frame : m_Frames) - { - delete[] frame.fifoData; - } } bool FifoDataFile::HasBrokenEFBCopies() const @@ -103,17 +99,17 @@ bool FifoDataFile::Save(const std::string& filename) // Write FIFO data file.Seek(0, SEEK_END); u64 dataOffset = file.Tell(); - file.WriteBytes(srcFrame.fifoData, srcFrame.fifoDataSize); + file.WriteBytes(srcFrame.fifoData.data(), srcFrame.fifoData.size()); u64 memoryUpdatesOffset = WriteMemoryUpdates(srcFrame.memoryUpdates, file); FileFrameInfo dstFrame; - dstFrame.fifoDataSize = srcFrame.fifoDataSize; + dstFrame.fifoDataSize = static_cast(srcFrame.fifoData.size()); dstFrame.fifoDataOffset = dataOffset; dstFrame.fifoStart = srcFrame.fifoStart; dstFrame.fifoEnd = srcFrame.fifoEnd; dstFrame.memoryUpdatesOffset = memoryUpdatesOffset; - dstFrame.numMemoryUpdates = (u32)srcFrame.memoryUpdates.size(); + dstFrame.numMemoryUpdates = static_cast(srcFrame.memoryUpdates.size()); // Write frame info u64 frameOffset = frameListOffset + (i * sizeof(FileFrameInfo)); @@ -179,13 +175,12 @@ std::unique_ptr FifoDataFile::Load(const std::string& filename, bo file.ReadBytes(&srcFrame, sizeof(FileFrameInfo)); FifoFrameInfo dstFrame; - dstFrame.fifoData = new u8[srcFrame.fifoDataSize]; - dstFrame.fifoDataSize = srcFrame.fifoDataSize; + dstFrame.fifoData.resize(srcFrame.fifoDataSize); dstFrame.fifoStart = srcFrame.fifoStart; dstFrame.fifoEnd = srcFrame.fifoEnd; file.Seek(srcFrame.fifoDataOffset, SEEK_SET); - file.ReadBytes(dstFrame.fifoData, srcFrame.fifoDataSize); + file.ReadBytes(dstFrame.fifoData.data(), srcFrame.fifoDataSize); ReadMemoryUpdates(srcFrame.memoryUpdatesOffset, srcFrame.numMemoryUpdates, dstFrame.memoryUpdates, file); diff --git a/Source/Core/Core/FifoPlayer/FifoDataFile.h b/Source/Core/Core/FifoPlayer/FifoDataFile.h index 269dc34742..45dee96dba 100644 --- a/Source/Core/Core/FifoPlayer/FifoDataFile.h +++ b/Source/Core/Core/FifoPlayer/FifoDataFile.h @@ -33,8 +33,7 @@ struct MemoryUpdate struct FifoFrameInfo { - u8* fifoData; - u32 fifoDataSize; + std::vector fifoData; u32 fifoStart; u32 fifoEnd; diff --git a/Source/Core/Core/FifoPlayer/FifoPlaybackAnalyzer.cpp b/Source/Core/Core/FifoPlayer/FifoPlaybackAnalyzer.cpp index 6d4e56ccb5..8b1e7f990b 100644 --- a/Source/Core/Core/FifoPlayer/FifoPlaybackAnalyzer.cpp +++ b/Source/Core/Core/FifoPlayer/FifoPlaybackAnalyzer.cpp @@ -19,7 +19,7 @@ struct CmdData { u32 size; u32 offset; - u8* ptr; + const u8* ptr; }; void FifoPlaybackAnalyzer::AnalyzeFrames(FifoDataFile* file, @@ -51,10 +51,10 @@ void FifoPlaybackAnalyzer::AnalyzeFrames(FifoDataFile* file, #if LOG_FIFO_CMDS // Debugging - vector prevCmds; + std::vector prevCmds; #endif - while (cmdStart < frame.fifoDataSize) + while (cmdStart < frame.fifoData.size()) { // Add memory updates that have occurred before this point in the frame while (nextMemUpdate < frame.memoryUpdates.size() && diff --git a/Source/Core/Core/FifoPlayer/FifoPlayer.cpp b/Source/Core/Core/FifoPlayer/FifoPlayer.cpp index 322cb019d7..41ad65c7cd 100644 --- a/Source/Core/Core/FifoPlayer/FifoPlayer.cpp +++ b/Source/Core/Core/FifoPlayer/FifoPlayer.cpp @@ -207,7 +207,7 @@ void FifoPlayer::WriteFrame(const FifoFrameInfo& frame, const AnalyzedFrameInfo& // Core timing information m_CyclesPerFrame = SystemTimers::GetTicksPerSecond() / VideoInterface::GetTargetRefreshRate(); m_ElapsedCycles = 0; - m_FrameFifoSize = frame.fifoDataSize; + m_FrameFifoSize = static_cast(frame.fifoData.size()); // Determine start and end objects u32 numObjects = (u32)(info.objectStarts.size()); @@ -256,7 +256,7 @@ void FifoPlayer::WriteFrame(const FifoFrameInfo& frame, const AnalyzedFrameInfo& } // Write data after the last object - WriteFramePart(position, frame.fifoDataSize, memoryUpdate, frame, info); + WriteFramePart(position, static_cast(frame.fifoData.size()), memoryUpdate, frame, info); FlushWGP(); @@ -271,7 +271,7 @@ void FifoPlayer::WriteFrame(const FifoFrameInfo& frame, const AnalyzedFrameInfo& void FifoPlayer::WriteFramePart(u32 dataStart, u32 dataEnd, u32& nextMemUpdate, const FifoFrameInfo& frame, const AnalyzedFrameInfo& info) { - u8* data = frame.fifoData; + const u8* const data = frame.fifoData.data(); while (nextMemUpdate < frame.memoryUpdates.size() && dataStart < dataEnd) { @@ -326,7 +326,7 @@ void FifoPlayer::WriteMemory(const MemoryUpdate& memUpdate) std::copy(memUpdate.data.begin(), memUpdate.data.end(), mem); } -void FifoPlayer::WriteFifo(u8* data, u32 start, u32 end) +void FifoPlayer::WriteFifo(const u8* data, u32 start, u32 end) { u32 written = start; u32 lastBurstEnd = end - 1; diff --git a/Source/Core/Core/FifoPlayer/FifoPlayer.h b/Source/Core/Core/FifoPlayer/FifoPlayer.h index db09fadde9..2b5e4b49ea 100644 --- a/Source/Core/Core/FifoPlayer/FifoPlayer.h +++ b/Source/Core/Core/FifoPlayer/FifoPlayer.h @@ -104,7 +104,7 @@ private: // writes a range of data to the fifo // start and end must be relative to frame's fifo data so elapsed cycles are figured correctly - void WriteFifo(u8* data, u32 start, u32 end); + void WriteFifo(const u8* data, u32 start, u32 end); void SetupFifo(); diff --git a/Source/Core/Core/FifoPlayer/FifoRecordAnalyzer.cpp b/Source/Core/Core/FifoPlayer/FifoRecordAnalyzer.cpp index e0e13d4419..c02e04845d 100644 --- a/Source/Core/Core/FifoPlayer/FifoRecordAnalyzer.cpp +++ b/Source/Core/Core/FifoPlayer/FifoRecordAnalyzer.cpp @@ -38,7 +38,7 @@ void FifoRecordAnalyzer::ProcessLoadIndexedXf(u32 val, int array) FifoRecorder::GetInstance().UseMemory(address, size * 4, MemoryUpdate::XF_DATA); } -void FifoRecordAnalyzer::WriteVertexArray(int arrayIndex, u8* vertexData, int vertexSize, +void FifoRecordAnalyzer::WriteVertexArray(int arrayIndex, const u8* vertexData, int vertexSize, int numVertices) { // Skip if not indexed array diff --git a/Source/Core/Core/FifoPlayer/FifoRecordAnalyzer.h b/Source/Core/Core/FifoPlayer/FifoRecordAnalyzer.h index b0ca59ce97..b5a02e5d21 100644 --- a/Source/Core/Core/FifoPlayer/FifoRecordAnalyzer.h +++ b/Source/Core/Core/FifoPlayer/FifoRecordAnalyzer.h @@ -16,5 +16,5 @@ namespace FifoRecordAnalyzer void Initialize(u32* cpMem); void ProcessLoadIndexedXf(u32 val, int array); -void WriteVertexArray(int arrayIndex, u8* vertexData, int vertexSize, int numVertices); +void WriteVertexArray(int arrayIndex, const u8* vertexData, int vertexSize, int numVertices); }; diff --git a/Source/Core/Core/FifoPlayer/FifoRecorder.cpp b/Source/Core/Core/FifoPlayer/FifoRecorder.cpp index b7858fecda..bd30d7213e 100644 --- a/Source/Core/Core/FifoPlayer/FifoRecorder.cpp +++ b/Source/Core/Core/FifoPlayer/FifoRecorder.cpp @@ -78,10 +78,7 @@ void FifoRecorder::WriteGPCommand(u8* data, u32 size) if (m_FrameEnded && m_FifoData.size() > 0) { - size_t dataSize = m_FifoData.size(); - m_CurrentFrame.fifoDataSize = (u32)dataSize; - m_CurrentFrame.fifoData = new u8[dataSize]; - memcpy(m_CurrentFrame.fifoData, m_FifoData.data(), dataSize); + m_CurrentFrame.fifoData = m_FifoData; { std::lock_guard lk(sMutex); diff --git a/Source/Core/DolphinWX/FifoPlayerDlg.cpp b/Source/Core/DolphinWX/FifoPlayerDlg.cpp index bffbbc26a3..33d083b61a 100644 --- a/Source/Core/DolphinWX/FifoPlayerDlg.cpp +++ b/Source/Core/DolphinWX/FifoPlayerDlg.cpp @@ -928,7 +928,7 @@ wxString FifoPlayerDlg::CreateRecordingFifoSizeLabel() const { size_t fifoBytes = 0; for (size_t i = 0; i < file->GetFrameCount(); ++i) - fifoBytes += file->GetFrame(i).fifoDataSize; + fifoBytes += file->GetFrame(i).fifoData.size(); return wxString::Format(_("%zu FIFO bytes"), fifoBytes); }