File: LegacyTrackHandler.h

package info (click to toggle)
spring 104.0%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 47,512 kB
  • sloc: cpp: 391,093; ansic: 79,943; python: 12,356; java: 12,201; awk: 5,889; sh: 1,826; xml: 655; makefile: 486; perl: 405; php: 211; objc: 194; sed: 2
file content (138 lines) | stat: -rw-r--r-- 2,590 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
128
129
130
131
132
133
134
135
136
137
138
/* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */

#ifndef LEGACYTRACKHANDLER_H
#define LEGACYTRACKHANDLER_H


#include <deque>
#include <vector>
#include <string>

#include "System/float3.h"
#include "System/EventClient.h"



class CSolidObject;
class CUnit;
class CVertexArray;

namespace Shader {
	struct IProgramObject;
}

struct TrackPart {
	TrackPart()
		: texPos(0.0f)
		, connected(false)
		, isNewTrack(false)
		, creationTime(0)
	{}
	float3 pos1;
	float3 pos2;
	float texPos;
	bool connected;
	bool isNewTrack;
	unsigned int creationTime;
};

struct UnitTrackStruct {
	UnitTrackStruct(CUnit* owner)
		: owner(owner)
		, lastUpdate(0)
		, lifeTime(0)
		, alphaFalloff(0.0f)
	{}

	CUnit* owner;

	unsigned int lastUpdate;
	unsigned int lifeTime;

	float alphaFalloff;

	TrackPart lastAdded;
	std::deque<TrackPart> parts;
};

struct TrackToClean {
	TrackToClean(UnitTrackStruct* t, std::vector<UnitTrackStruct*>* ts)
		: track(t)
		, tracks(ts)
	{}

	UnitTrackStruct* track;
	std::vector<UnitTrackStruct*>* tracks;
};



class LegacyTrackHandler: public CEventClient
{
public:
	LegacyTrackHandler();
	~LegacyTrackHandler();

	void Draw();

public:
	//CEventClient
	bool WantsEvent(const std::string& eventName) {
		return
			(eventName == "SunChanged") ||
			(eventName == "RenderUnitDestroyed") ||
			(eventName == "UnitMoved");
	}
	bool GetFullRead() const { return true; }
	int GetReadAllyTeam() const { return AllAccessTeam; }

	void SunChanged();
	void RenderUnitDestroyed(const CUnit*);
	void UnitMoved(const CUnit* unit);

private:
	bool GetDrawTracks() const;

	void LoadDecalShaders();
	void DrawObjectDecals();

	static void BindTextures();
	static void KillTextures();
	void BindShader(const float3& ambientColor);

	void AddTracks();
	void DrawTracks();
	void CleanTracks();


	static void RemoveTrack(CUnit* unit);
	void AddTrack(CUnit* unit, const float3& newPos);
	int GetTrackType(const std::string& name);
	unsigned int LoadTexture(const std::string& name);

private:
	struct TrackType {
		TrackType(const std::string& s, unsigned t): name(s), texture(t) {}
		std::string name;
		std::vector<UnitTrackStruct*> tracks;
		unsigned int texture;
	};

	std::vector<TrackType> trackTypes;

	enum DecalShaderProgram {
		DECAL_SHADER_ARB,
		DECAL_SHADER_GLSL,
		DECAL_SHADER_CURR,
		DECAL_SHADER_LAST
	};

	std::vector<Shader::IProgramObject*> decalShaders;

	std::vector<UnitTrackStruct*> tracksToBeAdded;
	std::vector<TrackToClean>     tracksToBeCleaned;
	std::vector<UnitTrackStruct*> tracksToBeDeleted;
};


#endif // LEGACYTRACKHANDLER_H