1 /* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */
2 
3 #ifndef SMFREADMAP_H
4 #define SMFREADMAP_H
5 
6 #include "SMFMapFile.h"
7 #include "Map/ReadMap.h"
8 #include "System/EventClient.h"
9 #include "System/type2.h"
10 
11 
12 class CSMFGroundDrawer;
13 
14 class CSMFReadMap : public CReadMap, public CEventClient
15 {
16 public:
17 	// CEventClient interface
GetReadAllyTeam()18 	int GetReadAllyTeam() const { return AllAccessTeam; }
WantsEvent(const std::string & eventName)19 	bool WantsEvent(const std::string& eventName) {
20 		return (eventName == "SunChanged");
21 	}
22 
23 	void SunChanged(const float3& sunDir);
24 
25 public:
26 	CR_DECLARE(CSMFReadMap)
27 
28 	CSMFReadMap(std::string mapname);
29 	~CSMFReadMap();
30 
31 	void UpdateShadingTexture();
32 	void UpdateHeightMapUnsynced(const SRectangle&);
33 
GetDetailTexture()34 	unsigned int GetDetailTexture() const { return detailTex; }
GetMiniMapTexture()35 	unsigned int GetMiniMapTexture() const { return minimapTex; }
GetMiniMapTextureSize()36 	int2 GetMiniMapTextureSize() const { return int2(1024, 1024); }
GetShadingTexture()37 	unsigned int GetShadingTexture() const { return shadingTex; }
GetNormalsTexture()38 	unsigned int GetNormalsTexture() const { return normalsTex; }
GetSpecularTexture()39 	unsigned int GetSpecularTexture() const { return specularTex; }
GetGrassShadingTexture()40 	unsigned int GetGrassShadingTexture() const { return grassShadingTex; }
GetSplatDetailTexture()41 	unsigned int GetSplatDetailTexture() const { return splatDetailTex; }
GetSplatDistrTexture()42 	unsigned int GetSplatDistrTexture() const { return splatDistrTex; }
GetSkyReflectModTexture()43 	unsigned int GetSkyReflectModTexture() const { return skyReflectModTex; }
GetDetailNormalTexture()44 	unsigned int GetDetailNormalTexture() const { return detailNormalTex; }
GetLightEmissionTexture()45 	unsigned int GetLightEmissionTexture() const { return lightEmissionTex; }
GetParallaxHeightTexture()46 	unsigned int GetParallaxHeightTexture() const { return parallaxHeightTex; }
47 
48 	void DrawMinimap() const;
49 	void GridVisibility(CCamera* cam, int quadSize, float maxdist, IQuadDrawer* cb, int extraSize);
50 
51 	void NewGroundDrawer();
52 
53 	int GetNumFeatureTypes();
54 	int GetNumFeatures();
55 	void GetFeatureInfo(MapFeatureInfo* f); // returns all feature info in MapFeatureInfo[NumFeatures]
56 	const char* GetFeatureTypeName(int typeID);
57 
58 	unsigned char* GetInfoMap(const std::string& name, MapBitmapInfo* bm);
59 	void FreeInfoMap(const std::string& name, unsigned char* data);
60 
61 	// NOTE: do not use, just here for backward compatibility with SMFGroundTextures.cpp
GetFile()62 	CSMFMapFile& GetFile() { return file; }
63 
64 
65 	void ConfigureAnisotropy();
GetAnisotropy()66 	float GetAnisotropy() const { return anisotropy; }
67 
HaveSpecularTexture()68 	bool HaveSpecularTexture() const { return haveSpecularTexture; }
HaveSplatTexture()69 	bool HaveSplatTexture() const { return haveSplatTexture; }
70 
71 private:
72 	void ParseHeader();
73 	void LoadHeightMap();
74 	void LoadMinimap();
75 	void InitializeWaterHeightColors();
76 	void CreateSpecularTex();
77 	void CreateSplatDetailTextures();
78 	void CreateGrassTex();
79 	void CreateDetailTex();
80 	void CreateShadingTex();
81 	void CreateNormalTex();
82 
83 	void UpdateVertexNormalsUnsynced(const SRectangle& update);
84 	void UpdateFaceNormalsUnsynced(const SRectangle& update);
85 	void UpdateNormalTexture(const SRectangle& update);
86 	void UpdateShadingTexture(const SRectangle& update);
87 
88 	inline void UpdateShadingTexPart(int idx1, int idx2, unsigned char* dst) const;
89 	inline CBaseGroundDrawer* GetGroundDrawer();
90 
91 	inline const float GetCenterHeightUnsynced(const int x, const int y) const;
92 
93 	inline float DiffuseSunCoeff(const int x, const int y) const;
94 	inline float3 GetLightValue(const int x, const int y) const;
95 	void ParseSMD(std::string filename);
96 
97 public:
98 	// constants
99 	static const int tileScale     =   4;
100 	static const int bigSquareSize = 128; // 32 * tileScale
101 
102 	// globals for SMFGround{Drawer, Textures}
103 	int numBigTexX;
104 	int numBigTexY;
105 	int bigTexSize;
106 	int tileMapSizeX;
107 	int tileMapSizeY;
108 	int tileCount;
109 	int mapSizeX;
110 	int mapSizeZ;
111 	int maxHeightMapIdx;
112 	int heightMapSizeX;
113 
114 	int2 normalTexSize;
115 
116 protected:
117 	CSMFMapFile file;
118 
119 	unsigned int detailTex;         // supplied by the map
120 	unsigned int specularTex;       // supplied by the map, moderates specular contribution
121 	unsigned int shadingTex;        // holds precomputed dot(lightDir, vertexNormal) values
122 	unsigned int normalsTex;        // holds vertex normals in RGBA32F internal format (GL_RGBA + GL_FLOAT)
123 	unsigned int minimapTex;        // supplied by the map
124 	unsigned int splatDetailTex;    // contains per-channel separate greyscale detail-textures (overrides detailTex)
125 	unsigned int splatDistrTex;     // specifies the per-channel distribution of splatDetailTex (map-wide, overrides detailTex)
126 	unsigned int grassShadingTex;   // specifies grass-blade modulation color (defaults to minimapTex)
127 	unsigned int skyReflectModTex;  // modulates sky-reflection RGB intensities (must be the same size as specularTex)
128 	unsigned int detailNormalTex;   // tangent-space offset normals
129 	unsigned int lightEmissionTex;
130 	unsigned int parallaxHeightTex;
131 
132 	bool haveSpecularTexture;
133 	bool haveSplatTexture;
134 
135 	unsigned char waterHeightColors[1024 * 4];
136 
137 	CSMFGroundDrawer* groundDrawer;
138 
139 private:
140 	std::vector<float> cornerHeightMapSynced;
141 	std::vector<float> cornerHeightMapUnsynced;
142 
143 	std::vector<unsigned char> shadingTexBuffer;
144 	bool shadingTexUpdateNeeded;
145 	int shadingTexUpdateProgress;
146 
147 	float anisotropy;
148 };
149 
150 #endif
151