1#ifndef GAME_MAP_RENDER_MAP_H
2#define GAME_MAP_RENDER_MAP_H
3
4#include <base/color.h>
5
6#include <game/map/render_interfaces.h>
7#include <game/mapitems.h>
8
9#include <array>
10#include <chrono>
11#include <memory>
12#include <vector>
13
14enum
15{
16 LAYERRENDERFLAG_OPAQUE = 1,
17 LAYERRENDERFLAG_TRANSPARENT = 2,
18
19 TILERENDERFLAG_EXTEND = 4,
20
21 OVERLAYRENDERFLAG_TEXT = 1,
22 OVERLAYRENDERFLAG_EDITOR = 2,
23};
24
25class IEnvelopePointAccess
26{
27public:
28 virtual ~IEnvelopePointAccess() = default;
29 virtual int NumPoints() const = 0;
30 virtual const CEnvPoint *GetPoint(int Index) const = 0;
31 virtual const CEnvPointBezier *GetBezier(int Index) const = 0;
32 int FindPointIndex(CFixedTime Time) const;
33};
34
35class CMapBasedEnvelopePointAccess : public IEnvelopePointAccess
36{
37 std::vector<const CMapItemEnvelope *> m_vpEnvelopes;
38 int m_StartPoint;
39 int m_NumPoints;
40 int m_NumPointsMax;
41 CEnvPoint *m_pPoints;
42 CEnvPointBezier *m_pPointsBezier;
43 CEnvPointBezier_upstream *m_pPointsBezierUpstream;
44
45public:
46 CMapBasedEnvelopePointAccess(class IMap *pMap);
47 const std::vector<const CMapItemEnvelope *> &Envelopes() const;
48 void SetPointsRange(int StartPoint, int NumPoints);
49 int StartPoint() const;
50 int NumPoints() const override;
51 int NumPointsMax() const;
52 const CEnvPoint *GetPoint(int Index) const override;
53 const CEnvPointBezier *GetBezier(int Index) const override;
54};
55
56class IGraphics;
57class ITextRender;
58
59class CTuneColorMapper
60{
61public:
62 CTuneColorMapper();
63 uint8_t TuneNumberToColorIndex(uint8_t TuneNumber);
64 ColorRGBA TuneColorIndexToColor(uint8_t TuneColorIndex) const;
65 void Reset();
66
67private:
68 std::array<uint8_t, 255> m_aTuneNumberToColorIndex;
69 uint8_t m_NextTuneNumberIndex = 0;
70};
71
72class CRenderMap
73{
74 IGraphics *m_pGraphics;
75 ITextRender *m_pTextRender;
76
77public:
78 void Init(IGraphics *pGraphics, ITextRender *pTextRender);
79 IGraphics *Graphics() { return m_pGraphics; }
80 ITextRender *TextRender() { return m_pTextRender; }
81
82 // map render methods (render_map.cpp)
83 static void RenderEvalEnvelope(const IEnvelopePointAccess *pPoints, std::chrono::nanoseconds TimeNanos, ColorRGBA &Result, size_t Channels);
84 void ForceRenderQuads(const CQuad *pQuads, int NumQuads, const IEnvelopeEval *pEnvEval, float Alpha);
85 void RenderTile(int x, int y, unsigned char Index, float Scale, ColorRGBA Color);
86 void RenderTilemap(const CTile *pTiles, int w, int h, float Scale, ColorRGBA Color, int RenderFlags);
87
88 // render a rectangle made of IndexIn tiles, over a background made of IndexOut tiles
89 // the rectangle include all tiles in [RectX, RectX+RectW-1] x [RectY, RectY+RectH-1]
90 void RenderTileRectangle(int RectX, int RectY, int RectW, int RectH, unsigned char IndexIn, unsigned char IndexOut, float Scale, ColorRGBA Color);
91
92 // DDRace
93 void RenderTeleOverlay(const CTeleTile *pTele, int w, int h, float Scale, int OverlayRenderFlags, float Alpha = 1.0f);
94 void RenderSpeedupOverlay(const CSpeedupTile *pSpeedup, int w, int h, float Scale, int OverlayRenderFlags, float Alpha = 1.0f);
95 void RenderSwitchOverlay(const CSwitchTile *pSwitch, int w, int h, float Scale, int OverlayRenderFlags, float Alpha = 1.0f);
96 void RenderTuneOverlay(const CTuneTile *pTune, int w, int h, float Scale, int OverlayRenderFlags, float Alpha = 1.0f);
97 void RenderTelemap(const CTeleTile *pTele, int w, int h, float Scale, ColorRGBA Color, bool ExtendTiles);
98 void RenderSwitchmap(const CSwitchTile *pSwitch, int w, int h, float Scale, ColorRGBA Color, bool ExtendTiles);
99 void RenderTunemap(const CTuneTile *pTune, int w, int h, float Scale, ColorRGBA Color, bool ExtendTiles, CTuneColorMapper *pTuneColorMapper);
100
101 void RenderDebugClip(float ClipX, float ClipY, float ClipW, float ClipH, ColorRGBA Color, float Zoom, const char *pLabel);
102};
103
104#endif
105