| 1 | //============================================================================ |
| 2 | // |
| 3 | // SSSS tt lll lll |
| 4 | // SS SS tt ll ll |
| 5 | // SS tttttt eeee ll ll aaaa |
| 6 | // SSSS tt ee ee ll ll aa |
| 7 | // SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator" |
| 8 | // SS SS tt ee ll ll aa aa |
| 9 | // SSSS ttt eeeee llll llll aaaaa |
| 10 | // |
| 11 | // Copyright (c) 1995-2019 by Bradford W. Mott, Stephen Anthony |
| 12 | // and the Stella Team |
| 13 | // |
| 14 | // See the file "License.txt" for information on usage and redistribution of |
| 15 | // this file, and for a DISCLAIMER OF ALL WARRANTIES. |
| 16 | //============================================================================ |
| 17 | |
| 18 | #ifndef STATE_MANAGER_HXX |
| 19 | #define STATE_MANAGER_HXX |
| 20 | |
| 21 | #define "06000003state" |
| 22 | |
| 23 | class OSystem; |
| 24 | class RewindManager; |
| 25 | |
| 26 | #include "Serializer.hxx" |
| 27 | |
| 28 | /** |
| 29 | This class provides an interface to all things related to emulation state. |
| 30 | States can be loaded or saved here, as well as recorded, rewound, and later |
| 31 | played back. |
| 32 | |
| 33 | @author Stephen Anthony |
| 34 | */ |
| 35 | class StateManager |
| 36 | { |
| 37 | public: |
| 38 | enum class Mode { |
| 39 | Off, |
| 40 | TimeMachine, |
| 41 | MovieRecord, |
| 42 | MoviePlayback |
| 43 | }; |
| 44 | |
| 45 | /** |
| 46 | Create a new statemananger class. |
| 47 | */ |
| 48 | explicit StateManager(OSystem& osystem); |
| 49 | ~StateManager(); |
| 50 | |
| 51 | public: |
| 52 | /** |
| 53 | Answers whether the manager is in record or playback mode. |
| 54 | */ |
| 55 | Mode mode() const { return myActiveMode; } |
| 56 | |
| 57 | #if 0 |
| 58 | /** |
| 59 | Toggle movie recording mode (FIXME - currently disabled) |
| 60 | */ |
| 61 | void toggleRecordMode(); |
| 62 | #endif |
| 63 | |
| 64 | /** |
| 65 | Toggle state rewind recording mode; this uses the RewindManager |
| 66 | for its functionality. |
| 67 | */ |
| 68 | void toggleTimeMachine(); |
| 69 | |
| 70 | /** |
| 71 | Sets state rewind recording mode; this uses the RewindManager |
| 72 | for its functionality. |
| 73 | */ |
| 74 | void setRewindMode(Mode mode) { myActiveMode = mode; } |
| 75 | |
| 76 | /** |
| 77 | Optionally adds one extra state when entering the Time Machine dialog; |
| 78 | this uses the RewindManager for its functionality. |
| 79 | */ |
| 80 | bool (const string& message); |
| 81 | |
| 82 | /** |
| 83 | Rewinds states; this uses the RewindManager for its functionality. |
| 84 | */ |
| 85 | bool rewindStates(uInt32 numStates = 1); |
| 86 | |
| 87 | /** |
| 88 | Unwinds states; this uses the RewindManager for its functionality. |
| 89 | */ |
| 90 | bool unwindStates(uInt32 numStates = 1); |
| 91 | |
| 92 | /** |
| 93 | Rewinds/unwinds states; this uses the RewindManager for its functionality. |
| 94 | */ |
| 95 | bool windStates(uInt32 numStates, bool unwind); |
| 96 | |
| 97 | /** |
| 98 | Updates the state of the system based on the currently active mode. |
| 99 | */ |
| 100 | void update(); |
| 101 | |
| 102 | /** |
| 103 | Load a state into the current system. |
| 104 | |
| 105 | @param slot The state 'slot' to load state from |
| 106 | */ |
| 107 | void loadState(int slot = -1); |
| 108 | |
| 109 | /** |
| 110 | Save the current state from the system. |
| 111 | |
| 112 | @param slot The state 'slot' to save into |
| 113 | */ |
| 114 | void saveState(int slot = -1); |
| 115 | |
| 116 | /** |
| 117 | Switches to the next higher state slot (circular queue style). |
| 118 | */ |
| 119 | void changeState(); |
| 120 | |
| 121 | /** |
| 122 | Toggles auto slot mode. |
| 123 | */ |
| 124 | void toggleAutoSlot(); |
| 125 | |
| 126 | /** |
| 127 | Load a state into the current system from the given Serializer. |
| 128 | No messages are printed to the screen. |
| 129 | |
| 130 | @param in The Serializer object to use |
| 131 | |
| 132 | @return False on any load errors, else true |
| 133 | */ |
| 134 | bool loadState(Serializer& in); |
| 135 | |
| 136 | /** |
| 137 | Save the current state from the system into the given Serializer. |
| 138 | No messages are printed to the screen. |
| 139 | |
| 140 | @param out The Serializer object to use |
| 141 | |
| 142 | @return False on any save errors, else true |
| 143 | */ |
| 144 | bool saveState(Serializer& out); |
| 145 | |
| 146 | /** |
| 147 | Resets manager to defaults. |
| 148 | */ |
| 149 | void reset(); |
| 150 | |
| 151 | /** |
| 152 | Returns the current slot number |
| 153 | */ |
| 154 | int currentSlot() const { return myCurrentSlot; } |
| 155 | |
| 156 | /** |
| 157 | The rewind facility for the state manager |
| 158 | */ |
| 159 | RewindManager& rewindManager() const { return *myRewindManager; } |
| 160 | |
| 161 | private: |
| 162 | // The parent OSystem object |
| 163 | OSystem& myOSystem; |
| 164 | |
| 165 | // The current slot for load/save states |
| 166 | int myCurrentSlot; |
| 167 | |
| 168 | // Whether the manager is in record or playback mode |
| 169 | Mode myActiveMode; |
| 170 | |
| 171 | // MD5 of the currently active ROM (either in movie or rewind mode) |
| 172 | string myMD5; |
| 173 | |
| 174 | // Serializer classes used to save/load the eventstream |
| 175 | Serializer myMovieWriter; |
| 176 | Serializer myMovieReader; |
| 177 | |
| 178 | // Stored savestates to be later rewound |
| 179 | unique_ptr<RewindManager> myRewindManager; |
| 180 | |
| 181 | private: |
| 182 | // Following constructors and assignment operators not supported |
| 183 | StateManager() = delete; |
| 184 | StateManager(const StateManager&) = delete; |
| 185 | StateManager(StateManager&&) = delete; |
| 186 | StateManager& operator=(const StateManager&) = delete; |
| 187 | StateManager& operator=(StateManager&&) = delete; |
| 188 | }; |
| 189 | |
| 190 | #endif |
| 191 | |