1 /* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */
2 
3 #ifndef s3o_H
4 #define s3o_H
5 
6 #include "System/Platform/byteorder.h"
7 
8 /// Structure in .s3o files representing draw primitives
9 struct Piece{
10 	int name;            ///< offset in file to char* name of this piece
11 	int numchildren;       ///< number of sub pieces this piece has
12 	int children;          ///< file offset to table of dwords containing offsets to child pieces
13 	int numVertices;     ///< number of vertices in this piece
14 	int vertices;        ///< file offset to vertices in this piece
15 	int vertexType;      ///< 0 for now
16 	int primitiveType;   ///< type of primitives for this piece, 0=triangles,1 triangle strips,2=quads
17 	int vertexTableSize; ///< number of indexes in vertice table
18 	int vertexTable;     ///< file offset to vertice table, vertice table is made up of dwords indicating vertices for this piece, to indicate end of a triangle strip use 0xffffffff
19 	int collisionData;   ///< offset in file to collision data, must be 0 for now (no collision data)
20 	float xoffset;       ///< offset from parent piece
21 	float yoffset;
22 	float zoffset;
23 
24 	/// Swap byte order (endianess) for big-endian machines
swapPiece25 	void swap()
26 	{
27 		swabDWordInPlace(name);
28 		swabDWordInPlace(numchildren);
29 		swabDWordInPlace(children);
30 		swabDWordInPlace(numVertices);
31 		swabDWordInPlace(vertices);
32 		swabDWordInPlace(vertexType);
33 		swabDWordInPlace(primitiveType);
34 		swabDWordInPlace(vertexTableSize);
35 		swabDWordInPlace(vertexTable);
36 		swabDWordInPlace(collisionData);
37 		swabFloatInPlace(xoffset);
38 		swabFloatInPlace(yoffset);
39 		swabFloatInPlace(zoffset);
40 	}
41 };
42 
43 /// Vertex structure for .s3o files. As far as I (Commander) can tell, this is never actually used.
44 struct Vertex{
45 	float xpos;    ///< position of vertex relative piece origin
46 	float ypos;
47 	float zpos;
48 	float xnormal; ///< normal of vertex relative piece rotation
49 	float ynormal;
50 	float znormal;
51 	float texu;    ///< texture offset for vertex
52 	float texv;
53 
54 	/// Swap byte order (endianess) for big-endian machines
swapVertex55 	void swap()
56 	{
57 		swabFloatInPlace(xpos);
58 		swabFloatInPlace(ypos);
59 		swabFloatInPlace(zpos);
60 		swabFloatInPlace(xnormal);
61 		swabFloatInPlace(ynormal);
62 		swabFloatInPlace(znormal);
63 		swabFloatInPlace(texu);
64 		swabFloatInPlace(texv);
65 	}
66 };
67 
68 /// Header structure for .s3o files
69 struct S3OHeader{
70 	char magic[12];    ///< "Spring unit\0"
71 	int version;       ///< 0 for this version
72 	float radius;      ///< radius of collision sphere
73 	float height;      ///< height of whole object
74 	float midx;        ///< these give the offset from origin(which is supposed to lay in the ground plane) to the middle of the unit collision sphere
75 	float midy;
76 	float midz;
77 	int rootPiece;     ///< offset in file to root piece
78 	int collisionData; ///< offset in file to collision data, must be 0 for now (no collision data)
79 	int texture1;      ///< offset in file to char* filename of first texture
80 	int texture2;      ///< offset in file to char* filename of second texture
81 
82 	/// Swap byte order (endianess) for big-endian machines
swapS3OHeader83 	void swap()
84 	{
85 		swabDWordInPlace(version);
86 		swabFloatInPlace(radius);
87 		swabFloatInPlace(height);
88 		swabFloatInPlace(midx);
89 		swabFloatInPlace(midy);
90 		swabFloatInPlace(midz);
91 		swabDWordInPlace(rootPiece);
92 		swabDWordInPlace(collisionData);
93 		swabDWordInPlace(texture1);
94 		swabDWordInPlace(texture2);
95 	}
96 };
97 
98 #endif // s3o_H
99