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 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270
|
/* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */
#ifndef GROUND_DECAL_HANDLER_H
#define GROUND_DECAL_HANDLER_H
#include <set>
#include <list>
#include <vector>
#include <string>
#include "System/float3.h"
#include "System/EventClient.h"
#include "Sim/Projectiles/ExplosionListener.h"
class CUnit;
class CBuilding;
class CVertexArray;
struct GhostBuilding;
namespace Shader {
struct IProgramObject;
}
struct TrackPart {
TrackPart()
: pos1(ZeroVector)
, pos2(ZeroVector)
, texPos(0.0f)
, connected(false)
, creationTime(0)
{}
float3 pos1;
float3 pos2;
float texPos;
bool connected;
unsigned int creationTime;
};
struct UnitTrackStruct {
UnitTrackStruct(CUnit* owner)
: owner(owner)
, lastUpdate(0)
, lifeTime(0)
, trackAlpha(255)
, alphaFalloff(0.0f)
, lastAdded(NULL)
{}
CUnit* owner;
unsigned int lastUpdate;
unsigned int lifeTime;
int trackAlpha;
float alphaFalloff;
TrackPart* lastAdded;
std::list<TrackPart*> parts;
};
struct TrackToAdd {
TrackToAdd()
: tp(NULL)
, unit(NULL)
, ts(NULL)
{}
TrackPart* tp;
CUnit* unit;
UnitTrackStruct* ts;
};
struct TrackToClean {
TrackToClean()
: track(NULL)
, tracks(NULL)
{}
TrackToClean(UnitTrackStruct* t, std::set<UnitTrackStruct*>* ts)
: track(t)
, tracks(ts)
{}
UnitTrackStruct* track;
std::set<UnitTrackStruct*>* tracks;
};
struct BuildingGroundDecal {
BuildingGroundDecal()
: va(NULL)
, owner(NULL)
, gbOwner(NULL)
, posx(0)
, posy(0)
, xsize(0)
, ysize(0)
, facing(-1)
, pos(ZeroVector)
, radius(0.0f)
, alpha(1.0f)
, alphaFalloff(1.0f)
{}
~BuildingGroundDecal();
CVertexArray* va;
CBuilding* owner;
GhostBuilding* gbOwner;
int posx;
int posy;
int xsize;
int ysize;
int facing;
float3 pos;
float radius;
float alpha;
float alphaFalloff;
};
class CGroundDecalHandler: public CEventClient, public IExplosionListener
{
public:
CGroundDecalHandler();
~CGroundDecalHandler();
void Draw();
void Update();
void SunChanged(const float3& sunDir);
void UnitMoved(const CUnit*);
void UnitMovedNow(CUnit* unit);
void RemoveUnit(CUnit* unit);
int GetTrackType(const std::string& name);
void AddExplosion(float3 pos, float damage, float radius, bool);
void AddBuilding(CBuilding* building);
void RemoveBuilding(CBuilding* building, GhostBuilding* gb);
void ForceRemoveBuilding(CBuilding* building);
int GetBuildingDecalType(const std::string& name);
bool GetDrawDecals() const { return drawDecals; }
void SetDrawDecals(bool v) { if (decalLevel > 0) { drawDecals = v; } }
bool WantsEvent(const std::string& eventName) {
return
(eventName == "UnitMoved") ||
(eventName == "SunChanged");
}
bool GetFullRead() const { return true; }
int GetReadAllyTeam() const { return AllAccessTeam; }
virtual void ExplosionOccurred(const CExplosionEvent& event);
private:
void LoadDecalShaders();
void DrawBuildingDecals();
void AddTracks();
void DrawTracks();
void CleanTracks();
void AddScars();
void DrawScars();
unsigned int scarTex;
unsigned int decalLevel;
bool groundScarAlphaFade;
struct TrackType {
TrackType()
: texture(0)
{}
std::string name;
std::set<UnitTrackStruct*> tracks;
unsigned int texture;
};
std::vector<TrackType*> trackTypes;
struct BuildingDecalType {
BuildingDecalType()
: texture(0)
{}
std::string name;
std::set<BuildingGroundDecal*> buildingDecals;
unsigned int texture;
};
std::vector<BuildingDecalType*> buildingDecalTypes;
struct Scar {
Scar()
: pos(ZeroVector)
, radius(0.0f)
, creationTime(0)
, lifeTime(0)
, alphaFalloff(0.0f)
, startAlpha(1.0f)
, texOffsetX(0.0f)
, texOffsetY(0.0f)
, x1(0)
, x2(0)
, y1(0)
, y2(0)
, basesize(0.0f)
, overdrawn(0.0f)
, lastTest(0)
, va(NULL)
{}
~Scar();
float3 pos;
float radius;
int creationTime;
int lifeTime;
float alphaFalloff;
float startAlpha;
float texOffsetX;
float texOffsetY;
int x1;
int x2;
int y1;
int y2;
float basesize;
float overdrawn;
int lastTest;
CVertexArray* va;
};
enum DecalShaderProgram {
DECAL_SHADER_ARB,
DECAL_SHADER_GLSL,
DECAL_SHADER_CURR,
DECAL_SHADER_LAST
};
std::vector<Shader::IProgramObject*> decalShaders;
std::vector<BuildingGroundDecal*> decalsToDraw;
std::list<Scar*> scars;
std::vector<Scar*> scarsToBeAdded;
std::vector<Scar*> scarsToBeChecked;
std::vector<TrackToAdd> tracksToBeAdded;
std::vector<TrackToClean> tracksToBeCleaned;
std::vector<UnitTrackStruct*> tracksToBeDeleted;
std::vector<CUnit*> moveUnits;
int lastTest;
float maxOverlap;
bool drawDecals;
std::set<Scar*>* scarField;
int scarFieldX;
int scarFieldY;
void DrawBuildingDecal(BuildingGroundDecal* decal);
void DrawGroundScar(Scar* scar, bool fade);
int OverlapSize(Scar* s1, Scar* s2);
void TestOverlaps(Scar* scar);
void RemoveScar(Scar* scar, bool removeFromScars);
unsigned int LoadTexture(const std::string& name);
void LoadScar(const std::string& file, unsigned char* buf, int xoffset,
int yoffset);
};
extern CGroundDecalHandler* groundDecals;
#endif // GROUND_DECAL_HANDLER_H
|