2009-02-17 15:05:16 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
* $URL$
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
*/
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2009-02-24 15:33:40 +00:00
|
|
|
#ifndef SCI_INCLUDE_ENGINE_H
|
|
|
|
#define SCI_INCLUDE_ENGINE_H
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2009-02-15 23:39:31 +00:00
|
|
|
#include "common/scummsys.h"
|
2009-02-22 21:38:46 +00:00
|
|
|
#include "common/array.h"
|
2009-03-15 20:31:29 +00:00
|
|
|
#include "common/serializer.h"
|
2010-03-18 15:09:24 +00:00
|
|
|
#include "common/str-array.h"
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2009-02-20 23:41:15 +00:00
|
|
|
namespace Common {
|
2011-04-25 19:29:26 +00:00
|
|
|
class SeekableReadStream;
|
|
|
|
class WriteStream;
|
2009-02-20 23:41:15 +00:00
|
|
|
}
|
|
|
|
|
2009-05-14 12:38:50 +00:00
|
|
|
#include "sci/sci.h"
|
2009-02-21 19:54:15 +00:00
|
|
|
#include "sci/engine/seg_manager.h"
|
2010-01-23 17:55:54 +00:00
|
|
|
|
|
|
|
#include "sci/parser/vocabulary.h"
|
|
|
|
|
2010-01-05 01:22:16 +00:00
|
|
|
#include "sci/sound/soundcmd.h"
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2009-02-21 10:23:36 +00:00
|
|
|
namespace Sci {
|
|
|
|
|
2010-06-09 07:59:42 +00:00
|
|
|
class EventManager;
|
2009-10-10 02:16:23 +00:00
|
|
|
class MessageState;
|
2009-11-12 15:24:11 +00:00
|
|
|
class SoundCommandParser;
|
2009-02-21 22:50:35 +00:00
|
|
|
|
2010-06-08 21:05:46 +00:00
|
|
|
enum AbortGameState {
|
|
|
|
kAbortNone = 0,
|
|
|
|
kAbortLoadGame = 1,
|
|
|
|
kAbortRestartGame = 2,
|
|
|
|
kAbortQuitGame = 3
|
|
|
|
};
|
|
|
|
|
2009-02-27 01:17:24 +00:00
|
|
|
class DirSeeker {
|
|
|
|
protected:
|
|
|
|
reg_t _outbuffer;
|
2010-08-29 15:13:25 +00:00
|
|
|
Common::StringArray _files;
|
|
|
|
Common::StringArray _virtualFiles;
|
2010-03-18 15:09:24 +00:00
|
|
|
Common::StringArray::const_iterator _iter;
|
2009-02-27 01:17:24 +00:00
|
|
|
|
|
|
|
public:
|
2010-01-10 21:13:38 +00:00
|
|
|
DirSeeker() {
|
2009-02-27 01:17:24 +00:00
|
|
|
_outbuffer = NULL_REG;
|
2010-08-29 15:13:25 +00:00
|
|
|
_iter = _files.begin();
|
2009-02-27 01:17:24 +00:00
|
|
|
}
|
2009-05-20 17:53:31 +00:00
|
|
|
|
2010-01-10 21:13:38 +00:00
|
|
|
reg_t firstFile(const Common::String &mask, reg_t buffer, SegManager *segMan);
|
|
|
|
reg_t nextFile(SegManager *segMan);
|
2010-08-29 15:13:25 +00:00
|
|
|
|
|
|
|
Common::String getVirtualFilename(uint fileNumber);
|
|
|
|
|
|
|
|
private:
|
|
|
|
void addAsVirtualFiles(Common::String title, Common::String fileMask);
|
2009-02-27 01:17:24 +00:00
|
|
|
};
|
2009-02-22 20:48:42 +00:00
|
|
|
|
2010-07-12 22:26:48 +00:00
|
|
|
enum {
|
|
|
|
MAX_SAVEGAME_NR = 20 /**< Maximum number of savegames */
|
|
|
|
};
|
|
|
|
|
2010-08-23 16:33:19 +00:00
|
|
|
// We assume that scripts give us savegameId 0->99 for creating a new save slot
|
|
|
|
// and savegameId 100->199 for existing save slots ffs. kfile.cpp
|
2010-07-12 22:26:48 +00:00
|
|
|
enum {
|
2010-08-23 16:33:19 +00:00
|
|
|
SAVEGAMEID_OFFICIALRANGE_START = 100,
|
|
|
|
SAVEGAMEID_OFFICIALRANGE_END = 199
|
2010-07-12 22:26:48 +00:00
|
|
|
};
|
|
|
|
|
2010-07-31 14:09:42 +00:00
|
|
|
enum {
|
|
|
|
GAMEISRESTARTING_NONE = 0,
|
|
|
|
GAMEISRESTARTING_RESTART = 1,
|
|
|
|
GAMEISRESTARTING_RESTORE = 2
|
|
|
|
};
|
|
|
|
|
2009-02-22 21:38:46 +00:00
|
|
|
class FileHandle {
|
|
|
|
public:
|
2009-02-27 01:17:24 +00:00
|
|
|
Common::String _name;
|
|
|
|
Common::SeekableReadStream *_in;
|
|
|
|
Common::WriteStream *_out;
|
2009-05-20 17:53:31 +00:00
|
|
|
|
2009-02-27 01:17:24 +00:00
|
|
|
public:
|
|
|
|
FileHandle();
|
|
|
|
~FileHandle();
|
2009-05-20 17:53:31 +00:00
|
|
|
|
2009-02-27 01:17:24 +00:00
|
|
|
void close();
|
|
|
|
bool isOpen() const;
|
2009-02-22 21:38:46 +00:00
|
|
|
};
|
|
|
|
|
2010-12-22 13:51:35 +00:00
|
|
|
enum VideoFlags {
|
|
|
|
kNone = 0,
|
|
|
|
kDoubled = 1 << 0,
|
|
|
|
kDropFrames = 1 << 1,
|
|
|
|
kBlackLines = 1 << 2,
|
|
|
|
kUnkBit3 = 1 << 3,
|
|
|
|
kGammaBoost = 1 << 4,
|
|
|
|
kHoldBlackFrame = 1 << 5,
|
|
|
|
kHoldLastFrame = 1 << 6,
|
|
|
|
kUnkBit7 = 1 << 7,
|
|
|
|
kStretch = 1 << 8
|
|
|
|
};
|
|
|
|
|
|
|
|
struct VideoState {
|
|
|
|
Common::String fileName;
|
|
|
|
uint16 x;
|
|
|
|
uint16 y;
|
|
|
|
uint16 flags;
|
|
|
|
|
|
|
|
void reset() {
|
|
|
|
fileName = "";
|
2010-12-22 14:19:38 +00:00
|
|
|
x = y = flags = 0;
|
2010-12-22 13:51:35 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2009-03-15 20:31:29 +00:00
|
|
|
struct EngineState : public Common::Serializable {
|
|
|
|
public:
|
2010-06-01 15:11:20 +00:00
|
|
|
EngineState(SegManager *segMan);
|
2009-03-15 20:31:29 +00:00
|
|
|
virtual ~EngineState();
|
2009-08-17 15:49:22 +00:00
|
|
|
|
2009-03-15 20:31:29 +00:00
|
|
|
virtual void saveLoadWithSerializer(Common::Serializer &ser);
|
2009-02-22 21:38:46 +00:00
|
|
|
|
2009-03-15 20:31:29 +00:00
|
|
|
public:
|
2010-02-03 01:32:27 +00:00
|
|
|
SegManager *_segMan; /**< The segment manager */
|
2009-02-15 06:10:59 +00:00
|
|
|
|
|
|
|
/* Non-VM information */
|
|
|
|
|
2010-06-10 11:18:10 +00:00
|
|
|
uint32 lastWaitTime; /**< The last time the game invoked Wait() */
|
2010-06-14 08:36:52 +00:00
|
|
|
uint32 _screenUpdateTime; /**< The last time the game updated the screen */
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2010-07-10 22:27:28 +00:00
|
|
|
void speedThrottler(uint32 neededSleep);
|
2010-02-23 22:44:46 +00:00
|
|
|
void wait(int16 ticks);
|
|
|
|
|
2010-01-17 18:41:28 +00:00
|
|
|
uint32 _throttleCounter; /**< total times kAnimate was invoked */
|
|
|
|
uint32 _throttleLastTime; /**< last time kAnimate was invoked */
|
|
|
|
bool _throttleTrigger;
|
2010-12-26 15:28:02 +00:00
|
|
|
bool _gameIsBenchmarking;
|
2009-10-14 21:45:16 +00:00
|
|
|
|
2009-02-15 06:10:59 +00:00
|
|
|
/* Kernel File IO stuff */
|
|
|
|
|
2009-04-27 12:29:51 +00:00
|
|
|
Common::Array<FileHandle> _fileHandles; /**< Array of file handles. Dynamically increased if required. */
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2009-02-27 01:17:24 +00:00
|
|
|
DirSeeker _dirseeker;
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2010-08-23 19:10:06 +00:00
|
|
|
int16 _lastSaveVirtualId; // last virtual id fed to kSaveGame, if no kGetSaveFiles was called inbetween
|
|
|
|
int16 _lastSaveNewId; // last newly created filename-id by kSaveGame
|
2010-07-12 22:26:48 +00:00
|
|
|
|
2010-08-29 15:13:25 +00:00
|
|
|
uint _chosenQfGImportItem; // Remembers the item selected in QfG import rooms
|
|
|
|
|
2010-08-31 15:50:46 +00:00
|
|
|
bool _cursorWorkaroundActive; // ffs. GfxCursor::setPosition()
|
|
|
|
Common::Point _cursorWorkaroundPoint;
|
|
|
|
Common::Rect _cursorWorkaroundRect;
|
|
|
|
|
2010-02-03 01:32:27 +00:00
|
|
|
public:
|
2009-02-15 06:10:59 +00:00
|
|
|
/* VM Information */
|
|
|
|
|
2009-05-28 22:42:18 +00:00
|
|
|
Common::List<ExecStack> _executionStack; /**< The execution stack */
|
2009-04-27 12:29:51 +00:00
|
|
|
/**
|
|
|
|
* When called from kernel functions, the vm is re-started recursively on
|
|
|
|
* the same stack. This variable contains the stack base for the current vm.
|
|
|
|
*/
|
2010-06-10 11:18:10 +00:00
|
|
|
int executionStackBase;
|
2009-04-28 15:58:19 +00:00
|
|
|
bool _executionStackPosChanged; /**< Set to true if the execution stack position should be re-evaluated by the vm */
|
2009-04-27 12:29:51 +00:00
|
|
|
|
2011-03-27 15:13:42 +00:00
|
|
|
// Registers
|
2009-04-27 12:29:51 +00:00
|
|
|
reg_t r_acc; /**< Accumulator */
|
|
|
|
reg_t r_prev; /**< previous comparison result */
|
2011-03-27 15:13:42 +00:00
|
|
|
int16 r_rest; /**< current &rest register */
|
2009-04-27 12:29:51 +00:00
|
|
|
|
|
|
|
StackPtr stack_base; /**< Pointer to the least stack element */
|
|
|
|
StackPtr stack_top; /**< First invalid stack element */
|
|
|
|
|
2010-06-06 23:00:33 +00:00
|
|
|
// Script state
|
|
|
|
ExecStack *xs;
|
|
|
|
reg_t *variables[4]; ///< global, local, temp, param, as immediate pointers
|
2010-06-10 11:43:20 +00:00
|
|
|
reg_t *variablesBase[4]; ///< Used for referencing VM ops
|
|
|
|
SegmentId variablesSegment[4]; ///< Same as above, contains segment IDs
|
|
|
|
int variablesMax[4]; ///< Max. values for all variables
|
2010-06-06 23:00:33 +00:00
|
|
|
|
2010-06-08 21:05:46 +00:00
|
|
|
AbortGameState abortScriptProcessing;
|
2010-07-31 14:09:42 +00:00
|
|
|
int16 gameIsRestarting; // is set when restarting (=1) or restoring the game (=2)
|
2010-06-08 21:05:46 +00:00
|
|
|
|
2010-06-10 11:18:10 +00:00
|
|
|
int scriptStepCounter; // Counts the number of steps executed
|
|
|
|
int scriptGCInterval; // Number of steps in between gcs
|
2010-06-06 23:00:33 +00:00
|
|
|
|
2009-06-04 20:50:51 +00:00
|
|
|
uint16 currentRoomNumber() const;
|
2010-01-03 15:08:26 +00:00
|
|
|
void setRoomNumber(uint16 roomNumber);
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2010-06-09 09:17:48 +00:00
|
|
|
/**
|
|
|
|
* Sets global variables from script 0
|
|
|
|
*/
|
|
|
|
void initGlobals();
|
|
|
|
|
2010-05-23 16:44:36 +00:00
|
|
|
/**
|
|
|
|
* Shrink execution stack to size.
|
2010-06-10 11:18:10 +00:00
|
|
|
* Contains an assert if it is not already smaller.
|
2010-05-23 16:44:36 +00:00
|
|
|
*/
|
|
|
|
void shrinkStackToBase();
|
|
|
|
|
2010-06-10 11:43:20 +00:00
|
|
|
int gcCountDown; /**< Number of kernel calls until next gc */
|
2010-02-03 01:32:27 +00:00
|
|
|
|
|
|
|
MessageState *_msgState;
|
|
|
|
|
|
|
|
// MemorySegment provides access to a 256-byte block of memory that remains
|
|
|
|
// intact across restarts and restores
|
|
|
|
enum {
|
|
|
|
kMemorySegmentMax = 256
|
|
|
|
};
|
2011-03-27 15:13:42 +00:00
|
|
|
uint16 _memorySegmentSize;
|
2010-02-03 01:32:27 +00:00
|
|
|
byte _memorySegment[kMemorySegmentMax];
|
|
|
|
|
2010-12-22 13:51:35 +00:00
|
|
|
VideoState _videoState;
|
|
|
|
bool _syncedAudioOptions;
|
|
|
|
|
2010-06-01 15:48:17 +00:00
|
|
|
/**
|
|
|
|
* Resets the engine state.
|
|
|
|
*/
|
|
|
|
void reset(bool isRestoring);
|
2009-02-21 10:47:56 +00:00
|
|
|
};
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2009-02-21 10:23:36 +00:00
|
|
|
} // End of namespace Sci
|
|
|
|
|
2009-02-24 15:33:40 +00:00
|
|
|
#endif // SCI_INCLUDE_ENGINE_H
|