[Scummvm-cvs-logs] SF.net SVN: scummvm: [22182] scummvm/trunk/engines/scumm
fingolfin at users.sourceforge.net
fingolfin at users.sourceforge.net
Wed Apr 26 07:06:03 CEST 2006
Revision: 22182
Author: fingolfin
Date: 2006-04-26 07:05:09 -0700 (Wed, 26 Apr 2006)
ViewCVS: http://svn.sourceforge.net/scummvm/?rev=22182&view=rev
Log Message:
-----------
Replaced _hFileTable by _hInFileTable/_hOutFileTable
Modified Paths:
--------------
scummvm/trunk/engines/scumm/he/intern_he.h
scummvm/trunk/engines/scumm/he/script_v100he.cpp
scummvm/trunk/engines/scumm/he/script_v60he.cpp
scummvm/trunk/engines/scumm/he/script_v72he.cpp
scummvm/trunk/engines/scumm/scumm.cpp
Modified: scummvm/trunk/engines/scumm/he/intern_he.h
===================================================================
--- scummvm/trunk/engines/scumm/he/intern_he.h 2006-04-26 13:12:33 UTC (rev 22181)
+++ scummvm/trunk/engines/scumm/he/intern_he.h 2006-04-26 14:05:09 UTC (rev 22182)
@@ -30,6 +30,11 @@
#include "scumm/he/wiz_he.h"
#endif
+namespace Common {
+class SeekableReadStream;
+class WriteStream;
+}
+
namespace Scumm {
#ifndef DISABLE_HE
@@ -49,7 +54,9 @@
const OpcodeEntryv60he *_opcodesv60he;
public:
- Common::File _hFileTable[17];
+ //Common::File _hFileTable[17];
+ Common::SeekableReadStream *_hInFileTable[17];
+ Common::WriteStream *_hOutFileTable[17];
int _heTimers[16];
int getHETimer(int timer);
@@ -57,6 +64,7 @@
public:
ScummEngine_v60he(OSystem *syst, const DetectorResult &dr);
+ ~ScummEngine_v60he();
virtual void scummInit();
Modified: scummvm/trunk/engines/scumm/he/script_v100he.cpp
===================================================================
--- scummvm/trunk/engines/scumm/he/script_v100he.cpp 2006-04-26 13:12:33 UTC (rev 22181)
+++ scummvm/trunk/engines/scumm/he/script_v100he.cpp 2006-04-26 14:05:09 UTC (rev 22182)
@@ -2308,19 +2308,20 @@
byte subOp = fetchScriptByte();
+ assert(_hOutFileTable[slot]);
switch (subOp) {
case 5:
fetchScriptByte();
writeFileFromArray(slot, resID);
break;
case 42:
- _hFileTable[slot].writeUint16LE(resID);
+ _hOutFileTable[slot]->writeUint16LE(resID);
break;
case 43:
- _hFileTable[slot].writeUint32LE(resID);
+ _hOutFileTable[slot]->writeUint32LE(resID);
break;
case 45:
- _hFileTable[slot].writeByte(resID);
+ _hOutFileTable[slot]->writeByte(resID);
break;
default:
error("o100_writeFile: default case %d", subOp);
@@ -2618,17 +2619,20 @@
break;
case 42:
slot = pop();
- val = _hFileTable[slot].readUint16LE();
+ assert(_hInFileTable[slot]);
+ val = _hInFileTable[slot]->readUint16LE();
push(val);
break;
case 43:
slot = pop();
- val = _hFileTable[slot].readUint32LE();
+ assert(_hInFileTable[slot]);
+ val = _hInFileTable[slot]->readUint32LE();
push(val);
break;
case 45:
slot = pop();
- val = _hFileTable[slot].readByte();
+ assert(_hInFileTable[slot]);
+ val = _hInFileTable[slot]->readByte();
push(val);
break;
default:
Modified: scummvm/trunk/engines/scumm/he/script_v60he.cpp
===================================================================
--- scummvm/trunk/engines/scumm/he/script_v60he.cpp 2006-04-26 13:12:33 UTC (rev 22181)
+++ scummvm/trunk/engines/scumm/he/script_v60he.cpp 2006-04-26 14:05:09 UTC (rev 22182)
@@ -985,7 +985,7 @@
}
void ScummEngine_v60he::o60_openFile() {
- int mode, len, slot, l, r;
+ int mode, len, slot, i, r;
byte filename[100];
convertMessageToString(_scriptPointer, filename, sizeof(filename));
@@ -1000,9 +1000,9 @@
mode = pop();
slot = -1;
- for (l = 0; l < 17; l++) {
- if (_hFileTable[l].isOpen() == false) {
- slot = l;
+ for (i = 0; i < 17; i++) {
+ if (_hInFileTable[i] == 0 && _hOutFileTable[i] == 0) {
+ slot = i;
break;
}
}
@@ -1010,18 +1010,25 @@
if (slot != -1) {
switch(mode) {
case 1:
- _hFileTable[slot].open((char*)filename + r, Common::File::kFileReadMode, _saveFileMan->getSavePath());
- if (_hFileTable[slot].isOpen() == false)
- _hFileTable[slot].open((char*)filename + r, Common::File::kFileReadMode);
+ // TODO / FIXME: Consider using listSavefiles to avoid unneccessary openForLoading calls
+ _hInFileTable[slot] = _saveFileMan->openForLoading((char*)filename + r);
+ if (_hInFileTable[slot] == 0) {
+ Common::File *f = new Common::File();
+ f->open((char*)filename + r, Common::File::kFileReadMode);
+ if (!f->isOpen())
+ delete f;
+ else
+ _hInFileTable[slot] = f;
+ }
break;
case 2:
- _hFileTable[slot].open((char*)filename + r, Common::File::kFileWriteMode, _saveFileMan->getSavePath());
+ _hOutFileTable[slot] = _saveFileMan->openForSaving((char*)filename + r);
break;
default:
error("o60_openFile(): wrong open file mode %d", mode);
}
- if (_hFileTable[slot].isOpen() == false)
+ if (_hInFileTable[slot] == 0 && _hOutFileTable[slot] == 0)
slot = -1;
}
@@ -1030,8 +1037,12 @@
void ScummEngine_v60he::o60_closeFile() {
int slot = pop();
- if (slot != -1)
- _hFileTable[slot].close();
+ if (0 <= slot && slot < 17) {
+ delete _hInFileTable[slot];
+ delete _hOutFileTable[slot];
+ _hInFileTable[slot] = 0;
+ _hOutFileTable[slot] = 0;
+ }
}
void ScummEngine_v60he::o60_deleteFile() {
@@ -1079,13 +1090,13 @@
}
int ScummEngine_v60he::readFileToArray(int slot, int32 size) {
+ assert(_hInFileTable[slot]);
if (size == 0)
- size = _hFileTable[slot].size() - _hFileTable[slot].pos();
+ size = _hInFileTable[slot]->size() - _hInFileTable[slot]->pos();
writeVar(0, 0);
-
ArrayHeader *ah = defineArray(0, kByteArray, 0, size);
- _hFileTable[slot].read(ah->data, size);
+ _hInFileTable[slot]->read(ah->data, size);
return readVar(0);
}
@@ -1099,11 +1110,12 @@
if ((_game.platform == Common::kPlatformPC) && (_game.id == GID_FBEAR))
size = -size;
+ assert(_hInFileTable[slot]);
if (size == -2) {
- val = _hFileTable[slot].readUint16LE();
+ val = _hInFileTable[slot]->readUint16LE();
push(val);
} else if (size == -1) {
- val = _hFileTable[slot].readByte();
+ val = _hInFileTable[slot]->readByte();
push(val);
} else {
val = readFileToArray(slot, size);
@@ -1115,7 +1127,8 @@
ArrayHeader *ah = (ArrayHeader *)getResourceAddress(rtString, resID);
int32 size = FROM_LE_16(ah->dim1) * FROM_LE_16(ah->dim2);
- _hFileTable[slot].write(ah->data, size);
+ assert(_hOutFileTable[slot]);
+ _hOutFileTable[slot]->write(ah->data, size);
}
void ScummEngine_v60he::o60_writeFile() {
@@ -1127,10 +1140,11 @@
if ((_game.platform == Common::kPlatformPC) && (_game.id == GID_FBEAR))
size = -size;
+ assert(_hOutFileTable[slot]);
if (size == -2) {
- _hFileTable[slot].writeUint16LE(resID);
+ _hOutFileTable[slot]->writeUint16LE(resID);
} else if (size == -1) {
- _hFileTable[slot].writeByte(resID);
+ _hOutFileTable[slot]->writeByte(resID);
} else {
writeFileFromArray(slot, resID);
}
@@ -1183,15 +1197,16 @@
if (slot == -1)
return;
+ assert(_hInFileTable[slot]);
switch (mode) {
case 1:
- _hFileTable[slot].seek(offset, SEEK_SET);
+ _hInFileTable[slot]->seek(offset, SEEK_SET);
break;
case 2:
- _hFileTable[slot].seek(offset, SEEK_CUR);
+ _hInFileTable[slot]->seek(offset, SEEK_CUR);
break;
case 3:
- _hFileTable[slot].seek(offset, SEEK_END);
+ _hInFileTable[slot]->seek(offset, SEEK_END);
break;
default:
error("o60_seekFilePos: default case %d", mode);
@@ -1206,7 +1221,8 @@
return;
}
- push(_hFileTable[slot].pos());
+ assert(_hInFileTable[slot]);
+ push(_hInFileTable[slot]->pos());
}
void ScummEngine_v60he::o60_redimArray() {
Modified: scummvm/trunk/engines/scumm/he/script_v72he.cpp
===================================================================
--- scummvm/trunk/engines/scumm/he/script_v72he.cpp 2006-04-26 13:12:33 UTC (rev 22181)
+++ scummvm/trunk/engines/scumm/he/script_v72he.cpp 2006-04-26 14:05:09 UTC (rev 22182)
@@ -1722,7 +1722,7 @@
slot = -1;
for (i = 1; i < 17; i++) {
- if (_hFileTable[i].isOpen() == false) {
+ if (_hInFileTable[i] == 0 && _hOutFileTable[i] == 0) {
slot = i;
break;
}
@@ -1731,18 +1731,25 @@
if (slot != -1) {
switch(mode) {
case 1:
- _hFileTable[slot].open((char*)filename + r, Common::File::kFileReadMode, _saveFileMan->getSavePath());
- if (_hFileTable[slot].isOpen() == false)
- _hFileTable[slot].open((char*)filename + r, Common::File::kFileReadMode, _gameDataPath.c_str());
+ // TODO / FIXME: Consider using listSavefiles to avoid unneccessary openForLoading calls
+ _hInFileTable[slot] = _saveFileMan->openForLoading((char*)filename + r);
+ if (_hInFileTable[slot] == 0) {
+ Common::File *f = new Common::File();
+ f->open((char*)filename + r, Common::File::kFileReadMode);
+ if (!f->isOpen())
+ delete f;
+ else
+ _hInFileTable[slot] = f;
+ }
break;
case 2:
- _hFileTable[slot].open((char*)filename + r, Common::File::kFileWriteMode, _saveFileMan->getSavePath());
+ _hOutFileTable[slot] = _saveFileMan->openForSaving((char*)filename + r);
break;
default:
error("o72_openFile(): wrong open file mode %d", mode);
}
- if (_hFileTable[slot].isOpen() == false)
+ if (_hInFileTable[slot] == 0 && _hOutFileTable[slot] == 0)
slot = -1;
}
@@ -1751,15 +1758,14 @@
}
int ScummEngine_v72he::readFileToArray(int slot, int32 size) {
+ assert(_hInFileTable[slot]);
if (size == 0)
- size = _hFileTable[slot].size() - _hFileTable[slot].pos();
+ size = _hInFileTable[slot]->size() - _hInFileTable[slot]->pos();
writeVar(0, 0);
ArrayHeader *ah = defineArray(0, kByteArray, 0, 0, 0, size);
+ _hInFileTable[slot]->read(ah->data, size + 1);
- if (_hFileTable[slot].isOpen())
- _hFileTable[slot].read(ah->data, size + 1);
-
return readVar(0);
}
@@ -1771,17 +1777,20 @@
switch (subOp) {
case 4:
slot = pop();
- val = _hFileTable[slot].readByte();
+ assert(_hInFileTable[slot]);
+ val = _hInFileTable[slot]->readByte();
push(val);
break;
case 5:
slot = pop();
- val = _hFileTable[slot].readUint16LE();
+ assert(_hInFileTable[slot]);
+ val = _hInFileTable[slot]->readUint16LE();
push(val);
break;
case 6:
slot = pop();
- val = _hFileTable[slot].readUint32LE();
+ assert(_hInFileTable[slot]);
+ val = _hInFileTable[slot]->readUint32LE();
push(val);
break;
case 8:
@@ -1801,7 +1810,8 @@
int32 size = (FROM_LE_32(ah->dim1end) - FROM_LE_32(ah->dim1start) + 1) *
(FROM_LE_32(ah->dim2end) - FROM_LE_32(ah->dim2start) + 1);
- _hFileTable[slot].write(ah->data, size);
+ assert(_hOutFileTable[slot]);
+ _hOutFileTable[slot]->write(ah->data, size);
}
void ScummEngine_v72he::o72_writeFile() {
@@ -1809,15 +1819,16 @@
int slot = pop();
byte subOp = fetchScriptByte();
+ assert(_hOutFileTable[slot]);
switch (subOp) {
case 4:
- _hFileTable[slot].writeByte(resID);
+ _hOutFileTable[slot]->writeByte(resID);
break;
case 5:
- _hFileTable[slot].writeUint16LE(resID);
+ _hOutFileTable[slot]->writeUint16LE(resID);
break;
case 6:
- _hFileTable[slot].writeUint32LE(resID);
+ _hOutFileTable[slot]->writeUint32LE(resID);
break;
case 8:
fetchScriptByte();
Modified: scummvm/trunk/engines/scumm/scumm.cpp
===================================================================
--- scummvm/trunk/engines/scumm/scumm.cpp 2006-04-26 13:12:33 UTC (rev 22181)
+++ scummvm/trunk/engines/scumm/scumm.cpp 2006-04-26 14:05:09 UTC (rev 22182)
@@ -799,9 +799,18 @@
ScummEngine_v60he::ScummEngine_v60he(OSystem *syst, const DetectorResult &dr)
: ScummEngine_v6(syst, dr) {
+ memset(_hInFileTable, 0, sizeof(_hInFileTable));
+ memset(_hOutFileTable, 0, sizeof(_hOutFileTable));
memset(_heTimers, 0, sizeof(_heTimers));
}
+ScummEngine_v60he::~ScummEngine_v60he() {
+ for (int i = 0; i < 17; ++i) {
+ delete _hInFileTable[i];
+ delete _hOutFileTable[i];
+ }
+}
+
#ifndef DISABLE_HE
ScummEngine_v70he::ScummEngine_v70he(OSystem *syst, const DetectorResult &dr)
: ScummEngine_v60he(syst, dr) {
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