From 99b202fd2eeac16e3c7776838e7b70c04a8a0883 Mon Sep 17 00:00:00 2001 From: nitsuja Date: Wed, 4 Jan 2012 00:42:22 -0800 Subject: [PATCH] savestate vertexmanager (base) since it affects VertexLoader::RunVertices which affects g_pVideoData --- Source/Core/Common/Src/ChunkFile.h | 11 ++++++++++- Source/Core/VideoCommon/Src/Fifo.cpp | 9 ++------- .../Core/VideoCommon/Src/VertexManagerBase.cpp | 17 +++++++++++++++++ Source/Core/VideoCommon/Src/VertexManagerBase.h | 6 ++++++ Source/Core/VideoCommon/Src/VideoState.cpp | 4 ++++ 5 files changed, 39 insertions(+), 8 deletions(-) diff --git a/Source/Core/Common/Src/ChunkFile.h b/Source/Core/Common/Src/ChunkFile.h index d3e0120672..01daec62c0 100644 --- a/Source/Core/Common/Src/ChunkFile.h +++ b/Source/Core/Common/Src/ChunkFile.h @@ -172,7 +172,16 @@ public: void Do(T &x) { DoVoid((void *)&x, sizeof(x)); } - + + template + void DoPointer(T* &x, T*const base) { + // pointers can be more than 2^31 apart, but you're using this function wrong if you need that much range + s32 offset = x - base; + Do(offset); + if (mode == MODE_READ) + x = base + offset; + } + template* (*TNew)(), void (*TFree)(LinkedListItem*), void (*TDo)(PointerWrap&, T*)> void DoLinkedList(LinkedListItem*& list_start, LinkedListItem** list_end=0) { diff --git a/Source/Core/VideoCommon/Src/Fifo.cpp b/Source/Core/VideoCommon/Src/Fifo.cpp index 18f2d42450..565684297a 100644 --- a/Source/Core/VideoCommon/Src/Fifo.cpp +++ b/Source/Core/VideoCommon/Src/Fifo.cpp @@ -45,13 +45,8 @@ void Fifo_DoState(PointerWrap &p) { p.DoArray(videoBuffer, FIFO_SIZE); p.Do(size); - int pos = (int)(g_pVideoData - videoBuffer); // get offset - p.Do(pos); // read or write offset (depending on the mode) - if (p.GetMode() == PointerWrap::MODE_READ) - { - g_pVideoData = &videoBuffer[pos]; - g_bSkipCurrentFrame = false; - } + p.DoPointer(g_pVideoData, videoBuffer); + p.Do(g_bSkipCurrentFrame); } void Fifo_PauseAndLock(bool doLock, bool unpauseOnUnlock) diff --git a/Source/Core/VideoCommon/Src/VertexManagerBase.cpp b/Source/Core/VideoCommon/Src/VertexManagerBase.cpp index d66da30273..b4e09a820e 100644 --- a/Source/Core/VideoCommon/Src/VertexManagerBase.cpp +++ b/Source/Core/VideoCommon/Src/VertexManagerBase.cpp @@ -308,3 +308,20 @@ shader_fail: ResetBuffer(); } #endif + +void VertexManager::DoState(PointerWrap& p) +{ + g_vertex_manager->vDoState(p); +} + +void VertexManager::DoStateShared(PointerWrap& p) +{ + p.DoPointer(s_pCurBufferPointer, LocalVBuffer); + p.DoArray(LocalVBuffer, MAXVBUFFERSIZE); + p.DoArray(TIBuffer, MAXIBUFFERSIZE); + p.DoArray(LIBuffer, MAXIBUFFERSIZE); + p.DoArray(PIBuffer, MAXIBUFFERSIZE); + + if (p.GetMode() == PointerWrap::MODE_READ) + Flushed = false; +} diff --git a/Source/Core/VideoCommon/Src/VertexManagerBase.h b/Source/Core/VideoCommon/Src/VertexManagerBase.h index 12dc02ae4b..bc30fa3fba 100644 --- a/Source/Core/VideoCommon/Src/VertexManagerBase.h +++ b/Source/Core/VideoCommon/Src/VertexManagerBase.h @@ -3,6 +3,7 @@ #define _VERTEXMANAGERBASE_H class NativeVertexFormat; +class PointerWrap; class VertexManager { @@ -44,6 +45,8 @@ public: static u16* GetPointIndexBuffer() { return PIBuffer; } static u8* GetVertexBuffer() { return LocalVBuffer; } + static void DoState(PointerWrap& p); + protected: // TODO: make private after Flush() is merged static void ResetBuffer(); @@ -55,6 +58,9 @@ protected: static bool Flushed; + virtual void vDoState(PointerWrap& p) { DoStateShared(p); } + void DoStateShared(PointerWrap& p); + private: static void AddIndices(int primitive, int numVertices); //virtual void Draw(u32 stride, bool alphapass) = 0; diff --git a/Source/Core/VideoCommon/Src/VideoState.cpp b/Source/Core/VideoCommon/Src/VideoState.cpp index 8b1045b71f..ad5384cda9 100644 --- a/Source/Core/VideoCommon/Src/VideoState.cpp +++ b/Source/Core/VideoCommon/Src/VideoState.cpp @@ -26,6 +26,7 @@ #include "PixelEngine.h" #include "PixelShaderManager.h" #include "VertexShaderManager.h" +#include "VertexManagerBase.h" static void DoState(PointerWrap &p) { @@ -68,6 +69,9 @@ static void DoState(PointerWrap &p) VertexShaderManager::DoState(p); p.DoMarker("VertexShaderManager"); + VertexManager::DoState(p); + p.DoMarker("VertexManager"); + // TODO: search for more data that should be saved and add it here }