xFile_Loader.h

00001 #ifndef _XFILE_H
00002 #define _XFILE_H
00003 
00004 #include <stdio.h>              // use for file input/output
00005 #include <string>               // useful string functions such as strlen(..)
00006 #include <fstream>
00007 #include <ctype.h>
00008 #include <iostream>
00009 #include <vector>
00010 #include <stack>
00011 #include <math.h>
00012 
00013 using namespace std;
00014 
00015 #ifndef _WIN32
00016         typedef unsigned long DWORD; // 32 bits
00017         typedef unsigned short WORD;    //16 bits
00018 #else
00019         #include "Windows.h"
00020 #endif
00021 
00022 typedef float FLOAT;
00023 typedef char CHAR; 
00024 typedef const char* LPCSTR;
00025 typedef unsigned int UINT;
00026 
00027 struct Frame;
00028 struct Mesh;
00029 
00030 #define DEBUG_X
00031 
00032 #include "XFile_Defines.h"
00033 
00044 struct stTemplate
00045 {
00046 public:
00047         stTemplate()
00048         {
00049                 Name = "";
00050                 type = NULL;
00051                 pdata = NULL;
00052                 parent = NULL;
00053                 heirachyDepth = 0;
00054         }
00055         string Name;
00056         const stXDefines* type;
00057         int heirachyDepth;
00058         void* pdata;
00059 
00060         stTemplate* parent;
00061         vector<stTemplate*> children;
00062 };
00063 
00073 class xFile_Loader
00074 {
00075 
00076         public:
00077                 
00078                 xFile_Loader();                                                                                         // Default no-args constructor.
00079                 virtual ~xFile_Loader();                                                                        // Default destructor.
00080 
00081                 virtual bool initialise();                                                                      // Initialises all data used by the class instance.
00082                 virtual bool cleanUp();                                                                         // Cleans up all data used by the class instance.
00083                 virtual bool reset();                                                                           // Resets all data used by the class instance.
00084 
00085                 bool load(LPCSTR fileName,bool verboseOutput = true);           // Loads the specified X-File data into memory.
00086                 
00087                 void outputTemplateHierarchyAsText();                                           // Public function for displaying the Template hierarchy (limited to showing the entire hierarchy from the root down).
00088                 void outputFrameHierarchyAsText();                                                      // Public function for displaying the Frame hierarchy (limited to showing the entire hierarchy from the root down).
00089 
00090                 // Flat Reference Lists
00091                 vector<Frame*>frames;                                                                           
00092                 vector<Mesh*> meshes;                                                                           
00093                 vector<Material*> materials;                                                            
00094                 vector<EffectInstance*> effectInstances;                                        
00095                 vector<TextureFilename*> textureFileNames;                                      
00096                 vector<AnimationSet*> animationSets;                                            
00097                 
00098                 Frame* rootFrame;                                                                                       
00099         
00100         protected:
00101                 
00102                 FrameTransformMatrix worldTransform;                                            
00103                 
00104                 bool verbose;                                                                                           
00105 
00106                 void displayFrameHierachy(Frame* parent);                                       // Outputs the Frame hierarchy as text recursively from the specified parent / root (used for debugging).
00107                 void displayHierarchy(stTemplate* parent);                                      // Outputs the file hierarchy as text recursively from the specified parent / root (used for debugging).
00108                 void clearHierarchy(stTemplate* parent);                                        // Clears recursively from the specified template.
00109 
00110                 const stXDefines* getType(LPCSTR str);                                          // Compares a specified string to the list of X-File Templates and returns a pointer to the stXDefines which specifies that type or NULL if no match found.
00111                 bool  processBlocks();                                                                          // Recursive function steps through file reading blocks and building up hierarchy of data structures.
00112                 
00113                 // Template parsing functions
00114                 Mesh* processMesh();                                                                            // Parses a Mesh block and fills in / returns a Mesh structure containing the data.
00115                 MeshNormals* processMeshNormals();                                                      // Parses a MeshNormals block and fills in / returns a MeshNormals structure containing the data.
00116                 MeshTextureCoords* processMeshTextureCoords();                          // Parses a MeshTextureCoords block and fills in / returns a MeshTextureCoords structure containing the data.
00117                 FrameTransformMatrix* processFrameTransformationMatrix();       // Parses a FrameTransformMatrix block and fills in / returns a FrameTransformMatrix structure containing the data.
00118                 Frame* processFrame();                                                                          // Parses a Frame block and fills in / returns a Frame structure containing the data.
00119                 MeshMaterialList* processMeshMaterilalList();                           // Parses a MeshMaterialList block and fills in / returns a Material structure containing the data.
00120                 Material* processMaterial();                                                            // Parses a Material block and fills in / returns a Material structure containing the data.
00121                 TextureFilename* processTextureFileName();                                      // Parses a TextureFilename block and fills in / returns a Material structure containing the data.
00122                 EffectInstance* processEffectInstance();                                        // Parses an EffectInstance block and fills in / returns an EffectInstance structure containing the data.
00123                 EffectParamDword* processEffectParamDword();                            // Parses an EffectParamDWORD block and fills in / returns an EffectParamDWORD structure containing the data.
00124                 EffectParamFloats* processEffectParamFloats();                          // Parses an EffectParamsFLOAT block and fills in / returns an EffectParamFloats structure containing the data.
00125                 EffectParamString* processEffectPramString();                           // Parses an EffectParamsSTRING block and fills in / returns an EffectParamStrings structure containing the data.
00126                 AnimationSet* processAnimationSet();                                            // Parses an AnimationSet block and fills in / returns an AnimationSet structure containing the data.
00127                 Animation* processAnimation();                                                          // Parses an Animation block and fills in / returns an Animation structure containing the data.
00128                 AnimationOptions* processAnimationOptions();                            // Parses an AnimationOptions block and fills in / returns an AnimationOptions structure containing the data.
00129                 AnimationKey* processAnimationKey();                                            // Parses an AnimationKey block and fills in / returns an AnimationKey structure containing the data.
00130 
00131 
00132                 stTemplate* root;                                                                                       
00133 
00134                 string current;                                                                                         
00135                 string back1;                                                                                           
00136                 string back2;                                                                                           
00137         
00138                 void getNext();                                                                                         
00139 
00140                 stack<stTemplate*> parents;                                                                     
00141 
00142                 void debug(char* message);                                                                      
00143 
00144                 ifstream oFile;                                                                                         
00145                 
00146                 LPCSTR FileName;                                                                                        
00147                 
00148                 stTemplate* newTemplate;                                                                        
00149 
00150                 string trimSpeechMarkString(string instr);                                      // Trims the ' " ',' " ' and ' ; ' characters from the ends of string values.
00151 };
00152 
00153 #endif

Generated on Sun May 18 21:45:09 2008 for PS2X by  doxygen 1.5.4