Make Random class serializable, and save to state files.

This commit is contained in:
Stephen Anthony 2017-08-18 12:36:54 -02:30
parent c1f7c5c90b
commit 48a99c6b6b
4 changed files with 64 additions and 2 deletions

View File

@ -37,6 +37,10 @@
then back again would pass a 'Tab' key event to the app, which in
most cases would navigate to the next UI element.
* Fixed potential issue with state file saving and the debugger; under
certain circumstances a rewind would give a different state than
before (note that the state file format has changed because of this).
* Fixed lockups when entering the debugger under certain circumstances.
* Reverted joystick changes for Decathlon ROMs from last release, as

View File

@ -22,6 +22,7 @@
#include "bspf.hxx"
#include "OSystem.hxx"
#include "Serializable.hxx"
/**
This is a quick-and-dirty random number generator. It is based on
@ -30,7 +31,7 @@
@author Bradford W. Mott
*/
class Random
class Random : public Serializable
{
public:
/**
@ -57,6 +58,59 @@ class Random
return (myValue = (myValue * 2416 + 374441) % 1771875);
}
/**
Save the current state of this device to the given Serializer.
@param out The Serializer object to use
@return False on any errors, else true
*/
bool save(Serializer& out) const override
{
try
{
out.putString(name());
out.putInt(myValue);
}
catch(...)
{
cerr << "ERROR: Random::save" << endl;
return false;
}
return true;
}
/**
Load the current state of this device from the given Serializer.
@param in The Serializer object to use
@return False on any errors, else true
*/
bool load(Serializer& in) override
{
try
{
if(in.getString() != name())
return false;
myValue = in.getInt();
}
catch(...)
{
cerr << "ERROR: Random::load" << endl;
return false;
}
return true;
}
/**
Get a descriptor for the device name (used in error checking).
@return The name of the object
*/
string name() const override { return "Random"; }
private:
// Set the OSystem we're using
const OSystem& myOSystem;

View File

@ -28,7 +28,7 @@
#include "StateManager.hxx"
#define STATE_HEADER "05000000state"
#define STATE_HEADER "05000200state"
#define MOVIE_HEADER "03030000movie"
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -221,6 +221,8 @@ bool System::save(Serializer& out) const
return false;
if(!myCart.save(out))
return false;
if(!randGenerator().save(out))
return false;
}
catch(...)
{
@ -251,6 +253,8 @@ bool System::load(Serializer& in)
return false;
if(!myCart.load(in))
return false;
if(!randGenerator().load(in))
return false;
}
catch(...)
{