ACCESS: Implemented room data loading

This commit is contained in:
Paul Gilbert 2014-08-06 22:43:40 -04:00
parent 3645aad6fb
commit 031cc32c84
12 changed files with 285 additions and 5 deletions

View File

@ -70,6 +70,13 @@ AccessEngine::AccessEngine(OSystem *syst, const AccessGameDescription *gameDesc)
_startup = 0;
_currentCharFlag = false;
_boxSelect = false;
_charFlag = 0;
_scaleH1 = _scaleH2 = 0;
_scaleN1 = 0;
_scaleT1 = 0;
_scaleMaxY = 0;
_scaleI = 0;
_playFieldHeight = 0;
_roomNumber = 0;
_rawPlayerXLow = 0;
@ -85,6 +92,10 @@ AccessEngine::AccessEngine(OSystem *syst, const AccessGameDescription *gameDesc)
_timerFlag = false;
Common::fill(&_flags[0], &_flags[99], 0);
Common::fill(&_useItem[0], &_useItem[23], 0);
Common::fill(&_establishTable[0], &_establishTable[100], 0);
_establishFlag = false;
_establishMode = 0;
_establishGroup = 0;
_guardLoc = 0;
_guardFind = 0;
_helpLevel = 0;
@ -192,6 +203,13 @@ int AccessEngine::getRandomNumber(int maxNumber) {
return _randomSource.getRandomNumber(maxNumber);
}
void AccessEngine::loadCells(Common::Array<CellIdent> &cells) {
for (uint i = 0; i < cells.size(); ++i) {
_objectsTable[cells[i]._cell] = _files->loadFile(
cells[i]._fileNum, cells[i]._subfile);
}
}
void AccessEngine::clearCellTable() {
Common::fill(&_objectsTable[0], &_objectsTable[100], (byte *)nullptr);
}
@ -228,4 +246,34 @@ void AccessEngine::freeManData() {
_man = nullptr;
}
void AccessEngine::establish(int v) {
_establishMode = 0;
_establishGroup = 0;
doEstablish(v);
}
void AccessEngine::establishCenter(int v) {
_establishMode = 1;
doEstablish(v);
}
void AccessEngine::doEstablish(int v) {
_screen->forceFadeOut();
_screen->clearScreen();
_screen->setPanel(3);
if (v != -1) {
_files->loadScreen(95, v);
_buffer2.copyBuffer(_screen);
}
warning("TODO: doEstablish");
}
void AccessEngine::loadPlayField(int fileNum, int subfile) {
// TODO
}
} // End of namespace Access

View File

@ -80,6 +80,8 @@ private:
void setVGA();
void dummyLoop();
void doEstablish(int v);
protected:
const AccessGameDescription *_gameDescription;
Common::RandomSource _randomSource;
@ -108,13 +110,18 @@ public:
SoundManager *_sound;
byte *_destIn;
Graphics::Surface _buffer1;
Graphics::Surface _buffer2;
ASurface _buffer1;
ASurface _buffer2;
byte *_objectsTable[100];
int _establishTable[100];
bool _establishFlag;
int _establishMode;
int _establishGroup;
int _numAnimTimers;
Common::Array<TimerEntry> _timers;
Common::Array<Common::Rect> _newRect;
Common::Array<Common::Rect> _oldRect;
Common::Array<ExtraCell> _extraCells;
int _pCount;
int _selectCommand;
bool _normalMouse;
@ -141,6 +148,13 @@ public:
int _startTravelBox;
bool _currentCharFlag;
bool _boxSelect;
int _charFlag;
int _scaleH1, _scaleH2;
int _scaleN1;
int _scaleT1;
int _scaleMaxY;
int _scaleI;
int _playFieldHeight;
// Fields that are included in savegames
int _roomNumber;
@ -202,6 +216,8 @@ public:
void freeAnimationData();
void loadCells(Common::Array<CellIdent> &cells);
/**
* Clear the cell table
*/
@ -231,6 +247,12 @@ public:
* Free animation data
*/
void freeManData();
void establish(int v);
void establishCenter(int v);
void loadPlayField(int fileNum, int subfile);
};
} // End of namespace Access

View File

@ -22,6 +22,7 @@
#include "common/scummsys.h"
#include "access/access.h"
#include "access/amazon/amazon_resources.h"
#include "access/amazon/amazon_room.h"
namespace Access {
@ -32,6 +33,10 @@ AmazonRoom::AmazonRoom(AccessEngine *vm): Room(vm) {
_antOutFlag = false;
}
void AmazonRoom::loadRoom(int roomNumber) {
loadRoomData(ROOM_TABLE[roomNumber]);
}
void AmazonRoom::reloadRoom() {
loadRoom(_vm->_roomNumber);

View File

@ -40,6 +40,8 @@ private:
void roomMenu();
protected:
virtual void loadRoom(int roomNumber);
virtual void reloadRoom();
virtual void reloadRoom1();

View File

@ -31,6 +31,8 @@ namespace Access {
class ASurface : public Graphics::Surface {
public:
void clearBuffer();
void copyBuffer(Graphics::Surface *src) { copyFrom(*src); }
};
} // End of namespace Access

View File

@ -39,6 +39,14 @@ struct TimerEntry {
}
};
class ExtraCell {
public:
int _vidTable;
int _vidTable1;
int _vidSTable;
int _vidSTable1;
};
} // End of namespace Access
#endif /* ACCESS_DATA_H */

View File

@ -21,6 +21,7 @@
*/
#include "common/scummsys.h"
#include "common/memstream.h"
#include "access/access.h"
#include "access/resources.h"
#include "access/room.h"
@ -131,8 +132,77 @@ void Room::clearRoom() {
_vm->freeManData();
}
void Room::loadRoom(int room) {
// TODO
void Room::loadRoomData(const byte *roomData) {
RoomInfo roomInfo(roomData);
_roomFlag = roomInfo._roomFlag;
_vm->_establishFlag = false;
if (roomInfo._estIndex != -1) {
_vm->_establishFlag = true;
if (_vm->_establishTable[roomInfo._estIndex] != 1) {
_vm->_establishTable[roomInfo._estIndex] = 1;
_vm->establish(0);
}
}
_vm->_sound->freeMusic();
if (roomInfo._musicFile._fileNum != -1) {
_vm->_sound->_music = _vm->_files->loadFile(roomInfo._musicFile._fileNum,
roomInfo._musicFile._subfile);
_vm->_sound->_midiSize = _vm->_files->_filesize;
_vm->_sound->midiPlay();
_vm->_sound->_musicRepeat = true;
}
_vm->_scaleH1 = roomInfo._scaleH1;
_vm->_scaleH2 = roomInfo._scaleH2;
_vm->_scaleN1 = roomInfo._scaleN1;
_vm->_scaleT1 = ((_vm->_scaleH2 - _vm->_scaleH1) << 8) / _vm->_scaleN1;
if (roomInfo._playFieldFile._fileNum != -1) {
_vm->loadPlayField(roomInfo._playFieldFile._fileNum,
roomInfo._playFieldFile._subfile);
setupRoom();
_vm->_scaleMaxY = _vm->_playFieldHeight << 4;
}
// Load cells
_vm->loadCells(roomInfo._cells);
// Load script data
_vm->_scripts->freeScriptData();
if (roomInfo._scriptFile._fileNum != -1)
_vm->_scripts->_script = _vm->_files->loadFile(roomInfo._scriptFile._fileNum,
roomInfo._scriptFile._subfile);
// Load animation data
_vm->freeAnimationData();
if (roomInfo._animFile._fileNum != -1)
_vm->_anim = _vm->_files->loadFile(roomInfo._animFile._fileNum,
roomInfo._animFile._subfile);
_vm->_scaleI = roomInfo._scaleI;
_vm->_screen->_scrollThreshold = roomInfo._scrollThreshold;
_vm->_screen->_startColor = roomInfo._startColor;
_vm->_screen->_numColors = roomInfo._numColors;
_vm->_screen->loadPalette(roomInfo._paletteFile._fileNum,
roomInfo._paletteFile._subfile);
// Load extra cells
_vm->_extraCells.clear();
for (uint i = 0; i < roomInfo._vidTable.size(); ++i) {
ExtraCell ec;
ec._vidTable = roomInfo._vidTable[i] & 0xffff;
ec._vidTable1 = roomInfo._vidTable[i] >> 16;
_vm->_extraCells.push_back(ec);
}
// Load sounds for the scene
_vm->_sound->loadSounds(roomInfo._sounds);
}
void Room::roomLoop() {
@ -156,4 +226,57 @@ void Room::buildScreen() {
// TODO
}
/*------------------------------------------------------------------------*/
RoomInfo::RoomInfo(const byte *data) {
Common::MemoryReadStream stream(data, 999);
_roomFlag = stream.readByte() != 0;
_estIndex = (int16)stream.readUint16LE();
_musicFile._fileNum = (int16)stream.readUint16LE();
_musicFile._subfile = stream.readUint16LE();
_scaleH1 = stream.readByte();
_scaleH2 = stream.readByte();
_scaleN1 = stream.readByte();
_playFieldFile._fileNum = (int16)stream.readUint16LE();
_playFieldFile._subfile = stream.readUint16LE();
for (byte cell = stream.readByte(); cell != 0xff; cell = stream.readByte()) {
CellIdent ci;
ci._cell = cell;
ci._fileNum = (int16)stream.readUint16LE();
ci._subfile = stream.readUint16LE();
_cells.push_back(ci);
}
_scriptFile._fileNum = (int16)stream.readUint16LE();
_scriptFile._subfile = stream.readUint16LE();
_animFile._fileNum = (int16)stream.readUint16LE();
_animFile._subfile = stream.readUint16LE();
_scaleI = stream.readByte();
_scrollThreshold = stream.readByte();
_paletteFile._fileNum = (int16)stream.readUint16LE();
_paletteFile._subfile = stream.readUint16LE();
_startColor = stream.readUint16LE();
_numColors = stream.readUint16LE();
for (int16 v = (int16)stream.readUint16LE(); v != -1;
v = (int16)stream.readUint16LE()) {
uint16 v2 = stream.readUint16LE();
_vidTable.push_back(v | ((uint32)v2 << 16));
}
for (int16 fileNum = (int16)stream.readUint16LE(); fileNum != -1;
fileNum = (int16)stream.readUint16LE()) {
FileIdent fi;
fi._fileNum = fileNum;
fi._subfile = stream.readUint16LE();
_sounds.push_back(fi);
}
};
} // End of namespace Access

View File

@ -35,10 +35,13 @@ private:
protected:
AccessEngine *_vm;
void loadRoomData(const byte *roomData);
void setupRoom();
void setWallCodes();
void buildScreen();
virtual void loadRoom(int roomNumber) = 0;
virtual void reloadRoom() = 0;
virtual void reloadRoom1() = 0;
@ -56,8 +59,38 @@ public:
* Clear all the data used by the room
*/
void clearRoom();
};
void loadRoom(int room);
struct FileIdent {
int _fileNum;
int _subfile;
};
struct CellIdent : FileIdent {
byte _cell;
};
class RoomInfo {
public:
bool _roomFlag;
int _estIndex;
FileIdent _musicFile;
int _scaleH1;
int _scaleH2;
int _scaleN1;
FileIdent _playFieldFile;
Common::Array<CellIdent> _cells;
FileIdent _scriptFile;
FileIdent _animFile;
int _scaleI;
int _scrollThreshold;
FileIdent _paletteFile;
int _startColor;
int _numColors;
Common::Array<uint32> _vidTable;
Common::Array<FileIdent> _sounds;
public:
RoomInfo(const byte *data);
};
} // End of namespace Access

View File

@ -26,6 +26,7 @@
#include "common/textconsole.h"
#include "common/system.h"
#include "graphics/palette.h"
#include "access/access.h"
#include "access/screen.h"
#include "access/resources.h"
@ -42,6 +43,8 @@ Screen::Screen(AccessEngine *vm) : _vm(vm) {
_topSkip = _bottomSkip = 0;
_clipWidth = _clipHeight = 0;
_scrollFlag = false;
_scrollThreshold = 0;
_startColor = _numColors = 0;
}
void Screen::setDisplayScan() {
@ -71,6 +74,12 @@ void Screen::loadPalette(Common::SeekableReadStream *stream) {
_loadPalFlag = true;
}
void Screen::loadPalette(int fileNum, int subfile) {
byte *palette = _vm->_files->loadFile(fileNum, subfile);
Common::copy(palette, palette + (_numColors * 3), &_rawPalette[_startColor * 3]);
delete[] palette;
}
void Screen::setPalette() {
g_system->getPaletteManager()->setPalette(&_rawPalette[0], 0, PALETTE_COUNT);
}

View File

@ -56,6 +56,8 @@ private:
public:
bool _loadPalFlag;
bool _scrollFlag;
int _scrollThreshold;
int _startColor, _numColors;
public:
Screen(AccessEngine *vm);
@ -89,6 +91,8 @@ public:
void loadPalette(Common::SeekableReadStream *stream);
void loadPalette(int fileNum, int subfile);
void setPalette();
/**

View File

@ -34,6 +34,8 @@ SoundManager::SoundManager(AccessEngine *vm, Audio::Mixer *mixer) :
_soundTable[i]._data = nullptr;
_music = nullptr;
_midiSize = 0;
_musicRepeat = false;
}
SoundManager::~SoundManager() {
@ -66,6 +68,14 @@ void SoundManager::playSound(byte *data, uint32 size) {
*/
}
void SoundManager::loadSounds(Common::Array<FileIdent> &sounds) {
// TODO
}
void SoundManager::midiPlay() {
// TODO
}
void SoundManager::midiRepeat() {
// TODO
}
@ -78,4 +88,9 @@ void SoundManager::freeSounds() {
// TODO
}
void SoundManager::freeMusic() {
delete[] _music;
_music = nullptr;
}
} // End of namespace Access

View File

@ -49,6 +49,9 @@ public:
SoundEntry _soundTable[MAX_SOUNDS];
int _soundPriority[MAX_SOUNDS];
byte *_music;
int _midiSize;
bool _musicRepeat;
public:
SoundManager(AccessEngine *vm, Audio::Mixer *mixer);
~SoundManager();
@ -57,11 +60,17 @@ public:
void playSound(int soundIndex);
void loadSounds(Common::Array<FileIdent> &sounds);
void midiPlay();
void midiRepeat();
void stopSong();
void freeSounds();
void freeMusic();
};
} // End of namespace Access