377 lines
10 KiB
C
Raw Normal View History

2009-05-26 14:13:08 +00:00
/* Residual - A 3D game interpreter
*
* Residual is the legal property of its developers, whose names
2011-04-16 14:12:44 +02:00
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
2006-04-02 14:20:45 +00:00
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
* This library 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
* Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
2003-08-15 18:00:22 +00:00
2009-05-26 09:39:42 +00:00
#ifndef GRIM_ENGINE_H
#define GRIM_ENGINE_H
2003-08-15 18:00:22 +00:00
#include "engines/engine.h"
2011-05-13 17:55:14 -07:00
#include "common/str-array.h"
#include "common/hashmap.h"
#include "engines/advancedDetector.h"
#include "engines/grim/textobject.h"
2011-07-17 18:17:07 +02:00
#include "engines/grim/iris.h"
2003-08-15 18:00:22 +00:00
2009-05-25 06:49:57 +00:00
namespace Grim {
2003-08-15 18:00:22 +00:00
class Actor;
2009-05-09 17:44:05 +00:00
class SaveGame;
2011-05-13 17:55:14 -07:00
class Bitmap;
class Font;
class Color;
class ObjectState;
class Scene;
class TextObject;
class PrimitiveObject;
2003-08-15 18:00:22 +00:00
2009-06-18 11:52:26 +00:00
enum enDebugLevels {
DEBUG_NONE, DEBUG_NORMAL, DEBUG_WARN, DEBUG_ERROR, DEBUG_LUA, DEBUG_BITMAPS, DEBUG_MODEL, DEBUG_STUB,
DEBUG_SMUSH, DEBUG_IMUSE, DEBUG_CHORES, DEBUG_ALL
};
#define ENGINE_MODE_PAUSE 1
#define ENGINE_MODE_NORMAL 2
#define ENGINE_MODE_SMUSH 3
#define ENGINE_MODE_DRAW 4
enum GrimGameType {
GType_GRIM,
GType_MONKEY4
};
struct GrimGameDescription;
2005-08-27 16:08:44 +00:00
typedef Common::HashMap<Common::String, const char *>StringPtrHashMap;
2008-08-17 12:01:26 +00:00
struct ControlDescriptor {
const char *name;
int key;
};
class GrimEngine : public Engine {
protected:
// Engine APIs
virtual Common::Error run();
2003-08-15 18:00:22 +00:00
public:
2011-05-23 17:06:16 +02:00
enum SpeechMode {
TextOnly = 1,
VoiceOnly = 2,
TextAndVoice = 3
};
typedef Common::HashMap<int32, Bitmap *> BitmapListType;
typedef Common::HashMap<int32, Font *> FontListType;
typedef Common::HashMap<int32, Color *> ColorListType;
2011-05-05 11:32:11 +02:00
typedef Common::HashMap<int32, ObjectState *> StateListType;
typedef Common::HashMap<int32, Scene *> SceneListType;
typedef Common::HashMap<int32, Actor *> ActorListType;
2011-05-05 11:32:11 +02:00
typedef Common::HashMap<int32, TextObject *> TextListType;
typedef Common::HashMap<int32, PrimitiveObject *> PrimitiveListType;
GrimEngine(OSystem *syst, uint32 gameFlags, GrimGameType gameType, Common::Platform platform, Common::Language language);
virtual ~GrimEngine();
int getGameFlags() { return _gameFlags; }
GrimGameType getGameType() { return _gameType; }
Common::Language getGameLanguage() { return _gameLanguage; }
bool loadSaveDirectory(void);
void makeSystemMenu(void);
int modifyGameSpeed(int speedChange);
int getTimerDelay() const;
void setMode(int mode) { _mode = mode; }
int getMode() { return _mode; }
2005-08-13 13:35:43 +00:00
void setPreviousMode(int mode) { _previousMode = mode; }
int getPreviousMode() { return _previousMode; }
2011-05-23 17:06:16 +02:00
void setSpeechMode(SpeechMode mode) { _speechMode = mode; }
SpeechMode getSpeechMode() { return _speechMode; }
SaveGame *savedState() { return _savedState; }
2005-08-13 13:35:43 +00:00
void handleDebugLoadResource();
void luaUpdate();
void updateDisplayScene();
2005-08-28 23:25:14 +00:00
void doFlip();
2005-08-13 16:25:51 +00:00
void setFlipEnable(bool state) { _flipEnable = state; }
bool getFlipEnable() { return _flipEnable; }
void refreshDrawMode() { _refreshDrawNeeded = true; }
2005-08-14 13:26:37 +00:00
void drawPrimitives();
2011-07-17 18:17:07 +02:00
void playIrisAnimation(Iris::Direction dir, int x, int y, int time);
void mainLoop();
2011-05-05 11:25:08 +02:00
unsigned getFrameStart() const { return _frameStart; }
unsigned getFrameTime() const { return _frameTime; }
2011-05-08 07:28:46 +02:00
int bundle_dofile(const char *filename);
int single_dofile(const char *filename);
// perSecond should allow rates of zero, some actors will accelerate
// up to their normal speed (such as the bone wagon) so handling
// a walking rate of zero should happen in the default actor creation
2011-05-05 11:25:08 +02:00
float getPerSecond(float rate) const;
2005-04-08 11:47:47 +00:00
int getTextSpeed() { return _textSpeed; }
void setTextSpeed(int speed);
2004-12-09 23:55:43 +00:00
void enableControl(int num) { _controlsEnabled[num] = true; }
void disableControl(int num) { _controlsEnabled[num] = false; }
2008-08-17 12:01:26 +00:00
float getControlAxis(int num);
bool getControlState(int num);
Scene *findScene(const Common::String &name);
void setSceneLock(const char *name, bool lockStatus);
Scene *loadScene(const Common::String &name);
void setScene(const char *name);
void setScene(Scene *scene);
2011-05-05 11:25:08 +02:00
Scene *getCurrScene() { return _currScene; }
const Common::String &getSceneName() const { return _currScene->getName(); }
void makeCurrentSetup(int num);
// Scene registration
2011-05-05 11:32:11 +02:00
SceneListType::const_iterator scenesBegin() const { return _scenes.begin(); }
SceneListType::const_iterator scenesEnd() const { return _scenes.end(); }
void registerScene(Scene *a);
void removeScene(Scene *a);
void killScenes();
int sceneId(Scene *s) const;
2011-05-05 11:32:11 +02:00
void flagRefreshShadowMask(bool flag) { _refreshShadowMask = flag; }
bool getFlagRefreshShadowMask() { return _refreshShadowMask; }
Bitmap *registerBitmap(const char *filename, const char *data, int len);
Bitmap *registerBitmap(const char *data, int width, int height, const char *filename);
void registerBitmap(Bitmap *bitmap);
void killBitmap(Bitmap *b);
void killBitmaps();
2011-05-02 03:50:09 +08:00
Bitmap *getBitmap(int32 id) const;
2009-06-26 16:13:11 +00:00
// Actor registration
2011-05-05 11:32:11 +02:00
ActorListType::const_iterator actorsBegin() const { return _actors.begin(); }
ActorListType::const_iterator actorsEnd() const { return _actors.end(); }
void registerActor(Actor *a);
void killActor(Actor *a);
2011-05-05 11:25:08 +02:00
Actor *getActor(int id) const;
Actor *getTalkingActor() const;
void setTalkingActor(Actor *actor);
2004-12-09 23:55:43 +00:00
void setSelectedActor(Actor *a) { _selectedActor = a; }
2011-05-05 11:25:08 +02:00
Actor *getSelectedActor() { return _selectedActor; }
2011-03-21 17:18:04 +01:00
void killActors();
2011-03-21 17:18:04 +01:00
// Text Object Registration
2011-05-05 11:32:11 +02:00
TextListType::const_iterator textsBegin() const { return _textObjects.begin(); }
TextListType::const_iterator textsEnd() const { return _textObjects.end(); }
void registerTextObject(TextObject *a);
void killTextObject(TextObject *a);
void killTextObjects();
2011-05-05 11:25:08 +02:00
TextObject *getTextObject(int id) const;
2005-04-07 19:29:06 +00:00
// Primitives Object Registration
2011-05-05 11:32:11 +02:00
PrimitiveListType::const_iterator primitivesBegin() const { return _primitiveObjects.begin(); }
PrimitiveListType::const_iterator primitivesEnd() const { return _primitiveObjects.end(); }
void registerPrimitiveObject(PrimitiveObject *a);
void killPrimitiveObject(PrimitiveObject *a);
void killPrimitiveObjects();
2011-05-05 11:25:08 +02:00
PrimitiveObject *getPrimitiveObject(int id) const;
2005-04-07 19:29:06 +00:00
void registerObjectState(ObjectState *o);
void killObjectState(ObjectState *o);
void killObjectStates();
2011-05-05 11:25:08 +02:00
ObjectState *getObjectState(int id) const;
2009-06-22 21:06:46 +00:00
void registerFont(Font *f);
void killFont(Font *f);
void killFonts();
2011-05-02 03:50:09 +08:00
Font *getFont(int32 id) const;
void registerColor(Color *c);
void killColor(Color *c);
void killColors();
2011-05-05 11:25:08 +02:00
Color *getColor(int32 id) const;
void saveGame(const Common::String &file);
void loadGame(const Common::String &file);
Common::StringArray _listFiles;
Common::StringArray::const_iterator _listFilesIter;
TextObjectDefaults _sayLineDefaults, _printLineDefaults, _blastTextDefaults;
private:
void handleControls(int operation, int key, int keyModifier, uint16 ascii);
void handleChars(int operation, int key, int keyModifier, uint16 ascii);
void handleUserPaint();
void handleExit();
void handlePause();
2004-11-01 16:36:41 +00:00
void savegameSave();
2011-05-26 10:24:09 -07:00
void saveGRIM();
void saveBitmaps();
void saveFonts();
template<typename T>
2011-05-26 10:24:09 -07:00
void saveObjects(Common::HashMap<int32, T *> &map, uint32 ID);
void savegameRestore();
2011-05-26 10:24:09 -07:00
void restoreGRIM();
void restoreBitmaps();
void restoreFonts();
template<typename T>
2011-05-26 10:24:09 -07:00
void restoreObjects(Common::HashMap<int32, T *> &map, uint32 ID);
2009-06-22 21:20:12 +00:00
2005-01-12 23:28:47 +00:00
void savegameCallback();
void storeSaveGameImage(SaveGame *savedState);
2004-11-01 09:47:19 +00:00
bool _savegameLoadRequest;
bool _savegameSaveRequest;
Common::String _savegameFileName;
SaveGame *_savedState;
2004-11-01 09:47:19 +00:00
2004-12-09 23:55:43 +00:00
Scene *_currScene;
2005-08-13 13:35:43 +00:00
int _mode, _previousMode;
2011-05-23 17:06:16 +02:00
SpeechMode _speechMode;
2005-04-08 11:47:47 +00:00
int _textSpeed;
2005-08-13 16:25:51 +00:00
bool _flipEnable;
bool _refreshDrawNeeded;
2005-08-28 23:25:14 +00:00
char _fps[8];
bool _doFlip;
bool _refreshShadowMask;
2003-08-15 18:00:22 +00:00
2004-12-09 23:55:43 +00:00
unsigned _frameStart, _frameTime, _movieTime;
2005-08-13 13:35:43 +00:00
unsigned int _frameTimeCollection;
int _prevSmushFrame;
unsigned int _frameCounter;
2011-06-09 18:36:57 -07:00
unsigned int _lastFrameTime;
unsigned _speedLimitMs;
bool _showFps;
bool _softRenderer;
2003-08-15 18:00:22 +00:00
bool *_controlsEnabled;
2008-08-17 12:01:26 +00:00
bool *_controlsState;
2003-08-15 18:00:22 +00:00
Actor *_selectedActor;
Actor *_talkingActor;
2011-07-17 18:17:07 +02:00
Iris *_iris;
SceneListType _scenes;
2004-12-10 07:26:03 +00:00
ActorListType _actors;
TextListType _textObjects;
2005-04-07 19:29:06 +00:00
PrimitiveListType _primitiveObjects;
BitmapListType _bitmaps;
StateListType _objectStates;
FontListType _fonts;
ColorListType _colors;
uint32 _gameFlags;
GrimGameType _gameType;
Common::Platform _gamePlatform;
Common::Language _gameLanguage;
2003-08-15 18:00:22 +00:00
};
2009-05-17 08:24:17 +00:00
extern GrimEngine *g_grim;
2005-01-03 16:27:57 +00:00
extern int g_imuseState;
extern Actor *g_currentUpdatedActor;
2005-01-01 10:12:16 +00:00
void vimaInit(uint16 *destTable);
void decompressVima(const byte *src, int16 *dest, int destLen, uint16 *destTable);
2008-08-17 12:01:26 +00:00
// Fake KEYCODE_* values for joystick and mouse events
enum {
KEYCODE_JOY1_B1 = 512,
KEYCODE_JOY1_B2,
KEYCODE_JOY1_B3,
KEYCODE_JOY1_B4,
KEYCODE_JOY1_B5,
KEYCODE_JOY1_B6,
KEYCODE_JOY1_B7,
KEYCODE_JOY1_B8,
KEYCODE_JOY1_B9,
KEYCODE_JOY1_B10,
KEYCODE_JOY1_B11,
KEYCODE_JOY1_B12,
KEYCODE_JOY1_B13,
KEYCODE_JOY1_B14,
KEYCODE_JOY1_B15,
KEYCODE_JOY1_B16,
KEYCODE_JOY1_B17,
KEYCODE_JOY1_B18,
KEYCODE_JOY1_B19,
KEYCODE_JOY1_B20,
2008-08-17 12:01:26 +00:00
KEYCODE_JOY1_HLEFT,
KEYCODE_JOY1_HUP,
KEYCODE_JOY1_HRIGHT,
KEYCODE_JOY1_HDOWN,
KEYCODE_JOY2_B1,
KEYCODE_JOY2_B2,
KEYCODE_JOY2_B3,
KEYCODE_JOY2_B4,
KEYCODE_JOY2_B5,
KEYCODE_JOY2_B6,
KEYCODE_JOY2_B7,
KEYCODE_JOY2_B8,
KEYCODE_JOY2_B9,
KEYCODE_JOY2_B10,
2011-05-08 07:36:38 +02:00
KEYCODE_JOY2_B11,
KEYCODE_JOY2_B12,
KEYCODE_JOY2_B13,
KEYCODE_JOY2_B14,
KEYCODE_JOY2_B15,
KEYCODE_JOY2_B16,
2008-08-17 12:01:26 +00:00
KEYCODE_JOY2_HLEFT,
KEYCODE_JOY2_HUP,
KEYCODE_JOY2_HRIGHT,
KEYCODE_JOY2_HDOWN,
KEYCODE_MOUSE_B1,
KEYCODE_MOUSE_B2,
KEYCODE_MOUSE_B3,
KEYCODE_MOUSE_B4,
KEYCODE_AXIS_JOY1_X,
KEYCODE_AXIS_JOY1_Y,
KEYCODE_AXIS_JOY1_Z,
KEYCODE_AXIS_JOY1_R,
KEYCODE_AXIS_JOY1_U,
KEYCODE_AXIS_JOY1_V,
KEYCODE_AXIS_JOY2_X,
KEYCODE_AXIS_JOY2_Y,
KEYCODE_AXIS_JOY2_Z,
KEYCODE_AXIS_JOY2_R,
KEYCODE_AXIS_JOY2_U,
KEYCODE_AXIS_JOY2_V,
KEYCODE_AXIS_MOUSE_X,
KEYCODE_AXIS_MOUSE_Y,
KEYCODE_AXIS_MOUSE_Z,
KEYCODE_EXTRA_LAST
};
extern const ControlDescriptor controls[];
2009-05-25 06:49:57 +00:00
} // end of namespace Grim
2003-08-15 18:00:22 +00:00
#endif