PINK: file code cleanup

This commit is contained in:
whiterandrek 2018-06-14 20:43:59 +03:00 committed by Eugene Sandulenko
parent e4402a90eb
commit bc4d32df8b
3 changed files with 15 additions and 28 deletions

View File

@ -20,10 +20,7 @@
*
*/
#include "common/str.h"
#include "pink/pink.h"
#include "pink/objects/pages/game_page.h"
namespace Pink {
@ -31,7 +28,7 @@ void ObjectDescription::load(Common::File &file) {
file.read(name, sizeof(name));
objectsOffset = file.readUint32LE();
objectsCount = file.readUint32LE();
/*objectsCount*/ file.readUint32LE();
resourcesOffset = file.readUint32LE();
resourcesCount = file.readUint32LE();
}
@ -44,10 +41,8 @@ void ResourceDescription::load(Common::File &file) {
inBro = (bool) file.readUint16LE();
}
OrbFile::OrbFile()
: File(), _timestamp(0),
_tableOffset(0),
_tableSize(0),
_table(nullptr) {}
@ -56,28 +51,24 @@ OrbFile::~OrbFile() {
}
bool OrbFile::open(const Common::String &name) {
if (!File::open(name))
return false;
if (readUint32BE() != 'ORB\0')
if (!File::open(name) || readUint32BE() != 'ORB\0')
return false;
uint16 minor = readUint16LE();
uint16 major = readUint16LE();
debug("Orb v%hu.%hu loaded", major, minor);
if (major != kOrbMajorVersion || minor != kOrbMinorVersion)
return false;
if (!(_timestamp = readUint32LE()))
return false;
_tableOffset = readUint32LE();
uint32 tableOffset = readUint32LE();
_tableSize = readUint32LE();
_table = new ObjectDescription[_tableSize];
seek(_tableOffset);
seek(tableOffset);
for (uint i = 0; i < _tableSize; ++i) {
_table[i].load(*this);
@ -115,7 +106,7 @@ ObjectDescription *OrbFile::getObjDesc(const char *name){
return desc;
}
ResourceDescription *OrbFile::getResDescTable(ObjectDescription *objDesc){
ResourceDescription *OrbFile::createResDescTable(ObjectDescription *objDesc){
ResourceDescription *table = new ResourceDescription[objDesc->resourcesCount];
seek(objDesc->resourcesOffset);
@ -131,7 +122,6 @@ void OrbFile::seekToObject(const char *name) {
seek(desc->objectsOffset);
}
bool BroFile::open(const Common::String &name, uint32 orbTimestamp) {
if (!File::open(name) || readUint32BE() != 'BRO\0')
return false;
@ -139,8 +129,6 @@ bool BroFile::open(const Common::String &name, uint32 orbTimestamp) {
uint16 minor = readUint16LE();
uint16 major = readUint16LE();
debug("Bro v%hu.%hu loaded", major, minor);
if (major != kBroMajorVersion || minor != kBroMinorVersion)
return false;

View File

@ -32,7 +32,7 @@ struct ObjectDescription {
char name[16];
uint32 objectsOffset;
uint32 objectsCount;
//uint32 objectsCount; never used
uint32 resourcesOffset;
uint32 resourcesCount;
};
@ -43,8 +43,7 @@ struct ResourceDescription {
char name[16];
uint32 offset;
uint32 size;
bool inBro; // in original it is short.
// Don't know what's better to use.(Perhaps no difference because of padding)
bool inBro;
};
class PinkEngine;
@ -56,28 +55,28 @@ public:
virtual ~OrbFile();
virtual bool open(const Common::String &name);
public:
void loadGame(PinkEngine *game);
void loadObject(Object *obj, const Common::String &name);
void loadObject(Object *obj, ObjectDescription *objDesc);
ResourceDescription *createResDescTable(ObjectDescription *objDesc);
ObjectDescription *getObjDesc(const char *name);
ResourceDescription *getResDescTable(ObjectDescription *objDesc);
uint32 getTimestamp() { return _timestamp; }
private:
void seekToObject(const char *name);
private:
ObjectDescription *_table;
uint32 _timestamp;
uint32 _tableOffset;
uint32 _tableSize;
uint32 _timestamp;
};
class BroFile : public Common::File {
public:
virtual bool open(const Common::String &name, uint32 orbTimestamp);
bool open(const Common::String &name, uint32 orbTimestamp);
};
} // End of namespace Pink

View File

@ -45,7 +45,7 @@ void ResourceMgr::init(PinkEngine *game, Page *page) {
ObjectDescription *objDesc = orb->getObjDesc(page->getName().c_str());
_resCount = objDesc->resourcesCount;
orb->loadObject(page, objDesc);
_resDescTable = orb->getResDescTable(objDesc);
_resDescTable = orb->createResDescTable(objDesc);
}
void ResourceMgr::clear() {