1 /*
2 	This file is part of Warzone 2100.
3 	Copyright (C) 1999-2004  Eidos Interactive
4 	Copyright (C) 2005-2020  Warzone 2100 Project
5 
6 	Warzone 2100 is free software; you can redistribute it and/or modify
7 	it under the terms of the GNU General Public License as published by
8 	the Free Software Foundation; either version 2 of the License, or
9 	(at your option) any later version.
10 
11 	Warzone 2100 is distributed in the hope that it will be useful,
12 	but WITHOUT ANY WARRANTY; without even the implied warranty of
13 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 	GNU General Public License for more details.
15 
16 	You should have received a copy of the GNU General Public License
17 	along with Warzone 2100; if not, write to the Free Software
18 	Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20 /***************************************************************************/
21 /*
22  * ivisdef.h
23  *
24  * type defines for all ivis library functions.
25  *
26  */
27 /***************************************************************************/
28 
29 #ifndef _ivisdef_h
30 #define _ivisdef_h
31 
32 #include "lib/framework/frame.h"
33 #include "lib/ivis_opengl/gfx_api.h"
34 #include "pietypes.h"
35 #include "tex.h"
36 
37 #include <vector>
38 #include <string>
39 
40 
41 //*************************************************************************
42 //
43 // screen surface structure
44 //
45 //*************************************************************************
46 struct iClip
47 {
48 	int32_t left, top, right, bottom;
49 };
50 
51 struct iSurface
52 {
53 	int xcentre;
54 	int ycentre;
55 	iClip clip;
56 
57 	int width;
58 	int height;
59 };
60 
61 //*************************************************************************
62 //
63 // imd structures
64 //
65 //*************************************************************************
66 
67 /// Stores the from and to verticles from an edge
68 struct EDGE
69 {
70 	uint32_t from, to;
71 };
72 
73 struct ANIMFRAME
74 {
75 	Vector3f scale = Vector3f(0.f, 0.f, 0.f);
76 	Position pos = Position(0, 0, 0);
77 	Rotation rot;
78 };
79 
80 struct iIMDPoly
81 {
82 	std::vector<Vector2f> texCoord;
83 	Vector2f texAnim = Vector2f(0.f, 0.f);
84 	uint32_t flags = 0;
85 	int32_t zcentre = 0;
86 	Vector3f normal = Vector3f(0.f, 0.f, 0.f);
87 	uint32_t pindex[3] = { 0 };
88 };
89 
90 enum VBO_TYPE
91 {
92 	VBO_VERTEX,
93 	VBO_TEXCOORD,
94 	VBO_MINIMAL,
95 	VBO_NORMAL = VBO_MINIMAL,
96 	VBO_INDEX,
97 	VBO_TANGENT,
98 	VBO_COUNT
99 };
100 
101 enum ANIMATION_EVENTS
102 {
103 	ANIM_EVENT_NONE,
104 	ANIM_EVENT_ACTIVE,
105 	ANIM_EVENT_FIRING, // should not be combined with fire-on-move, as this will look weird
106 	ANIM_EVENT_DYING,
107 	ANIM_EVENT_COUNT
108 };
109 
110 struct iIMDShape
111 {
112 	~iIMDShape();
113 
114 	Vector3i min = Vector3i(0, 0, 0);
115 	Vector3i max = Vector3i(0, 0, 0);
116 	unsigned int flags = 0;
117 	size_t texpage = iV_TEX_INVALID;
118 	size_t tcmaskpage = iV_TEX_INVALID;
119 	size_t normalpage = iV_TEX_INVALID;
120 	size_t specularpage = iV_TEX_INVALID;
121 	int sradius = 0;
122 	int radius = 0;
123 
124 	Vector3f ocen = Vector3f(0.f, 0.f, 0.f);
125 	unsigned short numFrames = 0;
126 	unsigned short animInterval = 0;
127 
128 	unsigned int nconnectors = 0;
129 	Vector3i *connectors = 0;
130 
131 	EDGE *shadowEdgeList = nullptr;
132 	size_t nShadowEdges = 0;
133 
134 	// The old rendering data
135 	std::vector<Vector3f> points;
136 	std::vector<iIMDPoly> polys;
137 
138 	// Data used for stencil shadows
139 	std::vector<Vector3f> altShadowPoints;
140 	std::vector<iIMDPoly> altShadowPolys;
141 	std::vector<Vector3f> *pShadowPoints = nullptr;
142 	std::vector<iIMDPoly> *pShadowPolys = nullptr;
143 
144 	// The new rendering data
145 	gfx_api::buffer* buffers[VBO_COUNT] = { nullptr };
146 	SHADER_MODE shaderProgram = SHADER_NONE; // if using specialized shader for this model
147 	uint16_t vertexCount = 0;
148 
149 	// object animation (animating a level, rather than its texture)
150 	std::vector<ANIMFRAME> objanimdata;
151 	int objanimframes = 0;
152 
153 	// more object animation, but these are only set for the first level
154 	int objanimtime = 0; ///< total time to render all animation frames
155 	int objanimcycles = 0; ///< Number of cycles to render, zero means infinitely many
156 	iIMDShape *objanimpie[ANIM_EVENT_COUNT] = { nullptr };
157 
158 	int interpolate = 1; // if the model wants to be interpolated
159 
160 	iIMDShape *next = nullptr;  // next pie in multilevel pies (NULL for non multilevel !)
161 };
162 
163 
164 //*************************************************************************
165 //
166 // immitmap image structures
167 //
168 //*************************************************************************
169 
170 struct ImageDef
171 {
172 	size_t TPageID;   /**< Which associated file to read our info from */
173 	unsigned int Tu;        /**< First vertex coordinate */
174 	unsigned int Tv;        /**< Second vertex coordinate */
175 	unsigned int Width;     /**< Width of image */
176 	unsigned int Height;    /**< Height of image */
177 	int XOffset;            /**< X offset into source position */
178 	int YOffset;            /**< Y offset into source position */
179 
180 	size_t textureId;		///< duplicate of below, fix later
181 	gfx_api::gfxFloat invTextureSize;
182 };
183 
184 struct Image;
185 
186 struct IMAGEFILE
187 {
188 	struct Page
189 	{
190 		size_t id;    /// OpenGL texture ID.
191 		int size;  /// Size of texture in pixels. (Should be square.)
192 	};
193 
194 	Image find(std::string const &name);  // Defined in bitimage.cpp.
195 
196 	std::vector<Page> pages;          /// Texture pages.
197 	std::vector<ImageDef> imageDefs;  /// Stored images.
198 	std::vector<std::pair<std::string, int>> imageNames;  ///< Names of images, sorted by name. Can lookup indices from name.
199 };
200 
201 struct Image
202 {
imagesImage203 	Image(IMAGEFILE const *images = nullptr, unsigned id = 0) : images(const_cast<IMAGEFILE *>(images)), id(id) {}
204 
isNullImage205 	bool isNull() const
206 	{
207 		return images == nullptr;
208 	}
widthImage209 	int width() const
210 	{
211 		return images->imageDefs[id].Width;
212 	}
heightImage213 	int height() const
214 	{
215 		return images->imageDefs[id].Height;
216 	}
xOffsetImage217 	int xOffset() const
218 	{
219 		return images->imageDefs[id].XOffset;
220 	}
yOffsetImage221 	int yOffset() const
222 	{
223 		return images->imageDefs[id].YOffset;
224 	}
225 
226 	IMAGEFILE *images;
227 	unsigned id;
228 };
229 
230 #endif // _ivisdef_h
231