LAB: Move the global variable g_resource to the main engine class

This commit is contained in:
Strangerke 2015-11-30 00:34:43 +01:00 committed by Willem Jan Palenstijn
parent 0c84355f4a
commit 771e558d90
12 changed files with 56 additions and 42 deletions

View File

@ -650,13 +650,13 @@ void LabEngine::mainGameLoop() {
RoomNum = 1;
Direction = NORTH;
g_resource->readRoomData("LAB:Doors");
g_resource->readInventory("LAB:Inventor");
_resource->readRoomData("LAB:Doors");
_resource->readInventory("LAB:Inventor");
if (!(_conditions = new LargeSet(HighestCondition + 1)))
if (!(_conditions = new LargeSet(HighestCondition + 1, this)))
return;
if (!(_roomsFound = new LargeSet(ManyRooms + 1)))
if (!(_roomsFound = new LargeSet(ManyRooms + 1, this)))
return;
_conditions->readInitialConditions("LAB:Conditio");
@ -1328,7 +1328,7 @@ void LabEngine::go() {
if (!dointro)
g_music->initMusic();
MsgFont = g_resource->getFont("P:AvanteG.12");
MsgFont = _resource->getFont("P:AvanteG.12");
_event->mouseHide();

View File

@ -93,7 +93,7 @@ bool readPict(const char *filename, bool PlayOnce) {
/* Reads in a music file. Ignores any graphics. */
/*****************************************************************************/
bool readMusic(const char *filename, bool waitTillFinished) {
Common::File *file = g_resource->openDataFile(filename, MKTAG('D', 'I', 'F', 'F'));
Common::File *file = g_lab->_resource->openDataFile(filename, MKTAG('D', 'I', 'F', 'F'));
g_music->updateMusic();
if (!g_music->_doNotFilestopSoundEffect)
g_music->stopSoundEffect();
@ -360,7 +360,7 @@ int32 LabEngine::longDrawMessage(const char *str) {
}
void LabEngine::drawStaticMessage(byte index) {
drawMessage(g_resource->getStaticText((StaticText)index).c_str());
drawMessage(_resource->getStaticText((StaticText)index).c_str());
}
/******************************************************************************/

View File

@ -347,7 +347,7 @@ void Intro::introSequence() {
blackAllScreen();
g_music->updateMusic();
_msgfont = g_resource->getFont("P:Map.fon");
_msgfont = g_lab->_resource->getFont("P:Map.fon");
nopalchange = true;
nReadPict("Intro.1", true);

View File

@ -73,6 +73,10 @@ LabEngine::LabEngine(OSystem *syst, const ADGameDescription *gameDesc)
_nextKeyOut = 0;
_isHiRes = false;
_event = nullptr;
_resource = nullptr;
//const Common::FSNode gameDataDir(ConfMan.get("path"));
//SearchMan.addSubDirectoryMatching(gameDataDir, "game");
//SearchMan.addSubDirectoryMatching(gameDataDir, "game/pict");
@ -83,6 +87,9 @@ LabEngine::LabEngine(OSystem *syst, const ADGameDescription *gameDesc)
LabEngine::~LabEngine() {
// Remove all of our debug levels here
DebugMan.clearAllDebugChannels();
delete _event;
delete _resource;
}
Common::Error LabEngine::run() {
@ -92,9 +99,9 @@ Common::Error LabEngine::run() {
initGraphics(640, 480, true);
_event = new EventManager(this);
_resource = new Resource(this);
g_music = new Music();
g_resource = new Resource();
if (getPlatform() == Common::kPlatformWindows) {
// Check if this is the Wyrmkeep trial

View File

@ -38,6 +38,7 @@
#include "lab/labfun.h"
#include "lab/interface.h"
#include "lab/mouse.h"
#include "lab/resource.h"
struct ADGameDescription;
@ -99,6 +100,8 @@ private:
public:
EventManager *_event;
Resource *_resource;
byte *_currentDsplayBuffer;
Common::Point _mousePos;

View File

@ -47,6 +47,8 @@
namespace Lab {
class LabEngine;
/* Direction defines */
#define NORTH 0
#define SOUTH 1
@ -209,12 +211,16 @@ extern Music *g_music;
class LargeSet {
public:
LargeSet(uint16 last);
LargeSet(uint16 last, LabEngine *vm);
~LargeSet();
bool in(uint16 element);
void inclElement(uint16 element);
void exclElement(uint16 element);
bool readInitialConditions(const char *fileName);
private:
LabEngine *_vm;
public:
uint16 _lastElement;
uint16 *_array;

View File

@ -28,13 +28,14 @@
*
*/
#include "lab/lab.h"
#include "lab/stddefines.h"
#include "lab/labfun.h"
#include "lab/resource.h"
namespace Lab {
LargeSet::LargeSet(uint16 last) {
LargeSet::LargeSet(uint16 last, LabEngine *vm) : _vm(vm) {
last = (((last + 15) >> 4) << 4);
_array = (uint16 *)calloc(last >> 3, 2);
@ -60,7 +61,7 @@ void LargeSet::exclElement(uint16 element) {
bool LargeSet::readInitialConditions(const char *fileName) {
Common::File *file;
if (file = g_resource->openDataFile(fileName, MKTAG('C', 'O', 'N', '0'))) {
if (file = _vm->_resource->openDataFile(fileName, MKTAG('C', 'O', 'N', '0'))) {
uint16 conditions = file->readUint16LE();
for (int i = 0; i < conditions; i++) {
inclElement(file->readUint16LE());

View File

@ -196,7 +196,7 @@ static bool loadMapData() {
BigMsgFont = &bmf;
if (!(BigMsgFont = g_resource->getFont("P:Map.fon")))
if (!(BigMsgFont = g_lab->_resource->getFont("P:Map.fon")))
BigMsgFont = MsgFont;
resetBuffer(); /* Make images load into start of buffer */
@ -249,7 +249,7 @@ static bool loadMapData() {
counter++;
}
Common::File *mapFile = g_resource->openDataFile("Lab:Maps", MKTAG('M', 'A', 'P', '0'));
Common::File *mapFile = g_lab->_resource->openDataFile("Lab:Maps", MKTAG('M', 'A', 'P', '0'));
if (!mapFile)
error("Corrupt map file");
g_music->updateMusic();
@ -611,31 +611,31 @@ void LabEngine::drawMap(uint16 CurRoom, uint16 CurMsg, uint16 Floor, bool fadeou
if (onFloor(HEDGEMAZEFLOOR))
drawImage(HugeMaze, mapScaleX(524), mapScaleY(97));
} else if (Floor == SURMAZEFLOOR) {
sptr = (char *)g_resource->getStaticText(kTextSurmazeMessage).c_str();
sptr = (char *)_resource->getStaticText(kTextSurmazeMessage).c_str();
flowText(MsgFont, 0, 7, 0, true, true, true, true, mapScaleX(360), 0, mapScaleX(660), mapScaleY(450), sptr);
}
switch (Floor) {
case LOWERFLOOR:
sptr = (char *)g_resource->getStaticText(kTextLowerFloor).c_str();
sptr = (char *)_resource->getStaticText(kTextLowerFloor).c_str();
break;
case MIDDLEFLOOR:
sptr = (char *)g_resource->getStaticText(kTextMiddleFloor).c_str();
sptr = (char *)_resource->getStaticText(kTextMiddleFloor).c_str();
break;
case UPPERFLOOR:
sptr = (char *)g_resource->getStaticText(kTextUpperFloor).c_str();
sptr = (char *)_resource->getStaticText(kTextUpperFloor).c_str();
break;
case MEDMAZEFLOOR:
sptr = (char *)g_resource->getStaticText(kTextMedMazeFloor).c_str();
sptr = (char *)_resource->getStaticText(kTextMedMazeFloor).c_str();
break;
case HEDGEMAZEFLOOR:
sptr = (char *)g_resource->getStaticText(kTextHedgeMazeFloor).c_str();
sptr = (char *)_resource->getStaticText(kTextHedgeMazeFloor).c_str();
break;
case SURMAZEFLOOR:
sptr = (char *)g_resource->getStaticText(kTextSurMazeFloor).c_str();
sptr = (char *)_resource->getStaticText(kTextSurMazeFloor).c_str();
break;
case CARNIVAL:
sptr = (char *)g_resource->getStaticText(kTextCarnivalFloor).c_str();
sptr = (char *)_resource->getStaticText(kTextCarnivalFloor).c_str();
break;
default:
sptr = NULL;
@ -795,7 +795,7 @@ void LabEngine::processMap(uint16 CurRoom) {
if (OldMsg != CurMsg) {
if (_rooms[CurMsg]._roomMsg == nullptr)
g_resource->readViews(CurMsg);
_resource->readViews(CurMsg);
if ((sptr = _rooms[CurMsg]._roomMsg)) {
_event->mouseHide();

View File

@ -96,7 +96,7 @@ ViewData *getViewData(uint16 roomNum, uint16 direction) {
ViewData *view = NULL;
if (!_rooms[roomNum]._roomMsg)
g_resource->readViews(roomNum);
g_lab->_resource->readViews(roomNum);
if (direction == NORTH)
view = _rooms[roomNum]._northView;
@ -202,13 +202,13 @@ void LabEngine::drawDirection(CloseDataPtr LCPtr) {
}
if (Direction == NORTH)
message += g_resource->getStaticText(kTextFacingNorth);
message += _resource->getStaticText(kTextFacingNorth);
else if (Direction == EAST)
message += g_resource->getStaticText(kTextFacingEast);
message += _resource->getStaticText(kTextFacingEast);
else if (Direction == SOUTH)
message += g_resource->getStaticText(kTextFacingSouth);
message += _resource->getStaticText(kTextFacingSouth);
else if (Direction == WEST)
message += g_resource->getStaticText(kTextFacingWest);
message += _resource->getStaticText(kTextFacingWest);
drawMessage(message.c_str());
}
@ -614,7 +614,7 @@ static bool doActionRuleSub(int16 action, int16 roomNum, CloseDataPtr LCPtr, Clo
RuleList *rules = _rooms[RoomNum]._rules;
if ((rules == NULL) && (roomNum == 0)) {
g_resource->readViews(roomNum);
g_lab->_resource->readViews(roomNum);
rules = _rooms[roomNum]._rules;
}
@ -671,7 +671,7 @@ static bool doOperateRuleSub(int16 ItemNum, int16 roomNum, CloseDataPtr LCPtr, C
RuleList *rules = _rooms[roomNum]._rules;
if ((rules == NULL) && (roomNum == 0)) {
g_resource->readViews(roomNum);
g_lab->_resource->readViews(roomNum);
rules = _rooms[roomNum]._rules;
}

View File

@ -39,9 +39,7 @@ extern RoomData *_rooms;
extern InventoryData *Inventory;
extern uint16 NumInv, ManyRooms, HighestCondition;
Resource *g_resource;
Resource::Resource() {
Resource::Resource(LabEngine *vm) : _vm(vm) {
readStaticText();
}

View File

@ -95,7 +95,7 @@ enum StaticText {
class Resource {
public:
Resource();
Resource(LabEngine *vm);
~Resource() {}
Common::File *openDataFile(const char * fileName, uint32 fileHeader);
@ -106,6 +106,7 @@ public:
Common::String getStaticText(byte index) const { return _staticText[index]; }
private:
LabEngine *_vm;
char *readString(Common::File *file);
int16 *readConditions(Common::File *file);
RuleList *readRule(Common::File *file);
@ -117,8 +118,6 @@ private:
Common::String _staticText[48];
};
extern Resource *g_resource;
} // End of namespace Lab
#endif /* LAB_RESOURCE_H */

View File

@ -461,7 +461,7 @@ void doNotes() {
/* Load in the data */
BigMsgFont = &bmfont;
if (!(BigMsgFont = g_resource->getFont("P:Note.fon"))) {
if (!(BigMsgFont = g_lab->_resource->getFont("P:Note.fon"))) {
BigMsgFont = NULL;
return;
}
@ -487,7 +487,7 @@ void doWestPaper() {
BigMsgFont = &bmfont;
if (!(BigMsgFont = g_resource->getFont("P:News22.fon"))) {
if (!(BigMsgFont = g_lab->_resource->getFont("P:News22.fon"))) {
BigMsgFont = NULL;
return;
}
@ -499,7 +499,7 @@ void doWestPaper() {
BigMsgFont = &bmfont;
if (!(BigMsgFont = g_resource->getFont("P:News32.fon"))) {
if (!(BigMsgFont = g_lab->_resource->getFont("P:News32.fon"))) {
BigMsgFont = NULL;
return;
}
@ -518,7 +518,7 @@ void doWestPaper() {
BigMsgFont = &bmfont;
if (!(BigMsgFont = g_resource->getFont("P:Note.fon"))) {
if (!(BigMsgFont = g_lab->_resource->getFont("P:Note.fon"))) {
BigMsgFont = NULL;
return;
}
@ -548,7 +548,7 @@ static bool loadJournalData() {
BigMsgFont = &bmfont;
if (!(BigMsgFont = g_resource->getFont("P:Journal.fon"))) {
if (!(BigMsgFont = g_lab->_resource->getFont("P:Journal.fon"))) {
BigMsgFont = NULL;
return false;
}
@ -1047,7 +1047,7 @@ void LabEngine::doMonitor(char *background, char *textfile, bool isinteractive,
BigMsgFont = &bmfont;
if (!(BigMsgFont = g_resource->getFont("P:Map.fon"))) {
if (!(BigMsgFont = _resource->getFont("P:Map.fon"))) {
freeAllStolenMem();
BigMsgFont = NULL;
return;