do the previous commit again but better

This commit is contained in:
Jaklyy 2024-08-25 23:50:15 -04:00
parent 54cf2cf2eb
commit fdf0fa2301
10 changed files with 64 additions and 19 deletions

View File

@ -569,20 +569,7 @@ void GPU3D::DoSavestate(Savestate* file) noexcept
} }
// save any renderer state that can persist through frames // save any renderer state that can persist through frames
if (softRenderer) CurrentRenderer->DoSavestate(file);
{
file->VarArray(softRenderer->StencilBuffer, sizeof(SoftRenderer::StencilBuffer));
file->VarArray(softRenderer->ShadowRendered, sizeof(SoftRenderer::ShadowRendered));
file->VarArray(softRenderer->ShadowRenderedi, sizeof(SoftRenderer::ShadowRenderedi));
}
else
{
u8 ph[256*2] {};
// placeholders for renderers that don't support the same variables
file->VarArray(ph, sizeof(SoftRenderer::StencilBuffer));
file->VarArray(ph, sizeof(SoftRenderer::ShadowRendered));
file->VarArray(ph, sizeof(SoftRenderer::ShadowRenderedi));
}
if (softRenderer && softRenderer->IsThreaded()) if (softRenderer && softRenderer->IsThreaded())
{ {

View File

@ -346,6 +346,7 @@ public:
Renderer3D& operator=(const Renderer3D&) = delete; Renderer3D& operator=(const Renderer3D&) = delete;
virtual void Reset(GPU& gpu) = 0; virtual void Reset(GPU& gpu) = 0;
virtual void DoSavestate(Savestate* file) = 0;
// This "Accelerated" flag currently communicates if the framebuffer should // This "Accelerated" flag currently communicates if the framebuffer should
// be allocated differently and other little misc handlers. Ideally there // be allocated differently and other little misc handlers. Ideally there

View File

@ -295,6 +295,23 @@ void ComputeRenderer::Reset(GPU& gpu)
Texcache.Reset(); Texcache.Reset();
} }
void ComputeRenderer::DoSavestate(Savestate* file)
{
// placeholder in case we need to add anything serializable later on
/*
bool secfound = file->Section("CR3D", true);
if (secfound)
{
}
else
{
}
*/
}
void ComputeRenderer::SetRenderSettings(int scale, bool highResolutionCoordinates) void ComputeRenderer::SetRenderSettings(int scale, bool highResolutionCoordinates)
{ {
CurGLCompositor.SetScaleFactor(scale); CurGLCompositor.SetScaleFactor(scale);

View File

@ -42,6 +42,7 @@ public:
~ComputeRenderer() override; ~ComputeRenderer() override;
void Reset(GPU& gpu) override; void Reset(GPU& gpu) override;
void DoSavestate(Savestate* file) override;
void SetRenderSettings(int scale, bool highResolutionCoordinates); void SetRenderSettings(int scale, bool highResolutionCoordinates);

View File

@ -317,6 +317,23 @@ void GLRenderer::Reset(GPU& gpu)
// except there's no such method right now. // except there's no such method right now.
} }
void GLRenderer::DoSavestate(Savestate* file)
{
// placeholder in case we need to add anything serializable later on
/*
bool secfound = file->Section("GL3D", true);
if (secfound)
{
}
else
{
}
*/
}
void GLRenderer::SetBetterPolygons(bool betterpolygons) noexcept void GLRenderer::SetBetterPolygons(bool betterpolygons) noexcept
{ {
SetRenderSettings(betterpolygons, ScaleFactor); SetRenderSettings(betterpolygons, ScaleFactor);

View File

@ -32,6 +32,7 @@ class GLRenderer : public Renderer3D
public: public:
~GLRenderer() override; ~GLRenderer() override;
void Reset(GPU& gpu) override; void Reset(GPU& gpu) override;
void DoSavestate(Savestate* file) override;
void SetRenderSettings(bool betterpolygons, int scale) noexcept; void SetRenderSettings(bool betterpolygons, int scale) noexcept;
void SetBetterPolygons(bool betterpolygons) noexcept; void SetBetterPolygons(bool betterpolygons) noexcept;

View File

@ -131,6 +131,24 @@ void SoftRenderer::Reset(GPU& gpu)
EnableRenderThread(); EnableRenderThread();
} }
void SoftRenderer::DoSavestate(Savestate* file)
{
bool secfound = file->Section("SW3D", true);
if (secfound)
{
file->VarArray(StencilBuffer, sizeof(StencilBuffer));
file->VarArray(ShadowRendered, sizeof(ShadowRendered));
file->VarArray(ShadowRenderedi, sizeof(ShadowRenderedi));
}
else
{
memset(StencilBuffer, 0, sizeof(StencilBuffer));
memset(ShadowRendered, 0, sizeof(ShadowRendered));
memset(ShadowRenderedi, 0, sizeof(ShadowRenderedi));
}
}
void SoftRenderer::SetThreaded(bool threaded, GPU& gpu) noexcept void SoftRenderer::SetThreaded(bool threaded, GPU& gpu) noexcept
{ {
if (Threaded != threaded) if (Threaded != threaded)

View File

@ -44,6 +44,7 @@ public:
SoftRenderer() noexcept; SoftRenderer() noexcept;
~SoftRenderer() override; ~SoftRenderer() override;
void Reset(GPU& gpu) override; void Reset(GPU& gpu) override;
void DoSavestate(Savestate* file) override;
void SetThreaded(bool threaded, GPU& gpu) noexcept; void SetThreaded(bool threaded, GPU& gpu) noexcept;
[[nodiscard]] bool IsThreaded() const noexcept { return Threaded; } [[nodiscard]] bool IsThreaded() const noexcept { return Threaded; }

View File

@ -153,9 +153,9 @@ Savestate::~Savestate()
} }
} }
void Savestate::Section(const char* magic) bool Savestate::Section(const char* magic, bool noerror)
{ {
if (Error || finished) return; if (Error || finished) return false;
if (Saving) if (Saving)
{ {
@ -174,6 +174,7 @@ void Savestate::Section(const char* magic)
// The 8 bytes afterward are reserved, so we skip them. // The 8 bytes afterward are reserved, so we skip them.
Var32(&zero); Var32(&zero);
Var32(&zero); Var32(&zero);
return true;
} }
else else
{ {
@ -182,12 +183,14 @@ void Savestate::Section(const char* magic)
if (section_offset != NO_SECTION) if (section_offset != NO_SECTION)
{ {
buffer_offset = section_offset; buffer_offset = section_offset;
return true;
} }
else else if (!noerror)
{ {
Log(LogLevel::Error, "savestate: section %s not found. blarg\n", magic); Log(LogLevel::Error, "savestate: section %s not found. blarg\n", magic);
Error = true; Error = true;
} }
return false;
} }
} }
@ -378,7 +381,6 @@ u32 Savestate::FindSection(const char* magic) const
} }
// We've reached the end of the file without finding the requested section... // We've reached the end of the file without finding the requested section...
Log(LogLevel::Error, "savestate: section %s not found. blarg\n", magic);
return NO_SECTION; return NO_SECTION;
} }

View File

@ -44,7 +44,7 @@ public:
u32 CurSection; u32 CurSection;
void Section(const char* magic); bool Section(const char* magic, bool noerror = false);
void Var8(u8* var) void Var8(u8* var)
{ {