use new operator instead of malloc() and added generic file loading function

svn-id: r10470
This commit is contained in:
Joost Peters 2003-09-28 19:57:01 +00:00
parent 07fe952eef
commit 84ed3e272d
3 changed files with 20 additions and 17 deletions

View File

@ -23,7 +23,7 @@
QueenLogic::QueenLogic(QueenResource *resource) { QueenLogic::QueenLogic(QueenResource *resource) {
_resource = resource; _resource = resource;
_jas = _resource->loadJAS(); _jas = _resource->loadFile("QUEEN.JAS");
initialise(); initialise();
} }
@ -49,7 +49,8 @@ void QueenLogic::initialise() {
//Object data //Object data
_objectData = (uint16 (*)[8])malloc((_numObjects + 1) * sizeof(_objectData[0])); _objectData = new uint16[_numObjects + 1][8];
//clear first object //clear first object
for (uint16 j = 0; j < 8; j++) for (uint16 j = 0; j < 8; j++)
_objectData[0][j] = 0; _objectData[0][j] = 0;
@ -61,7 +62,7 @@ void QueenLogic::initialise() {
} }
//Room data //Room data
_roomData = (uint16 *)malloc((_numRooms + 2) * sizeof(_roomData[0])); _roomData = new uint16[_numRooms + 2];
for (uint16 i = 1; i < (_numRooms + 2); i++) { for (uint16 i = 1; i < (_numRooms + 2); i++) {
_roomData[i] = READ_BE_UINT16(ptr); _roomData[i] = READ_BE_UINT16(ptr);
ptr += 2; ptr += 2;
@ -70,7 +71,7 @@ void QueenLogic::initialise() {
_roomData[_numRooms + 1] = _numObjects; _roomData[_numRooms + 1] = _numObjects;
//SFX Name //SFX Name
_sfxName = (uint16 *)malloc((_numRooms + 1) * sizeof(_sfxName[0])); _sfxName = new uint16[_numRooms + 1];
for (uint16 i = 0; i < (_numRooms + 1); i++) { for (uint16 i = 0; i < (_numRooms + 1); i++) {
_sfxName[i] = READ_BE_UINT16(ptr); _sfxName[i] = READ_BE_UINT16(ptr);
ptr += 2; ptr += 2;
@ -80,7 +81,8 @@ void QueenLogic::initialise() {
_numItems = READ_BE_UINT16(ptr); _numItems = READ_BE_UINT16(ptr);
ptr += 2; ptr += 2;
_itemData = (uint16 (*)[5])malloc((_numItems + 1) * sizeof(_itemData[0])); _itemData = new uint16[_numItems + 1][5];
for (uint16 i = 1; i < (_numItems + 1); i++) { for (uint16 i = 1; i < (_numItems + 1); i++) {
_itemData[i][0] = READ_BE_UINT16(ptr); _itemData[i][0] = READ_BE_UINT16(ptr);
ptr += 2; ptr += 2;
@ -95,7 +97,7 @@ void QueenLogic::initialise() {
_numGraphics = READ_BE_UINT16(ptr); _numGraphics = READ_BE_UINT16(ptr);
ptr += 2; ptr += 2;
_graphicData = (uint16 (*)[5])malloc((_numGraphics + 1) * sizeof(_graphicData[0])); _graphicData = new uint16[_numGraphics + 1][5];
for (uint16 i = 1; i < _numGraphics; i++) for (uint16 i = 1; i < _numGraphics; i++)
for (uint16 j = 0; j < 5; j++) { for (uint16 j = 0; j < 5; j++) {
@ -103,9 +105,9 @@ void QueenLogic::initialise() {
ptr += 2; ptr += 2;
} }
_objMax = (uint16 *)malloc((_numRooms + 1) * sizeof(_objMax[0])); _objMax = new uint16[_numRooms + 1];
_areaMax = (uint16 *)malloc((_numRooms + 1) * sizeof(_areaMax[0])); _areaMax = new uint16[_numRooms + 1];
_area = (uint16 (*)[11][8])malloc((_numRooms + 1) * sizeof(_area[0])); _area = new uint16[_numRooms + 1][11][8];
/* /*
for (uint16 i = 1; i < (_numRooms + 1); i++) { for (uint16 i = 1; i < (_numRooms + 1); i++) {
_objMax[i] = READ_BE_UINT16(ptr); _objMax[i] = READ_BE_UINT16(ptr);
@ -121,7 +123,7 @@ void QueenLogic::initialise() {
} }
_objectBox = (uint16 (*)[4])malloc((_numObjects + 1) * sizeof(_objectBox[0])); _objectBox = new uint16[_numObjects + 1][4];
for (uint16 i = 1; i < (_numObjects + 1); i++) for (uint16 i = 1; i < (_numObjects + 1); i++)
for (uint16 j = 0; j < 4; j++) { for (uint16 j = 0; j < 4; j++) {
_objectBox[i][j] = READ_BE_UINT16(ptr); _objectBox[i][j] = READ_BE_UINT16(ptr);

View File

@ -115,12 +115,13 @@ uint32 QueenResource::fileOffset(const char *filename) {
return _gameVersion->resourceTable[resourceIndex(filename)].offset; return _gameVersion->resourceTable[resourceIndex(filename)].offset;
} }
uint8 *QueenResource::loadJAS() { uint8 *QueenResource::loadFile(const char *filename) {
uint32 size = fileSize("QUEEN.JAS"); uint32 size = fileSize(filename);
uint8 *jas = (uint8 *)malloc(size); byte *mem = new byte[size];
_resourceFile->seek(fileOffset("QUEEN.JAS") + 20, SEEK_SET); //skip 20 byte header
_resourceFile->read(jas, size - 20); _resourceFile->seek(fileOffset(filename) + 20, SEEK_SET);
return jas; _resourceFile->read(mem, size - 20);
return mem;
} }
const char *QueenResource::JASVersion() { const char *QueenResource::JASVersion() {

View File

@ -44,7 +44,7 @@ class QueenResource {
public: public:
QueenResource(char *datafilePath); QueenResource(char *datafilePath);
~QueenResource(void); ~QueenResource(void);
uint8 *loadJAS(); uint8 *loadFile(const char *filename);
protected: protected:
File *_resourceFile; File *_resourceFile;