对照 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)。
66 lines
1.8 KiB
C++
66 lines
1.8 KiB
C++
#include "zeroerr/assert.h"
|
|
#include "zeroerr/unittest.h"
|
|
|
|
#include "building/Building.h"
|
|
#include "building/BuildingDef.h"
|
|
#include "building/Ghost.h"
|
|
#include "building/PlacementSystem.h"
|
|
#include "building/PlacementWorld.h"
|
|
#include "buildingfx/BuildingFx.h"
|
|
|
|
using namespace eve::building;
|
|
using namespace eve::buildingfx;
|
|
|
|
TEST_CASE("buildingfx.sync.lifecycle") {
|
|
BuildingRegistry::clear();
|
|
PlacementSystem::clearEvents();
|
|
PlacementSystem::ensureBuiltins();
|
|
|
|
BuildingDefinition hut;
|
|
hut.id = "hut";
|
|
hut.displayName = "Hut";
|
|
hut.footprintW = 2;
|
|
hut.footprintH = 1;
|
|
hut.renderMode = "2d";
|
|
hut.visual2d["colorR"] = "0.8";
|
|
hut.visual2d["colorG"] = "0.4";
|
|
hut.visual2d["colorB"] = "0.2";
|
|
BuildingRegistry::registerBuilding(hut);
|
|
|
|
PlacementWorld world(8, 8, 32.f);
|
|
BuildingFx *fx = BuildingFx::create();
|
|
REQUIRE(fx != nullptr);
|
|
|
|
REQUIRE(fx->attach(&world));
|
|
REQUIRE(fx->isAttached(&world));
|
|
REQUIRE_EQ(fx->getVisualCount(&world), 0);
|
|
|
|
const int a = world.placeAt("hut", 1, 1, 0.f);
|
|
const int b = world.placeAt("hut", 4, 2, 0.f);
|
|
REQUIRE(a > 0);
|
|
REQUIRE(b > 0);
|
|
fx->sync(&world);
|
|
REQUIRE_EQ(fx->getVisualCount(&world), 2);
|
|
|
|
REQUIRE(world.removeBuilding(a));
|
|
fx->sync(&world);
|
|
REQUIRE_EQ(fx->getVisualCount(&world), 1);
|
|
|
|
Ghost ghost;
|
|
ghost.setBuildingId("hut");
|
|
ghost.setFromWorld(&world, 140.f, 80.f);
|
|
fx->updateGhost(&world, &ghost);
|
|
fx->hideGhost(&world);
|
|
|
|
fx->setGridVisible(&world, true);
|
|
REQUIRE(fx->getGridVisible(&world));
|
|
fx->setGridVisible(&world, false);
|
|
REQUIRE(!fx->getGridVisible(&world));
|
|
|
|
REQUIRE(fx->detach(&world));
|
|
REQUIRE(!fx->isAttached(&world));
|
|
REQUIRE_EQ(fx->getVisualCount(&world), 0);
|
|
|
|
BuildingRegistry::clear();
|
|
}
|