From c73c60663884484fbaf57980479a1b81f37ffd00 Mon Sep 17 00:00:00 2001 From: Stephen Anthony Date: Sat, 11 Feb 2017 22:30:58 -0330 Subject: [PATCH] Implemented Serializable for Background, Ball and Playfield classes, since it looks like they won't be heavily modified any further. --- src/emucore/StateManager.cxx | 2 +- src/emucore/tia/Background.cxx | 14 ++++++--- src/emucore/tia/Ball.cxx | 55 ++++++++++++++++++++++++++++++--- src/emucore/tia/Playfield.cxx | 56 +++++++++++++++++++++++++++++++--- src/emucore/tia/Playfield.hxx | 2 +- 5 files changed, 115 insertions(+), 14 deletions(-) diff --git a/src/emucore/StateManager.cxx b/src/emucore/StateManager.cxx index 62cd6de36..8a055cc38 100644 --- a/src/emucore/StateManager.cxx +++ b/src/emucore/StateManager.cxx @@ -28,7 +28,7 @@ #include "StateManager.hxx" -#define STATE_HEADER "04080000state" +#define STATE_HEADER "04090100state" #define MOVIE_HEADER "03030000movie" // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/emucore/tia/Background.cxx b/src/emucore/tia/Background.cxx index b7eb6b674..7193893cd 100644 --- a/src/emucore/tia/Background.cxx +++ b/src/emucore/tia/Background.cxx @@ -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(...) { diff --git a/src/emucore/tia/Ball.cxx b/src/emucore/tia/Ball.cxx index 014f2ffb1..ff3be4c75 100644 --- a/src/emucore/tia/Ball.cxx +++ b/src/emucore/tia/Ball.cxx @@ -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(...) { diff --git a/src/emucore/tia/Playfield.cxx b/src/emucore/tia/Playfield.cxx index 5a4e0deeb..91d42d387 100644 --- a/src/emucore/tia/Playfield.cxx +++ b/src/emucore/tia/Playfield.cxx @@ -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(...) { diff --git a/src/emucore/tia/Playfield.hxx b/src/emucore/tia/Playfield.hxx index 1f5d1a70c..81e7cde16 100644 --- a/src/emucore/tia/Playfield.hxx +++ b/src/emucore/tia/Playfield.hxx @@ -75,7 +75,7 @@ class Playfield : public Serializable private: - enum ColorMode {normal, score}; + enum ColorMode: uInt8 {normal, score}; private: