Directly loading file packages in the AXP format is efficient and convenient, and has been entangled for a long time. Thanks to the help of netizens, I was inspired.
Ogre adopts two default file formats: folders and zip packages.
However, ogre provides an interface for loading custom files, that is, we can define any types of files, such as AXP.
Hand over the AXP file to the resource manager for Management. The manager locates all resources,
Script files such as materi in the resource are automatically analyzed,
If it is a file format supported by ogre, such as DDS, it is automatically loaded as needed
If it is a file format not directly supported by ogre, such as a binary or XML file
We can also get the file name from the resource manager and use the stream to load it by ourselves,
Datastreamptr mstreamptr = resourcegroupmanager: getsingleton (). openresource (
Filename, tlbb_resource_group );
In this way, all file paths are saved. The file paths have been saved when located by the resource manager.
To let the resource manager do everything for us,
You must use the following interface to define your own files.
Class myarchive: Public Archive
{
// The specific implementation is omitted here
}
Class myarchivefactory: Public Archive
{
// Some methods for implementing archivefactory are omitted here
Archive * createinstance (const string & name ){
Return new myarchive (name, "myarchivetype ");
}
};
Void function ()
{
Myarchivefactory * factory = new myarchivefactory;
Archivemanager: getsingleton (). addarchivefactory (factory );
}
The key point is your own implementation.
There are many things to be realistic, and almost all the two classes archive and archivefactory need to be rewritten.
Fortunately, we can write the code according to the implementation of the source file zip. cpp in the Ogre source code.
Most of the implementations are the same as those of zip.
Framework:
Class axppacker; </P> <p> class tlbbarchive: Public Archive <br/> {<br/> Public: <br/> tlbbarchive (const string & name, const string & archtype); <br/> ~ Tlbbarchive (); <br/> bool iscasesensitive (void) const {return false ;}; <br/> void load (); <br/> void unload (); <br/> datastreamptr open (const string & filename) const; <br/> stringvectorptr list (bool recursive = true, bool dirs = false ); <br/> fileinfolistptr listfileinfo (bool recursive = true, bool dirs = false); <br/> stringvectorptr find (const string & pattern, bool recursive = true, bool dirs = false ); <Br/> fileinfolistptr findfileinfo (const string & pattern, bool recursive = true, bool dirs = false); <br/> bool exists (const string & filename ); <br/> time_t getmodifiedtime (const string & filename); <br/> PRIVATE: <br/> axppacker * mpacker; <br/> }; </P> <p> class tlbbdatastream: Public datastream <br/>{< br/> Public: <br/> tlbbdatastream (const string & name, axppacker * packer ); <br/> ~ Tlbbdatastream (); <br/> size_t read (void * Buf, size_t count); <br/> void SKIP (Long Count ); <br/> void seek (size_t POS); <br/> size_t tell (void) const; <br/> bool EOF (void) const; <br/> void close (void); <br/> PRIVATE: <br/> string mfilename; <br/> axppacker * mpacker; <br/> DWORD mstart; <br/> DWORD mlen; <br/> DWORD mcurpos; <br/>}; </P> <p> class tlbbarchivefactory: public archivefactory <br/>{< br/> const string & GetType (void) const; <br/> archive * createinstance (const string & name ); <br/> void destroyinstance (archive * arch) {Delete arch ;}< br/> };
[Bootstrap]
Zip = ../data/ogrecore.zip
Zip = ../data/materialtemplates.zip
[AXP]
Axppack =.../../data/scene. AXP
Axppack =.../../data/material. AXP
Axppack =.../../data/model. AXP
Axppack =.../../data/brushes. AXP
Final effect:
07: 57: 52: archivefactory for archive type axppack registered.
07: 57: 52: Creating Resource Group AXP
07: 57: 52: added resource location '.../data/scene. AXP' of Type 'axppack' to Resource Group 'axp'
07: 57: 52: added resource location '.../../data/material. AXP' of Type 'axppack' to Resource Group 'axp'
07: 57: 52: added resource location '.../data/model. AXP' of Type 'axppack' to Resource Group 'axp'
07: 57: 52: added resource location '.../../data/brushes. AXP' of Type 'axppack' to Resource Group 'axp'
07: 57: 52: Creating Resource Group Bootstrap
07: 57: 52: added resource location '.../../data/ogrecore.zip' of Type 'zip' to Resource Group 'bootstrap'
07: 57: 52: added resource location '.../../data/materialtemplates.zip' of Type 'zip' to Resource Group 'bootstrap'
07: 57: 53: parsing scripts for Resource Group AXP
07: 57: 53: parsing script fairyterrain. Program
07: 57: 53: parsing script std_quad.program
07: 57: 53: parsing script fairyterrain. Material
07: 57: 53: parsing script all. Material
07: 57: 54: error at line 59378 of: Parent Material: npcnmonsteralphatemplate not found for new material: Boss Xuan sickle
07: 57: 54: error at line 59383 of: Parent Material: npcnmonsternoalphatemplate not found for new material
07: 57: 54: error at line 59388 of: Parent Material: npcnmonsterfacenoalphatemplate not found for new material: Boss peak ordinary Chivalrous Person
I put the original materialtemplates.zip file in front of it, but it was parsed later. It was very difficult, resulting in npcnmonsteralphatemplate not found
With the interface framework, you can write the code on your own. As for the AXP resource cracking, there seems to be something more clear on the Internet. If you are interested, you can search for it,