* Added DraciEngine::_initArchive and made Game use it. Fixes a memory bug because Game uses pointers from the init archive which should outlive it (but didn't previously).

* Added support for setting loop status to Game.
* Made some GPL commands check whether we are in the correct loop status before executing.

svn-id: r42731
This commit is contained in:
Denis Kasak 2009-07-25 03:28:04 +00:00
parent b7e97efb7f
commit d28658984d
5 changed files with 44 additions and 10 deletions

View File

@ -53,6 +53,7 @@ const Common::String roomsPath("MIST.DFW");
const Common::String animationsPath("ANIM.DFW");
const Common::String iconsPath("HRA.DFW");
const Common::String walkingMapsPath("MAPY.DFW");
const Common::String initPath("INIT.DFW");
DraciEngine::DraciEngine(OSystem *syst, const ADGameDescription *gameDesc)
: Engine(syst) {
@ -81,6 +82,7 @@ int DraciEngine::init() {
initGraphics(kScreenWidth, kScreenHeight, false);
// Open game's archives
_initArchive = new BArchive(initPath);
_objectsArchive = new BArchive(objectsPath);
_spritesArchive = new BArchive(spritesPath);
_paletteArchive = new BArchive(palettePath);
@ -227,6 +229,7 @@ DraciEngine::~DraciEngine() {
delete _script;
delete _anims;
delete _initArchive;
delete _paletteArchive;
delete _objectsArchive;
delete _spritesArchive;

View File

@ -68,6 +68,7 @@ public:
BArchive *_overlaysArchive;
BArchive *_animationsArchive;
BArchive *_walkingMapsArchive;
BArchive *_initArchive;
Common::RandomSource _rnd;
};

View File

@ -39,14 +39,13 @@ static double real_to_double(byte real[6]);
Game::Game(DraciEngine *vm) : _vm(vm) {
unsigned int i;
Common::String path("INIT.DFW");
BArchive initArchive(path);
BArchive *initArchive = _vm->_initArchive;
BAFile *file;
// Read in persons
file = initArchive.getFile(5);
file = initArchive->getFile(5);
Common::MemoryReadStream personData(file->_data, file->_length);
unsigned int numPersons = file->_length / personSize;
@ -63,7 +62,7 @@ Game::Game(DraciEngine *vm) : _vm(vm) {
// Read in dialog offsets
file = initArchive.getFile(4);
file = initArchive->getFile(4);
Common::MemoryReadStream dialogData(file->_data, file->_length);
unsigned int numDialogs = file->_length / sizeof(uint16);
@ -80,7 +79,7 @@ Game::Game(DraciEngine *vm) : _vm(vm) {
// Read in game info
file = initArchive.getFile(3);
file = initArchive->getFile(3);
Common::MemoryReadStream gameData(file->_data, file->_length);
_info._startRoom = gameData.readByte() - 1;
@ -105,7 +104,7 @@ Game::Game(DraciEngine *vm) : _vm(vm) {
// Read in variables
file = initArchive.getFile(2);
file = initArchive->getFile(2);
unsigned int numVariables = file->_length / sizeof (int16);
_variables = new int[numVariables];
@ -120,13 +119,13 @@ Game::Game(DraciEngine *vm) : _vm(vm) {
// Read in item icon status
file = initArchive.getFile(1);
file = initArchive->getFile(1);
_iconStatus = file->_data;
uint numIcons = file->_length;
// Read in object status
file = initArchive.getFile(0);
file = initArchive->getFile(0);
unsigned int numObjects = file->_length;
_objects = new GameObject[numObjects];
@ -153,6 +152,8 @@ Game::Game(DraciEngine *vm) : _vm(vm) {
}
void Game::init() {
_loopStatus = kStatusOrdinary;
loadObject(kDragonObject);
GameObject *dragon = getObject(kDragonObject);
@ -521,6 +522,14 @@ void Game::changeRoom(uint roomNum) {
loadOverlays();
}
void Game::setLoopStatus(LoopStatus status) {
_loopStatus = status;
}
LoopStatus Game::getLoopStatus() {
return _loopStatus;
}
int Game::getRoomNum() {
return _currentRoom._roomNum;
}

View File

@ -132,6 +132,12 @@ struct Room {
GPL2Program _program;
};
enum LoopStatus {
kStatusGate, kStatusOrdinary, kStatusInventory,
kStatusDialogue, kStatusTalk, kStatusStrange,
kStatusFade
};
class Game {
public:
@ -185,15 +191,22 @@ public:
int getMarkedAnimationIndex();
void setMarkedAnimationIndex(int index);
void setLoopStatus(LoopStatus status);
LoopStatus getLoopStatus();
private:
DraciEngine *_vm;
int *_variables;
GameInfo _info;
Person *_persons;
uint *_dialogOffsets;
int *_variables;
byte *_iconStatus;
Person *_persons;
GameObject *_objects;
Room _currentRoom;
LoopStatus _loopStatus;
int _markedAnimationIndex; //!< Used by the Mark GPL command
};

View File

@ -265,6 +265,10 @@ int Script::funcIsObjAway(int objID) {
/* GPL commands */
void Script::load(Common::Queue<int> &params) {
if (_vm->_game->getLoopStatus() == kStatusInventory) {
return;
}
int objID = params.pop() - 1;
int animID = params.pop() - 1;
@ -275,6 +279,10 @@ void Script::load(Common::Queue<int> &params) {
}
void Script::start(Common::Queue<int> &params) {
if (_vm->_game->getLoopStatus() == kStatusInventory) {
return;
}
int objID = params.pop() - 1;
int animID = params.pop() - 1;