Implemented Serializable for Background, Ball and Playfield classes,

since it looks like they won't be heavily modified any further.
This commit is contained in:
Stephen Anthony 2017-02-11 22:30:58 -03:30
parent e133a4a521
commit c73c606638
5 changed files with 115 additions and 14 deletions

View File

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

View File

@ -58,14 +58,16 @@ void Background::applyColors()
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// TODO: implement this once the class is finalized
bool Background::save(Serializer& out) const
{
try
{
out.putString(name());
// TODO - save instance variables
out.putByte(myColor);
out.putByte(myObjectColor);
out.putByte(myDebugColor);
out.putBool(myDebugEnabled);
}
catch(...)
{
@ -77,7 +79,6 @@ bool Background::save(Serializer& out) const
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// TODO: implement this once the class is finalized
bool Background::load(Serializer& in)
{
try
@ -85,7 +86,12 @@ bool Background::load(Serializer& in)
if(in.getString() != name())
return false;
// TODO - load instance variables
myColor = in.getByte();
myObjectColor = in.getByte();
myDebugColor = in.getByte();
myDebugEnabled = in.getBool();
applyColors();
}
catch(...)
{

View File

@ -206,14 +206,36 @@ void Ball::applyColors()
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// TODO: implement this once the class is finalized
bool Ball::save(Serializer& out) const
{
try
{
out.putString(name());
// TODO - save instance variables
out.putInt(collision);
out.putInt(myCollisionMaskDisabled);
out.putInt(myCollisionMaskEnabled);
out.putByte(myColor);
out.putByte(myObjectColor);
out.putByte(myDebugColor);
out.putBool(myDebugEnabled);
out.putBool(myIsEnabledOld);
out.putBool(myIsEnabledNew);
out.putBool(myIsEnabled);
out.putBool(myIsSuppressed);
out.putBool(myIsDelaying);
out.putByte(myHmmClocks);
out.putByte(myCounter);
out.putBool(myIsMoving);
out.putByte(myWidth);
out.putByte(myEffectiveWidth);
out.putByte(myLastMovementTick);
out.putBool(myIsRendering);
out.putByte(myRenderCounter);
}
catch(...)
{
@ -225,7 +247,6 @@ bool Ball::save(Serializer& out) const
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// TODO: implement this once the class is finalized
bool Ball::load(Serializer& in)
{
try
@ -233,7 +254,33 @@ bool Ball::load(Serializer& in)
if(in.getString() != name())
return false;
// TODO - load instance variables
collision = in.getInt();
myCollisionMaskDisabled = in.getInt();
myCollisionMaskEnabled = in.getInt();
myColor = in.getByte();
myObjectColor = in.getByte();
myDebugColor = in.getByte();
myDebugEnabled = in.getBool();
myIsEnabledOld = in.getBool();
myIsEnabledNew = in.getBool();
myIsEnabled = in.getBool();
myIsSuppressed = in.getBool();
myIsDelaying = in.getBool();
myHmmClocks = in.getByte();
myCounter = in.getByte();
myIsMoving = in.getBool();
myWidth = in.getByte();
myEffectiveWidth = in.getByte();
myLastMovementTick = in.getByte();
myIsRendering = in.getBool();
myRenderCounter = in.getByte();
updateEnabled();
applyColors();
}
catch(...)
{

View File

@ -193,14 +193,38 @@ void Playfield::updatePattern()
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// TODO: implement this once the class is finalized
bool Playfield::save(Serializer& out) const
{
try
{
out.putString(name());
// TODO - save instance variables
out.putInt(collision);
out.putInt(myCollisionMaskDisabled);
out.putInt(myCollisionMaskEnabled);
out.putBool(myIsSuppressed);
out.putByte(myColorLeft);
out.putByte(myColorRight);
out.putByte(myColorP0);
out.putByte(myColorP1);
out.putByte(myObjectColor);
out.putByte(myDebugColor);
out.putBool(myDebugEnabled);
out.putByte(myColorMode);
out.putInt(myPattern);
out.putInt(myEffectivePattern);
out.putBool(myRefp);
out.putBool(myReflected);
out.putByte(myPf0);
out.putByte(myPf1);
out.putByte(myPf2);
out.putInt(myX);
}
catch(...)
{
@ -212,7 +236,6 @@ bool Playfield::save(Serializer& out) const
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// TODO: implement this once the class is finalized
bool Playfield::load(Serializer& in)
{
try
@ -220,7 +243,32 @@ bool Playfield::load(Serializer& in)
if(in.getString() != name())
return false;
// TODO - load instance variables
collision = in.getInt();
myCollisionMaskDisabled = in.getInt();
myCollisionMaskEnabled = in.getInt();
myIsSuppressed = in.getBool();
myColorLeft = in.getByte();
myColorRight = in.getByte();
myColorP0 = in.getByte();
myColorP1 = in.getByte();
myObjectColor = in.getByte();
myDebugColor = in.getByte();
myDebugEnabled = in.getBool();
myColorMode = (ColorMode)in.getByte();
myPattern = in.getInt();
myEffectivePattern = in.getInt();
myRefp = in.getBool();
myReflected = in.getBool();
myPf0 = in.getByte();
myPf1 = in.getByte();
myPf2 = in.getByte();
myX = in.getInt();
}
catch(...)
{

View File

@ -75,7 +75,7 @@ class Playfield : public Serializable
private:
enum ColorMode {normal, score};
enum ColorMode: uInt8 {normal, score};
private: