scummvm/engine/engine.h

214 lines
5.8 KiB
C
Raw Normal View History

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
#ifndef ENGINE_H
#define ENGINE_H
2003-08-15 18:00:22 +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;
#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:
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; }
2004-03-20 08:22:51 +00:00
void setSpeechMode(int mode) { _speechMode = mode; }
int 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();
void setShadowColor(Color c);
void mainLoop();
2004-12-09 23:55:43 +00:00
unsigned frameStart() const { return _frameStart; }
unsigned frameTime() const { return _frameTime; }
// 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; }
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; }
Scene *findScene(const char *name);
void setSceneLock(const char *name, bool lockStatus);
void setScene(const char *name);
void setScene(Scene *scene);
2004-12-09 23:55:43 +00:00
Scene *currScene() { return _currScene; }
const char *sceneName() const { return _currScene->name(); }
// 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-12-10 07:26:03 +00:00
ActorListType::const_iterator actorsEnd() const {
2004-12-09 23:55:43 +00:00
return _actors.end();
}
void registerActor(Actor *a) { _actors.push_back(a); }
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; }
// 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-12-10 07:26:03 +00:00
TextListType::const_iterator textsEnd() const {
2004-12-09 23:55:43 +00:00
return _textObjects.end();
}
2004-12-09 23:55:43 +00:00
void registerTextObject(TextObject *a) { _textObjects.push_back(a); }
void killTextObject(TextObject *a) {
2004-12-09 23:55:43 +00:00
_textObjects.remove(a);
delete a;
}
void killTextObjects() {
2004-12-09 23:55:43 +00:00
while (!_textObjects.empty()) {
delete _textObjects.back();
_textObjects.pop_back();
}
}
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();
static void savegameRead(void *data, int size);
static void savegameWrite(void *data, int size);
void storeSaveGameImage(SaveGame *savedState);
2004-11-01 09:47:19 +00:00
bool _savegameLoadRequest;
bool _savegameSaveRequest;
char *_savegameFileName;
SaveGame *_savedState;
2004-11-01 09:47:19 +00:00
Engine();
~Engine();
private:
2003-08-15 18:00:22 +00:00
void handleButton(int operation, int key, int keyModifier, uint16 ascii);
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;
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
bool *_controlsEnabled;
2003-08-15 18:00:22 +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
};
extern Engine *g_engine;
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);
2003-08-15 18:00:22 +00:00
#endif