File: MeshDrawInfo.h

package info (click to toggle)
bzflag 2.4.30-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 26,488 kB
  • sloc: cpp: 150,376; ansic: 3,463; sh: 2,535; makefile: 2,194; perl: 486; python: 260; objc: 246; php: 206
file content (360 lines) | stat: -rw-r--r-- 7,096 bytes parent folder | download
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
/* bzflag
 * Copyright (c) 1993-2025 Tim Riker
 *
 * This package is free software;  you can redistribute it and/or
 * modify it under the terms of the license found in the file
 * named COPYING that should have accompanied this file.
 *
 * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 */

#ifndef _MESH_DRAW_INFO_H_
#define _MESH_DRAW_INFO_H_

// Top Dog, King of the Hill
#include "common.h"

// System headers
#include <map>
#include <string>
#include <vector>
#include <iostream>

// Common headers
#include "vectors.h"
#include "Extents.h"
#include "BzMaterial.h"
#include "MeshTransform.h"

class MeshObstacle;
class MeshDrawMgr;

class Corner;
class DrawCmd;
class DrawSet;
class DrawLod;
class AnimationInfo;

typedef std::map<unsigned int, unsigned int> UintMap;


class MeshDrawInfo
{
public:
    // server side generation
    MeshDrawInfo(const std::vector<std::string>& options);

    // client side unpacking
    MeshDrawInfo();

    // client side copies
    // - the vertex data belongs to the source
    // - the BzMaterials are regenerated from the map
    MeshDrawInfo(const MeshDrawInfo* drawInfo,
                 const MeshTransform& xform,
                 const std::map<const BzMaterial*, const BzMaterial*>&);

    ~MeshDrawInfo();

    bool parse(std::istream& in);

    bool isValid() const;

    bool clientSetup(const MeshObstacle* mesh);
    bool serverSetup(const MeshObstacle* mesh);

    bool isServerSide() const;

    bool isCopy() const;
    const MeshDrawInfo* getSource() const;

    bool isInvisible() const;

    void getMaterials(MaterialSet& matSet) const;

    MeshDrawMgr* getDrawMgr() const;
    void setDrawMgr(MeshDrawMgr*);

    void setName(const std::string&);
    const std::string& getName() const;

    const float* getSphere() const;
    const Extents& getExtents() const;

    int getLodCount() const;
    const DrawLod* getDrawLods() const;

    const afvec3* getVertices() const;
    const afvec3* getNormals() const;
    const afvec2* getTexcoords() const;

    int getRadarCount() const;
    const DrawLod* getRadarLods() const;

    int getLineCount() const;

    const MeshTransform::Tool* getTransformTool() const;
    const MaterialMap* getMaterialMap() const;

    void updateAnimation(double time);
    const AnimationInfo* getAnimationInfo() const;

    int packSize() const;
    void *pack(void*) const;
    const void *unpack(const void*);

    void print(std::ostream& out, const std::string& indent) const;

private:
    void init();
    void clear();
    bool validate(const MeshObstacle* mesh) const;

private:
    const MeshDrawInfo* source; // copy source, or NULL
    int lines;

    bool valid;
    bool serverSide;

    std::string name;

    std::vector<std::string> lodOptions;

    MeshDrawMgr* drawMgr;

    Extents extents;
    float sphere[4];

    MaterialMap* matMap;
    MeshTransform::Tool* xformTool;

    // elements
    int cornerCount;
    Corner* corners;
    afvec3* vertices;
    afvec3* normals;
    afvec2* texcoords;

    int rawVertCount;
    afvec3* rawVerts;
    int rawNormCount;
    afvec3* rawNorms;
    int rawTxcdCount;
    afvec2* rawTxcds;

    int lodCount;
    DrawLod* lods;

    int radarCount;
    DrawLod* radarLods;

    AnimationInfo* animInfo;
};

inline bool MeshDrawInfo::isValid() const
{
    return valid;
}
inline bool MeshDrawInfo::isServerSide() const
{
    return serverSide;
}

inline bool MeshDrawInfo::isCopy() const
{
    return (source != NULL);
}
inline void MeshDrawInfo::setDrawMgr(MeshDrawMgr* mgr)
{
    drawMgr = mgr;
}
inline const MeshDrawInfo* MeshDrawInfo::getSource() const
{
    return source;
}
inline const std::string& MeshDrawInfo::getName() const
{
    return name;
}
inline const float* MeshDrawInfo::getSphere() const
{
    return sphere;
}
inline const Extents& MeshDrawInfo::getExtents() const
{
    return extents;
}
inline int MeshDrawInfo::getLodCount() const
{
    return lodCount;
}
inline const DrawLod* MeshDrawInfo::getDrawLods() const
{
    return lods;
}
inline const afvec3* MeshDrawInfo::getVertices() const
{
    return vertices;
}
inline const afvec3* MeshDrawInfo::getNormals() const
{
    return normals;
}
inline const afvec2* MeshDrawInfo::getTexcoords() const
{
    return texcoords;
}
inline int MeshDrawInfo::getRadarCount() const
{
    return radarCount;
}
inline const DrawLod* MeshDrawInfo::getRadarLods() const
{
    return radarLods;
}
inline int MeshDrawInfo::getLineCount() const
{
    return lines;
}
inline const MeshTransform::Tool*  MeshDrawInfo::getTransformTool() const
{
    return xformTool;
}
inline const MaterialMap* MeshDrawInfo::getMaterialMap() const
{
    return matMap;
}
inline const AnimationInfo* MeshDrawInfo::getAnimationInfo() const
{
    return animInfo;
}


class Corner
{
public:
    Corner();
    ~Corner();
    int packSize() const;
    void *pack(void*) const;
    const void *unpack(const void*);
public:
    int vertex;
    int normal;
    int texcoord;
};


class DrawCmd
{
public:
    DrawCmd();

    void clear();

    void finalize();

    int packSize() const;
    void *pack(void*) const;
    const void *unpack(const void*);

public:
    enum DrawModes            // OpenGL
    {
        DrawPoints    = 0x0000, // 0x0000
        DrawLines     = 0x0001, // 0x0001
        DrawLineLoop  = 0x0002, // 0x0002
        DrawLineStrip = 0x0003, // 0x0003
        DrawTriangles = 0x0004, // 0x0004
        DrawTriangleStrip = 0x0005, // 0x0005
        DrawTriangleFan   = 0x0006, // 0x0006
        DrawQuads     = 0x0007, // 0x0007
        DrawQuadStrip = 0x0008, // 0x0008
        DrawPolygon   = 0x0009, // 0x0009
        DrawModeCount
    };
    enum DrawIndexType
    {
        DrawIndexUShort   = 0x1403, // 0x1403
        DrawIndexUInt = 0x1405, // 0x1405
        DrawIndexTypeCount
    };

public:
    unsigned int drawMode;
    int count;
    void* indices;
    unsigned int indexType;
    unsigned int minIndex;
    unsigned int maxIndex;
};


class DrawSet
{
public:
    DrawSet();

    void clear();

    int packSize() const;
    void *pack(void*) const;
    const void *unpack(const void*);

public:
    int count;
    DrawCmd* cmds;
    const BzMaterial* material;
    bool wantList;
    float sphere[4];
    int triangleCount;
};


class DrawLod
{
public:
    DrawLod();

    void clear();

    int packSize() const;
    void *pack(void*) const;
    const void *unpack(const void*);

public:
    int count;
    DrawSet* sets;
    float lengthPerPixel;
    int triangleCount;
};


class AnimationInfo
{
public:
    AnimationInfo();
    int packSize() const;
    void *pack(void*) const;
    const void *unpack(const void*);
public:
    float angvel;
    std::string dummy;
    float angle;
    float cos_val;
    float sin_val;
};


#endif // _MESH_DRAW_INFO_H_

// Local Variables: ***
// mode: C++ ***
// tab-width: 4 ***
// c-basic-offset: 4 ***
// indent-tabs-mode: nil ***
// End: ***
// ex: shiftwidth=4 tabstop=4