载入中...
搜索中...
未找到
RoadProfile.cpp
浏览该文件的文档.
2
3#include "common/Diagnostic.h"
4
5#include <cmath>
6
7namespace eve::procgen::road {
8namespace {
9
10Result<void> validateStyle(const RoadStyle& style) {
11 const float values[] = {style.laneWidth, style.curbWidth, style.curbHeight, style.sidewalkWidth,
12 style.sidewalkHeight, style.deckThickness, style.pierWidth, style.pierDepth,
13 style.pierSpacing, style.pierClearance, style.markingWidth, style.dashLength,
14 style.dashGap, style.uvMeters};
15 for (float v : values) {
16 if (!std::isfinite(v) || v < 0.f)
18 "road style values must be finite and non-negative",
19 "style"));
20 }
21 if (style.laneWidth <= 1e-4f)
23 Diagnostic::error(DiagnosticCode::InvalidArgument, "laneWidth must be positive", "laneWidth"));
24 if (style.uvMeters <= 1e-4f)
26 Diagnostic::error(DiagnosticCode::InvalidArgument, "uvMeters must be positive", "uvMeters"));
27 return Result<void>::success();
28}
29
30void pushPoint(RoadProfile& profile, float side, float up, RoadMaterial material) {
31 profile.points.push_back(RoadProfilePoint{side, up, material});
32}
33
34} // namespace
35
37 switch (material) {
38 case RoadMaterial::Asphalt: return "asphalt";
39 case RoadMaterial::Curb: return "curb";
40 case RoadMaterial::Sidewalk: return "sidewalk";
41 case RoadMaterial::Deck: return "deck";
42 case RoadMaterial::Pier: return "pier";
43 case RoadMaterial::Marking: return "marking";
44 case RoadMaterial::MarkingYellow: return "markingYellow";
45 case RoadMaterial::Nav: return "nav";
46 }
47 return "asphalt";
48}
49
50Result<RoadProfile> makeRoadProfile(const RoadStyle& style, int lanesForward, int lanesBackward) {
51 auto ok = validateStyle(style);
52 if (!ok.ok()) return Result<RoadProfile>::failure(ok.status());
53 if (lanesForward < 0 || lanesForward > 8)
55 Diagnostic::error(DiagnosticCode::InvalidArgument, "lanesForward must be in [0,8]", "lanesForward"));
56 if (lanesBackward < 0 || lanesBackward > 8)
58 Diagnostic::error(DiagnosticCode::InvalidArgument, "lanesBackward must be in [0,8]", "lanesBackward"));
59 if (lanesForward + lanesBackward < 1)
61 DiagnosticCode::InvalidArgument, "road must contain at least one directional lane", "lanes"));
62
63 const float asphaltHalf =
64 0.5f * style.laneWidth * static_cast<float>(lanesForward + lanesBackward);
65 const float barrierInner = asphaltHalf;
66 const float barrierOuter = asphaltHalf + style.curbWidth;
67 const float sidewalkOuter = barrierOuter + style.sidewalkWidth;
68 const float barrierTop = style.curbHeight;
69 const float walkH = style.sidewalkHeight;
70
71 RoadProfile profile;
72 profile.halfWidth = sidewalkOuter;
73
74 // Jersey-barrier U-channel matching the reference interchange look:
75 // sidewalk → tall barrier outer/top/inner → asphalt deck → mirror.
76 pushPoint(profile, -sidewalkOuter, walkH, RoadMaterial::Sidewalk);
77 pushPoint(profile, -barrierOuter, walkH, RoadMaterial::Sidewalk);
78 pushPoint(profile, -barrierOuter, barrierTop, RoadMaterial::Curb);
79 pushPoint(profile, -barrierInner, barrierTop, RoadMaterial::Curb);
80 pushPoint(profile, -barrierInner, 0.f, RoadMaterial::Curb);
81 pushPoint(profile, barrierInner, 0.f, RoadMaterial::Asphalt);
82 pushPoint(profile, barrierInner, barrierTop, RoadMaterial::Curb);
83 pushPoint(profile, barrierOuter, barrierTop, RoadMaterial::Curb);
84 pushPoint(profile, barrierOuter, walkH, RoadMaterial::Sidewalk);
85 pushPoint(profile, sidewalkOuter, walkH, RoadMaterial::Sidewalk);
86
87 return Result<RoadProfile>::success(std::move(profile));
88}
89
90} // namespace eve::procgen::road
Stable, structured diagnostics shared by engine modules.
std::map< std::string, Var > values
float v
HexVec3 up
Material * material
ecs::EntityHandle side
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={}, DiagnosticDetails details={}, std::string source={})
Construct an error diagnostic with the standard error severity.
Definition Diagnostic.h:125
Move-only operation result carrying either a value or Status.
Definition Result.h:155
static Result success(T value)
Construct a successful result owning value.
Definition Result.h:164
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:175
Result< RoadProfile > makeRoadProfile(const RoadStyle &style, int lanesForward, int lanesBackward)
Build a mathematical road cross-section for the given lane counts.
const char * roadMaterialGroup(RoadMaterial material) noexcept
Map a material tag to the MeshBuild group name used by the baker. @ownership borrowed — returns a poi...
RoadMaterial
Profile material tags used when lofting a road cross-section.
Definition RoadTypes.h:122
Owning open profile polyline for one edge style and lane layout.
Definition RoadTypes.h:141
Cross-section and structural style for one road edge.
Definition RoadTypes.h:19
float curbWidth
Jersey-barrier thickness.
Definition RoadTypes.h:21
float curbHeight
Raised barrier height (readable asphalt channel).
Definition RoadTypes.h:22