对照 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)。
38 lines
1.4 KiB
C++
38 lines
1.4 KiB
C++
#pragma once
|
||
|
||
#include "grid/GridConfig.h"
|
||
|
||
#include <cstdint>
|
||
#include <functional>
|
||
#include <vector>
|
||
|
||
namespace eve::grid {
|
||
|
||
/** cell -> 平面坐标 (px, py)。XY 平面:世界 (x, y);XZ 平面:世界 (x, z)。 */
|
||
void cellToWorld(const GridConfig &cfg, int cx, int cy, float &px, float &py);
|
||
|
||
/** 2D 排序键(格脚点 Y,与 map::tileToDepthY 语义一致);XZ 平面不使用。 */
|
||
float cellToDepthY(const GridConfig &cfg, int cx, int cy);
|
||
|
||
/**
|
||
* 平面坐标 -> 最近格子。staggered / hex 采用有界最近邻搜索
|
||
* (mapW / mapH 提供搜索范围,与 Tiled 拾取语义一致)。
|
||
*/
|
||
void worldToCell(const GridConfig &cfg, float px, float py, int &cx, int &cy,
|
||
int mapW = 1, int mapH = 1);
|
||
|
||
/**
|
||
* 旋转后的占地局部格枚举。mask 为行主序 w*h(空 = 实心矩形)。
|
||
* steps:cardinal 为 90° 步数(0..3);hexMode 为 60° 步数(0..5)。
|
||
* 回调收到归一化局部坐标(旋转后包围盒最小角归零,原点格为锚点)。
|
||
*/
|
||
void foreachRotatedFootprint(int w, int h, const std::vector<uint8_t> &mask, int steps,
|
||
bool hexMode,
|
||
const std::function<void(int lx, int ly)> &fn);
|
||
|
||
/** 旋转后的占地包围盒尺寸。 */
|
||
void rotatedFootprintSize(int w, int h, const std::vector<uint8_t> &mask, int steps,
|
||
bool hexMode, int &outW, int &outH);
|
||
|
||
} // namespace eve::grid
|