2006-04-02 14:20:45 +00:00
|
|
|
/* Residual - Virtual machine to run LucasArts' 3D adventure games
|
|
|
|
* Copyright (C) 2003-2006 The ScummVM-Residual Team (www.scummvm.org)
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
2003-08-15 19:41:26 +00:00
|
|
|
#ifndef ENGINE_H
|
|
|
|
#define ENGINE_H
|
2003-08-15 18:00:22 +00:00
|
|
|
|
2008-01-26 11:47:23 +00:00
|
|
|
#include "common/sys.h"
|
|
|
|
|
|
|
|
#include "engine/scene.h"
|
|
|
|
#include "engine/textobject.h"
|
|
|
|
#include "engine/primitives.h"
|
|
|
|
#include "engine/font.h"
|
|
|
|
#include "engine/lua.h"
|
|
|
|
#include "engine/savegame.h"
|
2005-01-01 12:27:57 +00:00
|
|
|
|
2003-08-15 18:00:22 +00:00
|
|
|
#include <cstdlib>
|
|
|
|
#include <list>
|
|
|
|
|
|
|
|
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
|
|
|
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();
|
2007-02-05 13:49:32 +00:00
|
|
|
void setShadowColor(Color c);
|
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); }
|
2006-02-26 20:04:25 +00:00
|
|
|
void killActor(Actor *a) { _actors.remove(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);
|
2007-01-19 14:21:29 +00:00
|
|
|
delete 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();
|
2006-05-13 15:07:35 +00:00
|
|
|
static void savegameRead(void *data, int size);
|
|
|
|
static void savegameWrite(void *data, int size);
|
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;
|
|
|
|
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();
|
2006-02-05 20:40:16 +00:00
|
|
|
~Engine();
|
2004-12-31 21:35:04 +00:00
|
|
|
|
|
|
|
private:
|
2003-08-15 18:00:22 +00:00
|
|
|
|
2006-02-05 20:40:16 +00:00
|
|
|
void handleButton(int operation, int key, int keyModifier, uint16 ascii);
|
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;
|
2006-01-21 17:22:39 +00:00
|
|
|
uint32 _lastUpdateTime;
|
2005-08-13 16:25:51 +00:00
|
|
|
bool _refreshDrawNeeded;
|
2005-08-28 23:25:14 +00:00
|
|
|
char _fps[8];
|
|
|
|
bool _doFlip;
|
2007-02-05 13:49:32 +00:00
|
|
|
Color _shadowColor;
|
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
|
|
|
|
2006-02-05 20:40:16 +00:00
|
|
|
bool *_controlsEnabled;
|
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-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
|