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
|
/* 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 "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
{
public:
static const size_t DRAW_QUAD_SIZE;
static const float QUAD_SCALE;
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();
size_t GetNumPoints() const { return numPoints; }
size_t GetNumLines() const { return numLines; }
struct MapDrawPrimitive {
public:
MapDrawPrimitive(bool spectator, int teamID, const TeamController* teamController)
: spectator(spectator)
, teamID(teamID)
, teamController(teamController)
{}
bool IsVisibleToPlayer(bool drawAllMarks) 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 {
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 {
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 {
std::vector<CInMapDrawModel::MapPoint> points;
std::vector<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
size_t numPoints;
/// total number of lines
size_t numLines;
};
extern CInMapDrawModel* inMapDrawerModel;
#endif /* IN_MAP_DRAW_MODEL_H */
|