NXEngine v1.0.0.6
[NXEngine.git] / siflib / sifloader.h
blob643fcd54f9351f62de5d369fee01dc819a2bd611
2 #ifndef _SIFLOADER_H
3 #define _SIFLOADER_H
5 //#include "sif2.h"
6 #include "../common/BList.h"
7 #define SIF_MAX_GROUPS 255 // limitation of SECTION_GROUPS format
9 /*
10 the .sif file format is designed to hold a number of different sprite-related data
11 and to be extensible while still being able to read older versions of the files.
13 the .sif file is essentially a container format, with individual subclasses to decode
14 each specific section type.
16 sections can then contain additional subsections.
18 the main section, SIF_SECTION_SPRITES, is an array of sprites. For each sprite entry,
19 data typecodes denote a variable in the SIFSprite structure and it's value. Any values
20 not mentioned are set to default values when loaded. Values set to defaults are not saved.
24 enum
26 SIF_SECTION_SESSION, // holds SIFEdit session info such as last sprite edited
27 SIF_SECTION_SHEETS, // filenames of spritesheets used by sprites
28 SIF_SECTION_SPRITES, // main sprite array
29 SIF_SECTION_NAMES, // names of sprites in array, minus the SPR_... prefix
30 SIF_SECTION_GROUPS, // names of SIFEdit directories for grouping sprites
31 SIF_SECTION_COMMENTS, // SIFEdit comments about sprites
32 SIF_SECTION_PATHS, // things like base directory of sheets, for SIFEdit
33 SIF_SECTION_DIRNAMES, // names/order of the SIFDir directions
35 SIF_SECTION_COUNT
39 // section entries in the header index table
40 struct SIFIndexEntry
42 uint8_t type; // section typecode (SIF_SECTION_...)
43 uint32_t foffset; // offset within file
44 uint32_t length; // length of section data
45 uint8_t *data; // the actual data, if it has already been loaded, else NULL
49 class SIFLoader
51 public:
52 SIFLoader();
53 ~SIFLoader();
55 // open a file handle to the given .sif and load the header and
56 // section index into memory.
57 bool LoadHeader(const char *filename);
59 // return a pointer to the section data of type 'type',
60 // or NULL if the file doesn't have a section of that type.
61 uint8_t *FindSection(int type, int *length_out);
63 // ---------------------------------------
64 // SIF-saving functions. You shouldn't use the same object for saving
65 // as currently has a file loaded, just construct a new one.
66 // But it is safe to save over the same file you are referencing data
67 // from using the "Load" object; because the changes are finalized to disk
68 // until you call EndSave().
70 // allocate memory etc to save a new file from provided data.
71 bool BeginSave();
73 // add a section to the SIF of the given type, containing the given data.
74 bool AddSection(int type, uint8_t *data, int datalen);
76 // finalize the changes and write them to disk in the given file.
77 bool EndSave(const char *filename);
79 // ---------------------------------------
81 // free any temporary memory and close the file handle.
82 void CloseFile();
85 private:
86 void ClearIndex();
88 BList fIndex; // index table from header (list of SIFIndexEntry)
89 FILE *fFP; // open file handle
91 uint32_t fTotalDataAdded; // for saving
95 #endif