mirror of https://github.com/stella-emu/stella.git
Make Random class serializable, and save to state files.
This commit is contained in:
parent
c1f7c5c90b
commit
48a99c6b6b
|
@ -37,6 +37,10 @@
|
||||||
then back again would pass a 'Tab' key event to the app, which in
|
then back again would pass a 'Tab' key event to the app, which in
|
||||||
most cases would navigate to the next UI element.
|
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.
|
* Fixed lockups when entering the debugger under certain circumstances.
|
||||||
|
|
||||||
* Reverted joystick changes for Decathlon ROMs from last release, as
|
* Reverted joystick changes for Decathlon ROMs from last release, as
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
|
|
||||||
#include "bspf.hxx"
|
#include "bspf.hxx"
|
||||||
#include "OSystem.hxx"
|
#include "OSystem.hxx"
|
||||||
|
#include "Serializable.hxx"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
This is a quick-and-dirty random number generator. It is based on
|
This is a quick-and-dirty random number generator. It is based on
|
||||||
|
@ -30,7 +31,7 @@
|
||||||
|
|
||||||
@author Bradford W. Mott
|
@author Bradford W. Mott
|
||||||
*/
|
*/
|
||||||
class Random
|
class Random : public Serializable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
|
@ -57,6 +58,59 @@ class Random
|
||||||
return (myValue = (myValue * 2416 + 374441) % 1771875);
|
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:
|
private:
|
||||||
// Set the OSystem we're using
|
// Set the OSystem we're using
|
||||||
const OSystem& myOSystem;
|
const OSystem& myOSystem;
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
|
|
||||||
#include "StateManager.hxx"
|
#include "StateManager.hxx"
|
||||||
|
|
||||||
#define STATE_HEADER "05000000state"
|
#define STATE_HEADER "05000200state"
|
||||||
#define MOVIE_HEADER "03030000movie"
|
#define MOVIE_HEADER "03030000movie"
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
|
|
@ -221,6 +221,8 @@ bool System::save(Serializer& out) const
|
||||||
return false;
|
return false;
|
||||||
if(!myCart.save(out))
|
if(!myCart.save(out))
|
||||||
return false;
|
return false;
|
||||||
|
if(!randGenerator().save(out))
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
catch(...)
|
catch(...)
|
||||||
{
|
{
|
||||||
|
@ -251,6 +253,8 @@ bool System::load(Serializer& in)
|
||||||
return false;
|
return false;
|
||||||
if(!myCart.load(in))
|
if(!myCart.load(in))
|
||||||
return false;
|
return false;
|
||||||
|
if(!randGenerator().load(in))
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
catch(...)
|
catch(...)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue