mirror of
https://github.com/libretro/scummvm.git
synced 2024-12-13 12:39:56 +00:00
use new operator instead of malloc() and added generic file loading function
svn-id: r10470
This commit is contained in:
parent
07fe952eef
commit
84ed3e272d
@ -23,7 +23,7 @@
|
||||
|
||||
QueenLogic::QueenLogic(QueenResource *resource) {
|
||||
_resource = resource;
|
||||
_jas = _resource->loadJAS();
|
||||
_jas = _resource->loadFile("QUEEN.JAS");
|
||||
|
||||
initialise();
|
||||
}
|
||||
@ -49,7 +49,8 @@ void QueenLogic::initialise() {
|
||||
|
||||
|
||||
//Object data
|
||||
_objectData = (uint16 (*)[8])malloc((_numObjects + 1) * sizeof(_objectData[0]));
|
||||
_objectData = new uint16[_numObjects + 1][8];
|
||||
|
||||
//clear first object
|
||||
for (uint16 j = 0; j < 8; j++)
|
||||
_objectData[0][j] = 0;
|
||||
@ -61,7 +62,7 @@ void QueenLogic::initialise() {
|
||||
}
|
||||
|
||||
//Room data
|
||||
_roomData = (uint16 *)malloc((_numRooms + 2) * sizeof(_roomData[0]));
|
||||
_roomData = new uint16[_numRooms + 2];
|
||||
for (uint16 i = 1; i < (_numRooms + 2); i++) {
|
||||
_roomData[i] = READ_BE_UINT16(ptr);
|
||||
ptr += 2;
|
||||
@ -70,7 +71,7 @@ void QueenLogic::initialise() {
|
||||
_roomData[_numRooms + 1] = _numObjects;
|
||||
|
||||
//SFX Name
|
||||
_sfxName = (uint16 *)malloc((_numRooms + 1) * sizeof(_sfxName[0]));
|
||||
_sfxName = new uint16[_numRooms + 1];
|
||||
for (uint16 i = 0; i < (_numRooms + 1); i++) {
|
||||
_sfxName[i] = READ_BE_UINT16(ptr);
|
||||
ptr += 2;
|
||||
@ -80,7 +81,8 @@ void QueenLogic::initialise() {
|
||||
_numItems = READ_BE_UINT16(ptr);
|
||||
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++) {
|
||||
_itemData[i][0] = READ_BE_UINT16(ptr);
|
||||
ptr += 2;
|
||||
@ -95,7 +97,7 @@ void QueenLogic::initialise() {
|
||||
_numGraphics = READ_BE_UINT16(ptr);
|
||||
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 j = 0; j < 5; j++) {
|
||||
@ -103,9 +105,9 @@ void QueenLogic::initialise() {
|
||||
ptr += 2;
|
||||
}
|
||||
|
||||
_objMax = (uint16 *)malloc((_numRooms + 1) * sizeof(_objMax[0]));
|
||||
_areaMax = (uint16 *)malloc((_numRooms + 1) * sizeof(_areaMax[0]));
|
||||
_area = (uint16 (*)[11][8])malloc((_numRooms + 1) * sizeof(_area[0]));
|
||||
_objMax = new uint16[_numRooms + 1];
|
||||
_areaMax = new uint16[_numRooms + 1];
|
||||
_area = new uint16[_numRooms + 1][11][8];
|
||||
/*
|
||||
for (uint16 i = 1; i < (_numRooms + 1); i++) {
|
||||
_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 j = 0; j < 4; j++) {
|
||||
_objectBox[i][j] = READ_BE_UINT16(ptr);
|
||||
|
@ -115,12 +115,13 @@ uint32 QueenResource::fileOffset(const char *filename) {
|
||||
return _gameVersion->resourceTable[resourceIndex(filename)].offset;
|
||||
}
|
||||
|
||||
uint8 *QueenResource::loadJAS() {
|
||||
uint32 size = fileSize("QUEEN.JAS");
|
||||
uint8 *jas = (uint8 *)malloc(size);
|
||||
_resourceFile->seek(fileOffset("QUEEN.JAS") + 20, SEEK_SET);
|
||||
_resourceFile->read(jas, size - 20);
|
||||
return jas;
|
||||
uint8 *QueenResource::loadFile(const char *filename) {
|
||||
uint32 size = fileSize(filename);
|
||||
byte *mem = new byte[size];
|
||||
//skip 20 byte header
|
||||
_resourceFile->seek(fileOffset(filename) + 20, SEEK_SET);
|
||||
_resourceFile->read(mem, size - 20);
|
||||
return mem;
|
||||
}
|
||||
|
||||
const char *QueenResource::JASVersion() {
|
||||
|
@ -44,7 +44,7 @@ class QueenResource {
|
||||
public:
|
||||
QueenResource(char *datafilePath);
|
||||
~QueenResource(void);
|
||||
uint8 *loadJAS();
|
||||
uint8 *loadFile(const char *filename);
|
||||
|
||||
protected:
|
||||
File *_resourceFile;
|
||||
|
Loading…
Reference in New Issue
Block a user