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
30namespace Common {
31class SeekableReadStream;
32class 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
43namespace Sci {
44
45class FileHandle;
46class DirSeeker;
47class EventManager;
48class MessageState;
49class SoundCommandParser;
50class VirtualIndexFile;
51
52enum 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
61enum {
62 SAVEGAMEID_OFFICIALRANGE_START = 100,
63 SAVEGAMEID_OFFICIALRANGE_END = 199
64};
65
66enum {
67 GAMEISRESTARTING_NONE = 0,
68 GAMEISRESTARTING_RESTART = 1,
69 GAMEISRESTARTING_RESTORE = 2
70};
71
72enum 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
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
113 void speedThrottler(uint32 neededSleep);
114 uint16 wait(uint16 ticks);
115 void sleep(uint16 ticks);
116
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;
167 SegmentId variablesSegment[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
183
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
212
216 bool callInStack(const reg_t object, const Selector selector) const;
217
224};
225
226} // End of namespace Sci
227
228#endif // SCI_ENGINE_STATE_H
Definition: array.h:52
Definition: list.h:44
Definition: serializer.h:352
Definition: serializer.h:80
Definition: str.h:59
static String format(MSVC_PRINTF const char *fmt,...) GCC_PRINTF(1
Definition: file.h:99
Definition: message.h:68
Definition: seg_manager.h:48
Definition: algorithm.h:29
Definition: console.h:28
Definition: rect.h:144
Definition: rect.h:536
Definition: state.h:100
int executionStackBase
Definition: state.h:152
void reset(bool isRestoring)
reg_t * variablesBase[4]
Used for referencing VM ops.
Definition: state.h:166
SegmentId variablesSegment[4]
Same as above, contains segment IDs.
Definition: state.h:167
SciCallOrigin getCurrentCallOrigin() const
StackPtr stack_top
Definition: state.h:161
SegManager * _segMan
Definition: state.h:106
uint32 _screenUpdateTime
Definition: state.h:111
Common::List< ExecStack > _executionStack
Definition: state.h:147
int variablesMax[4]
Max. values for all variables.
Definition: state.h:168
uint32 _throttleLastTime
Definition: state.h:119
bool _executionStackPosChanged
Definition: state.h:153
int16 r_rest
Definition: state.h:158
Common::String getGameVersionFromGlobal() const
StackPtr stack_base
Definition: state.h:160
int gcCountDown
Definition: state.h:190
bool callInStack(const reg_t object, const Selector selector) const
reg_t r_prev
Definition: state.h:157
uint32 lastWaitTime
Definition: state.h:110
uint32 _eventCounter
Definition: state.h:117
reg_t * variables[4]
global, local, temp, param, as immediate pointers
Definition: state.h:165
Common::Array< FileHandle > _fileHandles
Definition: state.h:124
void shrinkStackToBase()
uint32 _paletteSetIntensityCounter
Definition: state.h:118
reg_t r_acc
Definition: state.h:156
Definition: vm.h:79
Definition: state.h:88
Definition: vm_types.h:39