2009-05-26 14:13:08 +00:00
|
|
|
/* Residual - A 3D game interpreter
|
2008-06-13 14:57:47 +00:00
|
|
|
*
|
|
|
|
* Residual is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the AUTHORS
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
* $URL$
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
*/
|
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
|
|
|
|
2009-05-25 19:21:58 +00:00
|
|
|
#include "engines/engine.h"
|
|
|
|
|
2009-05-24 19:13:58 +00:00
|
|
|
#include "engines/grim/textobject.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;
|
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
|
|
|
|
};
|
|
|
|
|
2004-03-20 05:47:21 +00:00
|
|
|
#define ENGINE_MODE_IDLE 0
|
|
|
|
#define ENGINE_MODE_PAUSE 1
|
|
|
|
#define ENGINE_MODE_NORMAL 2
|
|
|
|
#define ENGINE_MODE_SMUSH 3
|
|
|
|
#define ENGINE_MODE_DRAW 4
|
|
|
|
|
2009-05-25 19:21:58 +00:00
|
|
|
enum GrimGameType {
|
|
|
|
GType_GRIM = 1,
|
|
|
|
GType_MONKEY
|
|
|
|
};
|
|
|
|
|
|
|
|
enum GrimGameFeatures {
|
|
|
|
GF_DEMO = 1 << 0
|
|
|
|
};
|
|
|
|
|
|
|
|
struct GrimGameDescription;
|
2005-08-27 16:08:44 +00:00
|
|
|
|
2009-05-25 19:21:58 +00:00
|
|
|
typedef Common::HashMap<Common::String, const char *> StringPtrHashMap;
|
|
|
|
|
2005-08-27 16:08:44 +00:00
|
|
|
#define GF_DEMO 1
|
|
|
|
|
2008-08-17 12:01:26 +00:00
|
|
|
struct ControlDescriptor {
|
|
|
|
const char *name;
|
|
|
|
int key;
|
|
|
|
};
|
|
|
|
|
2009-05-25 19:21:58 +00:00
|
|
|
class GrimEngine : public Engine {
|
|
|
|
|
|
|
|
protected:
|
|
|
|
// Engine APIs
|
|
|
|
virtual Common::Error run();
|
|
|
|
|
2003-08-15 18:00:22 +00:00
|
|
|
public:
|
2004-02-24 21:09:53 +00:00
|
|
|
|
2009-06-23 07:14:53 +00:00
|
|
|
GrimEngine(OSystem *syst, int gameFlags);
|
2009-05-25 19:21:58 +00:00
|
|
|
virtual ~GrimEngine();
|
|
|
|
|
2009-06-23 07:14:53 +00:00
|
|
|
int getGameFlags() { return _gameFlags; }
|
|
|
|
|
2009-05-25 19:21:58 +00:00
|
|
|
bool loadSaveDirectory(void);
|
|
|
|
void makeSystemMenu(void);
|
|
|
|
int modifyGameSpeed(int speedChange);
|
|
|
|
int getTimerDelay() const;
|
|
|
|
|
2004-03-20 05:47:21 +00:00
|
|
|
void setMode(int mode) { _mode = mode; }
|
2005-07-17 23:40:22 +00:00
|
|
|
int getMode() { return _mode; }
|
2005-08-13 13:35:43 +00:00
|
|
|
void setPreviousMode(int mode) { _previousMode = mode; }
|
|
|
|
int getPreviousMode() { return _previousMode; }
|
2004-03-20 08:22:51 +00:00
|
|
|
void setSpeechMode(int mode) { _speechMode = mode; }
|
|
|
|
int getSpeechMode() { return _speechMode; }
|
2005-12-26 02:36:00 +00:00
|
|
|
SaveGame *savedState() { return _savedState; }
|
2004-03-20 05:47:21 +00:00
|
|
|
|
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();
|
2005-08-13 11:33:12 +00:00
|
|
|
|
2004-02-24 21:09:53 +00:00
|
|
|
void mainLoop();
|
2004-12-09 23:55:43 +00:00
|
|
|
unsigned frameStart() const { return _frameStart; }
|
|
|
|
unsigned frameTime() const { return _frameTime; }
|
2004-02-24 21:09:53 +00:00
|
|
|
|
2005-08-01 03:49:02 +00:00
|
|
|
// 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
|
|
|
|
float perSecond(float rate) const { return rate * _frameTime / 1000; }
|
2004-02-24 21:09:53 +00:00
|
|
|
|
2005-04-08 11:47:47 +00:00
|
|
|
int getTextSpeed() { return _textSpeed; }
|
|
|
|
void setTextSpeed(int speed);
|
2005-04-05 13:50:54 +00:00
|
|
|
|
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);
|
2004-02-24 21:09:53 +00:00
|
|
|
|
2005-07-10 18:57:27 +00:00
|
|
|
Scene *findScene(const char *name);
|
|
|
|
void setSceneLock(const char *name, bool lockStatus);
|
2004-02-24 21:09:53 +00:00
|
|
|
void setScene(const char *name);
|
2005-07-10 18:57:27 +00:00
|
|
|
void setScene(Scene *scene);
|
2004-12-09 23:55:43 +00:00
|
|
|
Scene *currScene() { return _currScene; }
|
|
|
|
const char *sceneName() const { return _currScene->name(); }
|
2009-06-08 22:25:14 +00:00
|
|
|
void makeCurrentSetup(int num);
|
2004-02-24 21:09:53 +00:00
|
|
|
|
2005-07-10 18:57:27 +00:00
|
|
|
// Scene registration
|
2011-03-21 05:16:27 +08:00
|
|
|
typedef Common::HashMap<int, Scene *> SceneListType;
|
2005-07-10 18:57:27 +00:00
|
|
|
SceneListType::const_iterator scenesBegin() const {
|
|
|
|
return _scenes.begin();
|
|
|
|
}
|
|
|
|
SceneListType::const_iterator scenesEnd() const {
|
|
|
|
return _scenes.end();
|
|
|
|
}
|
2011-03-21 05:16:27 +08:00
|
|
|
void registerScene(Scene *a);
|
|
|
|
void removeScene(Scene *a);
|
|
|
|
void killScenes();
|
|
|
|
int sceneId(Scene *s) const;
|
|
|
|
Scene *scene(int id) const;
|
2005-07-10 18:57:27 +00:00
|
|
|
|
2008-07-05 08:48:39 +00:00
|
|
|
void flagRefreshShadowMask(bool flag) {
|
|
|
|
_refreshShadowMask = flag;
|
|
|
|
}
|
|
|
|
bool getFlagRefreshShadowMask() {
|
|
|
|
return _refreshShadowMask;
|
|
|
|
}
|
|
|
|
|
2009-06-26 16:13:11 +00:00
|
|
|
Bitmap *registerBitmap(const char *filename, const char *data, int len) {
|
|
|
|
Bitmap *b = new Bitmap(filename, data, len);
|
|
|
|
_bitmaps.push_back(b);
|
|
|
|
return b;
|
|
|
|
}
|
|
|
|
Bitmap *registerBitmap(const char *data, int width, int height, const char *filename) {
|
|
|
|
Bitmap *b = new Bitmap(data, width, height, filename);
|
|
|
|
_bitmaps.push_back(b);
|
|
|
|
return b;
|
|
|
|
}
|
2011-03-21 05:16:27 +08:00
|
|
|
void registerBitmap(Bitmap *bitmap) {
|
|
|
|
_bitmaps.push_back(bitmap);
|
|
|
|
}
|
2009-06-26 16:13:11 +00:00
|
|
|
void killBitmap(Bitmap *b) { _bitmaps.remove(b); }
|
|
|
|
|
2005-07-10 18:57:27 +00:00
|
|
|
// Actor registration
|
2011-03-21 05:16:27 +08:00
|
|
|
typedef Common::HashMap<int, Actor *> ActorListType;
|
2004-12-10 07:26:03 +00:00
|
|
|
ActorListType::const_iterator actorsBegin() const {
|
2004-12-09 23:55:43 +00:00
|
|
|
return _actors.begin();
|
2004-02-24 21:09:53 +00:00
|
|
|
}
|
2004-12-10 07:26:03 +00:00
|
|
|
ActorListType::const_iterator actorsEnd() const {
|
2004-12-09 23:55:43 +00:00
|
|
|
return _actors.end();
|
2004-02-24 21:09:53 +00:00
|
|
|
}
|
2011-03-21 05:16:27 +08:00
|
|
|
void registerActor(Actor *a);
|
|
|
|
void killActor(Actor *a);
|
|
|
|
int actorId(Actor *a) const;
|
|
|
|
Actor *actor(int id) const;
|
|
|
|
|
2004-12-09 23:55:43 +00:00
|
|
|
void setSelectedActor(Actor *a) { _selectedActor = a; }
|
|
|
|
Actor *selectedActor() { return _selectedActor; }
|
2011-03-21 17:18:04 +01:00
|
|
|
void killActors();
|
2004-02-24 21:09:53 +00:00
|
|
|
|
2011-03-21 17:18:04 +01:00
|
|
|
// Text Object Registration
|
2011-03-21 05:16:27 +08:00
|
|
|
typedef Common::HashMap<int, TextObject *> TextListType;
|
2004-12-10 07:26:03 +00:00
|
|
|
TextListType::const_iterator textsBegin() const {
|
2004-12-09 23:55:43 +00:00
|
|
|
return _textObjects.begin();
|
2004-02-24 21:09:53 +00:00
|
|
|
}
|
2004-12-10 07:26:03 +00:00
|
|
|
TextListType::const_iterator textsEnd() const {
|
2004-12-09 23:55:43 +00:00
|
|
|
return _textObjects.end();
|
2004-02-24 21:09:53 +00:00
|
|
|
}
|
2011-03-21 05:16:27 +08:00
|
|
|
void registerTextObject(TextObject *a);
|
|
|
|
void killTextObject(TextObject *a);
|
|
|
|
void killTextObjects();
|
|
|
|
int textObjectId(TextObject *t) const;
|
|
|
|
TextObject *textObject(int id) const;
|
2003-10-05 17:45:46 +00:00
|
|
|
|
2005-04-07 19:29:06 +00:00
|
|
|
// Primitives Object Registration
|
2011-03-21 05:16:27 +08:00
|
|
|
typedef Common::HashMap<int, PrimitiveObject *> PrimitiveListType;
|
2005-04-07 19:29:06 +00:00
|
|
|
PrimitiveListType::const_iterator primitivesBegin() const {
|
|
|
|
return _primitiveObjects.begin();
|
|
|
|
}
|
|
|
|
PrimitiveListType::const_iterator primitivesEnd() const {
|
|
|
|
return _primitiveObjects.end();
|
|
|
|
}
|
|
|
|
|
2011-03-21 05:16:27 +08:00
|
|
|
void registerPrimitiveObject(PrimitiveObject *a);
|
|
|
|
void killPrimitiveObject(PrimitiveObject *a);
|
|
|
|
void killPrimitiveObjects();
|
|
|
|
int primitiveObjectId(PrimitiveObject *p) const;
|
|
|
|
PrimitiveObject *primitiveObject(int id) const;
|
2005-04-07 19:29:06 +00:00
|
|
|
|
2011-03-21 05:16:27 +08:00
|
|
|
void registerObjectState(ObjectState *o);
|
|
|
|
void killObjectState(ObjectState *o);
|
|
|
|
void killObjectStates();
|
|
|
|
int objectStateId(ObjectState *o) const;
|
|
|
|
ObjectState *objectState(int id) const;
|
2009-06-22 21:06:46 +00:00
|
|
|
|
2004-11-01 16:36:41 +00:00
|
|
|
void savegameSave();
|
2009-06-22 14:11:40 +00:00
|
|
|
void saveActors(SaveGame *savedState);
|
2009-06-23 05:15:20 +00:00
|
|
|
void saveTextObjects(SaveGame *savedState);
|
2009-06-23 07:14:53 +00:00
|
|
|
void savePrimitives(SaveGame *savedState);
|
2009-06-24 17:30:34 +00:00
|
|
|
void saveScenes(SaveGame *savedState);
|
2011-03-21 05:16:27 +08:00
|
|
|
void saveObjectStates(SaveGame *savedState);
|
|
|
|
|
|
|
|
void savegameRestore();
|
|
|
|
void restoreActors(SaveGame *savedState);
|
|
|
|
void restoreTextObjects(SaveGame *savedState);
|
|
|
|
void restorePrimitives(SaveGame *savedState);
|
|
|
|
void restoreScenes(SaveGame *savedState);
|
|
|
|
void restoreObjectStates(SaveGame *savedState);
|
2009-06-22 21:20:12 +00:00
|
|
|
|
2005-01-12 23:28:47 +00:00
|
|
|
void savegameCallback();
|
2008-07-25 22:21:04 +00:00
|
|
|
static void savegameReadStream(void *data, int32 size);
|
|
|
|
static void savegameWriteStream(void *data, int32 size);
|
|
|
|
static int32 savegameReadSint32();
|
|
|
|
static void savegameWriteSint32(int32 val);
|
|
|
|
static uint32 savegameReadUint32();
|
|
|
|
static void savegameWriteUint32(uint32 val);
|
|
|
|
|
2006-05-14 07:51:41 +00:00
|
|
|
void storeSaveGameImage(SaveGame *savedState);
|
2006-05-13 15:07:35 +00:00
|
|
|
|
2004-11-01 09:47:19 +00:00
|
|
|
bool _savegameLoadRequest;
|
|
|
|
bool _savegameSaveRequest;
|
2008-07-20 13:34:04 +00:00
|
|
|
const char *_savegameFileName;
|
2005-12-26 02:36:00 +00:00
|
|
|
SaveGame *_savedState;
|
2004-11-01 09:47:19 +00:00
|
|
|
|
2004-12-31 21:35:04 +00:00
|
|
|
private:
|
2003-08-15 18:00:22 +00:00
|
|
|
|
2009-05-31 16:09:21 +00:00
|
|
|
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();
|
2005-04-05 13:50:54 +00:00
|
|
|
|
2004-12-09 23:55:43 +00:00
|
|
|
Scene *_currScene;
|
2005-08-13 13:35:43 +00:00
|
|
|
int _mode, _previousMode;
|
2004-03-20 08:22:51 +00:00
|
|
|
int _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;
|
2008-07-05 08:48:39 +00:00
|
|
|
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;
|
|
|
|
unsigned int _timeAccum;
|
2008-08-16 17:54:14 +00:00
|
|
|
unsigned _speedLimitMs;
|
2009-05-25 19:21:58 +00:00
|
|
|
bool _showFps;
|
|
|
|
bool _softRenderer;
|
2003-08-15 18:00:22 +00:00
|
|
|
|
2006-02-05 20:40:16 +00:00
|
|
|
bool *_controlsEnabled;
|
2008-08-17 12:01:26 +00:00
|
|
|
bool *_controlsState;
|
2003-08-15 18:00:22 +00:00
|
|
|
|
2005-07-10 18:57:27 +00:00
|
|
|
SceneListType _scenes;
|
2004-12-10 07:26:03 +00:00
|
|
|
ActorListType _actors;
|
2004-12-09 23:55:43 +00:00
|
|
|
Actor *_selectedActor;
|
2004-12-10 07:26:03 +00:00
|
|
|
TextListType _textObjects;
|
2005-04-07 19:29:06 +00:00
|
|
|
PrimitiveListType _primitiveObjects;
|
2009-06-26 16:13:11 +00:00
|
|
|
Common::List<Bitmap *> _bitmaps;
|
2011-03-21 05:16:27 +08:00
|
|
|
Common::HashMap<int, ObjectState *> _objectStates;
|
2009-06-23 07:14:53 +00:00
|
|
|
|
|
|
|
int _gameFlags;
|
2003-08-15 18:00:22 +00:00
|
|
|
};
|
|
|
|
|
2009-05-17 08:24:17 +00:00
|
|
|
extern GrimEngine *g_grim;
|
2004-12-31 21:35:04 +00:00
|
|
|
|
2005-01-03 16:27:57 +00:00
|
|
|
extern int g_imuseState;
|
|
|
|
|
2005-01-10 09:53:02 +00:00
|
|
|
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_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,
|
|
|
|
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
|