对照 Unity Grid/Tilemap 与 Grid Placement System 架构补齐建筑放置能力: - 新增 grid 模块:GridConfig(rectangle/hexagon/isometric/staggered/iso-z-as-y、cellGap、stagger、XY/XZ 平面轴)+ 投影/占地旋转纯函数;map::TileProjection 委托复用,公开 API 不变。 - PlacementWorld 支持可选 GridConfig、多通道占用(channel)、bindTileLayer + GID 地形懒解析、XZ 平面 3D 放置、surface 表面接口(内置 plane)。 - BuildingDefinition 新增 channel/renderMode/visual2d/visual3d;rotationMode 支持 hex(60°)。 - 新增 buildingfx 渲染桥:按定义生成/同步 Renderable2D/3D、鬼影+占地光标、2D/3D 网格可视化。 - 新增 PlacementSession(放置/拆除/旋转/指针更新)。 - 测试:grid/building/buildingfx 新用例(REQUIRE 级)+ map/sceneloader 回归;示例 building-tilemap(等距/六角)、building-3d(XZ 地面)。 - 顺带修复 HEAD 上 sceneloader 未迁移 SceneLink 新 API 导致的编译失败(SceneLoader.cpp / test/sceneloader.cpp)。
52 lines
1.6 KiB
C++
52 lines
1.6 KiB
C++
#include "map/TileProjection.h"
|
|
|
|
#include "grid/GridConfig.h"
|
|
#include "grid/GridProjection.h"
|
|
|
|
namespace eve::map {
|
|
namespace {
|
|
|
|
grid::GridConfig toGridConfig(const TileLayer::Config &cfg) {
|
|
grid::GridConfig g;
|
|
switch (cfg.orientation) {
|
|
case MapOrientation::Orthogonal:
|
|
g.layout = grid::GridLayout::Rectangle;
|
|
break;
|
|
case MapOrientation::Isometric:
|
|
g.layout = grid::GridLayout::Isometric;
|
|
break;
|
|
case MapOrientation::Staggered:
|
|
g.layout = grid::GridLayout::Staggered;
|
|
break;
|
|
case MapOrientation::Hexagonal:
|
|
g.layout = grid::GridLayout::Hexagon;
|
|
break;
|
|
}
|
|
g.cellW = cfg.tileW;
|
|
g.cellH = cfg.tileH;
|
|
g.originX = cfg.originX;
|
|
g.originY = cfg.originY;
|
|
g.staggerAxis = cfg.staggerAxis == StaggerAxis::Y ? grid::StaggerAxis::Y
|
|
: grid::StaggerAxis::X;
|
|
g.staggerIndex = cfg.staggerIndex == StaggerIndex::Odd ? grid::StaggerIndex::Odd
|
|
: grid::StaggerIndex::Even;
|
|
g.hexSideLength = cfg.hexSideLength;
|
|
return g;
|
|
}
|
|
|
|
} // namespace
|
|
|
|
void tileToWorld(const TileLayer::Config &cfg, int tx, int ty, float &wx, float &wy) {
|
|
grid::cellToWorld(toGridConfig(cfg), tx, ty, wx, wy);
|
|
}
|
|
|
|
float tileToDepthY(const TileLayer::Config &cfg, int tx, int ty) {
|
|
return grid::cellToDepthY(toGridConfig(cfg), tx, ty);
|
|
}
|
|
|
|
void worldToTile(const TileLayer::Config &cfg, float wx, float wy, int &tx, int &ty) {
|
|
grid::worldToCell(toGridConfig(cfg), wx, wy, tx, ty, cfg.mapW, cfg.mapH);
|
|
}
|
|
|
|
} // namespace eve::map
|