DDraceNetwork Docs
layer_tiles.h
Go to the documentation of this file.
1#ifndef GAME_EDITOR_MAPITEMS_LAYER_TILES_H
2#define GAME_EDITOR_MAPITEMS_LAYER_TILES_H
3
5#include <game/editor/enums.h>
6#include <map>
7
8#include "layer.h"
9
11{
15};
16
17template<typename T>
18using EditorTileStateChangeHistory = std::map<int, std::map<int, T>>;
19
20enum
21{
26};
27
28struct RECTi
29{
30 int x, y;
31 int w, h;
32};
33
34class CLayerTiles : public CLayer
35{
36protected:
37 template<typename T>
38 void ShiftImpl(T *pTiles, int Direction, int ShiftBy)
39 {
40 switch(Direction)
41 {
42 case DIRECTION_LEFT:
43 ShiftBy = minimum(ShiftBy, m_Width);
44 for(int y = 0; y < m_Height; ++y)
45 {
46 if(ShiftBy < m_Width)
47 mem_move(&pTiles[y * m_Width], &pTiles[y * m_Width + ShiftBy], (m_Width - ShiftBy) * sizeof(T));
48 mem_zero(&pTiles[y * m_Width + (m_Width - ShiftBy)], ShiftBy * sizeof(T));
49 }
50 break;
51 case DIRECTION_RIGHT:
52 ShiftBy = minimum(ShiftBy, m_Width);
53 for(int y = 0; y < m_Height; ++y)
54 {
55 if(ShiftBy < m_Width)
56 mem_move(&pTiles[y * m_Width + ShiftBy], &pTiles[y * m_Width], (m_Width - ShiftBy) * sizeof(T));
57 mem_zero(&pTiles[y * m_Width], ShiftBy * sizeof(T));
58 }
59 break;
60 case DIRECTION_UP:
61 ShiftBy = minimum(ShiftBy, m_Height);
62 for(int y = ShiftBy; y < m_Height; ++y)
63 {
64 mem_copy(&pTiles[(y - ShiftBy) * m_Width], &pTiles[y * m_Width], m_Width * sizeof(T));
65 }
66 for(int y = m_Height - ShiftBy; y < m_Height; ++y)
67 {
68 mem_zero(&pTiles[y * m_Width], m_Width * sizeof(T));
69 }
70 break;
71 case DIRECTION_DOWN:
72 ShiftBy = minimum(ShiftBy, m_Height);
73 for(int y = m_Height - ShiftBy - 1; y >= 0; --y)
74 {
75 mem_copy(&pTiles[(y + ShiftBy) * m_Width], &pTiles[y * m_Width], m_Width * sizeof(T));
76 }
77 for(int y = 0; y < ShiftBy; ++y)
78 {
79 mem_zero(&pTiles[y * m_Width], m_Width * sizeof(T));
80 }
81 break;
82 }
83 }
84 template<typename T>
85 void BrushFlipXImpl(T *pTiles)
86 {
87 for(int y = 0; y < m_Height; y++)
88 for(int x = 0; x < m_Width / 2; x++)
89 std::swap(pTiles[y * m_Width + x], pTiles[(y + 1) * m_Width - 1 - x]);
90 }
91 template<typename T>
92 void BrushFlipYImpl(T *pTiles)
93 {
94 for(int y = 0; y < m_Height / 2; y++)
95 for(int x = 0; x < m_Width; x++)
96 std::swap(pTiles[y * m_Width + x], pTiles[(m_Height - 1 - y) * m_Width + x]);
97 }
98
99public:
100 CLayerTiles(CEditor *pEditor, int w, int h);
101 CLayerTiles(const CLayerTiles &Other);
102 ~CLayerTiles();
103
104 virtual CTile GetTile(int x, int y);
105 virtual void SetTile(int x, int y, CTile Tile);
106 void SetTileIgnoreHistory(int x, int y, CTile Tile) const;
107
108 virtual void Resize(int NewW, int NewH);
109 virtual void Shift(int Direction);
110
111 void MakePalette() const;
112 void Render(bool Tileset = false) override;
113
114 int ConvertX(float x) const;
115 int ConvertY(float y) const;
116 void Convert(CUIRect Rect, RECTi *pOut) const;
117 void Snap(CUIRect *pRect) const;
118 void Clamp(RECTi *pRect) const;
119
120 virtual bool IsEntitiesLayer() const override;
121
122 virtual bool IsEmpty(const std::shared_ptr<CLayerTiles> &pLayer);
123 void BrushSelecting(CUIRect Rect) override;
124 int BrushGrab(std::shared_ptr<CLayerGroup> pBrush, CUIRect Rect) override;
125 void FillSelection(bool Empty, std::shared_ptr<CLayer> pBrush, CUIRect Rect) override;
126 void FillGameTiles(EGameTileOp Fill);
127 bool CanFillGameTiles() const;
128 void BrushDraw(std::shared_ptr<CLayer> pBrush, vec2 WorldPos) override;
129 void BrushFlipX() override;
130 void BrushFlipY() override;
131 void BrushRotate(float Amount) override;
132
133 std::shared_ptr<CLayer> Duplicate() const override;
134 const char *TypeName() const override;
135
136 virtual void ShowInfo();
138
140 {
141 enum
142 {
145 };
146 int m_Modified = 0;
147 int m_Width = -1;
148 int m_Height = -1;
149 int m_Color = 0;
150 };
151 static CUi::EPopupMenuFunctionResult RenderCommonProperties(SCommonPropState &State, CEditor *pEditor, CUIRect *pToolbox, std::vector<std::shared_ptr<CLayerTiles>> &vpLayers, std::vector<int> &vLayerIndices);
152
153 void ModifyImageIndex(FIndexModifyFunction pfnFunc) override;
154 void ModifyEnvelopeIndex(FIndexModifyFunction pfnFunc) override;
155
156 void PrepareForSave();
157 void ExtractTiles(int TilemapItemVersion, const CTile *pSavedTiles, size_t SavedTilesSize) const;
158
159 void GetSize(float *pWidth, float *pHeight) override
160 {
161 *pWidth = m_Width * 32.0f;
162 *pHeight = m_Height * 32.0f;
163 }
164
165 void FlagModified(int x, int y, int w, int h);
166
175
176 // DDRace
177
187
189 inline virtual void ClearHistory() { m_TilesHistory.clear(); }
190
191 static bool HasAutomapEffect(ETilesProp Prop);
192
193protected:
194 void RecordStateChange(int x, int y, CTile Previous, CTile Tile);
195
197
198 friend class CAutoMapper;
199};
200
201#endif
Definition: auto_map.h:9
Definition: editor.h:276
Definition: layer_tiles.h:35
int ConvertY(float y) const
Definition: layer_tiles.cpp:174
int BrushGrab(std::shared_ptr< CLayerGroup > pBrush, CUIRect Rect) override
Definition: layer_tiles.cpp:285
void FillSelection(bool Empty, std::shared_ptr< CLayer > pBrush, CUIRect Rect) override
Definition: layer_tiles.cpp:449
void BrushFlipX() override
Definition: layer_tiles.cpp:540
int m_Tune
Definition: layer_tiles.h:185
virtual void SetTile(int x, int y, CTile Tile)
Definition: layer_tiles.cpp:81
virtual bool IsEntitiesLayer() const override
Definition: layer_tiles.cpp:220
int m_Front
Definition: layer_tiles.h:183
static CUi::EPopupMenuFunctionResult RenderCommonProperties(SCommonPropState &State, CEditor *pEditor, CUIRect *pToolbox, std::vector< std::shared_ptr< CLayerTiles > > &vpLayers, std::vector< int > &vLayerIndices)
Definition: layer_tiles.cpp:1104
void Convert(CUIRect Rect, RECTi *pOut) const
Definition: layer_tiles.cpp:176
void FillGameTiles(EGameTileOp Fill)
Definition: layer_tiles.cpp:704
void BrushFlipY() override
Definition: layer_tiles.cpp:556
bool m_AutoAutoMap
Definition: layer_tiles.h:180
void ModifyEnvelopeIndex(FIndexModifyFunction pfnFunc) override
Definition: layer_tiles.cpp:1294
void ModifyImageIndex(FIndexModifyFunction pfnFunc) override
Definition: layer_tiles.cpp:1289
int m_Speedup
Definition: layer_tiles.h:182
CColor m_Color
Definition: layer_tiles.h:171
virtual void ClearHistory()
Definition: layer_tiles.h:189
int m_AutoMapperConfig
Definition: layer_tiles.h:178
void GetSize(float *pWidth, float *pHeight) override
Definition: layer_tiles.h:159
const char * TypeName() const override
Definition: layer_tiles.cpp:615
int m_Tele
Definition: layer_tiles.h:181
void ShiftImpl(T *pTiles, int Direction, int ShiftBy)
Definition: layer_tiles.h:38
void Clamp(RECTi *pRect) const
Definition: layer_tiles.cpp:194
CLayerTiles(CEditor *pEditor, int w, int h)
Definition: layer_tiles.cpp:16
int m_Game
Definition: layer_tiles.h:167
int ConvertX(float x) const
Definition: layer_tiles.cpp:173
void BrushFlipXImpl(T *pTiles)
Definition: layer_tiles.h:85
void RecordStateChange(int x, int y, CTile Previous, CTile Tile)
Definition: layer_tiles.cpp:93
int m_Switch
Definition: layer_tiles.h:184
~CLayerTiles()
Definition: layer_tiles.cpp:71
bool CanFillGameTiles() const
Definition: layer_tiles.cpp:893
void BrushFlipYImpl(T *pTiles)
Definition: layer_tiles.h:92
void ShowPreventUnusedTilesWarning()
Definition: layer_tiles.cpp:1299
char m_aFileName[IO_MAX_PATH_LENGTH]
Definition: layer_tiles.h:186
virtual void Resize(int NewW, int NewH)
Definition: layer_tiles.cpp:620
int m_Width
Definition: layer_tiles.h:169
int m_Seed
Definition: layer_tiles.h:179
virtual bool IsEmpty(const std::shared_ptr< CLayerTiles > &pLayer)
Definition: layer_tiles.cpp:225
void BrushSelecting(CUIRect Rect) override
Definition: layer_tiles.cpp:253
CTile * m_pTiles
Definition: layer_tiles.h:174
virtual void Shift(int Direction)
Definition: layer_tiles.cpp:656
void SetTileIgnoreHistory(int x, int y, CTile Tile) const
Definition: layer_tiles.cpp:88
void Render(bool Tileset=false) override
Definition: layer_tiles.cpp:131
int m_ColorEnv
Definition: layer_tiles.h:172
CUi::EPopupMenuFunctionResult RenderProperties(CUIRect *pToolbox) override
Definition: layer_tiles.cpp:905
int m_Height
Definition: layer_tiles.h:170
void PrepareForSave()
Definition: layer_tiles.cpp:101
virtual void ShowInfo()
Definition: layer_tiles.cpp:661
void MakePalette() const
Definition: layer_tiles.cpp:124
void BrushRotate(float Amount) override
Definition: layer_tiles.cpp:572
void Snap(CUIRect *pRect) const
Definition: layer_tiles.cpp:184
void FlagModified(int x, int y, int w, int h)
Definition: layer_tiles.cpp:1280
void BrushDraw(std::shared_ptr< CLayer > pBrush, vec2 WorldPos) override
Definition: layer_tiles.cpp:497
int m_Image
Definition: layer_tiles.h:168
void ExtractTiles(int TilemapItemVersion, const CTile *pSavedTiles, size_t SavedTilesSize) const
Definition: layer_tiles.cpp:115
static bool HasAutomapEffect(ETilesProp Prop)
Definition: layer_tiles.cpp:1309
EditorTileStateChangeHistory< STileStateChange > m_TilesHistory
Definition: layer_tiles.h:188
int m_ColorEnvOffset
Definition: layer_tiles.h:173
std::shared_ptr< CLayer > Duplicate() const override
Definition: layer_tiles.cpp:610
virtual CTile GetTile(int x, int y)
Definition: layer_tiles.cpp:76
Definition: layer.h:16
Definition: mapitems.h:236
Definition: ui_rect.h:11
EPopupMenuFunctionResult
Definition: ui.h:289
Definition: vmath.h:302
ETilesProp
Definition: mapitems.h:69
std::function< void(int *pIndex)> FIndexModifyFunction
Definition: editor.h:52
EGameTileOp
Definition: enums.h:20
void mem_zero(T *block, size_t size)
Definition: system.h:178
void mem_copy(void *dest, const void *source, size_t size)
Definition: system.cpp:174
void mem_move(void *dest, const void *source, size_t size)
Definition: system.cpp:179
std::map< int, std::map< int, T > > EditorTileStateChangeHistory
Definition: layer_tiles.h:18
@ DIRECTION_DOWN
Definition: layer_tiles.h:25
@ DIRECTION_LEFT
Definition: layer_tiles.h:22
@ DIRECTION_UP
Definition: layer_tiles.h:24
@ DIRECTION_RIGHT
Definition: layer_tiles.h:23
constexpr T minimum(T a, T b)
Definition: math.h:120
Definition: layer_tiles.h:140
@ MODIFIED_SIZE
Definition: layer_tiles.h:143
@ MODIFIED_COLOR
Definition: layer_tiles.h:144
int m_Height
Definition: layer_tiles.h:148
int m_Modified
Definition: layer_tiles.h:146
int m_Color
Definition: layer_tiles.h:149
int m_Width
Definition: layer_tiles.h:147
Definition: layer_tiles.h:29
int y
Definition: layer_tiles.h:30
int x
Definition: layer_tiles.h:30
int h
Definition: layer_tiles.h:31
int w
Definition: layer_tiles.h:31
Definition: layer_tiles.h:11
CTile m_Previous
Definition: layer_tiles.h:13
bool m_Changed
Definition: layer_tiles.h:12
CTile m_Current
Definition: layer_tiles.h:14
@ IO_MAX_PATH_LENGTH
Definition: types.h:43