X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Floader%2FObjectFile.h;h=178180a2f8c3eafe27926766cfe25b0c8546482c;hb=8c8061a4f8b88410d6d93c039afe6affc4b69cf2;hp=6a7d6773d6403016e7547e9bcf06c13ad4a15cc3;hpb=0f30d8254ff8b9e63795960ec031577cf68fbf95;p=l2e.git diff --git a/src/loader/ObjectFile.h b/src/loader/ObjectFile.h index 6a7d677..178180a 100644 --- a/src/loader/ObjectFile.h +++ b/src/loader/ObjectFile.h @@ -1,10 +1,3 @@ -/* - * ObjectFile.h - * - * Created on: Sep 15, 2012 - * Author: holy - */ - #ifndef LOADER_OBJECTFILE_H_ #define LOADER_OBJECTFILE_H_ @@ -12,95 +5,104 @@ namespace loader { -const int FORMAT_ID(1); - -struct ObjectFileHeader { - char ident[4]; - - int versionId; - - int exportsBegin; - int exportsEnd; - - int externalsBegin; - int externalsEnd; - - int exportStringsBegin; - int exportStringsEnd; - - int externalStringsBegin; - int externalStringsEnd; - - int imagesBegin; - int imagesEnd; - - int objectsBegin; - int objectsEnd; - - ObjectFileHeader(); -}; - -struct TypeOffset { - int typeId; - int begin; - int end; -}; +const unsigned int FORMAT_ID = 2; struct Export { - int nameOffset; - int typeId; - int dataOffset; + /// Offset of the identifier in the file. + unsigned int nameOffset; + /// Type ID of referenced object. + unsigned int typeId; + /// File-offset of the object's actual data. + unsigned int dataOffset; }; struct External { - int nameOffset; - int referenceOffset; - int inlined; + /// File-relative offset of the referenced object's + /// identifier. + unsigned int nameOffset; + /// Target position for linking/inlining. + unsigned int referenceOffset; + /// Nonzero if the object should be copied rather that + /// just writing a reference. + unsigned int inlined; }; -struct ImageProperties { - Uint32 flags; - int width; - int height; - int depth; - int pitch; - Uint32 rmask; - Uint32 gmask; - Uint32 bmask; - Uint32 amask; +struct Object { + unsigned int typeId; + unsigned int size; + char *RawObject(); + Object *Next(); }; -struct LoadedObjectFile { - char *allocPtr; - ObjectFileHeader *fileHeader; - - TypeOffset *typeOffsetsBegin; - TypeOffset *typeOffsetsEnd; - - Export *exportsBegin; - Export *exportsEnd; - - External *externalsBegin; - External *externalsEnd; - - char *exportStringsBegin; - char *exportStringsEnd; - - char *externalStringsBegin; - char *externalStringsEnd; - - char *imagesBegin; - char *imagesEnd; +struct Array { + unsigned int size; + bool ref; + char *Data(); + Array *Next(); +}; - char *objectsBegin; - char *objectsEnd; +struct ObjectFileHeader { + /// Has to be "L2E\n" + char ident[4]; - SDL_Surface **surfaces; - int surfaceCount; + /// Version ID of the object file format + /// For now it must match FORMAT_ID for the loader to be + /// able to read it. + /// Backwards compatibility might be implemented at some + /// point in the future, but don't bet on that ever + /// happening. + unsigned int versionId; + + /// File-relative offsets of the export section's begin + /// and end respectively. + /// Exports are named and typed addresses within the + /// file. This is essentially an array of Export structs. + unsigned int exportsBegin; + unsigned int exportsEnd; + + /// File-relative offsets of the externals section's + /// begin and end respectively. + /// Each external names an entity which must be linked in + /// for this object file to function properly. This is + /// essentially an array of External structs. + unsigned int externalsBegin; + unsigned int externalsEnd; + + /// File-relative offsets of the objet section's begin + /// and end respectively. + /// Each object begins with its type ID followed by its + /// size and finally the raw object data. + /// All referecte type fields should contain either a + /// file-relative offset or zero to indicate a null + /// reference. + /// This can be sen as a linked list where the next + /// object for a node can be obtained by adding the size + /// of to int and the object to the current node's + /// address. + unsigned int objectsBegin; + unsigned int objectsEnd; + + /// File-relative offsets of the array section's begin + /// and end respectively. + /// Each array consists of an unsigned integer indicating + /// its size followed by a boolean flag which is true if + /// the arrays consists of pointers followed by the data. + unsigned int arraysBegin; + unsigned int arraysEnd; - LoadedObjectFile(); + ObjectFileHeader(); - char *At(int offset) { return reinterpret_cast(fileHeader) + offset; } + /// Check if there are any problems with the file header. + /// Throws a std::runtime_error on failure. + void IntegrityCheck(unsigned int fileSize) const; + Export *ExportsBegin(); + Export *ExportsEnd(); + External *ExternalsBegin(); + External *ExternalsEnd(); + Object *ObjectsBegin(); + Object *ObjectsEnd(); + Array *ArraysBegin(); + Array *ArraysEnd(); }; struct LoadedExport { @@ -110,4 +112,4 @@ struct LoadedExport { } -#endif /* LOADER_OBJECTFILE_H_ */ +#endif