载入中...
搜索中...
未找到
TileLayer.h
浏览该文件的文档.
1#pragma once
2#include "common/Export.h"
3
4
5#include "common/ECS.h"
8
9#include <cstdint>
10#include <string>
11#include <vector>
12
13namespace eve::graphics {
14class Graphics;
15class Camera2D;
16class Canvas;
17class Texture;
18} // namespace eve::graphics
19
20namespace eve::map {
21
22using eve::Color;
23
32class EVENGINE_API_WORLD TileLayer : public ecs::Entity {
33public:
35 ENTITY(TileLayer, ecs::Entity)
36
37
38 void release() override {}
39
41 struct Config {
42 int mapW = 0;
43 int mapH = 0;
44 float tileW = 32.f;
45 float tileH = 32.f;
46 float cellGapX = 0.f;
47 float cellGapY = 0.f;
48 float originX = 0.f;
49 float originY = 0.f;
50 MapOrientation orientation = MapOrientation::Orthogonal;
51 StaggerAxis staggerAxis = StaggerAxis::Y;
52 StaggerIndex staggerIndex = StaggerIndex::Odd;
53 float hexSideLength = 0.f;
54 TileLayer *entity = nullptr;
55 };
56
57 struct Tiles {
59 struct Chunk {
60 int nonEmpty = 0;
61 };
62
63 static constexpr int kChunkSize = 32;
64 std::vector<uint32_t> gids;
65 std::vector<Chunk> chunks;
66 int chunkColumns = 0;
67 int chunkRows = 0;
68 uint64_t revision = 1;
69 std::vector<int> terrainIds;
70 };
71
72 struct Tileset {
75 int gid = 0;
76 int durationMs = 100;
77 };
78
80 struct Animation {
81 int gid = 0;
82 std::vector<AnimationFrame> frames;
83 };
84
86 struct TerrainRule {
87 int gid = 0;
88 int terrain = 0;
89 int neighborMask = 0;
90 int weight = 1;
91 };
92
95 int terrain = 0;
96 std::string kind = "terrain";
97 uint32_t seed = 0;
98 };
99
101 struct CustomData {
102 int gid = 0;
103 std::string name;
104 std::string type;
105 std::string value;
106 };
107
109 struct Visual {
111 struct Subtile {
112 int x = 0;
113 int y = 0;
114 int width = 0;
115 int height = 0;
116 float offsetX = 0.f;
117 float offsetY = 0.f;
118 };
119
122 std::vector<Subtile> parts;
123 int durationMs = 500;
124 };
125
128 float x = 0.f;
129 float y = 0.f;
130 float width = 0.f;
131 float height = 0.f;
132 };
133
134 int gid = 0;
135 int x = 0;
136 int y = 0;
137 int width = 0;
138 int height = 0;
139 float pivotX = 0.f;
140 float pivotY = 0.f;
141 float sortBias = 0.f;
142 int footprintW = 1;
143 int footprintH = 1;
144 bool walkable = true;
145 bool opaque = false;
146 float cost = 1.f;
147 uint8_t enterMask = 0xff;
148 uint8_t exitMask = 0xff;
149 uint32_t semanticFlags = 0;
150 std::vector<SubtileFrame> subtileFrames;
151 std::vector<CollisionShape> collisionShapes;
152 };
153
155 struct Atlas {
156 graphics::Texture *texture = nullptr;
157 int firstGid = 1;
158 int columns = 1;
159 int tileW = 32;
160 int tileH = 32;
161 int margin = 0;
162 int spacing = 0;
163 std::string imagePath;
164 };
165
166 graphics::Texture *texture = nullptr;
167 int firstGid = 1;
168 int columns = 1;
169 int tileW = 32;
170 int tileH = 32;
171 int margin = 0;
172 int spacing = 0;
173 std::vector<Visual> visuals;
174 std::vector<Animation> animations;
175 std::vector<TerrainRule> terrainRules;
176 std::vector<TerrainFamily> terrainFamilies;
177 std::vector<CustomData> customData;
178 std::vector<Atlas> atlases;
179 };
180
181 struct Draw {
182 graphics::Canvas *canvas = nullptr;
184 int layer = 0;
185 bool visible = true;
190 bool receiveLight = false;
191 Color tint{1.f, 1.f, 1.f, 1.f};
193 float visualScaleX = 1.f;
194 float visualScaleY = 1.f;
195 };
196
197 struct Resource {
198 std::string path;
199 std::string texturePath;
200 std::vector<std::string> dependencyPaths;
201 std::vector<int64_t> dependencyModtimes;
202 std::string sourceEngine;
203 std::string sourceVersion;
204 int64_t modtime = -1;
205 bool autoReload = true;
206 };
207
208 COMPONENT(Config, config)
209 COMPONENT(Tiles, tiles)
210 COMPONENT(Tileset, tileset)
211 COMPONENT(Draw, draw)
212 COMPONENT(Resource, resource)
213
214 static TileLayer *createLayer(int mapW, int mapH, float tileW = 32.f, float tileH = 32.f);
215
217 void setOrigin(float x, float y);
218 float getX();
219 float getY();
220
222 int getMapWidth();
223 int getMapHeight();
225 float getTileWidth();
226 float getTileHeight();
227 void setTileSize(float tileW, float tileH);
229 void setCellGap(float gapX, float gapY);
231 void setRenderSpacing(float spacingX, float spacingY);
233 float getCellGapX();
234 float getCellGapY();
236 float getRenderSpacingX();
237 float getRenderSpacingY();
244 void setVisualScale(float scaleX, float scaleY);
246 float getVisualScaleX();
248 float getVisualScaleY();
249
251 void resize(int mapW, int mapH);
252
254 void setTile(int tx, int ty, int gid);
255 int getTile(int tx, int ty);
257 void fillRect(int x, int y, int width, int height, int gid);
259 void fill(int gid);
261 void clear();
262
264 int getRevision();
266 int getChunkSize();
267 int getChunkCount();
268 int getNonEmptyChunkCount();
269
271 void rebuildSpatialIndex();
272
274 void clearTileAnimation(int gid);
275 void addTileAnimationFrame(int gid, int frameGid, int durationMs);
276 int getTileAnimationFrameCount(int gid);
278 void setTileDataString(int gid, const std::string &name, const std::string &value);
279 void setTileDataNumber(int gid, const std::string &name, float value);
280 void setTileDataBool(int gid, const std::string &name, bool value);
281 std::string getTileDataType(int gid, const std::string &name);
282 std::string getTileDataString(int gid, const std::string &name);
283 float getTileDataNumber(int gid, const std::string &name);
284 bool getTileDataBool(int gid, const std::string &name);
286 void setTerrainRule(int gid, int terrain, int neighborMask);
288 void defineAutotileFamily(int terrain, const std::string &kind, int seed = 0);
290 void setAutotileRule(int gid, int terrain, int neighborMask, int weight = 1);
291 void clearTerrainRules();
292 void paintTerrain(int x, int y, int terrain);
294 void paintTerrainRect(int x, int y, int width, int height, int terrain);
296 void fillTerrain(int terrain);
298 void eraseTerrainRect(int x, int y, int width, int height);
299 int getTerrain(int x, int y);
300
302 void setTileset(graphics::Texture *texture, int firstGid, int columns, int margin = 0,
303 int spacing = 0);
305 void setTilesetTileSize(int tileW, int tileH);
317 void setTileVisual(int gid, int x, int y, int width, int height, float pivotX,
318 float pivotY, float sortBias = 0.f);
320 void clearTileVisuals();
322 int getTileVisualCount();
324 void setTileMetadata(int gid, int footprintW, int footprintH, bool walkable,
325 float cost = 1.f);
327 void setTileNavigationProfile(int gid, bool walkable, float cost, int enterMask, int exitMask, bool opaque,
328 int semanticFlags = 0);
330 bool loadTilesetManifest(const std::string &path);
332 graphics::Texture *getTilesetTexture();
333 int getTilesetFirstGid();
334 int getTilesetColumns();
335
337 void setCanvas(graphics::Canvas *canvas);
338 void setCamera(graphics::Camera2D *camera);
339
341 void setLayer(int layer);
342 int getLayer();
343
344 void setVisible(bool visible);
345 bool isVisible();
350 void setReceiveLight(bool receive);
352 bool getReceiveLight();
353
354 void setTint(float r, float g, float b, float a = 1.f);
355
357 bool applyConfig(const std::string &json);
359 bool loadConfig(const std::string &path);
361 bool reloadConfig();
363 void setAutoReload(bool enable);
364 bool getAutoReload();
366 std::string getConfigPath();
367
369 void tileToWorld(int tx, int ty, float &wx, float &wy);
371 float depthY(int tx, int ty);
372 void worldToTile(float wx, float wy, int &tx, int &ty);
373
375 float tileToWorldX(int tx, int ty);
376 float tileToWorldY(int tx, int ty);
377 float depthYAt(int tx, int ty);
378 int worldToTileX(float wx, float wy);
379 int worldToTileY(float wx, float wy);
380};
381
383inline uint32_t tileGid(uint32_t raw) { return raw & 0x0FFFFFFFu; }
384
385} // namespace eve::map
double value
float y
Definition AnimClip.cpp:738
float x
Definition AnimClip.cpp:738
std::string terrain
eve::resource::CostSpec cost
#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
TokenKind kind
std::string name
MeleePoint3 b
Definition MeleeHit.cpp:41
MeleePoint3 a
Definition MeleeHit.cpp:40
MeshVfxBatchedDraw draw
std::vector< uint8_t > exitMask
TileLayer * layer
std::vector< uint8_t > enterMask
std::uint64_t revision
std::string path
Definition PlayHost.cpp:110
std::uint32_t seed
Definition PointSet.cpp:807
std::function< eve::Result< void >()> release
Definition Procgen.cpp:86
std::string resource
double spacingX
int spacing
int firstGid
int columns
float offsetX
float offsetY
int tileW
int margin
int tileH
bool visible
std::vector< WfcTile > tiles
Definition WfcSimple.cpp:22
float wx
float wy
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:18
ECS tile layer entity. Script mutates tile GIDs / tileset / draw; TileRenderSystem batch-draws atlas ...
Definition TileLayer.h:32
卡牌游戏 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:383
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
Config public API.
Definition TileLayer.h:41
std::vector< std::string > dependencyPaths
Definition TileLayer.h:200
std::vector< int64_t > dependencyModtimes
Definition TileLayer.h:201
std::vector< Chunk > chunks
Definition TileLayer.h:65
std::vector< uint32_t > gids
Definition TileLayer.h:64
std::vector< int > terrainIds
Definition TileLayer.h:69
std::vector< AnimationFrame > frames
Definition TileLayer.h:82
One Tiled atlas selected by the greatest firstGid not exceeding a GID.
Definition TileLayer.h:155
Versioned logical terrain family consumed by the canonical resolver.
Definition TileLayer.h:94
Per-GID visual metadata emitted by a project-defined asset pipeline.
Definition TileLayer.h:109
std::vector< CollisionShape > collisionShapes
Definition TileLayer.h:151
std::vector< SubtileFrame > subtileFrames
Definition TileLayer.h:150
std::vector< Atlas > atlases
Definition TileLayer.h:178
std::vector< TerrainFamily > terrainFamilies
Definition TileLayer.h:176
std::vector< TerrainRule > terrainRules
Definition TileLayer.h:175
std::vector< Animation > animations
Definition TileLayer.h:174
std::vector< CustomData > customData
Definition TileLayer.h:177
std::vector< Visual > visuals
Definition TileLayer.h:173