|
1 #ifndef __SKINSTRUCTURE_H__ |
2 #define __SKINSTRUCTURE_H__ |
3 |
4 #include <vector> |
5 |
6 #include "DataTypes.h" |
7 #include "FileBuffer.h" |
8 |
9 namespace SKIN |
10 { |
11 |
12 enum StructType { ST_BASE, ST_HEADER, ST_INDEX, ST_TRIANGLE, ST_PROPERTY, |
13 ST_SUBMESH, ST_TEXTURE}; |
14 |
15 class CBase |
16 { |
17 public: |
18 CBase(StructType type) : m_eType(type) {} |
19 virtual ~CBase() {} |
20 public: |
21 StructType m_eType; |
22 }; |
23 |
24 class CHeader : public CBase |
25 { |
26 public: |
27 CHeader() : CBase(ST_HEADER) {} |
28 virtual ~CHeader() {} |
29 |
30 int Read(CFileBuffer& fb) |
31 { |
32 return m_stHeader.Read(fb); |
33 } |
34 public: |
35 Header_t m_stHeader; |
36 }; |
37 |
38 template<StructType ST, typename T> |
39 class CSubStruct : public CBase |
40 { |
41 public: |
42 typedef std::vector<T> TVector; |
43 public: |
44 CSubStruct() : CBase(ST) {} |
45 virtual ~CSubStruct() {} |
46 |
47 int Read(CFileBuffer& fb, unsigned int offset, unsigned int size) |
48 { |
49 T data; |
50 fb.Seek(offset); |
51 for(unsigned int i = 0; i < size; ++ i) |
52 { |
53 data.Read(fb); |
54 m_vct.push_back(data); |
55 } |
56 return fb.Good() ? 0 : -1; |
57 } |
58 public: |
59 TVector m_vct; |
60 }; |
61 |
62 typedef CHeader THeader; |
63 typedef CSubStruct<ST_INDEX, UInt16_t> TIndex; |
64 typedef CSubStruct<ST_TRIANGLE, UInt16_t> TTriangle; |
65 typedef CSubStruct<ST_PROPERTY, UInt32_t> TProperty; |
66 typedef CSubStruct<ST_SUBMESH, SubMesh_t> TSubMesh; |
67 typedef CSubStruct<ST_TEXTURE, Texture_t> TTexture; |
68 |
69 |
70 }//skin |
71 |
72 #endif |
73 |
74 |