153 switch ( target.type ) {
154 case TargetType::PEDESTRIAN:
155 return get_ped_value(target, attr, pack);
156 case TargetType::EVENT:
157 return get_event_value(target, attr, pack);
158 case TargetType::LOCATION:
159 return get_location_value(target, attr, pack);
160 case TargetType::INVALID:
161 return {Type::INVALID,
nullptr};
164 return {Type::INVALID,
nullptr};
179 switch ( target.type ) {
180 case TargetType::PEDESTRIAN:
181 set_ped_value(target, attr, pack, state, value);
183 case TargetType::EVENT:
184 set_event_value(target, attr, pack, value);
186 case TargetType::LOCATION:
187 set_location_value(target, attr, pack, value);
189 case TargetType::INVALID:
206 switch ( target.type ) {
207 case TargetType::PEDESTRIAN:
208 scale_ped_value(target, attr, pack, state, value);
210 case TargetType::EVENT:
211 DSLException::error(
"Cannot Scale Event Value");
213 case TargetType::LOCATION:
214 DSLException::error(
"Cannot Scale Location Value");
216 case TargetType::INVALID:
232 return (value1.type == Type::COORD && value2.type == Type::LOCATION) ||
233 (value1.type == Type::LOCATION && value2.type == Type::COORD);
249 if ( value1.type == Type::COORD && value2.type == Type::LOCATION ) {
250 return pack.context.locations[value2.as<VIPRA::idx>()].is_point_inside(
254 if ( value2.type == Type::COORD && value1.type == Type::LOCATION ) {
255 return pack.context.locations[value1.as<VIPRA::idx>()].is_point_inside(
277 if ( value1.type != value2.type )
return false;
279 switch ( value1.type ) {
281 throw std::runtime_error(
"Invalid Attribute Type");
284 return value1.as<VIPRA::f_pnt>() == value2.as<VIPRA::f_pnt>();
288 return value1.as<stateUID>() == value2.as<stateUID>();
290 return value1.as<EventStatus>() == value2.as<EventStatus>();
292 return value1.as<VIPRA::idx>() == value2.as<VIPRA::idx>();
312 return !
is_equal(value1, value2, pack);
323 template <
typename value_t>
327 auto& valueStore = get_value_store();
328 valueStore.emplace_back(
329 type,
new std::remove_cvref_t<value_t>(std::forward<value_t>(value)));
330 return valueStore.back();
333 inline static void cleanup()
335 for (
auto data : get_value_store() ) {
337 switch ( data.type ) {
342 delete data.as_ptr<VIPRA::f_pnt>();
348 delete data.as_ptr<stateUID>();
351 delete data.as_ptr<EventStatus>();
355 case Type::TOWARDS_LOC:
356 delete data.as_ptr<VIPRA::idx>();
358 case Type::TOWARDS_ATTR:
359 delete data.as_ptr<Attribute>();
368 get_value_store().clear();
371 struct DeferedCleanup {
372 DeferedCleanup(DeferedCleanup
const&) =
default;
373 DeferedCleanup(DeferedCleanup&&) =
default;
374 auto operator=(DeferedCleanup
const&) -> DeferedCleanup& =
default;
375 auto operator=(DeferedCleanup&&) -> DeferedCleanup& =
default;
376 DeferedCleanup() =
default;
377 ~DeferedCleanup() { AttributeHandling::cleanup(); }
384 static inline auto get_value_store() -> std::vector<CAttributeValue>&
386 static std::vector<CAttributeValue> valueStore;
398 [[nodiscard]]
inline static auto get_ped_value(
Target target, Attribute attr,
402 case Attribute::POSITION:
403 return {Type::COORD, &pack.pedset.ped_coords(target.targetIdx)};
404 case Attribute::VELOCITY:
405 return {Type::COORD, &pack.state.velocities[target.targetIdx]};
406 case Attribute::END_GOAL:
407 return {Type::COORD, &pack.goals.end_goal(target.targetIdx)};
408 case Attribute::CURR_GOAL:
409 return {Type::COORD, &pack.goals.current_goal(target.targetIdx)};
410 case Attribute::STATE:
411 return {Type::STATE, &pack.context.pedStates[target.targetIdx]};
413 DSLException::error(
"Invalid Pedestrian Attribute");
425 [[nodiscard]]
inline static auto get_event_value(Target target, Attribute attr,
426 auto pack) -> CAttributeValue
429 case Attribute::LOCATION:
431 DSLException::error(
"Event Locations Not Implmented");
432 case Attribute::STATUS:
433 return {Type::STATUS, &pack.context.events[target.targetIdx].get_status()};
435 DSLException::error(
"Invalid Event Attribute");
447 [[nodiscard]]
inline static auto get_location_value(Target target, Attribute attr,
448 auto pack) -> CAttributeValue
451 case Attribute::POSITION:
452 return {Type::COORD, &pack.context.locations[target.targetIdx].center()};
453 case Attribute::DIMENSIONS:
455 DSLException::error(
"Invalid Location Attribute");
468 inline static void set_ped_value(Target target, Attribute attr, Simpack pack,
469 VIPRA::State& state, CAttributeValue value)
472 case Attribute::POSITION:
473 set_position(target, state, value);
475 case Attribute::VELOCITY:
476 set_velocity(target, pack, state, value);
478 case Attribute::END_GOAL:
479 set_goal(target, pack, value);
481 case Attribute::CURR_GOAL:
482 DSLException::error(
"Unable to set Pedestrian Current Goal");
484 case Attribute::STATE:
485 set_state(target, pack, value);
488 DSLException::error(
"Invalid Pedestrian Attribute");
500 inline static void set_location_value(Target , Attribute attr,
501 Simpack , CAttributeValue )
504 case Attribute::POSITION:
505 case Attribute::DIMENSIONS:
507 DSLException::error(
"Invalid Location Attribute");
520 inline static void scale_ped_value(Target target, Attribute attr, Simpack pack,
521 VIPRA::State& state, CAttributeValue value)
524 case Attribute::POSITION:
525 DSLException::error(
"Cannot Scale Pedestrian Position");
527 case Attribute::VELOCITY:
528 scale_velocity(target, pack, state, value);
530 case Attribute::CURR_GOAL:
531 case Attribute::END_GOAL:
532 DSLException::error(
"Cannot Scale Pedestrian Position");
534 case Attribute::STATE:
535 set_state(target, pack, value);
537 case Attribute::INVALID:
538 case Attribute::LOCATION:
539 case Attribute::STATUS:
540 DSLException::error(
"Invalid Pedestrian Attribute");
542 case Attribute::DIMENSIONS:
543 DSLException::error(
"Pedestrians Do Not Have Dimensions");
556 inline static void set_event_value(Target target, Attribute attr, Simpack pack,
557 CAttributeValue value)
560 case Attribute::LOCATION:
562 DSLException::error(
"Event Locations Not Implmented");
563 case Attribute::STATUS:
564 pack.context.events[target.targetIdx].set_status(
565 value.as<Behaviors::EventStatus>());
568 DSLException::error(
"Invalid Event Attribute");
581 static inline void set_position(Target target, VIPRA::State& state,
582 CAttributeValue value)
584 value.type_check(Type::COORD);
585 state.positions[target.targetIdx] = value.as<VIPRA::f3d>();
595 static inline void set_state(Target target, Simpack pack, CAttributeValue value)
597 value.type_check(Type::STATE);
598 pack.context.pedStates[target.targetIdx] = value.as<stateUID>();
608 static inline void set_goal(Target target, Simpack pack, CAttributeValue value)
610 auto& goals = pack.goals;
611 auto& context = pack.context;
612 auto const& pedset = pack.pedset;
614 if ( value.type == Type::COORD ) {
615 goals.change_end_goal(target.targetIdx, pedset.ped_coords(target.targetIdx),
616 value.as<VIPRA::f3d>(), context.engine);
618 else if ( value.type == Type::LOCATION ) {
620 goals.change_end_goal(
621 target.targetIdx, pedset.ped_coords(target.targetIdx),
622 context.locations[value.as<VIPRA::idx>()].random_point(context.engine),
635 static inline void set_velocity(Target target, Simpack pack, VIPRA::State& state,
636 CAttributeValue value)
638 value.type_check(Type::COORD);
640 state.velocities[target.targetIdx] = value.as<VIPRA::f3d>();
642 VIPRA::f3d originalPos = pack.pedset.ped_coords(target.targetIdx);
643 state.positions[target.targetIdx] =
644 originalPos + (state.velocities[target.targetIdx] * pack.dT);
659 static inline void scale_velocity(Target target, Simpack pack, VIPRA::State& state,
660 CAttributeValue value)
662 value.type_check(Type::NUMBER);
664 NumericValue
const& scale = *
static_cast<NumericValue const*
>(value.value);
666 VIPRA::f_pnt scaleVal = scale.value(target.targetIdx);
667 auto tempvel = state.velocities[target.targetIdx];
669 state.positions[target.targetIdx] =
670 pack.pedset.ped_coords(target.targetIdx) + (tempvel * pack.dT);