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
|
/* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */
#ifndef SMFREADMAP_H
#define SMFREADMAP_H
#include "SMFMapFile.h"
#include "Map/ReadMap.h"
#include "System/EventClient.h"
#include "System/type2.h"
class CSMFGroundDrawer;
class CSMFReadMap : public CReadMap, public CEventClient
{
public:
// CEventClient interface
int GetReadAllyTeam() const { return AllAccessTeam; }
bool WantsEvent(const std::string& eventName) {
return (eventName == "SunChanged");
}
void SunChanged(const float3& sunDir);
public:
CR_DECLARE(CSMFReadMap)
CSMFReadMap(std::string mapname);
~CSMFReadMap();
void UpdateShadingTexture();
void UpdateHeightMapUnsynced(const SRectangle&);
unsigned int GetDetailTexture() const { return detailTex; }
unsigned int GetMiniMapTexture() const { return minimapTex; }
int2 GetMiniMapTextureSize() const { return int2(1024, 1024); }
unsigned int GetShadingTexture() const { return shadingTex; }
unsigned int GetNormalsTexture() const { return normalsTex; }
unsigned int GetSpecularTexture() const { return specularTex; }
unsigned int GetGrassShadingTexture() const { return grassShadingTex; }
unsigned int GetSplatDetailTexture() const { return splatDetailTex; }
unsigned int GetSplatDistrTexture() const { return splatDistrTex; }
unsigned int GetSkyReflectModTexture() const { return skyReflectModTex; }
unsigned int GetDetailNormalTexture() const { return detailNormalTex; }
unsigned int GetLightEmissionTexture() const { return lightEmissionTex; }
unsigned int GetParallaxHeightTexture() const { return parallaxHeightTex; }
void DrawMinimap() const;
void GridVisibility(CCamera* cam, int quadSize, float maxdist, IQuadDrawer* cb, int extraSize);
void NewGroundDrawer();
int GetNumFeatureTypes();
int GetNumFeatures();
void GetFeatureInfo(MapFeatureInfo* f); // returns all feature info in MapFeatureInfo[NumFeatures]
const char* GetFeatureTypeName(int typeID);
unsigned char* GetInfoMap(const std::string& name, MapBitmapInfo* bm);
void FreeInfoMap(const std::string& name, unsigned char* data);
// NOTE: do not use, just here for backward compatibility with SMFGroundTextures.cpp
CSMFMapFile& GetFile() { return file; }
void ConfigureAnisotropy();
float GetAnisotropy() const { return anisotropy; }
bool HaveSpecularTexture() const { return haveSpecularTexture; }
bool HaveSplatTexture() const { return haveSplatTexture; }
private:
void ParseHeader();
void LoadHeightMap();
void LoadMinimap();
void InitializeWaterHeightColors();
void CreateSpecularTex();
void CreateSplatDetailTextures();
void CreateGrassTex();
void CreateDetailTex();
void CreateShadingTex();
void CreateNormalTex();
void UpdateVertexNormalsUnsynced(const SRectangle& update);
void UpdateFaceNormalsUnsynced(const SRectangle& update);
void UpdateNormalTexture(const SRectangle& update);
void UpdateShadingTexture(const SRectangle& update);
inline void UpdateShadingTexPart(int idx1, int idx2, unsigned char* dst) const;
inline CBaseGroundDrawer* GetGroundDrawer();
inline const float GetCenterHeightUnsynced(const int x, const int y) const;
inline float DiffuseSunCoeff(const int x, const int y) const;
inline float3 GetLightValue(const int x, const int y) const;
void ParseSMD(std::string filename);
public:
// constants
static const int tileScale = 4;
static const int bigSquareSize = 128; // 32 * tileScale
// globals for SMFGround{Drawer, Textures}
int numBigTexX;
int numBigTexY;
int bigTexSize;
int tileMapSizeX;
int tileMapSizeY;
int tileCount;
int mapSizeX;
int mapSizeZ;
int maxHeightMapIdx;
int heightMapSizeX;
int2 normalTexSize;
protected:
CSMFMapFile file;
unsigned int detailTex; // supplied by the map
unsigned int specularTex; // supplied by the map, moderates specular contribution
unsigned int shadingTex; // holds precomputed dot(lightDir, vertexNormal) values
unsigned int normalsTex; // holds vertex normals in RGBA32F internal format (GL_RGBA + GL_FLOAT)
unsigned int minimapTex; // supplied by the map
unsigned int splatDetailTex; // contains per-channel separate greyscale detail-textures (overrides detailTex)
unsigned int splatDistrTex; // specifies the per-channel distribution of splatDetailTex (map-wide, overrides detailTex)
unsigned int grassShadingTex; // specifies grass-blade modulation color (defaults to minimapTex)
unsigned int skyReflectModTex; // modulates sky-reflection RGB intensities (must be the same size as specularTex)
unsigned int detailNormalTex; // tangent-space offset normals
unsigned int lightEmissionTex;
unsigned int parallaxHeightTex;
bool haveSpecularTexture;
bool haveSplatTexture;
unsigned char waterHeightColors[1024 * 4];
CSMFGroundDrawer* groundDrawer;
private:
std::vector<float> cornerHeightMapSynced;
std::vector<float> cornerHeightMapUnsynced;
std::vector<unsigned char> shadingTexBuffer;
bool shadingTexUpdateNeeded;
int shadingTexUpdateProgress;
float anisotropy;
};
#endif
|