summaryrefslogtreecommitdiff
path: root/common/pieceinf.h
blob: 56892c8338d8f79a5291191fb37427222e9a50dd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
//
//	pieceinf.h
////////////////////////////////////////////////////

#ifndef _PIECEINF_H_
#define _PIECEINF_H_

#include <stdio.h>
#ifndef GLuint
#include "opengl.h"
#endif
#include "algebra.h"

#define LC_PIECE_COUNT						0x01 // Count this piece in the totals ?
#define LC_PIECE_LONGDATA					0x02 // unsigned long/short index
#define LC_PIECE_CCW							0x04 // Use back-face culling
#define LC_PIECE_SMALL						0x10 // scale = 10000
#define LC_PIECE_MEDIUM						0x20 // scale = 1000 (otherwise = 100)
#define LC_PIECE_LONGDATA_RUNTIME	0x40 // If the original data is 16 bits but we expanded to 32 bits

class File;
class Texture;

typedef struct
{
	unsigned char type;
	float center[3];
	float normal[3];
} CONNECTIONINFO;

typedef struct
{
	unsigned short connections[6];
	void* drawinfo;
} DRAWGROUP;

typedef struct TEXTURE
{
	Texture* texture;
	unsigned char color;
	float vertex[4][3];
	float coords[4][2];
} TEXTURE;

unsigned char ConvertColor(int c);

class PieceInfo
{
 public:
  PieceInfo ();
  ~PieceInfo ();

	bool IsPatterned() const
	{
		const char* Name = m_strName;

		while (*Name)
		{
			if (*Name < '0' || *Name > '9')
				break;

			Name++;
		}

		if (*Name == 'P')
			return true;

		return false;
	}

	bool IsSubPiece() const
	{
		return (m_strDescription[0] == '~');
	}

	Vector3 GetCenter() const
	{
		return Vector3((m_fDimensions[0] + m_fDimensions[3]) * 0.5f,
		               (m_fDimensions[1] + m_fDimensions[4]) * 0.5f,
		               (m_fDimensions[2] + m_fDimensions[5]) * 0.5f);
	}

	// Operations
	void ZoomExtents(float Fov, float Aspect, float* EyePos = NULL) const;
	void RenderOnce(int nColor);
	void RenderPiece(int nColor);
	void WriteWavefront(FILE* file, unsigned char color, unsigned long* start);

	// Implementation
	GLuint GetBoxDisplayList()
	{
		if (!m_nBoxList)
			CreateBoxDisplayList();
		return m_nBoxList;
	};
	void LoadIndex(File& file);
	void AddRef();
	void DeRef();

public:
	// Attributes
	char m_strName[9];
	char m_strDescription[65];
	float m_fDimensions[6];
	unsigned long m_nOffset;
	unsigned long m_nSize;

	// Nobody should change these
	unsigned char	m_nFlags;
	unsigned long 	m_nVertexCount;
	float*			m_fVertexArray;
	unsigned short	m_nConnectionCount;
	CONNECTIONINFO*	m_pConnections;
	unsigned short	m_nGroupCount;
	DRAWGROUP*		m_pGroups;
	unsigned char	m_nTextureCount;
	TEXTURE*		m_pTextures;

protected:
	int m_nRef;
	GLuint m_nBoxList;

	void LoadInformation();
	void FreeInformation();
	void CreateBoxDisplayList();
};

#endif // _PIECEINF_H_