scummvm/engine.h

265 lines
6.6 KiB
C
Raw Normal View History

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
#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"
#include "scene.h"
#include "textobject.h"
2005-04-07 19:29:06 +00:00
#include "primitives.h"
#include "font.h"
#include "lua.h"
2005-01-01 12:27:57 +00:00
2003-08-15 18:00:22 +00:00
#include <cstdlib>
#include <list>
#include <SDL_keysym.h>
2003-08-15 18:00:22 +00:00
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
// Fake SDLK_* values for joystick and mouse events
enum {
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:
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 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); }
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);
}
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();
2004-11-01 16:36:41 +00:00
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);
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
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;
#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
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