[Scummvm-cvs-logs] SF.net SVN: scummvm:[53651] scummvm/trunk/engines/saga
h00ligan at users.sourceforge.net
h00ligan at users.sourceforge.net
Wed Oct 20 22:53:32 CEST 2010
Revision: 53651
http://scummvm.svn.sourceforge.net/scummvm/?rev=53651&view=rev
Author: h00ligan
Date: 2010-10-20 20:53:32 +0000 (Wed, 20 Oct 2010)
Log Message:
-----------
SAGA: replace StringTable "::realloc" with Common::Array; reduce amount of memory for every string table
Modified Paths:
--------------
scummvm/trunk/engines/saga/actor.cpp
scummvm/trunk/engines/saga/resource_res.cpp
scummvm/trunk/engines/saga/saga.cpp
scummvm/trunk/engines/saga/saga.h
scummvm/trunk/engines/saga/scene.cpp
scummvm/trunk/engines/saga/script.cpp
scummvm/trunk/engines/saga/script.h
Modified: scummvm/trunk/engines/saga/actor.cpp
===================================================================
--- scummvm/trunk/engines/saga/actor.cpp 2010-10-20 20:46:52 UTC (rev 53650)
+++ scummvm/trunk/engines/saga/actor.cpp 2010-10-20 20:53:32 UTC (rev 53651)
@@ -296,7 +296,6 @@
debug(9, "Actor::~Actor()");
free(_pathCell);
- _actorsStrings.freeMem();
//release resources
freeProtagStates();
freeActorList();
Modified: scummvm/trunk/engines/saga/resource_res.cpp
===================================================================
--- scummvm/trunk/engines/saga/resource_res.cpp 2010-10-20 20:46:52 UTC (rev 53650)
+++ scummvm/trunk/engines/saga/resource_res.cpp 2010-10-20 20:53:32 UTC (rev 53651)
@@ -108,7 +108,7 @@
_vm->_actor->_protagonist->_sceneNumber = _metaResource.sceneIndex;
- _vm->_actor->_objectsStrings.freeMem();
+ _vm->_actor->_objectsStrings.clear();
_vm->_resource->loadResource(resourceContext, _metaResource.objectsStringsResourceID, resourcePointer, resourceLength);
_vm->loadStrings(_vm->_actor->_objectsStrings, resourcePointer, resourceLength);
@@ -142,7 +142,7 @@
_vm->_interface->_defPortraits.clear();
_vm->_sprite->loadList(_metaResource.protagFaceSpritesID, _vm->_interface->_defPortraits);
- _vm->_actor->_actorsStrings.freeMem();
+ _vm->_actor->_actorsStrings.clear();
_vm->_resource->loadResource(resourceContext, _metaResource.actorsStringsResourceID, resourcePointer, resourceLength);
_vm->loadStrings(_vm->_actor->_actorsStrings, resourcePointer, resourceLength);
Modified: scummvm/trunk/engines/saga/saga.cpp
===================================================================
--- scummvm/trunk/engines/saga/saga.cpp 2010-10-20 20:46:52 UTC (rev 53650)
+++ scummvm/trunk/engines/saga/saga.cpp 2010-10-20 20:53:32 UTC (rev 53651)
@@ -397,24 +397,22 @@
uint16 stringsCount;
size_t offset;
size_t prevOffset = 0;
- int i;
+ Common::Array<size_t> tempOffsets;
+ uint ui;
if (stringsLength == 0) {
error("SagaEngine::loadStrings() Error loading strings list resource");
}
- stringsTable.stringsPointer = (byte*)malloc(stringsLength);
- memcpy(stringsTable.stringsPointer, stringsPointer, stringsLength);
+ MemoryReadStreamEndian scriptS(stringsPointer, stringsLength, isBigEndian()); //TODO: get endianess from context
- MemoryReadStreamEndian scriptS(stringsTable.stringsPointer, stringsLength, isBigEndian()); //TODO: get endianess from context
-
offset = scriptS.readUint16();
stringsCount = offset / 2;
- stringsTable.strings = (const char **)malloc(stringsCount * sizeof(*stringsTable.strings));
- i = 0;
+ ui = 0;
scriptS.seek(0);
- while (i < stringsCount) {
+ tempOffsets.resize(stringsCount);
+ while (ui < stringsCount) {
offset = scriptS.readUint16();
// In some rooms in IHNM, string offsets can be greater than the maximum value than a 16-bit integer can hold
// We detect this by checking the previous offset, and if it was bigger than the current one, an overflow
@@ -424,33 +422,43 @@
offset += 65536;
prevOffset = offset;
if (offset == stringsLength) {
- stringsCount = i;
- const char **tmp = (const char **)realloc(stringsTable.strings, stringsCount * sizeof(*stringsTable.strings));
- if ((tmp != NULL) || (stringsCount == 0)) {
- stringsTable.strings = tmp;
- } else {
- error("SagaEngine::loadStrings() Error while reallocating memory");
- }
+ stringsCount = ui;
+ tempOffsets.resize(stringsCount);
break;
}
if (offset > stringsLength) {
// This case should never occur, but apparently it does in the Italian fan
// translation of IHNM
warning("SagaEngine::loadStrings wrong strings table");
- stringsCount = i;
- const char **tmp = (const char **)realloc(stringsTable.strings, stringsCount * sizeof(*stringsTable.strings));
- if ((tmp != NULL) || (stringsCount == 0)) {
- stringsTable.strings = tmp;
- } else {
- error("SagaEngine::loadStrings() Error while reallocating memory");
- }
+ stringsCount = ui;
+ tempOffsets.resize(stringsCount);
break;
}
- stringsTable.strings[i] = (const char *)stringsTable.stringsPointer + offset;
- debug(9, "string[%i]=%s", i, stringsTable.strings[i]);
- i++;
+ tempOffsets[ui] = offset;
+ ui++;
}
- stringsTable.stringsCount = stringsCount;
+
+ prevOffset = scriptS.pos();
+ int32 left = scriptS.size() - prevOffset;
+ if (left < 0) {
+ error("SagaEngine::loadStrings() Error loading strings buffer");
+ }
+
+ stringsTable.buffer.resize(left);
+ if (left > 0) {
+ scriptS.read(&stringsTable.buffer.front(), left);
+ }
+
+ stringsTable.strings.resize(tempOffsets.size());
+ for (ui = 0; ui < tempOffsets.size(); ui++) {
+ offset = tempOffsets[ui] - prevOffset;
+ if (offset >= stringsTable.buffer.size()) {
+ error("SagaEngine::loadStrings() Wrong offset");
+ }
+ stringsTable.strings[ui] = &stringsTable.buffer[offset];
+
+ debug(9, "string[%i]=%s", ui, stringsTable.strings[ui]);
+ }
}
const char *SagaEngine::getObjectName(uint16 objectId) {
Modified: scummvm/trunk/engines/saga/saga.h
===================================================================
--- scummvm/trunk/engines/saga/saga.h 2010-10-20 20:46:52 UTC (rev 53650)
+++ scummvm/trunk/engines/saga/saga.h 2010-10-20 20:53:32 UTC (rev 53651)
@@ -381,31 +381,22 @@
};
struct StringsTable {
- byte *stringsPointer;
- int stringsCount;
- const char **strings;
+ Common::Array<char> buffer;
+ Common::Array<char *> strings;
- const char *getString(int index) const {
- if ((stringsCount <= index) || (index < 0)) {
+ const char *getString(uint index) const {
+ if ((strings.size() <= index) || (index < 0)) {
// This occurs at the end of Ted's chapter, right after the ending cutscene
- warning("StringsTable::getString wrong index 0x%X (%d)", index, stringsCount);
+ warning("StringsTable::getString wrong index 0x%X (%d)", index, strings.size());
return "";
}
return strings[index];
}
- void freeMem() {
- free(strings);
- free(stringsPointer);
- memset(this, 0, sizeof(*this));
+ void clear() {
+ strings.clear();
+ buffer.clear();
}
-
- StringsTable() {
- memset(this, 0, sizeof(*this));
- }
- ~StringsTable() {
- freeMem();
- }
};
typedef Common::Array<Point> PointList;
Modified: scummvm/trunk/engines/saga/scene.cpp
===================================================================
--- scummvm/trunk/engines/saga/scene.cpp 2010-10-20 20:46:52 UTC (rev 53650)
+++ scummvm/trunk/engines/saga/scene.cpp 2010-10-20 20:53:32 UTC (rev 53651)
@@ -1249,7 +1249,7 @@
_objectMap->freeMem();
_actionMap->freeMem();
_entryList.freeMem();
- _sceneStrings.freeMem();
+ _sceneStrings.clear();
if (_vm->getGameId() == GID_ITE)
_vm->_isoMap->freeMem();
Modified: scummvm/trunk/engines/saga/script.cpp
===================================================================
--- scummvm/trunk/engines/saga/script.cpp 2010-10-20 20:46:52 UTC (rev 53650)
+++ scummvm/trunk/engines/saga/script.cpp 2010-10-20 20:53:32 UTC (rev 53651)
@@ -158,7 +158,6 @@
SAGA1Script::~SAGA1Script() {
debug(8, "Shutting down scripting subsystem.");
- _mainStrings.freeMem();
_globalVoiceLUT.freeMem();
freeModules();
Modified: scummvm/trunk/engines/saga/script.h
===================================================================
--- scummvm/trunk/engines/saga/script.h 2010-10-20 20:46:52 UTC (rev 53650)
+++ scummvm/trunk/engines/saga/script.h 2010-10-20 20:53:32 UTC (rev 53651)
@@ -159,7 +159,7 @@
StringsTable strings;
VoiceLUT voiceLUT;
void freeMem() {
- strings.freeMem();
+ strings.clear();
voiceLUT.freeMem();
free(moduleBase);
free(entryPoints);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Scummvm-git-logs
mailing list