载入中...
搜索中...
未找到
TileLayer.h
浏览该文件的文档.
1#pragma once
2#include "common/Export.h"
3
4
5#include "common/ECS.h"
7#include "map/TileLayerRef.h"
9
10#include <cstdint>
11#include <string>
12#include <vector>
13
14namespace eve::graphics {
15class Graphics;
16class Camera2D;
17class Canvas;
18class Texture;
19} // namespace eve::graphics
20
21namespace eve::map {
22
23using eve::Color;
24
33class EVENGINE_API_WORLD TileLayer : public ecs::Entity {
34public:
36 ENTITY(TileLayer, ecs::Entity)
37
38
39 void release() override {}
40
47 [[nodiscard]] TileLayerRef layerRef() const noexcept { return TileLayerRef{id, generation}; }
48
50 struct Config {
51 int mapW = 0;
52 int mapH = 0;
53 float tileW = 32.f;
54 float tileH = 32.f;
55 float cellGapX = 0.f;
56 float cellGapY = 0.f;
57 float originX = 0.f;
58 float originY = 0.f;
59 MapOrientation orientation = MapOrientation::Orthogonal;
60 StaggerAxis staggerAxis = StaggerAxis::Y;
61 StaggerIndex staggerIndex = StaggerIndex::Odd;
62 float hexSideLength = 0.f;
63 TileLayer *entity = nullptr;
64 };
65
66 struct Tiles {
68 struct Chunk {
69 int nonEmpty = 0;
70 };
71
72 static constexpr int kChunkSize = 32;
73 std::vector<uint32_t> gids;
74 std::vector<Chunk> chunks;
75 int chunkColumns = 0;
76 int chunkRows = 0;
77 uint64_t revision = 1;
78 std::vector<int> terrainIds;
79 };
80
81 struct Tileset {
84 int gid = 0;
85 int durationMs = 100;
86 };
87
89 struct Animation {
90 int gid = 0;
91 std::vector<AnimationFrame> frames;
92 };
93
95 struct TerrainRule {
96 int gid = 0;
97 int terrain = 0;
98 int neighborMask = 0;
99 int weight = 1;
100 };
101
104 int terrain = 0;
105 std::string kind = "terrain";
106 uint32_t seed = 0;
107 };
108
110 struct CustomData {
111 int gid = 0;
112 std::string name;
113 std::string type;
114 std::string value;
115 };
116
118 struct Visual {
120 struct Subtile {
121 int x = 0;
122 int y = 0;
123 int width = 0;
124 int height = 0;
125 float offsetX = 0.f;
126 float offsetY = 0.f;
127 };
128
131 std::vector<Subtile> parts;
132 int durationMs = 500;
133 };
134
137 float x = 0.f;
138 float y = 0.f;
139 float width = 0.f;
140 float height = 0.f;
141 };
142
143 int gid = 0;
144 int x = 0;
145 int y = 0;
146 int width = 0;
147 int height = 0;
148 float pivotX = 0.f;
149 float pivotY = 0.f;
150 float sortBias = 0.f;
151 int footprintW = 1;
152 int footprintH = 1;
153 bool walkable = true;
154 bool opaque = false;
155 float cost = 1.f;
156 uint8_t enterMask = 0xff;
157 uint8_t exitMask = 0xff;
158 uint32_t semanticFlags = 0;
159 std::vector<SubtileFrame> subtileFrames;
160 std::vector<CollisionShape> collisionShapes;
161 };
162
164 struct Atlas {
166 int firstGid = 1;
167 int columns = 1;
168 int tileW = 32;
169 int tileH = 32;
170 int margin = 0;
171 int spacing = 0;
172 std::string imagePath;
173 };
174
176 int firstGid = 1;
177 int columns = 1;
178 int tileW = 32;
179 int tileH = 32;
180 int margin = 0;
181 int spacing = 0;
182 std::vector<Visual> visuals;
183 std::vector<Animation> animations;
184 std::vector<TerrainRule> terrainRules;
185 std::vector<TerrainFamily> terrainFamilies;
186 std::vector<CustomData> customData;
187 std::vector<Atlas> atlases;
188 };
189
190 struct Draw {
191 graphics::Canvas *canvas = nullptr;
193 int layer = 0;
194 bool visible = true;
199 bool receiveLight = false;
200 Color tint{1.f, 1.f, 1.f, 1.f};
202 float visualScaleX = 1.f;
203 float visualScaleY = 1.f;
204 };
205
206 struct Resource {
207 std::string path;
208 std::string texturePath;
209 std::vector<std::string> dependencyPaths;
210 std::vector<int64_t> dependencyModtimes;
211 std::string sourceEngine;
212 std::string sourceVersion;
213 int64_t modtime = -1;
214 bool autoReload = true;
215 };
216
217 COMPONENT(Config, config)
218 COMPONENT(Tiles, tiles)
219 COMPONENT(Tileset, tileset)
220 COMPONENT(Draw, draw)
221 COMPONENT(Resource, resource)
222
223 static TileLayer *createLayer(int mapW, int mapH, float tileW = 32.f, float tileH = 32.f);
224
226 void setOrigin(float x, float y);
227 float getX();
228 float getY();
229
231 int getMapWidth();
232 int getMapHeight();
234 float getTileWidth();
235 float getTileHeight();
236 void setTileSize(float tileW, float tileH);
238 void setCellGap(float gapX, float gapY);
240 void setRenderSpacing(float spacingX, float spacingY);
242 float getCellGapX();
243 float getCellGapY();
245 float getRenderSpacingX();
246 float getRenderSpacingY();
253 void setVisualScale(float scaleX, float scaleY);
255 float getVisualScaleX();
257 float getVisualScaleY();
258
260 void resize(int mapW, int mapH);
261
263 void setTile(int tx, int ty, int gid);
264 int getTile(int tx, int ty);
266 void fillRect(int x, int y, int width, int height, int gid);
268 void fill(int gid);
270 void clear();
271
273 int getRevision();
275 int getChunkSize();
276 int getChunkCount();
277 int getNonEmptyChunkCount();
278
280 void rebuildSpatialIndex();
281
283 void clearTileAnimation(int gid);
284 void addTileAnimationFrame(int gid, int frameGid, int durationMs);
285 int getTileAnimationFrameCount(int gid);
287 void setTileDataString(int gid, const std::string &name, const std::string &value);
288 void setTileDataNumber(int gid, const std::string &name, float value);
289 void setTileDataBool(int gid, const std::string &name, bool value);
290 std::string getTileDataType(int gid, const std::string &name);
291 std::string getTileDataString(int gid, const std::string &name);
292 float getTileDataNumber(int gid, const std::string &name);
293 bool getTileDataBool(int gid, const std::string &name);
295 void setTerrainRule(int gid, int terrain, int neighborMask);
297 void defineAutotileFamily(int terrain, const std::string &kind, int seed = 0);
299 void setAutotileRule(int gid, int terrain, int neighborMask, int weight = 1);
300 void clearTerrainRules();
301 void paintTerrain(int x, int y, int terrain);
303 void paintTerrainRect(int x, int y, int width, int height, int terrain);
305 void fillTerrain(int terrain);
307 void eraseTerrainRect(int x, int y, int width, int height);
308 int getTerrain(int x, int y);
309
311 void setTileset(graphics::Texture *texture, int firstGid, int columns, int margin = 0,
312 int spacing = 0);
314 void setTilesetTileSize(int tileW, int tileH);
326 void setTileVisual(int gid, int x, int y, int width, int height, float pivotX,
327 float pivotY, float sortBias = 0.f);
329 void clearTileVisuals();
331 int getTileVisualCount();
333 void setTileMetadata(int gid, int footprintW, int footprintH, bool walkable,
334 float cost = 1.f);
336 void setTileNavigationProfile(int gid, bool walkable, float cost, int enterMask, int exitMask, bool opaque,
337 int semanticFlags = 0);
339 bool loadTilesetManifest(const std::string &path);
341 graphics::Texture *getTilesetTexture();
342 int getTilesetFirstGid();
343 int getTilesetColumns();
344
346 void setCanvas(graphics::Canvas *canvas);
347 void setCamera(graphics::Camera2D *camera);
348
350 void setLayer(int layer);
351 int getLayer();
352
353 void setVisible(bool visible);
354 bool isVisible();
359 void setReceiveLight(bool receive);
361 bool getReceiveLight();
362
363 void setTint(float r, float g, float b, float a = 1.f);
364
366 bool applyConfig(const std::string &json);
368 bool loadConfig(const std::string &path);
370 bool reloadConfig();
372 void setAutoReload(bool enable);
373 bool getAutoReload();
375 std::string getConfigPath();
376
378 void tileToWorld(int tx, int ty, float &wx, float &wy);
380 float depthY(int tx, int ty);
381 void worldToTile(float wx, float wy, int &tx, int &ty);
382
384 float tileToWorldX(int tx, int ty);
385 float tileToWorldY(int tx, int ty);
386 float depthYAt(int tx, int ty);
387 int worldToTileX(float wx, float wy);
388 int worldToTileY(float wx, float wy);
389};
390
392inline uint32_t tileGid(uint32_t raw) { return raw & 0x0FFFFFFFu; }
393
394} // namespace eve::map
double y
double x
std::string terrain
std::uint64_t revision
eve::resource::CostSpec cost
Generation generation
Definition ECS.cpp:40
std::string name
Definition ECS.cpp:154
double raw
#define EVENGINE_API_WORLD
Definition Export.h:109
tensor::Graph g
Definition GpuGraph.cpp:7
float camera[2]
glm::vec4 tint
double r
std::uint32_t height
std::uint32_t width
std::string id
MeleePoint3 b
Definition MeleeHit.cpp:41
MeleePoint3 a
Definition MeleeHit.cpp:40
MeshVfxBatchedDraw draw
Texture * texture
std::vector< uint8_t > exitMask
TileLayer * layer
std::vector< uint8_t > enterMask
std::string path
Definition PlayHost.cpp:111
Object::Ptr value
const EntityFact * entity
std::vector< WfcTile > tiles
std::string kind
std::string resource
double spacingX
int spacing
int firstGid
int columns
float offsetX
float offsetY
int tileW
int margin
int tileH
bool visible
一层地块的稳定身份(脚本与原生消费者都能解释)。
uint32_t seed
Definition TreeMesh.cpp:276
double weight
Declarative 2D camera (viewport center + zoom).
Canvas public API.
Definition Canvas.h:17
GPU texture created via Graphics::newTexture. Owns GPU resources through an opaque backend handle.
Definition Texture.h:15
ECS tile layer entity. Script mutates tile GIDs / tileset / draw; TileRenderSystem batch-draws atlas ...
Definition TileLayer.h:33
TileLayerRef layerRef() const noexcept
这一层的稳定身份:ECS 槽位 + 换代号。
Definition TileLayer.h:47
卡牌游戏 UI 工具模块:工厂 + 脚本绑定入口。 功能参考 ycarowr/UiCard:扇形手牌布局、抽牌/洗牌、悬浮放大、拖拽到落牌区、 敌方手牌(背面/偷看)、费用不足置灰,以及可实时调节的布局...
Definition Animation.h:25
放置世界:格子占用(多通道)+ 地形语义 + 已放置建筑实例。 行为由 PlacementSystem 提供;本类暴露便于脚本绑定的薄封装方法。 坐标换算统一走 eve::grid(支持 rectang...
MapOrientation
Tile map layout: orthogonal, isometric, staggered, or hexagonal.
void worldToTile(const TileLayer::Config &cfg, float wx, float wy, int &tx, int &ty)
Converts world pixels back to the containing tile index.
uint32_t tileGid(uint32_t raw)
Strip Tiled flip / rotate flags; keep low 28 bits.
Definition TileLayer.h:392
StaggerIndex
Which rows/columns are offset by half a tile.
void tileToWorld(const TileLayer::Config &cfg, int tx, int ty, float &wx, float &wy)
Converts a tile index to world pixels using the layer's projection.
StaggerAxis
Stagger axis for staggered/hex maps (shift every other row/column).
glm::vec4 Color
Render-neutral RGBA color shared by graphics-facing modules.
Definition RenderTypes.h:8
一层地块的稳定身份:ECS 槽位 + 换代号。
Config public API.
Definition TileLayer.h:50
std::vector< std::string > dependencyPaths
Definition TileLayer.h:209
std::vector< int64_t > dependencyModtimes
Definition TileLayer.h:210
std::vector< Chunk > chunks
Definition TileLayer.h:74
std::vector< uint32_t > gids
Definition TileLayer.h:73
std::vector< int > terrainIds
Definition TileLayer.h:78
std::vector< AnimationFrame > frames
Definition TileLayer.h:91
One Tiled atlas selected by the greatest firstGid not exceeding a GID.
Definition TileLayer.h:164
Versioned logical terrain family consumed by the canonical resolver.
Definition TileLayer.h:103
Per-GID visual metadata emitted by a project-defined asset pipeline.
Definition TileLayer.h:118
std::vector< CollisionShape > collisionShapes
Definition TileLayer.h:160
std::vector< SubtileFrame > subtileFrames
Definition TileLayer.h:159
std::vector< Atlas > atlases
Definition TileLayer.h:187
std::vector< TerrainFamily > terrainFamilies
Definition TileLayer.h:185
std::vector< TerrainRule > terrainRules
Definition TileLayer.h:184
std::vector< Animation > animations
Definition TileLayer.h:183
std::vector< CustomData > customData
Definition TileLayer.h:186
std::vector< Visual > visuals
Definition TileLayer.h:182