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
|
/* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */
#ifndef LEGACYTRACKHANDLER_H
#define LEGACYTRACKHANDLER_H
#include <array>
#include <deque>
#include <vector>
#include <string>
#include "Rendering/GL/RenderDataBufferFwd.hpp"
#include "System/float3.h"
#include "System/EventClient.h"
#include "System/UnorderedMap.hpp"
// comment out if using DecalsDrawerGL4
#define USE_DECALHANDLER_STATE
class CSolidObject;
class CUnit;
struct SolidObjectDecalDef;
namespace Shader {
struct IProgramObject;
}
class LegacyTrackHandler: public CEventClient
{
public:
LegacyTrackHandler();
~LegacyTrackHandler();
void Draw(Shader::IProgramObject* shader);
public:
//CEventClient
bool WantsEvent(const std::string& eventName) override {
return
(eventName == "SunChanged") ||
(eventName == "RenderUnitDestroyed") ||
(eventName == "UnitMoved");
}
bool GetFullRead() const override { return true; }
int GetReadAllyTeam() const override { return AllAccessTeam; }
void SunChanged() override;
void RenderUnitDestroyed(const CUnit*) override;
void UnitMoved(const CUnit* unit) override;
private:
bool GetDrawTracks() const;
void LoadDecalShaders();
void DrawObjectDecals();
static void BindTextures();
static void KillTextures();
void BindShader(const float3& ambientColor);
void AddTracks();
void DrawTracks(GL::RenderDataBufferTC* buffer, Shader::IProgramObject* shader);
void CleanTracks();
void RemoveTrack(CUnit* unit);
void AddTrack(const CUnit* unit, const float3& newPos);
void CreateOrAddTrackPart(const CUnit* unit, const SolidObjectDecalDef& decalDef, const float3& pos);
int GetTrackType(const SolidObjectDecalDef& def);
unsigned int LoadTexture(const std::string& name);
private:
struct TrackPart {
float3 pos1;
float3 pos2;
float texPos = 0.0f;
unsigned int creationTime = 0;
bool connected = false;
};
struct UnitTrack {
UnitTrack( ) = default;
UnitTrack(const UnitTrack& ut) = delete;
UnitTrack( UnitTrack&& ut) { *this = std::move(ut); }
UnitTrack& operator = (const UnitTrack& ut) = delete;
UnitTrack& operator = ( UnitTrack&& ut) {
owner = ut.owner;
ut.owner = nullptr;
id = ut.id;
lastUpdate = ut.lastUpdate;
lifeTime = ut.lifeTime;
alphaFalloff = ut.alphaFalloff;
parts = std::move(ut.parts);
return *this;
}
const CUnit* owner = nullptr;
unsigned int id = -1u;
unsigned int lastUpdate = 0;
unsigned int lifeTime = 0;
float alphaFalloff = 0.0f;
std::deque<TrackPart> parts;
};
struct TrackType {
TrackType(const std::string& s, unsigned t): name(s), texture(t) {}
std::string name;
std::vector<unsigned int> trackIDs;
unsigned int texture;
};
struct TrackToClean {
TrackToClean(unsigned int id, unsigned tti): trackID(id), ttIndex(tti) {}
unsigned int trackID;
unsigned int ttIndex;
};
enum DecalShaderProgram {
DECAL_SHADER_NULL,
DECAL_SHADER_GLSL,
DECAL_SHADER_CURR,
DECAL_SHADER_LAST
};
#ifndef USE_DECALHANDLER_STATE
std::array<Shader::IProgramObject*, DECAL_SHADER_LAST> decalShaders;
#endif
std::vector<TrackType> trackTypes;
spring::unsynced_map<int, UnitTrack> unitTracks;
std::vector<unsigned int> updatedTrackIDs;
std::vector<TrackToClean> cleanedTrackIDs;
};
#endif // LEGACYTRACKHANDLER_H
|