File: InMapDrawModel.h

package info (click to toggle)
spring 98.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 41,928 kB
  • ctags: 60,665
  • sloc: cpp: 356,167; ansic: 39,434; python: 12,228; java: 12,203; awk: 5,856; sh: 1,719; xml: 997; perl: 405; php: 253; objc: 194; makefile: 72; sed: 2
file content (158 lines) | stat: -rw-r--r-- 3,723 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
/* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */

#ifndef IN_MAP_DRAW_MODEL_H
#define IN_MAP_DRAW_MODEL_H

#include <string>
#include <vector>
#include <list>

#include "System/float3.h"
#include "System/creg/creg_cond.h"

class CPlayer;
class TeamController;

/**
 * The M in MVC for InMapDraw.
 * @see CInMapDrawView for V
 * @see CInMapDraw for C
 */
class CInMapDrawModel
{
	CR_DECLARE_STRUCT(CInMapDrawModel)
	CR_DECLARE_SUB(MapDrawPrimitive)
	CR_DECLARE_SUB(MapPoint)
	CR_DECLARE_SUB(MapLine)
	CR_DECLARE_SUB(DrawQuad)

public:
	static const size_t DRAW_QUAD_SIZE;
	static const float QUAD_SCALE;

	CInMapDrawModel();
	~CInMapDrawModel();

	void PostLoad();

	void SetAllMarksVisible(bool newState) { drawAllMarks = newState; }
	bool GetAllMarksVisible() const { return drawAllMarks; }

	bool AddPoint(const float3& pos, const std::string& label, int playerID);
	bool AddLine(const float3& pos1, const float3& pos2, int playerID);
	void EraseNear(const float3& pos, int playerID);
	void EraseAll();

	int GetNumPoints() const { return numPoints; }
	int GetNumLines() const { return numLines; }


	struct MapDrawPrimitive {
		CR_DECLARE(MapDrawPrimitive)

	public:
		MapDrawPrimitive(bool spectator, int teamID, const TeamController* teamController)
			: spectator(spectator)
			, teamID(teamID)
			, teamController(teamController)
		{}

		bool IsLocalPlayerAllowedToSee(const CInMapDrawModel* inMapDraw) const;

		/**
		 * Was the creator of this map-drawing spectator at the time it was
		 * created?
		 * @see #GetTeamController
		 */
		bool IsBySpectator() const { return spectator; }
		/**
		 * The team-id of the creator of this map-drawing at the time of
		 * creation.
		 * @see #GetTeamController
		 */
		int GetTeamID() const { return teamID; }
		/**
		 * The team-controller that created this map-drawing.
		 */
		const TeamController* GetTeamController() const { return teamController; }

	private:
		bool spectator;
		int teamID;
		const TeamController* teamController;
	};

	struct MapPoint : public MapDrawPrimitive {
		CR_DECLARE(MapPoint)

	public:
		MapPoint(bool spectator, int teamID, const TeamController* teamController, const float3& pos, const std::string& label)
			: MapDrawPrimitive(spectator, teamID, teamController)
			, pos(pos)
			, label(label)
		{}

		const float3& GetPos() const { return pos; }
		const std::string& GetLabel() const { return label; }

	private:
		float3 pos;
		std::string label;
	};

	struct MapLine : public MapDrawPrimitive {
		CR_DECLARE(MapLine)

	public:
		MapLine(bool spectator, int teamID, const TeamController* teamController, const float3& pos1, const float3& pos2)
			: MapDrawPrimitive(spectator, teamID, teamController)
			, pos1(pos1)
			, pos2(pos2)
		{}

		/**
		 * The start position of the line.
		 */
		const float3& GetPos1() const { return pos1; }
		/**
		 * The end position of the line.
		 */
		const float3& GetPos2() const { return pos2; }

	private:
		float3 pos1;
		float3 pos2;
	};

	/**
	 * This is meant to be a QuadTree implementation, but in reality it is a
	 * cell of a grid structure.
	 */
	struct DrawQuad {
		CR_DECLARE_STRUCT(DrawQuad)
		std::list<CInMapDrawModel::MapPoint> points;
		std::list<CInMapDrawModel::MapLine> lines;
	};

	int GetDrawQuadX() const { return drawQuadsX; }
	int GetDrawQuadY() const { return drawQuadsY; }
	const DrawQuad* GetDrawQuad(int x, int y) const;

private:
	bool AllowedMsg(const CPlayer* sender) const;

	int drawQuadsX;
	int drawQuadsY;
	std::vector<DrawQuad> drawQuads;

	bool drawAllMarks;

	/// total number of points
	int numPoints;
	/// total number of lines
	int numLines;
};

extern CInMapDrawModel* inMapDrawerModel;

#endif /* IN_MAP_DRAW_MODEL_H */