MOHAWK: Turn MystView::scriptResources into a Common::Array

This commit is contained in:
Bastien Bouclet 2016-02-06 16:42:49 +01:00
parent 32f1ee73ad
commit a3064b9027
2 changed files with 47 additions and 51 deletions

View file

@ -90,9 +90,6 @@ MohawkEngine_Myst::MohawkEngine_Myst(OSystem *syst, const MohawkGameDescription
_cursorHints = nullptr; _cursorHints = nullptr;
_prevStack = nullptr; _prevStack = nullptr;
_view.scriptResCount = 0;
_view.scriptResources = nullptr;
} }
MohawkEngine_Myst::~MohawkEngine_Myst() { MohawkEngine_Myst::~MohawkEngine_Myst() {
@ -771,16 +768,16 @@ void MohawkEngine_Myst::loadCard() {
} }
// Resources that scripts can call upon // Resources that scripts can call upon
_view.scriptResCount = viewStream->readUint16LE(); uint16 scriptResCount = viewStream->readUint16LE();
debugC(kDebugView, "Script Resource Count: %d", _view.scriptResCount); debugC(kDebugView, "Script Resource Count: %d", scriptResCount);
if (_view.scriptResCount != 0) { for (uint16 i = 0; i < scriptResCount; i++) {
_view.scriptResources = new MystView::ScriptResource[_view.scriptResCount]; MystView::ScriptResource scriptResource;
for (uint16 i = 0; i < _view.scriptResCount; i++) {
debugC(kDebugView, "\tResource %d:", i);
_view.scriptResources[i].type = viewStream->readUint16LE();
debugC(kDebugView, "\t\t Type: %d", _view.scriptResources[i].type);
switch (_view.scriptResources[i].type) { debugC(kDebugView, "\tResource %d:", i);
scriptResource.type = viewStream->readUint16LE();
debugC(kDebugView, "\t\t Type: %d", scriptResource.type);
switch (scriptResource.type) {
case 1: case 1:
debugC(kDebugView, "\t\t\t\t= Image"); debugC(kDebugView, "\t\t\t\t= Image");
break; break;
@ -795,25 +792,26 @@ void MohawkEngine_Myst::loadCard() {
break; break;
} }
if (_view.scriptResources[i].type == 3) { if (scriptResource.type == 3) {
_view.scriptResources[i].var = viewStream->readUint16LE(); scriptResource.var = viewStream->readUint16LE();
debugC(kDebugView, "\t\t Var: %d", _view.scriptResources[i].var); debugC(kDebugView, "\t\t Var: %d", scriptResource.var);
_view.scriptResources[i].count = viewStream->readUint16LE(); scriptResource.count = viewStream->readUint16LE();
debugC(kDebugView, "\t\t Resource List Count: %d", _view.scriptResources[i].count); debugC(kDebugView, "\t\t Resource List Count: %d", scriptResource.count);
_view.scriptResources[i].u0 = viewStream->readUint16LE(); scriptResource.u0 = viewStream->readUint16LE();
debugC(kDebugView, "\t\t u0: %d", _view.scriptResources[i].u0); debugC(kDebugView, "\t\t u0: %d", scriptResource.u0);
_view.scriptResources[i].resource_list = new int16[_view.scriptResources[i].count]; scriptResource.resource_list = new int16[scriptResource.count];
for (uint16 j = 0; j < _view.scriptResources[i].count; j++) { for (uint16 j = 0; j < scriptResource.count; j++) {
_view.scriptResources[i].resource_list[j] = viewStream->readSint16LE(); scriptResource.resource_list[j] = viewStream->readSint16LE();
debugC(kDebugView, "\t\t Resource List %d: %d", j, _view.scriptResources[i].resource_list[j]); debugC(kDebugView, "\t\t Resource List %d: %d", j, scriptResource.resource_list[j]);
} }
} else { } else {
_view.scriptResources[i].resource_list = nullptr; scriptResource.resource_list = nullptr;
_view.scriptResources[i].id = viewStream->readUint16LE(); scriptResource.id = viewStream->readUint16LE();
debugC(kDebugView, "\t\t Id: %d", _view.scriptResources[i].id); debugC(kDebugView, "\t\t Id: %d", scriptResource.id);
}
} }
_view.scriptResources.push_back(scriptResource);
} }
// Identifiers for other resources. 0 if non existent. There is always an RLST. // Identifiers for other resources. 0 if non existent. There is always an RLST.
@ -854,8 +852,8 @@ void MohawkEngine_Myst::loadCard() {
} }
// Precache Script Resources // Precache Script Resources
if (_view.scriptResCount != 0) { if (_view.scriptResources.size() != 0) {
for (uint16 i = 0; i < _view.scriptResCount; i++) { for (uint16 i = 0; i < _view.scriptResources.size(); i++) {
switch (_view.scriptResources[i].type) { switch (_view.scriptResources[i].type) {
case 1: case 1:
cachePreload(cacheImageType, _view.scriptResources[i].id); cachePreload(cacheImageType, _view.scriptResources[i].id);
@ -878,12 +876,10 @@ void MohawkEngine_Myst::unloadCard() {
_view.conditionalImages.clear(); _view.conditionalImages.clear();
_view.soundList.clear(); _view.soundList.clear();
for (uint16 i = 0; i < _view.scriptResCount; i++) for (uint16 i = 0; i < _view.scriptResources.size(); i++)
delete[] _view.scriptResources[i].resource_list; delete[] _view.scriptResources[i].resource_list;
delete[] _view.scriptResources; _view.scriptResources.clear();
_view.scriptResources = nullptr;
_view.scriptResCount = 0;
} }
void MohawkEngine_Myst::runInitScript() { void MohawkEngine_Myst::runInitScript() {

View file

@ -132,7 +132,6 @@ struct MystView {
Common::Array<MystSoundItem> soundList; Common::Array<MystSoundItem> soundList;
// Script Resources // Script Resources
uint16 scriptResCount;
struct ScriptResource { struct ScriptResource {
uint16 type; uint16 type;
uint16 id; // Not used by type 3 uint16 id; // Not used by type 3
@ -141,7 +140,8 @@ struct MystView {
uint16 count; // Used by type 3 only uint16 count; // Used by type 3 only
uint16 u0; // Used by type 3 only uint16 u0; // Used by type 3 only
int16 *resource_list; // Used by type 3 only int16 *resource_list; // Used by type 3 only
} *scriptResources; };
Common::Array<ScriptResource> scriptResources;
// Resource ID's // Resource ID's
uint16 rlst; uint16 rlst;