mirror of
https://github.com/libretro/scummvm.git
synced 2024-12-15 06:08:35 +00:00
replace class instances into global refrences
This commit is contained in:
parent
a9d6e1ccd0
commit
fa8e82812d
26
actor.cpp
26
actor.cpp
@ -37,7 +37,7 @@ Actor::Actor(const char *name) :
|
||||
_turnCostume(NULL), _leftTurnChore(-1), _rightTurnChore(-1),
|
||||
_lastTurnDir(0), _currTurnDir(0),
|
||||
_mumbleCostume(NULL), _mumbleChore(-1) {
|
||||
Engine::instance()->registerActor(this);
|
||||
g_engine->registerActor(this);
|
||||
_lookingMode = false;
|
||||
_constrain = false;
|
||||
|
||||
@ -87,7 +87,7 @@ bool Actor::isTurning() const {
|
||||
}
|
||||
|
||||
void Actor::walkForward() {
|
||||
float dist = Engine::instance()->perSecond(_walkRate);
|
||||
float dist = g_engine->perSecond(_walkRate);
|
||||
float yaw_rad = _yaw * (M_PI / 180), pitch_rad = _pitch * (M_PI / 180);
|
||||
Vector3d forwardVec(-std::sin(yaw_rad) * std::cos(pitch_rad),
|
||||
std::cos(yaw_rad) * std::cos(pitch_rad),
|
||||
@ -98,7 +98,7 @@ void Actor::walkForward() {
|
||||
_pos = destPos;
|
||||
_walkedCur = true;
|
||||
} else {
|
||||
Sector *sector = Engine::instance()->currScene()->findPointSector(destPos, 0x1000);
|
||||
Sector *sector = g_engine->currScene()->findPointSector(destPos, 0x1000);
|
||||
if (sector != NULL) {
|
||||
_pos = sector->projectToPlane(destPos);
|
||||
_walkedCur = true;
|
||||
@ -110,7 +110,7 @@ Vector3d Actor::puckVector() const {
|
||||
float yaw_rad = _yaw * (M_PI / 180);
|
||||
Vector3d forwardVec(-std::sin(yaw_rad), std::cos(yaw_rad), 0);
|
||||
|
||||
Sector *sector = Engine::instance()->currScene()->findPointSector(_pos, 0x1000);
|
||||
Sector *sector = g_engine->currScene()->findPointSector(_pos, 0x1000);
|
||||
if (sector == NULL)
|
||||
return forwardVec;
|
||||
else
|
||||
@ -185,7 +185,7 @@ void Actor::setMumbleChore(int chore, Costume *cost) {
|
||||
}
|
||||
|
||||
void Actor::turn(int dir) {
|
||||
float delta = Engine::instance()->perSecond(_turnRate) * dir;
|
||||
float delta = g_engine->perSecond(_turnRate) * dir;
|
||||
_yaw += delta;
|
||||
_currTurnDir = dir;
|
||||
}
|
||||
@ -223,11 +223,11 @@ void Actor::sayLine(const char *msg) {
|
||||
// if (_talkSound) // Only one line at a time, please :)
|
||||
// shutUp();
|
||||
|
||||
std::string msgText = Localizer::instance()->localize(secondSlash + 1);
|
||||
std::string msgText = g_localizer->localize(secondSlash + 1);
|
||||
std::string msgId(msg + 1, secondSlash);
|
||||
|
||||
// _talkSound = ResourceLoader::instance()->loadSound((msgId + ".wav").c_str());
|
||||
_lipSynch = ResourceLoader::instance()->loadLipSynch((msgId + ".lip").c_str());
|
||||
// _talkSound = g_resourceloader->loadSound((msgId + ".wav").c_str());
|
||||
_lipSynch = g_resourceloader->loadLipSynch((msgId + ".lip").c_str());
|
||||
|
||||
/* if (_talkSound != NULL) {
|
||||
Mixer::instance()->playVoice(_talkSound);
|
||||
@ -270,7 +270,7 @@ void Actor::shutUp() {
|
||||
}
|
||||
|
||||
void Actor::pushCostume(const char *name) {
|
||||
Costume *newCost = ResourceLoader::instance()->loadCostume(name, currentCostume());
|
||||
Costume *newCost = g_resourceloader->loadCostume(name, currentCostume());
|
||||
_costumeStack.push_back(newCost);
|
||||
}
|
||||
|
||||
@ -325,11 +325,11 @@ void Actor::update() {
|
||||
// necessary for example after activating/deactivating
|
||||
// walkboxes, etc.
|
||||
if (_constrain && !_walking) {
|
||||
Engine::instance()->currScene()->findClosestSector(_pos, NULL, &_pos);
|
||||
g_engine->currScene()->findClosestSector(_pos, NULL, &_pos);
|
||||
}
|
||||
|
||||
if (_turning) {
|
||||
float turnAmt = Engine::instance()->perSecond(_turnRate);
|
||||
float turnAmt = g_engine->perSecond(_turnRate);
|
||||
float dyaw = _destYaw - _yaw;
|
||||
while (dyaw > 180)
|
||||
dyaw -= 360;
|
||||
@ -353,7 +353,7 @@ void Actor::update() {
|
||||
if (dist > 0)
|
||||
dir /= dist;
|
||||
|
||||
float walkAmt = Engine::instance()->perSecond(_walkRate);
|
||||
float walkAmt = g_engine->perSecond(_walkRate);
|
||||
|
||||
if (walkAmt >= dist) {
|
||||
_pos = _destPos;
|
||||
@ -423,7 +423,7 @@ void Actor::update() {
|
||||
}
|
||||
|
||||
if (_lookingMode) {
|
||||
float lookAtAmt = Engine::instance()->perSecond(_lookAtRate);
|
||||
float lookAtAmt = g_engine->perSecond(_lookAtRate);
|
||||
}
|
||||
}
|
||||
|
||||
|
24
costume.cpp
24
costume.cpp
@ -158,7 +158,7 @@ BitmapComponent::BitmapComponent(Costume::Component *parent, int parentID, const
|
||||
}
|
||||
|
||||
void BitmapComponent::setKey(int val) {
|
||||
ObjectState *state = Engine::instance()->currScene()->findState(_filename.c_str());
|
||||
ObjectState *state = g_engine->currScene()->findState(_filename.c_str());
|
||||
|
||||
if (state != NULL)
|
||||
state->setNumber(val);
|
||||
@ -177,9 +177,9 @@ void ModelComponent::init() {
|
||||
// constructor before
|
||||
if (_cmap == NULL) {
|
||||
warning("No colormap specified for %s\n", _filename.c_str());
|
||||
_cmap = ResourceLoader::instance()->loadColormap("item.cmp");
|
||||
_cmap = g_resourceloader->loadColormap("item.cmp");
|
||||
}
|
||||
_obj = ResourceLoader::instance()->loadModel(_filename.c_str(), *_cmap);
|
||||
_obj = g_resourceloader->loadModel(_filename.c_str(), *_cmap);
|
||||
_hier = _obj->copyHierarchy();
|
||||
_hier->_hierVisible = false;
|
||||
}
|
||||
@ -279,7 +279,7 @@ private:
|
||||
|
||||
ColormapComponent::ColormapComponent(Costume::Component *parent, int parentID, const char *filename) :
|
||||
Costume::Component(parent, parentID) {
|
||||
_cmap = ResourceLoader::instance()->loadColormap(filename);
|
||||
_cmap = g_resourceloader->loadColormap(filename);
|
||||
|
||||
ModelComponent *mc = dynamic_cast<ModelComponent *>(parent);
|
||||
if (mc != NULL)
|
||||
@ -312,10 +312,10 @@ KeyframeComponent::KeyframeComponent(Costume::Component *parent, int parentID, c
|
||||
const char *comma = std::strchr(filename, ',');
|
||||
if (comma != NULL) {
|
||||
std::string realName(filename, comma);
|
||||
_keyf = ResourceLoader::instance()->loadKeyframe(realName.c_str());
|
||||
_keyf = g_resourceloader->loadKeyframe(realName.c_str());
|
||||
std::sscanf(comma + 1, "%d,%d", &_priority1, &_priority2);
|
||||
} else
|
||||
_keyf = ResourceLoader::instance()->loadKeyframe(filename);
|
||||
_keyf = g_resourceloader->loadKeyframe(filename);
|
||||
}
|
||||
|
||||
void KeyframeComponent::setKey(int val) {
|
||||
@ -349,7 +349,7 @@ void KeyframeComponent::update() {
|
||||
if (_currTime < 0) // For first time through
|
||||
_currTime = 0;
|
||||
else
|
||||
_currTime += Engine::instance()->frameTime();
|
||||
_currTime += g_engine->frameTime();
|
||||
|
||||
int animLength = (int)(_keyf->length() * 1000);
|
||||
|
||||
@ -436,8 +436,8 @@ void MaterialComponent::init() {
|
||||
// The parent model and thus all its textures should have been
|
||||
// loaded by now, so passing an arbitrary colormap here
|
||||
// shouldn't cause problems.
|
||||
ResPtr<CMap> cmap = ResourceLoader::instance()->loadColormap("item.cmp");
|
||||
_mat = ResourceLoader::instance()->loadMaterial(_filename.c_str(), *cmap);
|
||||
ResPtr<CMap> cmap = g_resourceloader->loadColormap("item.cmp");
|
||||
_mat = g_resourceloader->loadMaterial(_filename.c_str(), *cmap);
|
||||
}
|
||||
|
||||
void MaterialComponent::setKey(int val) {
|
||||
@ -487,9 +487,9 @@ SoundComponent::SoundComponent(Costume::Component *parent, int parentID, const c
|
||||
const char *comma = std::strchr(filename, ',');
|
||||
if (comma != NULL) {
|
||||
std::string realName(filename, comma);
|
||||
// _sound = ResourceLoader::instance()->loadSound(realName.c_str());
|
||||
// _sound = g_resourceloader->loadSound(realName.c_str());
|
||||
} else {
|
||||
// _sound = ResourceLoader::instance()->loadSound(filename);
|
||||
// _sound = g_resourceloader->loadSound(filename);
|
||||
}
|
||||
}
|
||||
|
||||
@ -667,7 +667,7 @@ void Costume::Chore::update() {
|
||||
if (_currTime < 0)
|
||||
newTime = 0; // For first time through
|
||||
else
|
||||
newTime = _currTime + Engine::instance()->frameTime();
|
||||
newTime = _currTime + g_engine->frameTime();
|
||||
|
||||
setKeys(_currTime, newTime);
|
||||
|
||||
|
@ -31,7 +31,7 @@
|
||||
|
||||
#include "driver_gl.h"
|
||||
|
||||
Engine *Engine::_instance = NULL;
|
||||
Engine *g_engine = NULL;
|
||||
|
||||
extern Imuse *g_imuse;
|
||||
|
||||
@ -227,11 +227,11 @@ void Engine::mainLoop() {
|
||||
}
|
||||
|
||||
void Engine::savegameGzread(void *data, int size) {
|
||||
gzread(Engine::instance()->_savegameFileHandle, data, size);
|
||||
gzread(g_engine->_savegameFileHandle, data, size);
|
||||
}
|
||||
|
||||
void Engine::savegameGzwrite(void *data, int size) {
|
||||
gzwrite(Engine::instance()->_savegameFileHandle, data, size);
|
||||
gzwrite(g_engine->_savegameFileHandle, data, size);
|
||||
}
|
||||
|
||||
void Engine::savegameRestore() {
|
||||
@ -334,7 +334,7 @@ void Engine::savegameSave() {
|
||||
}
|
||||
|
||||
void Engine::setScene(const char *name) {
|
||||
Block *b = ResourceLoader::instance()->getFileBlock(name);
|
||||
Block *b = g_resourceloader->getFileBlock(name);
|
||||
if (b == NULL)
|
||||
warning("Could not find scene file %s\n", name);
|
||||
delete _currScene;
|
||||
|
14
engine.h
14
engine.h
@ -88,11 +88,6 @@ enum {
|
||||
|
||||
class Engine {
|
||||
public:
|
||||
static Engine *instance() {
|
||||
if (_instance == NULL)
|
||||
_instance = new Engine;
|
||||
return _instance;
|
||||
}
|
||||
|
||||
void setMode(int mode) { _mode = mode; }
|
||||
void setSpeechMode(int mode) { _speechMode = mode; }
|
||||
@ -153,11 +148,10 @@ public:
|
||||
char *_savegameFileName;
|
||||
gzFile _savegameFileHandle;
|
||||
|
||||
private:
|
||||
static Engine *_instance;
|
||||
|
||||
Engine();
|
||||
~Engine() { }
|
||||
~Engine() {}
|
||||
|
||||
private:
|
||||
|
||||
Scene *_currScene;
|
||||
int _mode;
|
||||
@ -172,4 +166,6 @@ private:
|
||||
TextListType _textObjects;
|
||||
};
|
||||
|
||||
extern Engine *g_engine;
|
||||
|
||||
#endif
|
||||
|
@ -37,25 +37,18 @@ McmpMgr::McmpMgr() {
|
||||
}
|
||||
|
||||
McmpMgr::~McmpMgr() {
|
||||
if (_file) {
|
||||
// fclose(_file);
|
||||
}
|
||||
free(_compTable);
|
||||
free(_compInput);
|
||||
}
|
||||
|
||||
bool McmpMgr::openSound(const char *filename, byte **resPtr, int &offsetData) {
|
||||
_file = ResourceLoader::instance()->openNewStream(filename);
|
||||
_file = g_resourceloader->openNewStream(filename);
|
||||
|
||||
if (!_file) {
|
||||
warning("McmpMgr::openFile() Can't open MCMP file: %s", filename);
|
||||
return false;
|
||||
}
|
||||
|
||||
// int filePos = ftell(_file);
|
||||
// _file = fdopen(fileno(_file), "rb");
|
||||
// fseek(_file, filePos, SEEK_SET);
|
||||
|
||||
uint32 tag;
|
||||
fread(&tag, 1, 4, _file);
|
||||
if (READ_BE_UINT32(&tag) != MKID_BE('MCMP')) {
|
||||
|
@ -166,7 +166,7 @@ ImuseSndMgr::SoundStruct *ImuseSndMgr::openSound(const char *soundName, int volG
|
||||
sound->volGroupId = volGroupId;
|
||||
|
||||
if (strcasecmp(extension, "imu") == 0) {
|
||||
Block *b = ResourceLoader::instance()->getFileBlock(soundName);
|
||||
Block *b = g_resourceloader->getFileBlock(soundName);
|
||||
if (b != NULL) {
|
||||
ptr = (byte *)b->data();
|
||||
delete b;
|
||||
|
@ -22,13 +22,7 @@
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
|
||||
Localizer *Localizer::_instance = NULL;
|
||||
|
||||
Localizer *Localizer::instance() {
|
||||
if (_instance == NULL)
|
||||
_instance = new Localizer;
|
||||
return _instance;
|
||||
}
|
||||
Localizer *g_localizer = NULL;
|
||||
|
||||
Localizer::Localizer() {
|
||||
std::FILE *f;
|
||||
|
@ -23,18 +23,17 @@
|
||||
|
||||
class Localizer {
|
||||
public:
|
||||
static Localizer *instance();
|
||||
|
||||
std::string localize(const char *str) const;
|
||||
|
||||
private:
|
||||
Localizer();
|
||||
~Localizer() { }
|
||||
|
||||
static Localizer *_instance;
|
||||
private:
|
||||
|
||||
typedef std::map<std::string, std::string> StringMap;
|
||||
StringMap _entries;
|
||||
};
|
||||
|
||||
extern Localizer *g_localizer;
|
||||
|
||||
#endif
|
||||
|
78
lua.cpp
78
lua.cpp
@ -196,7 +196,7 @@ static void FunctionName() {
|
||||
|
||||
static void CheckForFile() {
|
||||
char *filename = luaL_check_string(1);
|
||||
pushbool(ResourceLoader::instance()->fileExists(filename));
|
||||
pushbool(g_resourceloader->fileExists(filename));
|
||||
}
|
||||
|
||||
// Color functions
|
||||
@ -248,7 +248,7 @@ static void WriteRegistryValue() {
|
||||
|
||||
static void LocalizeString() {
|
||||
char *str = luaL_check_string(1);
|
||||
std::string result = Localizer::instance()->localize(str);
|
||||
std::string result = g_localizer->localize(str);
|
||||
lua_pushstring(const_cast<char *>(result.c_str()));
|
||||
}
|
||||
|
||||
@ -265,7 +265,7 @@ static void LoadActor() {
|
||||
|
||||
static void SetSelectedActor() {
|
||||
Actor *act = check_actor(1);
|
||||
Engine::instance()->setSelectedActor(act);
|
||||
g_engine->setSelectedActor(act);
|
||||
}
|
||||
|
||||
static void SetActorTalkColor() {
|
||||
@ -659,9 +659,9 @@ static void SetActorFollowBoxes() { // Constrain actor to walkplanes?
|
||||
|
||||
static void GetVisibleThings() {
|
||||
lua_Object result = lua_createtable();
|
||||
Actor *sel = Engine::instance()->selectedActor();
|
||||
for (Engine::ActorListType::const_iterator i = Engine::instance()->actorsBegin(); i != Engine::instance()->actorsEnd(); i++) {
|
||||
if (!(*i)->inSet(Engine::instance()->sceneName()))
|
||||
Actor *sel = g_engine->selectedActor();
|
||||
for (Engine::ActorListType::const_iterator i = g_engine->actorsBegin(); i != g_engine->actorsEnd(); i++) {
|
||||
if (!(*i)->inSet(g_engine->sceneName()))
|
||||
continue;
|
||||
if (sel->angleTo(*(*i)) < 90) {
|
||||
lua_pushobject(result);
|
||||
@ -717,7 +717,7 @@ static void GetActorSector(void) {
|
||||
Actor *act = check_actor(1);
|
||||
int sectorType = check_int(2);
|
||||
|
||||
Sector *result = Engine::instance()->currScene()->findPointSector(act->pos(), sectorType);
|
||||
Sector *result = g_engine->currScene()->findPointSector(act->pos(), sectorType);
|
||||
if (result != NULL) {
|
||||
lua_pushnumber(result->id());
|
||||
lua_pushstring(const_cast<char *>(result->name()));
|
||||
@ -732,10 +732,10 @@ static void GetActorSector(void) {
|
||||
static void IsActorInSector(void) {
|
||||
Actor *act = check_actor(1);
|
||||
const char *name = luaL_check_string(2);
|
||||
int i, numSectors = Engine::instance()->currScene()->getSectorCount();
|
||||
int i, numSectors = g_engine->currScene()->getSectorCount();
|
||||
|
||||
for (i=0; i<numSectors; i++) {
|
||||
Sector *sector = Engine::instance()->currScene()->getSectorBase(i);
|
||||
Sector *sector = g_engine->currScene()->getSectorBase(i);
|
||||
|
||||
if (sector->visible() && strstr(sector->name(), name)) {
|
||||
if (sector->isPointInSector(act->pos())) {
|
||||
@ -755,18 +755,18 @@ static void MakeSectorActive(void) {
|
||||
int i = 0, numSectors;
|
||||
|
||||
// FIXME: This happens on initial load. Are we initting something in the wrong order?
|
||||
if (!Engine::instance()->currScene()) {
|
||||
if (!g_engine->currScene()) {
|
||||
warning("!!!! Trying to call MakeSectorActive without a scene!");
|
||||
return;
|
||||
}
|
||||
|
||||
numSectors = Engine::instance()->currScene()->getSectorCount();
|
||||
numSectors = g_engine->currScene()->getSectorCount();
|
||||
|
||||
if (lua_isstring(sectorName)) {
|
||||
char *name = luaL_check_string(1);
|
||||
|
||||
for (i=0; i<numSectors; i++) {
|
||||
Sector *sector = Engine::instance()->currScene()->getSectorBase(i);
|
||||
Sector *sector = g_engine->currScene()->getSectorBase(i);
|
||||
if (strstr(sector->name(), name)) {
|
||||
sector->setVisible(visible);
|
||||
return;
|
||||
@ -776,7 +776,7 @@ static void MakeSectorActive(void) {
|
||||
int id = check_int(1);
|
||||
|
||||
for (i=0; i<numSectors; i++) {
|
||||
Sector *sector = Engine::instance()->currScene()->getSectorBase(i);
|
||||
Sector *sector = g_engine->currScene()->getSectorBase(i);
|
||||
if (sector->id() == id) {
|
||||
sector->setVisible(visible);
|
||||
return;
|
||||
@ -792,14 +792,14 @@ static void MakeSectorActive(void) {
|
||||
|
||||
static void MakeCurrentSet() {
|
||||
const char *name = luaL_check_string(1);
|
||||
Engine::instance()->setScene(name);
|
||||
g_engine->setScene(name);
|
||||
}
|
||||
|
||||
static void MakeCurrentSetup() {
|
||||
int num = check_int(1);
|
||||
int prevSetup = Engine::instance()->currScene()->setup();
|
||||
int prevSetup = g_engine->currScene()->setup();
|
||||
|
||||
Engine::instance()->currScene()->setSetup(num);
|
||||
g_engine->currScene()->setSetup(num);
|
||||
|
||||
lua_beginblock();
|
||||
lua_Object camChangeHandler = getEventHandler("camChangeHandler");
|
||||
@ -821,8 +821,8 @@ static void MakeCurrentSetup() {
|
||||
|
||||
static void GetCurrentSetup() {
|
||||
const char *name = luaL_check_string(1);
|
||||
if (std::strcmp(name, Engine::instance()->sceneName()) == 0)
|
||||
lua_pushnumber(Engine::instance()->currScene()->setup());
|
||||
if (std::strcmp(name, g_engine->sceneName()) == 0)
|
||||
lua_pushnumber(g_engine->currScene()->setup());
|
||||
else
|
||||
lua_pushnil();
|
||||
}
|
||||
@ -1006,17 +1006,17 @@ void setMovieTime(float movieTime) {
|
||||
|
||||
void PerSecond() {
|
||||
float rate = luaL_check_number(1);
|
||||
lua_pushnumber(Engine::instance()->perSecond(rate));
|
||||
lua_pushnumber(g_engine->perSecond(rate));
|
||||
}
|
||||
|
||||
void EnableControl() {
|
||||
int num = check_control(1);
|
||||
Engine::instance()->enableControl(num);
|
||||
g_engine->enableControl(num);
|
||||
}
|
||||
|
||||
void DisableControl() {
|
||||
int num = check_control(1);
|
||||
Engine::instance()->disableControl(num);
|
||||
g_engine->disableControl(num);
|
||||
}
|
||||
|
||||
void GetControlState() {
|
||||
@ -1079,18 +1079,18 @@ static void KillTextObject() {
|
||||
|
||||
if (lua_isnil(lua_getparam(1))) { // FIXME: check this.. nil is kill all lines?
|
||||
error("KillTextObject(NULL)");
|
||||
//Engine::instance()->killTextObjects();
|
||||
//g_engine->killTextObjects();
|
||||
return;
|
||||
}
|
||||
|
||||
textID = lua_getstring(lua_getparam(1));
|
||||
|
||||
for (Engine::TextListType::const_iterator i = Engine::instance()->textsBegin();
|
||||
i != Engine::instance()->textsEnd(); i++) {
|
||||
for (Engine::TextListType::const_iterator i = g_engine->textsBegin();
|
||||
i != g_engine->textsEnd(); i++) {
|
||||
TextObject *textO = *i;
|
||||
|
||||
if (strstr(textO->name(), textID)) {
|
||||
Engine::instance()->killTextObject(textO);
|
||||
g_engine->killTextObject(textO);
|
||||
delete textO;
|
||||
return;
|
||||
}
|
||||
@ -1142,7 +1142,7 @@ static void ChangeTextObject() {
|
||||
lua_Object tableObj = lua_getparam(2);
|
||||
TextObject *modifyObject = NULL;
|
||||
|
||||
for (Engine::TextListType::const_iterator i = Engine::instance()->textsBegin(); i != Engine::instance()->textsEnd(); i++) {
|
||||
for (Engine::TextListType::const_iterator i = g_engine->textsBegin(); i != g_engine->textsEnd(); i++) {
|
||||
TextObject *textO = *i;
|
||||
|
||||
if (strstr(textO->name(), textID)) {
|
||||
@ -1172,17 +1172,17 @@ static void GetTextObjectDimensions() {
|
||||
static void SetSpeechMode() {
|
||||
int mode = check_int(1);
|
||||
if ((mode >= 1) && (mode <= 3))
|
||||
Engine::instance()->setSpeechMode(mode);
|
||||
g_engine->setSpeechMode(mode);
|
||||
}
|
||||
|
||||
static void GetSpeechMode() {
|
||||
int mode = Engine::instance()->getSpeechMode();
|
||||
int mode = g_engine->getSpeechMode();
|
||||
lua_pushnumber(mode);
|
||||
}
|
||||
|
||||
static void StartFullscreenMovie() {
|
||||
bool mode = getbool(2);
|
||||
Engine::instance()->setMode(ENGINE_MODE_SMUSH);
|
||||
g_engine->setMode(ENGINE_MODE_SMUSH);
|
||||
pushbool(g_smush->play(luaL_check_string(1), 0, 0));
|
||||
}
|
||||
|
||||
@ -1197,7 +1197,7 @@ static void StartMovie() {
|
||||
if (!lua_isnil(lua_getparam(4)))
|
||||
y = check_int(4);
|
||||
|
||||
Engine::instance()->setMode(ENGINE_MODE_NORMAL);
|
||||
g_engine->setMode(ENGINE_MODE_NORMAL);
|
||||
pushbool(g_smush->play(luaL_check_string(1), x, y));
|
||||
}
|
||||
|
||||
@ -1249,7 +1249,7 @@ static void NewObjectState() {
|
||||
zbitmap = luaL_check_string(4);
|
||||
|
||||
object = new ObjectState(setupID, pos, bitmap, zbitmap, visible);
|
||||
Engine::instance()->currScene()->addObjectState(object);
|
||||
g_engine->currScene()->addObjectState(object);
|
||||
lua_pushusertag(object, object_tag);
|
||||
}
|
||||
|
||||
@ -1266,27 +1266,27 @@ static void GetCurrentScript() {
|
||||
static void Load() {
|
||||
lua_Object fileName = lua_getparam(1);
|
||||
if (lua_isnil(fileName)) {
|
||||
Engine::instance()->_savegameFileName = NULL;
|
||||
g_engine->_savegameFileName = NULL;
|
||||
} else if (lua_isstring(fileName)) {
|
||||
Engine::instance()->_savegameFileName = lua_getstring(fileName);
|
||||
g_engine->_savegameFileName = lua_getstring(fileName);
|
||||
} else {
|
||||
warning("Load() fileName is wrong");
|
||||
return;
|
||||
}
|
||||
Engine::instance()->_savegameLoadRequest = true;
|
||||
g_engine->_savegameLoadRequest = true;
|
||||
}
|
||||
|
||||
static void Save() {
|
||||
lua_Object fileName = lua_getparam(1);
|
||||
if (lua_isnil(fileName)) {
|
||||
Engine::instance()->_savegameFileName = NULL;
|
||||
g_engine->_savegameFileName = NULL;
|
||||
} else if (lua_isstring(fileName)) {
|
||||
Engine::instance()->_savegameFileName = lua_getstring(fileName);
|
||||
g_engine->_savegameFileName = lua_getstring(fileName);
|
||||
} else {
|
||||
warning("Save() fileName is wrong");
|
||||
return;
|
||||
}
|
||||
Engine::instance()->_savegameSaveRequest = true;
|
||||
g_engine->_savegameSaveRequest = true;
|
||||
}
|
||||
|
||||
static int SaveCallback(int tag, int value, SaveRestoreFunc saveFunc) {
|
||||
@ -1378,7 +1378,7 @@ static void BlastText() {
|
||||
}
|
||||
|
||||
warning("STUB: BlastText(\"%s\", x = %d, y = %d)\n",
|
||||
Localizer::instance()->localize(str).c_str(), x, y);
|
||||
g_localizer->localize(str).c_str(), x, y);
|
||||
}
|
||||
|
||||
#define STUB_FUNC(name) static void name() { stubWarning(#name); }
|
||||
@ -2143,7 +2143,7 @@ void register_lua() {
|
||||
}
|
||||
|
||||
int bundle_dofile(const char *filename) {
|
||||
Block *b = ResourceLoader::instance()->getFileBlock(filename);
|
||||
Block *b = g_resourceloader->getFileBlock(filename);
|
||||
if (b == NULL) {
|
||||
delete b;
|
||||
// Don't print warnings on Scripts\foo.lua,
|
||||
|
39
main.cpp
39
main.cpp
@ -23,6 +23,7 @@
|
||||
#include "debug.h"
|
||||
#include "lua.h"
|
||||
#include "registry.h"
|
||||
#include "localize.h"
|
||||
#include "engine.h"
|
||||
#include "timer.h"
|
||||
#include "smush.h"
|
||||
@ -78,6 +79,8 @@ static bool parseBoolStr(const char *val) {
|
||||
return false;
|
||||
}
|
||||
|
||||
void quit();
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int i;
|
||||
|
||||
@ -112,9 +115,11 @@ int main(int argc, char *argv[]) {
|
||||
if (SDL_Init(SDL_INIT_EVERYTHING) < 0)
|
||||
return 1;
|
||||
|
||||
atexit(SDL_Quit);
|
||||
atexit(saveRegistry);
|
||||
atexit(quit);
|
||||
|
||||
g_engine = new Engine();
|
||||
g_resourceloader = new ResourceLoader();
|
||||
g_localizer = new Localizer();
|
||||
g_mixer = new SoundMixer();
|
||||
g_mixer->setVolume(255);
|
||||
g_timer = new Timer();
|
||||
@ -122,7 +127,7 @@ int main(int argc, char *argv[]) {
|
||||
g_driver = new Driver(640, 480, 24);
|
||||
g_imuse = new Imuse(10);
|
||||
|
||||
Bitmap *splash_bm = ResourceLoader::instance()->loadBitmap("splash.bm");
|
||||
Bitmap *splash_bm = g_resourceloader->loadBitmap("splash.bm");
|
||||
|
||||
SDL_Event event;
|
||||
|
||||
@ -155,18 +160,30 @@ int main(int argc, char *argv[]) {
|
||||
// lua_pushnumber(0); // bootParam
|
||||
lua_call("BOOT");
|
||||
|
||||
Engine::instance()->setMode(ENGINE_MODE_NORMAL);
|
||||
Engine::instance()->mainLoop();
|
||||
g_engine->setMode(ENGINE_MODE_NORMAL);
|
||||
g_engine->mainLoop();
|
||||
|
||||
quit();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void quit() {
|
||||
saveRegistry();
|
||||
|
||||
delete g_smush;
|
||||
delete g_imuse;
|
||||
delete g_localizer;
|
||||
delete g_resourceloader;
|
||||
delete g_engine;
|
||||
delete g_timer;
|
||||
delete g_mixer;
|
||||
delete g_driver;
|
||||
|
||||
lua_removelibslists();
|
||||
lua_close();
|
||||
|
||||
delete g_imuse;
|
||||
delete g_smush;
|
||||
delete g_timer;
|
||||
delete g_mixer;
|
||||
|
||||
return 0;
|
||||
SDL_Quit();
|
||||
}
|
||||
|
||||
StackLock::StackLock(MutexRef mutex) :
|
||||
|
@ -41,7 +41,7 @@ void Model::loadBinary(const char *data, const CMap &cmap) {
|
||||
data += 8;
|
||||
_materials = new ResPtr<Material>[_numMaterials];
|
||||
for (int i = 0; i < _numMaterials; i++) {
|
||||
_materials[i] = ResourceLoader::instance()->loadMaterial(data, cmap);
|
||||
_materials[i] = g_resourceloader->loadMaterial(data, cmap);
|
||||
data += 32;
|
||||
}
|
||||
data += 32; // skip name
|
||||
@ -246,7 +246,7 @@ void Model::loadText(TextSplitter &ts, const CMap &cmap) {
|
||||
int num;
|
||||
char name[32];
|
||||
ts.scanString("%d: %32s", 2, &num, name);
|
||||
_materials[num] = ResourceLoader::instance()->loadMaterial(name, cmap);
|
||||
_materials[num] = g_resourceloader->loadMaterial(name, cmap);
|
||||
}
|
||||
|
||||
ts.expectString("section: geometrydef");
|
||||
|
@ -2,9 +2,9 @@
|
||||
|
||||
ObjectState::ObjectState(int setupID, ObjectState::Position pos, const char *bitmap, const char *zbitmap, bool visible) :
|
||||
_setupID(setupID), _pos(pos) {
|
||||
_bitmap = ResourceLoader::instance()->loadBitmap(bitmap);
|
||||
_bitmap = g_resourceloader->loadBitmap(bitmap);
|
||||
if (zbitmap)
|
||||
_zbitmap = ResourceLoader::instance()->loadBitmap(zbitmap);
|
||||
_zbitmap = g_resourceloader->loadBitmap(zbitmap);
|
||||
|
||||
int initialImage = 0;
|
||||
if (visible)
|
||||
|
@ -35,7 +35,7 @@ static void makeLower(std::string& s) {
|
||||
std::transform(s.begin(), s.end(), s.begin(), tolower);
|
||||
}
|
||||
|
||||
ResourceLoader *ResourceLoader::_instance = NULL;
|
||||
ResourceLoader *g_resourceloader = NULL;
|
||||
|
||||
ResourceLoader::ResourceLoader() {
|
||||
const char *directory = Registry::instance()->get("DataDir");
|
||||
|
15
resource.h
15
resource.h
@ -89,12 +89,6 @@ public:
|
||||
std::FILE *openNewStream(const char *filename) const;
|
||||
int fileLength(const char *filename) const;
|
||||
|
||||
static ResourceLoader *instance() {
|
||||
if (_instance == NULL)
|
||||
_instance = new ResourceLoader;
|
||||
return _instance;
|
||||
}
|
||||
|
||||
Bitmap *loadBitmap(const char *fname);
|
||||
CMap *loadColormap(const char *fname);
|
||||
Costume *loadCostume(const char *fname, Costume *prevCost);
|
||||
@ -104,12 +98,11 @@ public:
|
||||
LipSynch *loadLipSynch(const char *fname);
|
||||
void uncache(const char *fname);
|
||||
|
||||
private:
|
||||
ResourceLoader();
|
||||
ResourceLoader(const ResourceLoader &);
|
||||
~ResourceLoader();
|
||||
~ResourceLoader() { }
|
||||
|
||||
static ResourceLoader *_instance;
|
||||
private:
|
||||
|
||||
typedef std::list<Lab *> LabList;
|
||||
LabList _labs;
|
||||
@ -123,9 +116,11 @@ private:
|
||||
friend class dummy;
|
||||
};
|
||||
|
||||
extern ResourceLoader *g_resourceloader;
|
||||
|
||||
inline void Resource::deref() {
|
||||
if (--_ref == 0) {
|
||||
ResourceLoader::instance()->uncache(_fname.c_str());
|
||||
g_resourceloader->uncache(_fname.c_str());
|
||||
delete this;
|
||||
}
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ Scene::Scene(const char *name, const char *buf, int len) :
|
||||
char cmap_name[256];
|
||||
for (int i = 0; i < _numCmaps; i++) {
|
||||
ts.scanString(" colormap %256s", 1, cmap_name);
|
||||
_cmaps[i] = ResourceLoader::instance()->loadColormap(cmap_name);
|
||||
_cmaps[i] = g_resourceloader->loadColormap(cmap_name);
|
||||
}
|
||||
|
||||
ts.expectString("section: setups");
|
||||
@ -104,14 +104,14 @@ void Scene::Setup::load(TextSplitter &ts) {
|
||||
_name = buf;
|
||||
|
||||
ts.scanString(" background %256s", 1, buf);
|
||||
_bkgndBm = ResourceLoader::instance()->loadBitmap(buf);
|
||||
_bkgndBm = g_resourceloader->loadBitmap(buf);
|
||||
|
||||
// ZBuffer is optional
|
||||
if (!ts.checkString("zbuffer")) {
|
||||
_bkgndZBm = NULL;
|
||||
} else {
|
||||
ts.scanString(" zbuffer %256s", 1, buf);
|
||||
_bkgndZBm = ResourceLoader::instance()->loadBitmap(buf);
|
||||
_bkgndZBm = g_resourceloader->loadBitmap(buf);
|
||||
}
|
||||
|
||||
ts.scanString(" position %f %f %f", 3, &_pos.x(), &_pos.y(), &_pos.z());
|
||||
|
12
smush.cpp
12
smush.cpp
@ -165,7 +165,7 @@ void Smush::handleFrame() {
|
||||
_frame++;
|
||||
if (_frame == _nbframes) {
|
||||
_videoFinished = true;
|
||||
Engine::instance()->setMode(ENGINE_MODE_NORMAL);
|
||||
g_engine->setMode(ENGINE_MODE_NORMAL);
|
||||
}
|
||||
|
||||
_movieTime += _speed / 1000;
|
||||
@ -234,7 +234,7 @@ bool Smush::setupAnim(const char *file, int x, int y) {
|
||||
|
||||
void Smush::stop() {
|
||||
deinit();
|
||||
Engine::instance()->setMode(ENGINE_MODE_NORMAL);
|
||||
g_engine->setMode(ENGINE_MODE_NORMAL);
|
||||
}
|
||||
|
||||
bool Smush::play(const char *filename, int x, int y) {
|
||||
@ -271,14 +271,14 @@ bool zlibFile::open(const char *filename) {
|
||||
if (filename == NULL || *filename == 0)
|
||||
return false;
|
||||
|
||||
_handle = ResourceLoader::instance()->openNewStream(filename);
|
||||
_handle = g_resourceloader->openNewStream(filename);
|
||||
if (!_handle) {
|
||||
warning("zlibFile %s not found", filename);
|
||||
return false;
|
||||
}
|
||||
// int filePos = ftell(_handle);
|
||||
// _handle = fdopen(fileno(_handle), "rb");
|
||||
// fseek(_handle, filePos, SEEK_SET);
|
||||
int filePos = ftell(_handle);
|
||||
_handle = fdopen(fileno(_handle), "rb");
|
||||
fseek(_handle, filePos, SEEK_SET);
|
||||
|
||||
// Read in the GZ header
|
||||
fread(_inBuf, 2, sizeof(char), _handle); // Header
|
||||
|
@ -25,7 +25,7 @@
|
||||
TextObject::TextObject(const char *text, const int x, const int y, const Color& fgColor) :
|
||||
_fgColor(fgColor), _x(x), _y(y) {
|
||||
strcpy(_textID, text);
|
||||
Engine::instance()->registerTextObject(this);
|
||||
g_engine->registerTextObject(this);
|
||||
}
|
||||
|
||||
void TextObject::setX(int x) {_x = x; }
|
||||
@ -33,7 +33,7 @@ void TextObject::setY(int y) {_y = y; }
|
||||
void TextObject::setColor(Color *newcolor) { _fgColor = newcolor; }
|
||||
|
||||
void TextObject::draw() {
|
||||
const char *localString = Localizer::instance()->localize(_textID).c_str();
|
||||
const char *localString = g_localizer->localize(_textID).c_str();
|
||||
// This is also used for things like debugging in addition
|
||||
// to dialogue so there aren't always translations
|
||||
if (strrchr(localString, '/') != NULL) {
|
||||
|
Loading…
Reference in New Issue
Block a user