7Result<void> CrowdRuntimeApplier::apply(
const CrowdDocumentTarget& document,
8 crowd::Crowd* runtime)
const {
10 return eve::editing::failed<void>(EditorStatus::Rejected,
RuleId(
"editor.crowd.runtime"),
11 "Live Crowd runtime is required");
12 const auto diagnostics = document.validate();
13 for (
const auto& diagnostic : diagnostics)
16 const auto agents = document.agents();
17 if (agents.size() >
static_cast<std::size_t
>(runtime->getMaxAgents()))
18 return eve::editing::failed<void>(EditorStatus::Rejected,
RuleId(
"editor.crowd.runtime-capacity"),
19 "Crowd document exceeds the runtime agent capacity");
20 std::map<StableId, CrowdPathRecord>
paths;
22 runtime->clearAgents();
23 for (
const auto& agent : agents) {
24 const int index = runtime->addNamedAgent(agent.id.value(),
static_cast<float>(agent.x),
25 static_cast<float>(agent.y),
static_cast<float>(agent.heading),
static_cast<float>(agent.radius));
27 runtime->clearAgents();
28 return eve::editing::failed<void>(EditorStatus::Failed,
RuleId(
"editor.crowd.runtime-capacity"),
29 "Crowd runtime rejected an agent or reached capacity");
31 runtime->setAgentSpeed(
index,
static_cast<float>(agent.maximumSpeed));
32 std::string
action = agent.behavior;
33 if (action ==
"path") {
36 runtime->clearAgents();
37 return eve::editing::failed<void>(EditorStatus::Conflict,
RuleId(
"editor.crowd.runtime-path"),
38 "Path agent has no runtime waypoint");
41 runtime->setAgentTarget(
index,
static_cast<float>(
found->second.points.front().x),
42 static_cast<float>(
found->second.points.front().y));
44 if (!runtime->setAgentAction(
index, action)) {
45 runtime->clearAgents();
46 return eve::editing::failed<void>(EditorStatus::Failed,
RuleId(
"editor.crowd.runtime-action"),
47 "Crowd runtime rejected an agent behavior");
50 return eve::editing::applied<void>();
std::map< std::string, std::string > paths
editing::Status EditorStatus
editing::DiagnosticSeverity DiagnosticSeverity
Build metadata (engine git commit, build time, third-party version).