File: RoamMeshDrawer.h

package info (click to toggle)
spring 106.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 55,260 kB
  • sloc: cpp: 543,946; ansic: 44,800; python: 12,575; java: 12,201; awk: 5,889; sh: 1,796; asm: 1,546; xml: 655; perl: 405; php: 211; objc: 194; makefile: 76; sed: 2
file content (96 lines) | stat: -rw-r--r-- 2,589 bytes parent folder | download | duplicates (3)
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
/* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */

#ifndef _ROAM_MESH_DRAWER_H_
#define _ROAM_MESH_DRAWER_H_

#include <vector>

#include "Patch.h"
#include "Map/BaseGroundDrawer.h"
#include "Map/SMF/IMeshDrawer.h"
#include "System/EventHandler.h"



class CSMFGroundDrawer;
class CCamera;



// Visualize visible patches in Minimap for debugging?
// #define DRAW_DEBUG_IN_MINIMAP


/**
 * Map mesh drawer implementation; based on the Tread Marks engine
 * by Longbow Digital Arts (www.LongbowDigitalArts.com, circa 2000)
 */
class CRoamMeshDrawer : public IMeshDrawer, public CEventClient
{
public:
	// CEventClient interface
	bool WantsEvent(const std::string& eventName) override {
		return (eventName == "UnsyncedHeightMapUpdate") || (eventName == "DrawInMiniMap");
	}
	bool GetFullRead() const override { return true; }
	int  GetReadAllyTeam() const override { return AllAccessTeam; }

	void UnsyncedHeightMapUpdate(const SRectangle& rect) override;
	void DrawInMiniMap() override;

public:
	enum {
		MESH_NORMAL = 0,
		MESH_SHADOW = 1,
		MESH_COUNT  = 2,
	};

	CRoamMeshDrawer(CSMFGroundDrawer* gd);
	~CRoamMeshDrawer();

	void Update() override;

	void DrawMesh(const DrawPass::e& drawPass) override;
	void DrawBorderMesh(const DrawPass::e& drawPass) override;

	static void ForceNextTesselation(bool normal, bool shadow) {
		forceNextTesselation[MESH_NORMAL] = normal;
		forceNextTesselation[MESH_SHADOW] = shadow;
	}

private:
	void Reset(bool shadowPass);
	void Tessellate(std::vector<Patch>& patches, const CCamera* cam, int viewRadius, bool shadowPass);

private:
	CSMFGroundDrawer* smfGroundDrawer;

	int numPatchesX = 0;
	int numPatchesY = 0;
	std::array<int, MESH_COUNT> lastGroundDetail = {};

	bool heightMapChanged = false;

	std::array<float3, MESH_COUNT> lastCamPos;
	std::array<float3, MESH_COUNT> lastCamDir;

	std::array<int, MESH_COUNT> numPatchesLeftVisibility = {};
	std::array<int, MESH_COUNT> tesselationsSinceLastReset = {};
	std::function<bool(std::vector<Patch>&, const CCamera*, int, bool)> tesselateFuncs[2];

	// [1] is used for the shadow pass, [0] is used for all other passes
	std::vector< Patch > patchMeshGrid[MESH_COUNT];
	std::vector< Patch*> borderPatches[MESH_COUNT];

	// char instead of bool, accessors to different elements must be thread-safe
	std::vector<uint8_t> patchVisFlags[MESH_COUNT];

	// whether tessellation should be forcibly performed next frame
	static bool forceNextTesselation[MESH_COUNT];

#ifdef DRAW_DEBUG_IN_MINIMAP
	std::vector<float3> debugColors;
#endif
};

#endif // _ROAM_MESH_DRAWER_H_