mirror of https://github.com/stenzek/duckstation
Save state support
parent
851ef67814
commit
2560efbebd
@ -0,0 +1,53 @@
|
||||
#include "host_interface.h"
|
||||
#include "YBaseLib/ByteStream.h"
|
||||
#include "system.h"
|
||||
|
||||
HostInterface::HostInterface() = default;
|
||||
|
||||
HostInterface::~HostInterface() = default;
|
||||
|
||||
bool HostInterface::LoadState(const char* filename)
|
||||
{
|
||||
ByteStream* stream;
|
||||
if (!ByteStream_OpenFileStream(filename, BYTESTREAM_OPEN_READ | BYTESTREAM_OPEN_STREAMED, &stream))
|
||||
return false;
|
||||
|
||||
ReportMessage(SmallString::FromFormat("Loading state from %s...", filename));
|
||||
|
||||
const bool result = m_system->LoadState(stream);
|
||||
if (!result)
|
||||
{
|
||||
ReportMessage(SmallString::FromFormat("Loading state from %s failed. Resetting.", filename));
|
||||
m_system->Reset();
|
||||
}
|
||||
|
||||
stream->Release();
|
||||
return result;
|
||||
}
|
||||
|
||||
bool HostInterface::SaveState(const char* filename)
|
||||
{
|
||||
ByteStream* stream;
|
||||
if (!ByteStream_OpenFileStream(filename,
|
||||
BYTESTREAM_OPEN_CREATE | BYTESTREAM_OPEN_WRITE | BYTESTREAM_OPEN_TRUNCATE |
|
||||
BYTESTREAM_OPEN_ATOMIC_UPDATE | BYTESTREAM_OPEN_STREAMED,
|
||||
&stream))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
const bool result = m_system->SaveState(stream);
|
||||
if (!result)
|
||||
{
|
||||
ReportMessage(SmallString::FromFormat("Saving state to %s failed.", filename));
|
||||
stream->Discard();
|
||||
}
|
||||
else
|
||||
{
|
||||
ReportMessage(SmallString::FromFormat("State saved to %s.", filename));
|
||||
stream->Commit();
|
||||
}
|
||||
|
||||
stream->Release();
|
||||
return result;
|
||||
}
|
||||
@ -1,16 +1,29 @@
|
||||
#pragma once
|
||||
#include "types.h"
|
||||
#include <memory>
|
||||
|
||||
namespace GL {
|
||||
class Texture;
|
||||
}
|
||||
|
||||
class System;
|
||||
|
||||
class HostInterface
|
||||
{
|
||||
public:
|
||||
HostInterface();
|
||||
virtual ~HostInterface();
|
||||
|
||||
virtual void SetDisplayTexture(GL::Texture* texture, u32 offset_x, u32 offset_y, u32 width, u32 height) = 0;
|
||||
virtual void ReportMessage(const char* message) = 0;
|
||||
|
||||
// Adds OSD messages, duration is in seconds.
|
||||
virtual void AddOSDMessage(const char* message, float duration = 2.0f) = 0;
|
||||
|
||||
protected:
|
||||
bool LoadState(const char* filename);
|
||||
bool SaveState(const char* filename);
|
||||
|
||||
std::unique_ptr<System> m_system;
|
||||
bool m_running = false;
|
||||
};
|
||||
|
||||
Loading…
Reference in New Issue