diff options
author | Sven Hesse | 2008-05-10 20:59:43 +0000 |
---|---|---|
committer | Sven Hesse | 2008-05-10 20:59:43 +0000 |
commit | 257aaa3ced14645d4410a272e89cafb7282836ac (patch) | |
tree | bfe6be04b32b7d40d3096fa2e14f49625a7f8b25 /engines/gob/saveload.cpp | |
parent | b2defd0eac9401ffeea91ef0154650e108ffc179 (diff) | |
download | scummvm-rg350-257aaa3ced14645d4410a272e89cafb7282836ac.tar.gz scummvm-rg350-257aaa3ced14645d4410a272e89cafb7282836ac.tar.bz2 scummvm-rg350-257aaa3ced14645d4410a272e89cafb7282836ac.zip |
Restructured saving/loading and added a stub for Woodruff
svn-id: r31989
Diffstat (limited to 'engines/gob/saveload.cpp')
-rw-r--r-- | engines/gob/saveload.cpp | 724 |
1 files changed, 423 insertions, 301 deletions
diff --git a/engines/gob/saveload.cpp b/engines/gob/saveload.cpp index 717bc143a6..e0854151a0 100644 --- a/engines/gob/saveload.cpp +++ b/engines/gob/saveload.cpp @@ -24,456 +24,493 @@ */ #include "common/endian.h" -#include "common/file.h" +#include "common/savefile.h" #include "gob/gob.h" #include "gob/saveload.h" -#include "gob/global.h" #include "gob/draw.h" -#include "gob/video.h" namespace Gob { -SaveLoad::SaveLoad(GobEngine *vm, const char *targetName) : _vm(vm) { - _curSlot = -1; +TempSprite::TempSprite() { + _sprite = 0; + _width = _height = 0; + _size = -1; + memset(_palette, 0, 768); +} - _stagesCount = 0; - _buffer = 0; +TempSprite::~TempSprite() { + delete[] _sprite; +} - _tempSprite = 0; - memset(_tempPal, 0, 768); - _tempSpriteSize = -1; +int TempSprite::getSpriteIndex(int32 size) const { + if (size < -1000) + size += 1000; - _saveFiles = new char*[5]; + return -size - 1; +} - assert(_saveFiles); +bool TempSprite::getSpritePalette(int32 size) const { + return size < -1000; +} - _saveFiles[0] = new char[strlen(targetName) + 5]; - _saveFiles[1] = 0; - _saveFiles[2] = new char[strlen(targetName) + 5]; - _saveFiles[3] = _saveFiles[0]; - _saveFiles[4] = 0; +bool TempSprite::getProperties(int16 dataVar, int32 size, int32 offset, + int &index, bool &palette) const { - assert(_saveFiles[0] && _saveFiles[2]); + if (size >= 0) { + warning("Invalid index (%d)", size); + return false; + } - sprintf(_saveFiles[0], "%s.s00", targetName); - sprintf(_saveFiles[2], "%s.blo", targetName); -} + index = getSpriteIndex(size); + palette = getSpritePalette(size); -SaveLoad::~SaveLoad() { - if (_buffer) { - for (int i = 0; i < _stagesCount; i++) - delete[] _buffer[i]; - delete[] _buffer; + if ((index < 0) || (index >= SPRITES_COUNT)) { + warning("Index out of range (%d)", index); + return false; } - delete _tempSprite; + return true; +} - delete[] _saveFiles[0]; - delete[] _saveFiles[2]; - delete[] _saveFiles; +int32 TempSprite::getSize() const { + return _size; } -const char *SaveLoad::setCurSlot(int slot) { - static char *slotBase = _saveFiles[0] + strlen(_saveFiles[0]) - 2; +bool TempSprite::saveSprite(const SurfaceDesc &surfDesc) { + delete[] _sprite; - if (_curSlot != slot) { - _curSlot = slot; + _width = surfDesc.getWidth(); + _height = surfDesc.getHeight(); + _size = _width * _height; + _sprite = new byte[_size]; - if (_curSlot >= 0) - snprintf(slotBase, 3, "%02d", slot); - } + memcpy(_sprite, surfDesc.getVidMem(), _size); - return _saveFiles[0]; + return true; } -uint32 SaveLoad::read(Common::ReadStream &in, byte *buf, - byte *sizes, uint32 count) { - uint32 nRead; +bool TempSprite::savePalette(const Video::Color *palette) { + memcpy((byte *) _palette, (byte *) palette, 768); + return true; +} - nRead = in.read(buf, count); - if (nRead != count) { - warning("Can't read data: requested %d, got %d", count, nRead); - return 0; +bool TempSprite::loadSprite(SurfaceDesc &surfDesc) { + if (!_sprite) { + warning("No sprite saved"); + return false; } - nRead = in.read(sizes, count); - if (nRead != count) { - warning("Can't read data sizes: requested %d, got %d", count, nRead); - return 0; + if (_size != (surfDesc.getWidth() * surfDesc.getHeight())) { + warning("Dimensions don't match (%dx%d - %dx%d", + _width, _height, surfDesc.getWidth(), surfDesc.getHeight()); + return false; } - return count; + memcpy(surfDesc.getVidMem(), _sprite, _size); + + return true; } -uint32 SaveLoad::write(Common::WriteStream &out, byte *buf, - byte *sizes, uint32 count) { - uint32 written; +bool TempSprite::loadPalette(Video::Color *palette) { + memcpy((byte *) palette, (byte *) _palette, 768); + return true; +} - written = out.write(buf, count); - if (written != count) { - warning("Can't write data: requested %d, wrote %d", count, written); - return 0; +bool TempSprite::toBuffer(byte *buffer, int32 size, bool palette) const { + + int32 haveSize = _size + (palette ? 768 : 0); + if (size != haveSize) { + warning("Sizes don't match (%d != %d)", size, haveSize); + return false; } - written = out.write(sizes, count); - if (written != count) { - warning("Can't write data: requested %d, wrote %d", count, written); - return 0; + if (palette) { + memcpy(buffer, (byte *) _palette, 768); + buffer += 768; } - return count; + memcpy(buffer, _sprite, _size); + + return true; } -bool SaveLoad::loadDataEndian(Common::ReadStream &in, - int16 dataVar, uint32 size) { +bool TempSprite::fromBuffer(const byte *buffer, int32 size, bool palette) { + if (palette) { + memcpy((byte *) _palette, buffer, 768); + buffer += 768; + size -= 768; + } - bool retVal = false; + _size = size; - byte *varBuf = new byte[size]; - byte *sizeBuf = new byte[size]; + delete[] _sprite; + _sprite = new byte[_size]; - assert(varBuf && sizeBuf); + memcpy(_sprite, buffer, _size); - if (read(in, varBuf, sizeBuf, size) == size) { - if (fromEndian(varBuf, sizeBuf, size)) { - memcpy(_vm->_global->_inter_variables + dataVar, varBuf, size); - memcpy(_vm->_global->_inter_variablesSizes + dataVar, sizeBuf, size); - retVal = true; - } - } + return true; +} - delete[] varBuf; - delete[] sizeBuf; - return retVal; +PlainSave::PlainSave() { } -bool SaveLoad::saveDataEndian(Common::WriteStream &out, - int16 dataVar, uint32 size) { +PlainSave::~PlainSave() { +} - bool retVal = false; +bool PlainSave::save(int16 dataVar, int32 size, int32 offset, const char *name, + const byte *variables, const byte *variableSizes) const { - byte *varBuf = new byte[size]; - byte *sizeBuf = new byte[size]; + if ((size <= 0) || (offset != 0)) { + warning("Invalid size (%d) or offset (%d)", size, offset); + return false; + } - assert(varBuf && sizeBuf); + Common::SaveFileManager *saveMan = g_system->getSavefileManager(); + Common::OutSaveFile *out = saveMan->openForSaving(name); - memcpy(varBuf, _vm->_global->_inter_variables + dataVar, size); - memcpy(sizeBuf, _vm->_global->_inter_variablesSizes + dataVar, size); + if (!out) { + warning("Can't open file \"%s\" for writing", name); + return false; + } - if (toEndian(varBuf, sizeBuf, size)) - if (write(out, varBuf, sizeBuf, size) == size) - retVal = true; + bool retVal; + retVal = SaveLoad::saveDataEndian(*out, dataVar, size, variables, variableSizes); - delete[] varBuf; - delete[] sizeBuf; + out->finalize(); + if (out->ioFailed()) { + warning("Can't write to file \"%s\"", name); + retVal = false; + } + delete out; return retVal; } -int32 SaveLoad::getSize(SaveType type) { - switch (type) { - case kSaveNone: - return -1; - break; - - case kSaveGame: - return getSizeGame(); - break; +bool PlainSave::load(int16 dataVar, int32 size, int32 offset, const char *name, + byte *variables, byte *variableSizes) const { - case kSaveTempSprite: - return getSizeTempSprite(); - break; - - case kSaveNotes: - return getSizeNotes(); - break; + if ((size <= 0) || (offset != 0)) { + warning("Invalid size (%d) or offset (%d)", size, offset); + return false; + } - case kSaveScreenshot: - return getSizeScreenshot(); - break; + Common::SaveFileManager *saveMan = g_system->getSavefileManager(); + Common::InSaveFile *in = saveMan->openForLoading(name); - case kSaveIgnore: - return -1; - break; + if (!in) { + warning("Can't open file \"%s\" for reading", name); + return false; } - return -1; + bool retVal = SaveLoad::loadDataEndian(*in, dataVar, size, variables, variableSizes); + delete in; + return retVal; } -bool SaveLoad::load(SaveType type, int16 dataVar, int32 size, int32 offset) { - switch (type) { - case kSaveNone: - return false; - break; - - case kSaveGame: - return loadGame(dataVar, size, offset); - break; - case kSaveTempSprite: - return loadTempSprite(dataVar, size, offset); - break; +StagedSave::StagedSave() { + _mode = kModeNone; + _name = 0; + _loaded = false; +} - case kSaveNotes: - return loadNotes(dataVar, size, offset); - break; +StagedSave::~StagedSave() { + clear(); +} - case kSaveScreenshot: - return loadScreenshot(dataVar, size, offset); - break; +void StagedSave::addStage(int32 size, bool endianed) { + int32 offset = 0; - case kSaveIgnore: - return true; - break; - } + if (!_stages.empty()) + offset = _stages[_stages.size() - 1].offset + + _stages[_stages.size() - 1].size; - return false; + Stage stage(size, offset, endianed); + _stages.push_back(stage); } -bool SaveLoad::save(SaveType type, int16 dataVar, int32 size, int32 offset) { - switch (type) { - case kSaveNone: - return false; - break; +int StagedSave::findStage(int16 dataVar, int32 size, int32 offset) const { + for (uint i = 0; i < _stages.size(); i++) + if ((_stages[i].size == size) && + (_stages[i].offset == offset)) + return i; + + return -1; +} - case kSaveGame: - return saveGame(dataVar, size, offset); - break; +bool StagedSave::allSaved() const { + for (uint i = 0; i < _stages.size(); i++) + if (!_stages[i].bufVar) + return false; - case kSaveTempSprite: - return saveTempSprite(dataVar, size, offset); - break; + return true; +} - case kSaveNotes: - return saveNotes(dataVar, size, offset); - break; +uint32 StagedSave::getSize() const { + uint32 size = 0; - case kSaveScreenshot: - return saveScreenshot(dataVar, size, offset); - break; + for (uint i = 0; i < _stages.size(); i++) { + if (_stages[i].endianed) + size += 2 * _stages[i].size; + else + size += _stages[i].size; + } + + return size; +} - case kSaveIgnore: - return true; - break; +void StagedSave::clear() { + for (uint i = 0; i < _stages.size(); i++) { + delete[] _stages[i].bufVar; + delete[] _stages[i].bufVarSizes; + _stages[i].bufVar = 0; + _stages[i].bufVarSizes = 0; } - return false; + delete[] _name; + _name = 0; + + _mode = kModeNone; + _loaded = false; } -int32 SaveLoad::getSizeTempSprite() { - return _tempSpriteSize; +void StagedSave::assertMode(Mode mode, const char *name) { + if ((_mode != mode) || ((name[0] != '\0') && strcmp(_name, name))) { + clear(); + _mode = mode; + _name = new char[strlen(name) + 1]; + strcpy(_name, name); + } } -bool SaveLoad::loadTempSprite(int16 dataVar, int32 size, int32 offset) { - int index; - bool readPal; +bool StagedSave::save(int16 dataVar, int32 size, int32 offset, const char *name, + const byte *variables, const byte *variableSizes) { - if (size >= 0) { - warning("Invalid attempt at loading from the temporary sprite"); + if ((dataVar < 0) || (size <= 0) || (offset < 0)) { + warning("Invalid dataVar (%d), size (%d) or offset (%d)", dataVar, size, offset); return false; } - index = getSpriteIndex(size); - readPal = getSpritePalette(size); + int stage = findStage(dataVar, size, offset); + if (stage == -1) { + warning("Invalid saving procedure"); + return false; + } - if ((index < 0) || (index >= SPRITES_COUNT)) { - warning("Index out of range while loading from the temporary " - "sprite (%d)", index); + if (!variables || (_stages[stage].endianed && !variableSizes)) { + warning("Missing data"); return false; } - return loadTempSprite(index, readPal); -} + assertMode(kModeSave, name); -bool SaveLoad::saveTempSprite(int16 dataVar, int32 size, int32 offset) { - int index; - bool readPal; + _stages[stage].bufVar = new byte[size]; + memcpy(_stages[stage].bufVar, variables + dataVar, size); - if (size >= 0) { - warning("Invalid attempt at saving to the temporary sprite"); - return false; + if (_stages[stage].endianed) { + _stages[stage].bufVarSizes = new byte[size]; + memcpy(_stages[stage].bufVarSizes, variableSizes + dataVar, size); } - index = getSpriteIndex(size); - readPal = getSpritePalette(size); - - if ((index < 0) || (index >= SPRITES_COUNT)) { - warning("Index out of range while saving to the temporary sprite (%d)", - index); - return false; + if (allSaved()) { + bool result = write(); + clear(); + return result; } - return saveTempSprite(index, readPal); + return true; } -bool SaveLoad::loadTempSprite(uint32 index, bool palette) { - SurfaceDesc *sprite; +bool StagedSave::load(int16 dataVar, int32 size, int32 offset, const char *name, + byte *variables, byte *variableSizes) { - if (palette) { - memcpy((char *) _vm->_global->_pPaletteDesc->vgaPal, - (char *) _tempPal, 768); - _vm->_video->setFullPalette(_vm->_global->_pPaletteDesc); - } - - sprite = _vm->_draw->_spritesArray[index]; - - if (!sprite) { - warning("Couldn't load from the temporary sprite: " - "No such sprite %d", index); + if ((dataVar < 0) || (size <= 0) || (offset < 0)) { + warning("Invalid dataVar (%d), size (%d) or offset (%d)", dataVar, size, offset); return false; } - if ((sprite->getWidth() != _tempSprite->getWidth()) || - (sprite->getHeight() != _tempSprite->getHeight())) { - warning("Resolution doesn't match while loading from the " - "temporary sprite (%d: %dx%d vs. %dx%d)", index, - sprite->getWidth(), sprite->getHeight(), - _tempSprite->getWidth(), _tempSprite->getHeight()); + int stage = findStage(dataVar, size, offset); + if (stage == -1) { + warning("Invalid loading procedure"); return false; } - _vm->_video->drawSprite(_tempSprite, sprite, 0, 0, - sprite->getWidth() - 1, sprite->getHeight() - 1, 0, 0, 0); + assertMode(kModeLoad, name); - if (index == 21) { - _vm->_draw->forceBlit(); - _vm->_video->retrace(); + if (!_loaded) { + if (!read()) { + clear(); + return false; + } } + if (variables) + memcpy(variables + dataVar, _stages[stage].bufVar, size); + if (_stages[stage].endianed && variableSizes) + memcpy(variableSizes + dataVar, _stages[stage].bufVarSizes, size); + return true; } -bool SaveLoad::saveTempSprite(uint32 index, bool palette) { - SurfaceDesc *sprite = _vm->_draw->_spritesArray[index]; +bool StagedSave::write() const { + Common::SaveFileManager *saveMan = g_system->getSavefileManager(); + Common::OutSaveFile *out = saveMan->openForSaving(_name); - if (!sprite) { - warning("Couldn't save to the temporary sprite: " - "No such sprite %d", index); + if (!out) { + warning("Can't open file \"%s\" for writing", _name); return false; } - delete _tempSprite; - _tempSprite = _vm->_video->initSurfDesc(_vm->_global->_videoMode, - sprite->getWidth(), sprite->getHeight(), 0); + bool result = true; + for (uint i = 0; (i < _stages.size()) && result; i++) { + if (!_stages[i].endianed) { - _vm->_video->drawSprite(sprite, _tempSprite, 0, 0, - sprite->getWidth() - 1, sprite->getHeight() - 1, 0, 0, 0); + uint32 written = out->write(_stages[i].bufVar, _stages[i].size); - _tempSpriteSize = _vm->_draw->getSpriteRectSize(index); + result = (written == ((uint32) _stages[i].size)); + if (!result) + warning("Can't write data: requested %d, wrote %d", _stages[i].size, written); - if (palette) { - memcpy((char *) _tempPal, - (char *) _vm->_global->_pPaletteDesc->vgaPal, 768); - _tempSpriteSize += 768; + } else + result = SaveLoad::saveDataEndian(*out, 0, _stages[i].size, + _stages[i].bufVar, _stages[i].bufVarSizes); } - return true; + if (result) { + out->finalize(); + if (out->ioFailed()) { + warning("Can't write to file \"%s\"", _name); + result = false; + } + } + + delete out; + return result; } -bool SaveLoad::loadSprite(Common::ReadStream &in, int32 size) { - SurfaceDesc *sprite; - byte *buf; - int nRead; - int index; - bool readPal; +bool StagedSave::read() { + Common::SaveFileManager *saveMan = g_system->getSavefileManager(); + Common::InSaveFile *in = saveMan->openForLoading(_name); - if (size >= 0) { - warning("Invalid attempt at loading a sprite"); + if (!in) { + warning("Can't open file \"%s\" for reading", _name); return false; } - index = getSpriteIndex(size); - readPal = getSpritePalette(size); - - if ((index < 0) || (index >= SPRITES_COUNT)) { - warning("Index out of range while loading a sprite (%d)", - index); + uint32 saveSize = getSize(); + if (in->size() != saveSize) { + warning("Wrong size (%d != %d)", in->size(), saveSize); return false; } - size = _vm->_draw->getSpriteRectSize(index); - sprite = _vm->_draw->_spritesArray[index]; + bool result = true; + for (uint i = 0; ((i < _stages.size()) && result); i++) { + _stages[i].bufVar = new byte[_stages[i].size]; - if (!sprite) { - warning("Couldn't load sprite: No such sprite %d", index); - return false; - } + if (!_stages[i].endianed) { - buf = new byte[MAX<int>(768, size)]; - assert(buf); + uint32 nRead = in->read(_stages[i].bufVar, _stages[i].size); - if (readPal) { - nRead = in.read(buf, 768); - if (nRead != 768) { - warning("Couldn't read a palette: requested 768, got %d", nRead); - delete[] buf; - return false; - } + result = (nRead == ((uint32) _stages[i].size)); + if (!result) + warning("Can't read data: requested %d, got %d", _stages[i].size, nRead); - memcpy((char *) _vm->_global->_pPaletteDesc->vgaPal, - (char *) buf, 768); - _vm->_video->setFullPalette(_vm->_global->_pPaletteDesc); - } + } else { + _stages[i].bufVarSizes = new byte[_stages[i].size]; - nRead = in.read(buf, size); - if (nRead != size) { - warning("Couldn't read sprite data: requested %d, got %d", size, nRead); - delete[] buf; - return false; + result = SaveLoad::loadDataEndian(*in, 0, _stages[i].size, + _stages[i].bufVar, _stages[i].bufVarSizes); + } } - memcpy((char *) sprite->getVidMem(), buf, size); + if (result) + _loaded = true; - delete[] buf; - return true; + delete in; + return result; } -bool SaveLoad::saveSprite(Common::WriteStream &out, int32 size) { - SurfaceDesc *sprite; - int written; - int index; - bool readPal; - if (size >= 0) { - warning("Invalid attempt at saving a sprite"); - return false; - } +SaveLoad::SaveLoad(GobEngine *vm, const char *targetName) : _vm(vm) { - index = getSpriteIndex(size); - readPal = getSpritePalette(size); + _targetName = new char[strlen(targetName) + 1]; + strcpy(_targetName, targetName); +} - if ((index < 0) || (index >= SPRITES_COUNT)) { - warning("Index out of range while saving a sprite (%d)", - index); - return false; - } +SaveLoad::~SaveLoad() { + delete[] _targetName; +} + +int32 SaveLoad::getSize(const char *fileName) { + int type; + + type = getSaveType(stripPath(fileName)); + if (type == -1) + return -1; + + debugC(3, kDebugSaveLoad, "Requested size of save file \"%s\" (type %d)", + fileName, type); + + return getSizeVersioned(type); +} - size = _vm->_draw->getSpriteRectSize(index); - sprite = _vm->_draw->_spritesArray[index]; +bool SaveLoad::load(const char *fileName, int16 dataVar, int32 size, int32 offset) { + int type; - if (!sprite) { - warning("Couldn't save sprite: No such sprite %d", index); + type = getSaveType(stripPath(fileName)); + if (type == -1) return false; - } - if (readPal) { - written = out.write((char *) _vm->_global->_pPaletteDesc->vgaPal, 768); - if (written != 768) { - warning("Couldn't write a palette: requested 768, wrote %d", written); - return false; - } - } + debugC(3, kDebugSaveLoad, "Requested loading of save file \"%s\" (type %d) - %d, %d, %d", + fileName, type, dataVar, size, offset); - written = out.write((char *) sprite->getVidMem(), size); - if (written != size) { - warning("Couldn't write a sprite: requested %d, wrote %d", - size, written); + return loadVersioned(type, dataVar, size, offset); +} + +bool SaveLoad::save(const char *fileName, int16 dataVar, int32 size, int32 offset) { + int type; + + type = getSaveType(stripPath(fileName)); + if (type == -1) return false; - } - return true; + debugC(3, kDebugSaveLoad, "Requested saving of save file \"%s\" (type %d) - %d, %d, %d", + fileName, type, dataVar, size, offset); + + return saveVersioned(type, dataVar, size, offset); +} + +const char *SaveLoad::stripPath(const char *fileName) { + const char *backSlash; + if ((backSlash = strrchr(fileName, '\\'))) + return backSlash + 1; + + return fileName; +} + +char *SaveLoad::setCurrentSlot(char *destName, int slot) { + char *slotBase = destName + strlen(destName) - 2; + + snprintf(slotBase, 3, "%02d", slot); + + return destName; +} + +void SaveLoad::buildIndex(byte *buffer, char *name, int n, int32 size, int32 offset) { + Common::SaveFileManager *saveMan = g_system->getSavefileManager(); + Common::InSaveFile *in; + + for (int i = 0; i < n; i++, buffer += size) { + in = saveMan->openForLoading(setCurrentSlot(name, i)); + if (in) { + in->seek(offset); + in->read(buffer, size); + delete in; + } else + memset(buffer, 0, size); + } } bool SaveLoad::fromEndian(byte *buf, const byte *sizes, uint32 count) { @@ -514,4 +551,89 @@ bool SaveLoad::toEndian(byte *buf, const byte *sizes, uint32 count) { return true; } +uint32 SaveLoad::read(Common::ReadStream &in, + byte *buf, byte *sizes, uint32 count) { + uint32 nRead; + + nRead = in.read(buf, count); + if (nRead != count) { + warning("Can't read data: requested %d, got %d", count, nRead); + return 0; + } + + nRead = in.read(sizes, count); + if (nRead != count) { + warning("Can't read data sizes: requested %d, got %d", count, nRead); + return 0; + } + + return count; +} + +uint32 SaveLoad::write(Common::WriteStream &out, + const byte *buf, const byte *sizes, uint32 count) { + uint32 written; + + written = out.write(buf, count); + if (written != count) { + warning("Can't write data: requested %d, wrote %d", count, written); + return 0; + } + + written = out.write(sizes, count); + if (written != count) { + warning("Can't write data: requested %d, wrote %d", count, written); + return 0; + } + + return count; +} + +bool SaveLoad::loadDataEndian(Common::ReadStream &in, + int16 dataVar, uint32 size, byte *variables, byte *variableSizes) { + + bool retVal = false; + + byte *varBuf = new byte[size]; + byte *sizeBuf = new byte[size]; + + assert(varBuf && sizeBuf); + + if (read(in, varBuf, sizeBuf, size) == size) { + if (fromEndian(varBuf, sizeBuf, size)) { + memcpy(variables + dataVar, varBuf, size); + memcpy(variableSizes + dataVar, sizeBuf, size); + retVal = true; + } + } + + delete[] varBuf; + delete[] sizeBuf; + + return retVal; +} + +bool SaveLoad::saveDataEndian(Common::WriteStream &out, + int16 dataVar, uint32 size, const byte *variables, const byte *variableSizes) { + + bool retVal = false; + + byte *varBuf = new byte[size]; + byte *sizeBuf = new byte[size]; + + assert(varBuf && sizeBuf); + + memcpy(varBuf, variables + dataVar, size); + memcpy(sizeBuf, variableSizes + dataVar, size); + + if (toEndian(varBuf, sizeBuf, size)) + if (write(out, varBuf, sizeBuf, size) == size) + retVal = true; + + delete[] varBuf; + delete[] sizeBuf; + + return retVal; +} + } // End of namespace Gob |