VR-Forces 4.3.1 Class Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
trpage_read.h
Go to the documentation of this file.
1 /* ************************
2  Copyright Terrain Experts Inc.
3  Terrain Experts Inc (TERREX) reserves all rights to this source code
4  unless otherwise specified in writing by the President of TERREX.
5  This copyright may be updated in the future, in which case that version
6  supercedes this one.
7  -------------------
8  Terrex Experts Inc.
9  4400 East Broadway #314
10  Tucson, AZ 85711
11  info@terrex.com
12  Tel: (520) 323-7990
13  ************************
14  */
15 
16 #ifndef _txpage_read_h_
17 
18 #define _txpage_read_h_
19 
20 /* txpage_read.h
21  Classes used to represent read objects for paging files.
22 */
23 
25 
27 
28 /* Callback base class
29  Called when a given token is found.
30  {group:Archive Reading}
31 */
33 {
34 public:
35  virtual ~trpgr_Callback(void) { };
36  virtual void *Parse(trpgToken,trpgReadBuffer &) { return (void *)1; };
37 };
38 
39 /* Paging Token
40  Stores callback info associated with a given token.
41  {group:Archive Reading}
42 */
44 {
45 public:
46  trpgr_Token(void);
47  trpgr_Token(int,trpgr_Callback *,bool destroy=true);
48  ~trpgr_Token(void);
49  void init(int,trpgr_Callback *,bool destroy=true);
50  int Token;
52  bool destroy;
53  void Destruct(void);
54 };
55 
56 /* Parse class for paging data structures.
57  This executes callbacks
58  {group:Archive Reading}
59 */
61 {
62 public:
63  trpgr_Parser(void);
64  virtual ~trpgr_Parser(void);
65  bool isValid(void) const;
66 
68  virtual void AddCallback(trpgToken,trpgr_Callback *,bool destroy = true);
69  virtual void AddCallback(trpgToken,trpgReadWriteable *);
70  virtual const trpgr_Callback *GetCallback(trpgToken tok) const;
71  virtual trpgr_Callback *GetCallback(trpgToken tok);
72  virtual void RemoveCallback(trpgToken);
73  virtual void SetDefaultCallback(trpgr_Callback *,bool destroy = true);
75  virtual bool Parse(trpgReadBuffer &);
76  virtual bool TokenIsValid(trpgToken);
77 protected:
78  void *lastObject;
79 private:
82 #if defined(_WIN32)
83  typedef std::map<trpgToken,trpgr_Token> tok_map;
84 #else
85  typedef std::map< trpgToken,trpgr_Token,std::less<trpgToken> > tok_map;
86 #endif
89 };
90 
91 /* Image Read Helper.
92  Used to help read Local and Tile Local textures into
93  memory (in OpenGL format). You're on your own for External
94  textures.
95  If you want to add additional ways to read textures, feel free
96  to subclass this object.
97 */
98 class trpgwImageHelper;
100 {
101  public:
103  trpgrImageHelper(trpgEndian ness,char *dir,const trpgMatTable &,const trpgTexTable &,bool separateGeoTyp);
105  virtual void Init(trpgEndian ness,char *dir,const trpgMatTable &,const trpgTexTable &,bool separateGeoTyp);
106  virtual ~trpgrImageHelper(void);
107 
108  /* Fetch the bytes for the given texture.
109  This is only valid for Local textures.
110  */
111  virtual bool GetLocalGL(const trpgTexture *,char *data,int32 dataSize);
112 
113  /* Fetch the bytes for the given mip level of a given texture.
114  This is only valid for Local textures.
115  */
116  virtual bool GetMipLevelLocalGL(int miplevel, const trpgTexture *,char *data,int32 dataSize);
117 
118  /* Do the lookups to figure out the correct material
119  and Template (or Local) texture for a given Local Material.
120  You'll need this for sizes (among other things).
121  This routine also calculates the total size, including mipmaps if they're there.
122  */
123  virtual bool GetImageInfoForLocalMat(const trpgLocalMaterial *locMat,
124  const trpgMaterial **retMat,const trpgTexture **retTex,
125  int &totSize);
126 
127  /* Same as above, but gets info for nth image associated with this local material
128  */
129  virtual bool GetNthImageInfoForLocalMat(const trpgLocalMaterial *locMat, int index,
130  const trpgMaterial **retMat,const trpgTexture **retTex,
131  int &totSize);
132 
133  /* Fetch the bytes for the given Local Material (and
134  associated texture). This is for Tile Local and
135  Global textures.
136  Data is a pre-allocated buffer for the data and
137  dataSize is the size of that buffer.
138  */
139  virtual bool GetImageForLocalMat(const trpgLocalMaterial *locMat,char *data,int dataSize);
140 
141  /* Same as above, but gets nth image associated with this local material
142  */
143  virtual bool GetNthImageForLocalMat(const trpgLocalMaterial *locMat, int index, char *data,int dataSize);
144 
145  /* Same as the one above, just fetch single mip levels
146  */
147  virtual bool GetMipLevelForLocalMat(int miplevel, const trpgLocalMaterial *locMat,char *data,int dataSize);
148 
149  /* Get mip levels for one of multiple images
150  */
151  virtual bool GetNthImageMipLevelForLocalMat(int miplevel, const trpgLocalMaterial *locMat, int index, char *data,int dataSize);
152 
153  /* Determine the full path of the image in the given
154  trpgTexture class.
155  Only useful for External images.
156  */
157  virtual bool GetImagePath(const trpgTexture *,char *,int len);
158 
159  virtual trpgrAppFileCache* GetNewRAppFileCache(const char *fullBase,const char *ext);
160 
161  trpgrAppFileCache *GetGeoTypCache()
162  {
163  return geotypCache;
164  }
165  void SetTexTable(trpgTexTable *texTable)
166  {
167  this->texTable = texTable;
168  }
169  protected:
170  char dir[1024];
174 
178 };
179 
180 /* Paging Archive (read version)
181  This just reads the first bits of the file (and the header)
182  and lets you parse from there.
183  {group:Archive Reading}
184 */
186 {
187 public:
188  trpgr_Archive(void);
189  virtual ~trpgr_Archive(void);
190 
191  virtual void SetDirectory(const char *);
192  virtual bool OpenFile(const char *);
193  virtual void CloseFile(void);
194  virtual bool ReadHeader(void);
195  //overload that lets you specify if you want to read all the blocks now,
196  //or defer reading them for later.
197  virtual bool ReadHeader(bool readAllBlocks);
198  bool ReadSubArchive(int row, int col, trpgEndian cpuNess);
200  virtual bool ReadTile(uint32 x, uint32 y, uint32 lod,trpgMemReadBuffer &);
201  virtual bool ReadTile(const trpgwAppAddress& addr, trpgMemReadBuffer &buf);
202  virtual bool ReadExternalTile(uint32 x,uint32 y,uint32 lod,trpgMemReadBuffer &buf);
203 
205  virtual const trpgHeader *GetHeader(void) const;
206  virtual const trpgMatTable *GetMaterialTable(void) const;
207  virtual trpgTexTable *GetTexTable(void) ;
208  virtual const trpgModelTable *GetModelTable(void) const;
209  virtual const trpgTileTable *GetTileTable(void) const;
210  virtual const trpgLightTable *GetLightTable(void) const;
211  virtual const trpgRangeTable *GetRangeTable(void) const;
212  virtual const trpgLabelPropertyTable *GetLabelPropertyTable() const;
213  virtual const trpgTextStyleTable *GetTextStyleTable() const;
214  virtual const trpgSupportStyleTable *GetSupportStyleTable() const;
215 
217  virtual bool trpgGetTileMBR(uint32 x,uint32 y,uint32 lod,
218  trpg3dPoint &ll,trpg3dPoint &ur) const;
219 
220  trpgEndian GetEndian(void) const;
221  char* getDir(void){return dir;};
222  virtual trpgrImageHelper* GetNewRImageHelper(trpgEndian ness,char *dir,const trpgMatTable &matTable,const trpgTexTable &texTable);
223  virtual trpgrAppFileCache* GetNewRAppFileCache(const char *fullBase, const char *ext);
224  virtual int32 GetHeaderData(char *dataPtr,int32 length,FILE *filehandle);
225  virtual int32 GetMagicNumber() {return TRPG_MAGIC;};
226 protected:
227  bool headerRead;
229  FILE *fp;
230  int fid;
232  char dir[1024];
243 
245 };
246 
247 class trpgSceneHelperPush;
248 class trpgSceneHelperPop;
249 class trpgSceneHelperDefault;
250 /* Scene Parser
251  This class assists in parsing a scene graph structure (tiles and models).
252  To use it, do an archive ReadTile and pass the resulting Read Buffer to this
253  parser.
254  {group:Archive Reading}
255 */
257 {
258  friend class trpgSceneHelperPush;
259  friend class trpgSceneHelperPop;
260  friend class trpgSceneHelperDefault;
261 public:
262  trpgSceneParser(void);
263  virtual ~trpgSceneParser(void);
264 protected:
266  virtual bool StartChildren(void *) { return true;};
267  virtual bool EndChildren(void *) { return true;};
268 
270  std::vector<void *> parents;
271 };
272 
273 #endif

Document ID: Generated on Wed Jul 29 00:55:00 EDT 2015 from SVN revision 155257
Copyright © 2005-2015 VT MÄK. All Rights Reserved (www.mak.com)