MACVENTURE: Add wrapper class for global settings

This commit is contained in:
Borja Lorente 2016-08-13 17:45:49 +02:00
parent 44a6f8a1db
commit 019f3d4b62
4 changed files with 99 additions and 70 deletions

View File

@ -314,14 +314,14 @@ WindowReference Gui::createInventoryWindow(ObjID objRef) {
if (_windowData->back().refcon < 0x80) { // There is already another inventory window
newData.bounds = _windowData->back().bounds; // Inventory windows are always last
newData.bounds.translate(newData.bounds.left + settings.invOffsetX, newData.bounds.top + settings.invOffsetY);
newData.bounds.translate(newData.bounds.left + settings._invOffsetX, newData.bounds.top + settings._invOffsetY);
} else {
BorderBounds bbs = borderBounds(kInvWindow);
newData.bounds = Common::Rect(
settings.invLeft - bbs.leftOffset,
settings.invTop - bbs.topOffset,
settings.invLeft + settings.invWidth,
settings.invTop + settings.invHeight);
settings._invLeft - bbs.leftOffset,
settings._invTop - bbs.topOffset,
settings._invLeft + settings._invWidth,
settings._invTop + settings._invHeight);
}
newData.type = kInvWindow;
newData.hasCloseBox = true;

View File

@ -56,6 +56,7 @@ MacVentureEngine::MacVentureEngine(OSystem *syst, const ADGameDescription *gameD
_debugger = NULL;
_resourceManager = NULL;
_globalSettings = NULL;
_gui = NULL;
_world = NULL;
_scriptEngine = NULL;
@ -87,6 +88,9 @@ MacVentureEngine::~MacVentureEngine() {
if (_resourceManager)
delete _resourceManager;
if (_globalSettings)
delete _globalSettings;
if (_gui)
delete _gui;
@ -487,7 +491,7 @@ Common::String MacVentureEngine::getStartGameFileName() {
}
const GlobalSettings& MacVentureEngine::getGlobalSettings() const {
return _globalSettings;
return *_globalSettings;
}
// Private engine methods
@ -979,7 +983,7 @@ uint32 MacVentureEngine::randBetween(uint32 min, uint32 max) {
}
uint32 MacVentureEngine::getInvolvedObjects() {
return (_selectedControl ? _globalSettings.cmdArgCnts[_selectedControl - 1] : 3000);
return (_selectedControl ? getGlobalSettings()._cmdArgCnts[_selectedControl - 1] : 3000);
}
Common::Point MacVentureEngine::getObjPosition(ObjID objID) {
@ -1084,37 +1088,8 @@ bool MacVentureEngine::loadGlobalSettings() {
Common::SeekableReadStream *res;
res = _resourceManager->getResource(MKTAG('G', 'N', 'R', 'L'), kGlobalSettingsID);
if (res) {
_globalSettings.numObjects = res->readUint16BE();
_globalSettings.numGlobals = res->readUint16BE();
_globalSettings.numCommands = res->readUint16BE();
_globalSettings.numAttributes = res->readUint16BE();
_globalSettings.numGroups = res->readUint16BE();
res->readUint16BE(); // unknown
_globalSettings.invTop = res->readUint16BE();
_globalSettings.invLeft = res->readUint16BE();
_globalSettings.invWidth = res->readUint16BE();
_globalSettings.invHeight = res->readUint16BE();
_globalSettings.invOffsetY = res->readUint16BE();
_globalSettings.invOffsetX = res->readSint16BE();
_globalSettings.defaultFont = res->readUint16BE();
_globalSettings.defaultSize = res->readUint16BE();
_globalSettings.attrIndices = new uint8[_globalSettings.numAttributes];
res->read(_globalSettings.attrIndices, _globalSettings.numAttributes);
_globalSettings.attrMasks = new uint16[_globalSettings.numAttributes];
for (int i = 0; i < _globalSettings.numAttributes; i++)
_globalSettings.attrMasks[i] = res->readUint16BE();
_globalSettings.attrShifts = new uint8[_globalSettings.numAttributes];
res->read(_globalSettings.attrShifts, _globalSettings.numAttributes);
_globalSettings.cmdArgCnts = new uint8[_globalSettings.numCommands];
res->read(_globalSettings.cmdArgCnts, _globalSettings.numCommands);
_globalSettings.commands = new uint8[_globalSettings.numCommands];
res->read(_globalSettings.commands, _globalSettings.numCommands);
_globalSettings = new GlobalSettings();
_globalSettings->loadSettings(res);
delete res;
return true;
}
@ -1149,7 +1124,6 @@ bool MacVentureEngine::loadTextHuffman() {
_textHuffman = new HuffmanLists(numEntries, lengths, masks, values);
debugC(4, kMVDebugMain, "Text is huffman-encoded");
delete res;
delete masks;
delete lengths;
@ -1159,6 +1133,52 @@ bool MacVentureEngine::loadTextHuffman() {
return false;
}
// Global Settings
GlobalSettings::GlobalSettings() {
}
GlobalSettings::~GlobalSettings() {
}
void GlobalSettings::loadSettings(Common::SeekableReadStream *dataStream) {
_numObjects = dataStream->readUint16BE();
_numGlobals = dataStream->readUint16BE();
_numCommands = dataStream->readUint16BE();
_numAttributes = dataStream->readUint16BE();
_numGroups = dataStream->readUint16BE();
dataStream->readUint16BE(); // unknown
_invTop = dataStream->readUint16BE();
_invLeft = dataStream->readUint16BE();
_invWidth = dataStream->readUint16BE();
_invHeight = dataStream->readUint16BE();
_invOffsetY = dataStream->readUint16BE();
_invOffsetX = dataStream->readSint16BE();
_defaultFont = dataStream->readUint16BE();
_defaultSize = dataStream->readUint16BE();
uint8 *attrIndices = new uint8[_numAttributes];
dataStream->read(attrIndices, _numAttributes);
_attrIndices = Common::Array<uint8>(attrIndices, _numAttributes);
delete[] attrIndices;
for (int i = 0; i < _numAttributes; i++)
_attrMasks.push_back(dataStream->readUint16BE());
uint8 *attrShifts = new uint8[_numAttributes];
dataStream->read(attrShifts, _numAttributes);
_attrShifts = Common::Array<uint8>(attrShifts, _numAttributes);
delete[] attrShifts;
uint8 *cmdArgCnts = new uint8[_numCommands];
dataStream->read(cmdArgCnts, _numCommands);
_cmdArgCnts = Common::Array<uint8>(cmdArgCnts, _numCommands);
delete[] cmdArgCnts;
uint8 *commands = new uint8[_numCommands];
dataStream->read(commands, _numCommands);
_commands = Common::Array<uint8>(commands, _numCommands);
delete[] commands;
}
} // End of namespace MacVenture

View File

@ -91,25 +91,34 @@ enum FilePathID {
};
struct GlobalSettings {
uint16 numObjects; // number of game objects defined
uint16 numGlobals; // number of globals defined
uint16 numCommands; // number of commands defined
uint16 numAttributes; // number of attributes
uint16 numGroups; // number of object groups
uint16 invTop; // inventory window bounds
uint16 invLeft;
uint16 invHeight;
uint16 invWidth;
uint16 invOffsetY; // positioning offset for
uint16 invOffsetX; // new inventory windows
uint16 defaultFont; // default font
uint16 defaultSize; // default font size
uint8 *attrIndices; // attribute indices into attribute table
uint16 *attrMasks; // attribute masks
uint8 *attrShifts; // attribute bit shifts
uint8 *cmdArgCnts; // command argument counts
uint8 *commands; // command buttons
class GlobalSettings {
public:
GlobalSettings();
~GlobalSettings();
void loadSettings(Common::SeekableReadStream *dataStream);
// HACK MAybe this should be private, but the class is only here to handle
// memory allocation/deallocation
public:
uint16 _numObjects; // number of game objects defined
uint16 _numGlobals; // number of globals defined
uint16 _numCommands; // number of commands defined
uint16 _numAttributes; // number of attributes
uint16 _numGroups; // number of object groups
uint16 _invTop; // inventory window bounds
uint16 _invLeft;
uint16 _invHeight;
uint16 _invWidth;
uint16 _invOffsetY; // positioning offset for
uint16 _invOffsetX; // new inventory windows
uint16 _defaultFont; // default font
uint16 _defaultSize; // default font size
Common::Array<uint8> _attrIndices; // attribute indices into attribute table
Common::Array<uint16> _attrMasks; // attribute masks
Common::Array<uint8> _attrShifts; // attribute bit shifts
Common::Array<uint8> _cmdArgCnts; // command argument counts
Common::Array<uint8> _commands; // command buttons
};
enum GameState {
@ -327,7 +336,7 @@ private: // Attributes
// Engine state
GameState _gameState;
GlobalSettings _globalSettings;
GlobalSettings *_globalSettings;
HuffmanLists *_textHuffman;
bool _oldTextEncoding;
bool _paused, _halted, _cmdReady, _prepared;

View File

@ -56,7 +56,7 @@ void World::startNewGame() {
uint32 World::getObjAttr(ObjID objID, uint32 attrID) {
uint res;
uint32 index = _engine->getGlobalSettings().attrIndices[attrID];
uint32 index = _engine->getGlobalSettings()._attrIndices[attrID];
// HACK, but if I try to initialize it in the else clause, it goes out of scope and segfaults
Common::SeekableReadStream *objStream = _objectConstants->getItem(objID);
if (!(index & 0x80)) { // It's not a constant
@ -69,8 +69,8 @@ uint32 World::getObjAttr(ObjID objID, uint32 attrID) {
res = objStream->readByte() << 8;
res |= objStream->readByte();
}
res &= _engine->getGlobalSettings().attrMasks[attrID];
res >>= _engine->getGlobalSettings().attrShifts[attrID];
res &= _engine->getGlobalSettings()._attrMasks[attrID];
res >>= _engine->getGlobalSettings()._attrShifts[attrID];
if (res & 0x8000)
res = -((res ^ 0xffff) + 1);
debugC(5, kMVDebugMain, "Attribute %x from object %x is %x", attrID, objID, res);
@ -88,11 +88,11 @@ void World::setObjAttr(ObjID objID, uint32 attrID, Attribute value) {
if (attrID < kAttrOtherDoor)
_engine->enqueueObject(kUpdateObject, objID);
uint32 idx = _engine->getGlobalSettings().attrIndices[attrID];
value <<= _engine->getGlobalSettings().attrShifts[attrID];
value &= _engine->getGlobalSettings().attrMasks[attrID];
uint32 idx = _engine->getGlobalSettings()._attrIndices[attrID];
value <<= _engine->getGlobalSettings()._attrShifts[attrID];
value &= _engine->getGlobalSettings()._attrMasks[attrID];
Attribute oldVal = _saveGame->getAttr(objID, idx);
oldVal &= ~_engine->getGlobalSettings().attrMasks[attrID];
oldVal &= ~_engine->getGlobalSettings()._attrMasks[attrID];
_saveGame->setAttr(idx, objID, (value | oldVal));
_engine->gameChanged();
}
@ -195,7 +195,7 @@ bool World::intersects(ObjID objID, Common::Rect rect) {
void World::calculateObjectRelations() {
_relations.clear();
ObjID val, next;
uint32 numObjs = _engine->getGlobalSettings().numObjects;
uint32 numObjs = _engine->getGlobalSettings()._numObjects;
const AttributeGroup &parents = *_saveGame->getGroup(0);
for (uint i = 0; i < numObjs * 2; i++) {
_relations.push_back(0);
@ -305,9 +305,9 @@ void SaveGame::saveInto(Common::OutSaveFile *file) {
void SaveGame::loadGroups(MacVentureEngine *engine, Common::SeekableReadStream * res) {
GlobalSettings settings = engine->getGlobalSettings();
for (int i = 0; i < settings.numGroups; ++i) {
for (int i = 0; i < settings._numGroups; ++i) {
AttributeGroup g;
for (int j = 0; j < settings.numObjects; ++j)
for (int j = 0; j < settings._numObjects; ++j)
g.push_back(res->readUint16BE());
_groups.push_back(g);
@ -316,7 +316,7 @@ void SaveGame::loadGroups(MacVentureEngine *engine, Common::SeekableReadStream *
void SaveGame::loadGlobals(MacVentureEngine *engine, Common::SeekableReadStream * res) {
GlobalSettings settings = engine->getGlobalSettings();
for (int i = 0; i < settings.numGlobals; ++i) {
for (int i = 0; i < settings._numGlobals; ++i) {
_globals.push_back(res->readUint16BE());
}
}