2003-08-15 18:00:22 +00:00
|
|
|
// Residual - Virtual machine to run LucasArts' 3D adventure games
|
2005-01-01 10:23:18 +00:00
|
|
|
// Copyright (C) 2003-2005 The ScummVM-Residual Team (www.scummvm.org)
|
2003-08-15 18:00:22 +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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
|
2003-08-15 19:41:26 +00:00
|
|
|
#ifndef ENGINE_H
|
|
|
|
#define ENGINE_H
|
2003-08-15 18:00:22 +00:00
|
|
|
|
2005-01-01 12:27:57 +00:00
|
|
|
#include "bits.h"
|
2003-08-15 19:41:26 +00:00
|
|
|
#include "scene.h"
|
2003-08-21 15:42:36 +00:00
|
|
|
#include "textobject.h"
|
2005-04-07 19:29:06 +00:00
|
|
|
#include "primitives.h"
|
2005-03-19 21:48:23 +00:00
|
|
|
#include "font.h"
|
2004-12-25 18:23:07 +00:00
|
|
|
#include "lua.h"
|
2005-01-01 12:27:57 +00:00
|
|
|
|
2003-08-15 18:00:22 +00:00
|
|
|
#include <cstdlib>
|
|
|
|
#include <list>
|
2003-08-15 20:16:25 +00:00
|
|
|
#include <SDL_keysym.h>
|
2003-08-15 18:00:22 +00:00
|
|
|
|
|
|
|
class Actor;
|
|
|
|
|
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
|
|
|
|
|
2005-08-27 16:08:44 +00:00
|
|
|
extern int g_flags;
|
|
|
|
|
|
|
|
#define GF_DEMO 1
|
|
|
|
|
2003-08-15 18:00:22 +00:00
|
|
|
// Fake SDLK_* values for joystick and mouse events
|
|
|
|
enum {
|
2004-02-24 21:09:53 +00:00
|
|
|
SDLK_JOY1_B1 = SDLK_LAST,
|
|
|
|
SDLK_JOY1_B2,
|
|
|
|
SDLK_JOY1_B3,
|
|
|
|
SDLK_JOY1_B4,
|
|
|
|
SDLK_JOY1_B5,
|
|
|
|
SDLK_JOY1_B6,
|
|
|
|
SDLK_JOY1_B7,
|
|
|
|
SDLK_JOY1_B8,
|
|
|
|
SDLK_JOY1_B9,
|
|
|
|
SDLK_JOY1_B10,
|
|
|
|
SDLK_JOY1_HLEFT,
|
|
|
|
SDLK_JOY1_HUP,
|
|
|
|
SDLK_JOY1_HRIGHT,
|
|
|
|
SDLK_JOY1_HDOWN,
|
|
|
|
SDLK_JOY2_B1,
|
|
|
|
SDLK_JOY2_B2,
|
|
|
|
SDLK_JOY2_B3,
|
|
|
|
SDLK_JOY2_B4,
|
|
|
|
SDLK_JOY2_B5,
|
|
|
|
SDLK_JOY2_B6,
|
|
|
|
SDLK_JOY2_B7,
|
|
|
|
SDLK_JOY2_B8,
|
|
|
|
SDLK_JOY2_B9,
|
|
|
|
SDLK_JOY2_B10,
|
|
|
|
SDLK_JOY2_HLEFT,
|
|
|
|
SDLK_JOY2_HUP,
|
|
|
|
SDLK_JOY2_HRIGHT,
|
|
|
|
SDLK_JOY2_HDOWN,
|
|
|
|
SDLK_MOUSE_B1,
|
|
|
|
SDLK_MOUSE_B2,
|
|
|
|
SDLK_MOUSE_B3,
|
|
|
|
SDLK_MOUSE_B4,
|
|
|
|
SDLK_AXIS_JOY1_X,
|
|
|
|
SDLK_AXIS_JOY1_Y,
|
|
|
|
SDLK_AXIS_JOY1_Z,
|
|
|
|
SDLK_AXIS_JOY1_R,
|
|
|
|
SDLK_AXIS_JOY1_U,
|
|
|
|
SDLK_AXIS_JOY1_V,
|
|
|
|
SDLK_AXIS_JOY2_X,
|
|
|
|
SDLK_AXIS_JOY2_Y,
|
|
|
|
SDLK_AXIS_JOY2_Z,
|
|
|
|
SDLK_AXIS_JOY2_R,
|
|
|
|
SDLK_AXIS_JOY2_U,
|
|
|
|
SDLK_AXIS_JOY2_V,
|
|
|
|
SDLK_AXIS_MOUSE_X,
|
|
|
|
SDLK_AXIS_MOUSE_Y,
|
|
|
|
SDLK_AXIS_MOUSE_Z,
|
|
|
|
SDLK_EXTRA_LAST
|
2005-04-07 19:29:06 +00:00
|
|
|
};
|
2003-08-15 18:00:22 +00:00
|
|
|
|
|
|
|
class Engine {
|
|
|
|
public:
|
2004-02-24 21:09:53 +00:00
|
|
|
|
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; }
|
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(); }
|
2004-02-24 21:09:53 +00:00
|
|
|
|
2005-07-10 18:57:27 +00:00
|
|
|
// Scene registration
|
|
|
|
typedef std::list<Scene *> SceneListType;
|
|
|
|
SceneListType::const_iterator scenesBegin() const {
|
|
|
|
return _scenes.begin();
|
|
|
|
}
|
|
|
|
SceneListType::const_iterator scenesEnd() const {
|
|
|
|
return _scenes.end();
|
|
|
|
}
|
|
|
|
void registerScene(Scene *a) { _scenes.push_back(a); }
|
|
|
|
void removeScene(Scene *a) {
|
|
|
|
_scenes.remove(a);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Actor registration
|
2004-12-10 07:26:03 +00:00
|
|
|
typedef std::list<Actor *> ActorListType;
|
|
|
|
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
|
|
|
}
|
2005-07-10 18:57:27 +00:00
|
|
|
void registerActor(Actor *a) { _actors.push_back(a); }
|
2004-12-09 23:55:43 +00:00
|
|
|
void setSelectedActor(Actor *a) { _selectedActor = a; }
|
|
|
|
Actor *selectedActor() { return _selectedActor; }
|
2004-02-24 21:09:53 +00:00
|
|
|
|
2005-04-05 13:50:54 +00:00
|
|
|
// Text Object Registration
|
2004-12-10 07:26:03 +00:00
|
|
|
typedef std::list<TextObject *> TextListType;
|
|
|
|
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
|
|
|
}
|
2004-12-09 23:55:43 +00:00
|
|
|
void registerTextObject(TextObject *a) { _textObjects.push_back(a); }
|
2004-02-24 21:09:53 +00:00
|
|
|
void killTextObject(TextObject *a) {
|
2004-12-09 23:55:43 +00:00
|
|
|
_textObjects.remove(a);
|
2004-02-24 21:09:53 +00:00
|
|
|
}
|
|
|
|
void killTextObjects() {
|
2004-12-09 23:55:43 +00:00
|
|
|
while (!_textObjects.empty()) {
|
|
|
|
delete _textObjects.back();
|
|
|
|
_textObjects.pop_back();
|
2004-02-24 21:09:53 +00:00
|
|
|
}
|
|
|
|
}
|
2003-10-05 17:45:46 +00:00
|
|
|
|
2005-04-07 19:29:06 +00:00
|
|
|
// Primitives Object Registration
|
|
|
|
typedef std::list<PrimitiveObject *> PrimitiveListType;
|
|
|
|
PrimitiveListType::const_iterator primitivesBegin() const {
|
|
|
|
return _primitiveObjects.begin();
|
|
|
|
}
|
|
|
|
PrimitiveListType::const_iterator primitivesEnd() const {
|
|
|
|
return _primitiveObjects.end();
|
|
|
|
}
|
|
|
|
|
|
|
|
void registerPrimitiveObject(PrimitiveObject *a) { _primitiveObjects.push_back(a); }
|
|
|
|
void killPrimitiveObject(PrimitiveObject *a) {
|
|
|
|
_primitiveObjects.remove(a);
|
|
|
|
}
|
|
|
|
void killPrimitiveObjects() {
|
|
|
|
while (!_primitiveObjects.empty()) {
|
|
|
|
delete _primitiveObjects.back();
|
|
|
|
_primitiveObjects.pop_back();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-11-01 16:36:41 +00:00
|
|
|
void savegameSave();
|
|
|
|
void savegameRestore();
|
2005-01-12 23:28:47 +00:00
|
|
|
void savegameCallback();
|
2004-11-01 16:36:41 +00:00
|
|
|
|
2004-11-01 09:47:19 +00:00
|
|
|
bool _savegameLoadRequest;
|
|
|
|
bool _savegameSaveRequest;
|
|
|
|
char *_savegameFileName;
|
2005-12-26 02:36:00 +00:00
|
|
|
SaveGame *_savedState;
|
2004-11-01 09:47:19 +00:00
|
|
|
|
2004-02-24 21:09:53 +00:00
|
|
|
Engine();
|
2004-12-31 21:35:04 +00:00
|
|
|
~Engine() {}
|
|
|
|
|
|
|
|
private:
|
2003-08-15 18:00:22 +00:00
|
|
|
|
2005-12-26 19:26:46 +00:00
|
|
|
void handleButton(int operation, int key, int keyModifier);
|
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;
|
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;
|
2003-08-15 18:00:22 +00:00
|
|
|
|
2004-12-09 23:55:43 +00:00
|
|
|
bool _controlsEnabled[SDLK_EXTRA_LAST];
|
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;
|
2003-08-15 18:00:22 +00:00
|
|
|
};
|
|
|
|
|
2004-12-31 21:35:04 +00:00
|
|
|
extern Engine *g_engine;
|
|
|
|
|
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-04-08 22:29:06 +00:00
|
|
|
#ifdef _WIN32
|
2005-04-08 17:32:02 +00:00
|
|
|
|
|
|
|
extern WIN32_FIND_DATAA g_find_file_data;
|
|
|
|
extern HANDLE g_searchFile;
|
|
|
|
extern bool g_firstFind;
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
2005-08-10 05:30:58 +00:00
|
|
|
extern char g_find_file_data[100];
|
2005-04-08 17:32:02 +00:00
|
|
|
extern DIR *g_searchFile;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2005-01-01 10:12:16 +00:00
|
|
|
void vimaInit(uint16 *destTable);
|
|
|
|
void decompressVima(const byte *src, int16 *dest, int destLen, uint16 *destTable);
|
|
|
|
|
2003-08-15 18:00:22 +00:00
|
|
|
#endif
|