载入中...
搜索中...
未找到
PlacementSession.h
浏览该文件的文档.
1#pragma once
2#include "common/Export.h"
3
4
5// 放置会话:封装「选择建筑 -> 跟随指针 -> 校验 -> 放置 / 拆除」的交互状态。
6// 纯逻辑、不接输入设备;脚本每帧喂指针坐标 / 表面命中,会话内部驱动 Ghost。
7
8#include <string>
9#include <vector>
10
12
13namespace eve::building {
14
15class PlacementWorld;
16class Ghost;
17
36
39public:
43 ~PlacementSession() = default;
44
47
49 void destroy();
50
52 bool startPlacement(PlacementWorld *world, const std::string &buildingId);
54 void stopPlacement();
56 bool isActive() const { return active_; }
58 PlacementWorld *getWorld() const { return world_; }
60 std::string getBuildingId() const;
62 Ghost *getGhost() const { return ghost_; }
63
66 void setMode(const std::string &mode);
68 std::string getMode() const { return mode_; }
69
71 void setRotationDeg(float deg);
73 void rotateBy(float deltaDeg);
75 float getRotationDeg() const;
76
79 bool updateFromWorld(PlacementWorld *world, float worldX, float worldY);
82 bool updateFromWorld3D(PlacementWorld *world, float worldX, float worldY, float worldZ);
85 bool updateFromSurface(PlacementWorld *world, const std::string &surface, float x, float y);
87 EdgeUpdateStatus updateEdge(PlacementWorld *world, int cellX, int cellY,
88 const std::string &direction);
90 CornerUpdateStatus updateCorner(PlacementWorld *world, int vertexX, int vertexY);
92 FreeUpdateStatus updateFree(PlacementWorld *world, float worldX, float worldY,
93 float elevation = 0.f);
94
96 bool isValid() const;
98 std::string getReason() const;
99
106 int execute();
108 EdgeLineExecuteStatus executeEdgeLine(int startVertexX, int startVertexY, int endVertexX,
109 int endVertexY);
111 EdgePathUpdateStatus beginEdgePath(int vertexX, int vertexY);
113 EdgePathUpdateStatus appendEdgePathVertex(int vertexX, int vertexY);
115 EdgeLineExecuteStatus executeEdgePath();
117 int getEdgePathVertexCount() const { return static_cast<int>(edgePathVertices_.size()); }
119 EdgePathUpdateStatus beginEdgeCurve(float x, float y);
121 EdgePathUpdateStatus appendEdgeCurveControlPoint(float x, float y);
123 EdgeLineExecuteStatus executeEdgeCurve(int subdivisions);
131 EdgeLineExecuteStatus executeEdgeCurveOnSurface(int subdivisions,
132 const std::string &surfaceName);
135 return static_cast<int>(edgeCurveControlPoints_.size());
136 }
138 const std::vector<PlacementSystem::EdgeCurvePoint> &edgeCurveControlPoints() const {
139 return edgeCurveControlPoints_;
140 }
142 int getLastPlacedCount() const { return static_cast<int>(lastPlacedIds_.size()); }
144 int getLastPlacedId(int index) const;
146 PlacementEditExecuteStatus executeMove(int instanceId);
148 PlacementEditExecuteStatus executeReplace(int instanceId);
150 int getLastEditedId() const { return lastEditedId_; }
152 AreaExecuteStatus previewRectangle(int minCellX, int minCellY, int maxCellX, int maxCellY);
154 AreaExecuteStatus previewBrush(int centerCellX, int centerCellY, int radius);
156 AreaExecuteStatus executeRectangle(int minCellX, int minCellY, int maxCellX, int maxCellY);
158 AreaExecuteStatus executeBrush(int centerCellX, int centerCellY, int radius);
160 int getAreaPreviewCount() const { return static_cast<int>(areaPreview_.cells.size()); }
162 int getAreaPreviewCellX(int index) const;
164 int getAreaPreviewCellY(int index) const;
166 bool getAreaPreviewAccepted(int index) const;
168 std::string getAreaPreviewReason(int index) const;
169
176 PatternUpdateStatus beginPattern(const std::string &kind);
178 PatternUpdateStatus appendPatternPoint(float x, float y);
180 PatternUpdateStatus setPatternRadius(int radius);
182 PatternUpdateStatus setPatternSubdivisions(int subdivisions);
184 PatternUpdateStatus setPatternSurface(const std::string &surfaceName);
186 PatternUpdateStatus previewPattern();
188 PatternExecuteStatus executePattern();
190 std::string getPatternKind() const;
193 return static_cast<int>(patternRequest_.points.size());
194 }
197 return patternPreview_.anchorCount();
198 }
200 int getPatternPreviewX(int index) const;
202 int getPatternPreviewY(int index) const;
204 std::string getPatternPreviewAxis(int index) const;
206 bool getPatternPreviewAccepted(int index) const;
208 std::string getPatternPreviewReason(int index) const;
209
210private:
211 void refreshValidate();
212
213 PlacementWorld *world_ = nullptr;
214 Ghost *ghost_ = nullptr;
215 std::string mode_ = "place";
216 bool active_ = false;
217 std::vector<int> lastPlacedIds_;
218 std::vector<CornerAddress> edgePathVertices_;
219 std::vector<PlacementSystem::EdgeCurvePoint> edgeCurveControlPoints_;
220 int lastEditedId_ = 0;
221 PlacementSystem::AreaPreview areaPreview_;
222 PlacementSystem::PatternRequest patternRequest_;
223 PlacementSystem::PatternPreview patternPreview_;
224 bool patternActive_ = false;
225};
226
227} // namespace eve::building
float y
Definition AnimClip.cpp:738
float x
Definition AnimClip.cpp:738
#define EVENGINE_API_WORLD
Definition Export.h:109
float elevation
void(* destroy)(void *)
TokenKind kind
World3D * world
float radius
RoadLaneDirection direction
uint32_t index
EVENGINE_API_WORLD public API.
Definition Ghost.h:16
EVENGINE_API_WORLD public API.
PlacementSession(const PlacementSession &)=delete
PlacementWorld * getWorld() const
Returns the world.
int getAreaPreviewCount() const
Number of cells in the last successful preview.
bool isActive() const
True when active.
std::string getMode() const
Returns the mode.
int getLastPlacedCount() const
Number of ids committed by the last successful edge-line operation.
int getLastEditedId() const
Instance id affected by the last successful move/replace, or zero.
int getPatternPointCount() const
Number of authoring points in the current pattern.
int getEdgeCurveControlPointCount() const
Number of currently authored cubic Bezier control points.
~PlacementSession()=default
Placement session.
PlacementSession & operator=(const PlacementSession &)=delete
int getPatternPreviewCount() const
Number of concrete edge/cell anchors in the last pattern preview.
Ghost * getGhost() const
Returns the ghost.
int getEdgePathVertexCount() const
Number of logical vertices in the current edge path.
const std::vector< PlacementSystem::EdgeCurvePoint > & edgeCurveControlPoints() const
Borrow the authored controls for same-frame presentation adapters.
格子型建筑放置世界(脚本可直接操作)。
建筑放置模块入口:定义 / 放置世界 / 鬼影 / 变更事件的脚本绑定点。 设计文档:docs/dev/建筑放置系统设计.md
Definition Building.cpp:7
EdgeLineExecuteStatus
Outcome of committing one continuous edge line.
AreaExecuteStatus
Outcome of refreshing or committing an area tool request.
EdgePathUpdateStatus
Outcome of adding a logical vertex to an edge path preview.
FreeUpdateStatus
Outcome of refreshing an exact free-object placement preview.
PatternUpdateStatus
Outcome of configuring or previewing a unified placement pattern.
CornerUpdateStatus
Outcome of refreshing a corner placement preview.
PlacementEditExecuteStatus
Outcome of committing one move or replace edit.
PatternExecuteStatus
Outcome of atomically committing a unified placement pattern.
EdgeUpdateStatus
Outcome of refreshing an edge placement preview.
Owning row-major preview for a rectangular or circular brush request.
Owning non-mutating expansion of an edge or area pattern.
Owning, renderer-neutral request for one atomic placement pattern.