File: WorldObjectModelRenderer.h

package info (click to toggle)
spring 88.0%2Bdfsg1-1.1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 41,524 kB
  • sloc: cpp: 343,114; ansic: 38,414; python: 12,257; java: 12,203; awk: 5,748; sh: 1,204; xml: 997; perl: 405; objc: 192; makefile: 181; php: 134; sed: 2
file content (127 lines) | stat: -rwxr-xr-x 4,300 bytes parent folder | download | duplicates (2)
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
/* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */

#ifndef WORLDOBJECT_MODEL_RENDERER_HDR
#define WORLDOBJECT_MODEL_RENDERER_HDR

#define MDL_TYPE(o) (o->model->type)
#define TEX_TYPE(o) (o->model->textureType)

#include <map>
#include <set>

#include "Rendering/Models/3DModel.h"

class CUnit;
class CFeature;
class CProjectile;

class IWorldObjectModelRenderer {
public:
	static IWorldObjectModelRenderer* GetInstance(int);

	IWorldObjectModelRenderer(int mdlType): modelType(mdlType) {
		numUnits = 0;
		numFeatures = 0;
		numFeaturesSave = 0;
		numProjectiles = 0;
	}
	virtual ~IWorldObjectModelRenderer();

	virtual void Draw();
	virtual void PushRenderState() {}
	virtual void PopRenderState() {}

	virtual void AddUnit(const CUnit*);
	virtual void DelUnit(const CUnit*);
	virtual void AddFeature(const CFeature*, float alpha = 0.99f);
	virtual void DelFeature(const CFeature*);
	virtual void SwapFeatures();
	virtual void AddProjectile(const CProjectile*);
	virtual void DelProjectile(const CProjectile*);

	int GetNumUnits() const { return numUnits; }
	int GetNumFeatures() const { return numFeatures; }
	int GetNumProjectiles() const { return numProjectiles; }

protected:
	typedef std::set<CUnit*>                       UnitSet;
	typedef std::set<CUnit*>::const_iterator       UnitSetIt;
	typedef std::map<CFeature*, float>                 FeatureSet;
	typedef std::map<CFeature*, float>::const_iterator FeatureSetIt;
	typedef std::set<CProjectile*>                 ProjectileSet;
	typedef std::set<CProjectile*>::const_iterator ProjectileSetIt;

	// textureType ==> modelSet
	typedef std::map<int, UnitSet>                       UnitRenderBin;
	typedef std::map<int, UnitSet>::const_iterator       UnitRenderBinIt;
	typedef std::map<int, FeatureSet>                    FeatureRenderBin;
	typedef std::map<int, FeatureSet>::const_iterator    FeatureRenderBinIt;
	typedef std::map<int, ProjectileSet>                 ProjectileRenderBin;
	typedef std::map<int, ProjectileSet>::const_iterator ProjectileRenderBinIt;

	virtual void DrawModels(const UnitSet&);
	virtual void DrawModels(const FeatureSet&);
	virtual void DrawModels(const ProjectileSet&);
	virtual void DrawModel(const CUnit*) {}
	virtual void DrawModel(const CFeature*) {}
	virtual void DrawModel(const CProjectile*) {}

	UnitRenderBin units;              // all opaque or all cloaked
	FeatureRenderBin features;        // opaque only, culled via GridVisibility()
	FeatureRenderBin featuresSave;    // opaque only, culled via GridVisibility()
	ProjectileRenderBin projectiles;  // opaque only, (synced && (piece || weapon)) only

	int modelType;

	int numUnits;
	int numFeatures;
	int numFeaturesSave;
	int numProjectiles;

public:
	const UnitSet& GetUnitSet(int texType) { return units[texType]; }
	const FeatureSet& GetFeatureSet(int texType) { return features[texType]; }
	const ProjectileSet& GetProjectileSet(int texType) { return projectiles[texType]; }

	const UnitRenderBin& GetUnitBin() const { return units; }
	const FeatureRenderBin& GetFeatureBin() const { return features; }
	const ProjectileRenderBin& GetProjectileBin() const { return projectiles; }

	UnitRenderBin& GetUnitBinMutable() { return units; }
	FeatureRenderBin& GetFeatureBinMutable() { return features; }
	ProjectileRenderBin& GetProjectileBinMutable() { return projectiles; }
};

class WorldObjectModelRenderer3DO: public IWorldObjectModelRenderer {
public:
	WorldObjectModelRenderer3DO(): IWorldObjectModelRenderer(MODELTYPE_3DO) {}
	void PushRenderState();
	void PopRenderState();
};

class WorldObjectModelRendererS3O: public IWorldObjectModelRenderer {
public:
	WorldObjectModelRendererS3O(): IWorldObjectModelRenderer(MODELTYPE_S3O) {}
	void PushRenderState();
	void PopRenderState();

	void DrawModel(const CUnit*);
	void DrawModel(const CFeature*);
	void DrawModel(const CProjectile*);
};

class WorldObjectModelRendererOBJ: public IWorldObjectModelRenderer {
public:
	WorldObjectModelRendererOBJ(): IWorldObjectModelRenderer(MODELTYPE_OBJ) {}
	void PushRenderState();
	void PopRenderState();
};

class WorldObjectModelRendererASS: public IWorldObjectModelRenderer {
public:
	WorldObjectModelRendererASS(): IWorldObjectModelRenderer(MODELTYPE_ASS) {}
	void PushRenderState();
	void PopRenderState();
};

#endif