ScummVM API documentation
state.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef SCI_ENGINE_STATE_H
23 #define SCI_ENGINE_STATE_H
24 
25 #include "common/scummsys.h"
26 #include "common/array.h"
27 #include "common/serializer.h"
28 #include "common/str-array.h"
29 
30 namespace Common {
31 class SeekableReadStream;
32 class WriteStream;
33 }
34 
35 #include "sci/sci.h"
36 #include "sci/engine/file.h"
37 #include "sci/engine/seg_manager.h"
38 
39 #include "sci/parser/vocabulary.h"
40 
41 #include "sci/sound/soundcmd.h"
42 
43 namespace Sci {
44 
45 class FileHandle;
46 class DirSeeker;
47 class EventManager;
48 class MessageState;
49 class SoundCommandParser;
50 class VirtualIndexFile;
51 
52 enum AbortGameState {
53  kAbortNone = 0,
54  kAbortLoadGame = 1,
55  kAbortRestartGame = 2,
56  kAbortQuitGame = 3
57 };
58 
59 // We assume that scripts give us savegameId 0->99 for creating a new save slot
60 // and savegameId 100->199 for existing save slots. Refer to kfile.cpp
61 enum {
62  SAVEGAMEID_OFFICIALRANGE_START = 100,
63  SAVEGAMEID_OFFICIALRANGE_END = 199
64 };
65 
66 enum {
67  GAMEISRESTARTING_NONE = 0,
68  GAMEISRESTARTING_RESTART = 1,
69  GAMEISRESTARTING_RESTORE = 2
70 };
71 
72 enum VideoFlags {
73  kNone = 0,
74  kDoubled = 1 << 0,
75  kDropFrames = 1 << 1,
76  kBlackLines = 1 << 2,
77  kUnkBit3 = 1 << 3,
78  kGammaBoost = 1 << 4,
79  kHoldBlackFrame = 1 << 5,
80  kHoldLastFrame = 1 << 6,
81  kUnkBit7 = 1 << 7,
82  kStretch = 1 << 8
83 };
84 
88 struct SciCallOrigin {
89  int scriptNr; //< The source script of the function
90  Common::String objectName; //< The name of the object being called
91  Common::String methodName; //< The name of the method being called
92  int localCallOffset; //< The byte offset of a local script subroutine called by the origin method. -1 if not in a local subroutine.
93  int roomNr; //< The room that was loaded at the time of the call
94 
95  Common::String toString() const {
96  return Common::String::format("method %s::%s (room %d, script %d, localCall %x)", objectName.c_str(), methodName.c_str(), roomNr, scriptNr, localCallOffset);
97  }
98 };
99 
101  EngineState(SegManager *segMan);
102  ~EngineState() override;
103 
104  void saveLoadWithSerializer(Common::Serializer &ser) override;
105 
108  /* Non-VM information */
109 
110  uint32 lastWaitTime;
113  void speedThrottler(uint32 neededSleep);
114  uint16 wait(uint16 ticks);
115  void sleep(uint16 ticks);
116 
117  uint32 _eventCounter;
120  bool _throttleTrigger;
121 
122  /* Kernel File IO stuff */
123 
126  DirSeeker _dirseeker;
127 
128  int16 _lastSaveVirtualId; // last virtual id fed to kSaveGame, if no kGetSaveFiles was called inbetween
129  int16 _lastSaveNewId; // last newly created filename-id by kSaveGame
130 
131  // see detection.cpp / SciEngine::loadGameState()
132  int _delayedRestoreGameId; // the saved game id, that it supposed to get restored (triggered by ScummVM menu)
133 
134  // see kmisc.cpp / kMacPlatform32
135  int _kq7MacSaveGameId; // the saved game id to use when saving (might not exist yet)
136  Common::String _kq7MacSaveGameDescription; // description to use when saving game
137 
138  uint _chosenQfGImportItem; // Remembers the item selected in QfG import rooms
139 
140  bool _cursorWorkaroundActive; // Refer to GfxCursor::setPosition()
141  int16 _cursorWorkaroundPosCount; // When the cursor is reported to be at the previously set coordinate, we won't disable the workaround unless it happened for this many times
142  Common::Point _cursorWorkaroundPoint;
143  Common::Rect _cursorWorkaroundRect;
144 
145  /* VM Information */
146 
155  // Registers
158  int16 r_rest;
163  // Script state
164  ExecStack *xs;
165  reg_t *variables[4];
166  reg_t *variablesBase[4];
167  SegmentId variablesSegment[4];
168  int variablesMax[4];
169 
170  AbortGameState abortScriptProcessing;
171  int16 gameIsRestarting; // is set when restarting (=1) or restoring the game (=2)
172 
173  int scriptStepCounter; // Counts the number of steps executed
174  int scriptGCInterval; // Number of steps in between gcs
175 
176  uint16 currentRoomNumber() const;
177  void setRoomNumber(uint16 roomNumber);
178 
182  void initGlobals();
183 
188  void shrinkStackToBase();
189 
192  MessageState *_msgState;
193  void initMessageState();
194 
195  // MemorySegment provides access to a 256-byte block of memory that remains
196  // intact across restarts and restores
197  enum {
198  kMemorySegmentMax = 256
199  };
200  uint16 _memorySegmentSize;
201  byte _memorySegment[kMemorySegmentMax];
202 
206  void reset(bool isRestoring);
207 
211  SciCallOrigin getCurrentCallOrigin() const;
212 
216  bool callInStack(const reg_t object, const Selector selector) const;
217 
223  Common::String getGameVersionFromGlobal() const;
224 };
225 
226 } // End of namespace Sci
227 
228 #endif // SCI_ENGINE_STATE_H
Definition: state.h:100
Definition: str.h:59
SegManager * _segMan
Definition: state.h:106
static String format(MSVC_PRINTF const char *fmt,...) GCC_PRINTF(1
reg_t r_acc
Definition: state.h:156
Definition: array.h:52
int executionStackBase
Definition: state.h:152
Definition: list.h:44
Definition: file.h:99
Definition: rect.h:144
int gcCountDown
Definition: state.h:190
Definition: serializer.h:79
int16 r_rest
Definition: state.h:158
uint32 _screenUpdateTime
Definition: state.h:111
StackPtr stack_base
Definition: state.h:160
reg_t r_prev
Definition: state.h:157
Definition: algorithm.h:29
uint32 _paletteSetIntensityCounter
Definition: state.h:118
Definition: rect.h:45
Definition: console.h:28
Definition: serializer.h:308
Definition: state.h:88
Common::Array< FileHandle > _fileHandles
Definition: state.h:124
Definition: seg_manager.h:48
uint32 _throttleLastTime
Definition: state.h:119
uint32 _eventCounter
Definition: state.h:117
Definition: vm.h:79
uint32 lastWaitTime
Definition: state.h:110
Common::List< ExecStack > _executionStack
Definition: state.h:147
Definition: message.h:68
bool _executionStackPosChanged
Definition: state.h:153
Definition: vm_types.h:39
StackPtr stack_top
Definition: state.h:161