载入中...
搜索中...
未找到
RoadRecipeNetwork.cpp
浏览该文件的文档.
1#include <algorithm>
4namespace eve::procgen::road {
6 auto snapshot = captureRoadNetwork(network);
7 if (!snapshot.ok()) return Result<void>::failure(snapshot.status());
8 auto json = snapshot.value().toJson();
9 if (!json.ok()) return Result<void>::failure(json.status());
10 if (json.value().size() > 8u * 1024u * 1024u)
12 "road recipe snapshot exceeds 8 MiB", "networkSnapshot"));
13 params.setString("networkSnapshot", json.value());
14 return Result<void>::success();
15}
17 Result<RoadNetwork> network = [&]() -> Result<RoadNetwork> {
18 if (params.has("networkSnapshot")) {
19 auto text = params.getString("networkSnapshot", "");
20 if (text.empty() || text.size() > 8u * 1024u * 1024u)
23 "networkSnapshot must be nonempty JSON at most 8 MiB", "networkSnapshot"));
25 if (!value.ok()) return Result<RoadNetwork>::failure(value.status());
26 return restoreRoadNetwork(value.value());
27 }
28 return RoadNetwork::makeScene(params.getString("scene", "straight"), params.getFloat("span", 36.f),
29 params.getFloat("bridgeHeight", 6.f), std::max(1, params.getInt("lanes", 2)),
30 params.getSeed());
31 }();
32 if (!network.ok()) return network;
33
34 const auto roadType = params.getString("roadType", "highway");
35 if (roadType == "highway") return network;
36 if (roadType != "railway")
38 Diagnostic::error(DiagnosticCode::InvalidArgument, "roadType must be highway or railway", "roadType"));
39 // Authored snapshots already carry per-edge styles; only project railway onto demo scenes.
40 if (params.has("networkSnapshot")) return network;
41
42 const int tracks = std::clamp(params.getInt("lanes", 1), 1, 2);
43 auto applied = applyRailwayRoadType(network.value(), tracks);
44 if (!applied.ok()) return Result<RoadNetwork>::failure(applied.status());
45 return network;
46}
47} // namespace eve::procgen::road
std::vector< Track > tracks
Snapshot snapshot
std::vector< RecipeParam > params
Object::Ptr value
std::string text
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={})
Construct an error diagnostic with the standard error severity.
Move-only operation result carrying either a value or Status.
Definition Result.h:176
static Result success(T value)
Construct a successful result owning value.
Definition Result.h:185
const T & value() const &
Borrow the value from a const lvalue after checking success.
Definition Result.h:339
bool ok() const noexcept
Whether this result represents a non-failure outcome.
Definition Result.h:286
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:196
static Result< Value > fromJson(std::string_view json)
Parse one strict JSON value into an owning Value.
Definition Value.cpp:177
Owning, typed generation parameters.
Definition Params.h:27
Owning directed road graph with lane connectivity.
Definition RoadNetwork.h:19
static Result< RoadNetwork > makeScene(const std::string &scene, float span=36.f, float bridgeHeight=6.f, int lanes=2, std::uint32_t seed=1)
Dispatch a named debug/demo scene.
Result< eve::Value > captureRoadNetwork(const RoadNetwork &network)
Capture validated, owning author data using the editor-compatible roadNetwork schema v1....
Result< RoadNetwork > restoreRoadNetwork(const eve::Value &snapshot)
Decode schema v1 privately; unknown fields are ignored and unsupported versions rejected.
EVENGINE_API_DOMAINS Result< void > setRoadRecipeNetwork(Params &params, const RoadNetwork &network)
Store canonical validated author data in the standard recipe's networkSnapshot parameter....
EVENGINE_API_DOMAINS Result< RoadNetwork > resolveRoadRecipeNetwork(const Params &params)
Resolve the recipe's author snapshot, or its procedural scene when no snapshot was supplied.
Result< void > applyRailwayRoadType(RoadNetwork &network, int tracks)
Rewrite every edge to a railway style while preserving bridge/tunnel intervals.