18 #include "precompiled.h"
36 m_Simulation(simulation), m_DirtyID(0), m_Texture(0), m_MapSize(0), m_TextureSize(0)
55 if (!cmpTerritoryManager)
106 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_TextureSize, m_TextureSize, 0, GL_BGRA_EXT, GL_UNSIGNED_BYTE, texData);
109 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
110 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
111 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
112 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
134 float s =
m_MapSize / (float)m_TextureSize;
155 PROFILE(
"recompute territory texture");
157 std::vector<u8> bitmap;
161 if (!cmpTerritoryManager)
169 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_MapSize, m_MapSize, GL_BGRA_EXT, GL_UNSIGNED_BYTE, &bitmap[0]);
175 int alphaFalloff = 0x20;
179 std::vector<CColor> colors;
181 for (
i32 p = 0; p < numPlayers; ++p)
186 color = cmpPlayer->GetColour();
187 colors.push_back(color);
191 for (
ssize_t j = 0; j < h; ++j)
193 for (
ssize_t i = 0; i < w; ++i)
200 color =
CColor(1, 1, 1, 0);
201 else if (val < colors.size())
204 *p++ = (int)(color.
b*255.f);
205 *p++ = (int)(color.
g*255.f);
206 *p++ = (int)(color.
r*255.f);
225 for (
ssize_t j = 0; j < h; ++j)
230 for (
ssize_t i = 0; i < w; ++i)
232 a = std::max(a - alphaFalloff, (
int)bitmap[(j*w+i)*4 + 3]);
233 bitmap[(j*w+i)*4 + 3] = a;
237 for (
ssize_t i = w-1; i >= 0; --i)
239 a = std::max(a - alphaFalloff, (
int)bitmap[(j*w+i)*4 + 3]);
240 bitmap[(j*w+i)*4 + 3] = a;
244 for (
ssize_t i = 0; i < w; ++i)
249 for (
ssize_t j = 0; j < w; ++j)
251 a = std::max(a - alphaFalloff, (
int)bitmap[(j*w+i)*4 + 3]);
252 bitmap[(j*w+i)*4 + 3] = a;
256 for (
ssize_t j = w-1; j >= 0; --j)
258 a = std::max(a - alphaFalloff, (
int)bitmap[(j*w+i)*4 + 3]);
259 bitmap[(j*w+i)*4 + 3] = a;
264 for (
ssize_t j = 0; j < h; ++j)
266 for (
ssize_t i = 0; i < w; ++i)
268 if (bitmap[(j*w+i)*4 + 3] == alphaMax)
269 bitmap[(j*w+i)*4 + 3] = 0;
274 for (
ssize_t j = 0; j < h; ++j)
276 for (
ssize_t i = 0; i < w; ++i)
279 if (bitmap[idx] == 255 && bitmap[idx+1] == 255 && bitmap[idx+2] == 255)
CTerritoryTexture(CSimulation2 &simulation)
const ssize_t TERRAIN_TILE_SIZE
metres [world space units] per tile in x and z
virtual const Grid< u8 > & GetTerritoryGrid()=0
For each tile, the TERRITORY_PLAYER_MASK bits are player ID; TERRITORY_CONNECTED_MASK is set if the t...
const float * GetMinimapTextureMatrix()
Returns a matrix to map (0,0)-(1,1) texture coordinates onto texture coordinates, in the form expecte...
virtual bool NeedUpdate(size_t *dirtyID)=0
void BindTexture(int unit)
Recomputes the territory texture if necessary, and binds it to the requested texture unit...
const entity_id_t SYSTEM_ENTITY
Entity ID for singleton 'system' components.
Public API for simulation system.
CMatrix3D m_TextureMatrix
#define ENSURE(expr)
ensure the expression <expr> evaluates to non-zero.
T round_up_to_pow2(T x)
round up to next larger power of two.
bool UpdateDirty()
Returns true if the territory state has changed since the last call to this function.
virtual entity_id_t GetPlayerByID(int32_t id)=0
void GenerateBitmap(const Grid< u8 > &territories, u8 *bitmap, ssize_t w, ssize_t h)
GLuint GetTexture()
Recomputes the territory texture if necessary, and returns the texture handle.
virtual u16 GetVerticesPerSide()=0
Returns number of vertices per side on the terrain.
CMatrix3D m_MinimapTextureMatrix
A simplified syntax for accessing entity components.
const float * GetTextureMatrix()
Returns a matrix to map (x,y,z) world coordinates onto (u,v) texture coordinates, in the form expecte...
static const int TERRITORY_PLAYER_MASK
void RecomputeTexture(int unit)
T & get(int i, int j) const
void ConstructTexture(int unit)
virtual int32_t GetNumPlayers()=0
CSimulation2 & m_Simulation