VIPRA Documentation
Loading...
Searching...
No Matches
selector_exactly_N.hpp
1
2#pragma once
3
4#include "vipra/logging/logging.hpp"
5
6#include "vipra/vipra_behaviors/selectors/subselector.hpp"
7#include "vipra/vipra_behaviors/values/numeric_value.hpp"
8
9namespace VIPRA::Behaviors {
14struct SelectorExactlyN {
15 NON_DEFAULT_CONSTRUCTIBLE(SelectorExactlyN)
16 COPYABLE(SelectorExactlyN)
17 MOVEABLE(SelectorExactlyN)
18
19 explicit SelectorExactlyN(NumericValue count) : selectCount(std::move(count)) {}
20
21 NumericValue selectCount;
22 auto operator()(const VIPRA::idxVec& /*unused*/, const VIPRA::idxVec& group,
23 auto pack) const -> SelectorResult
24 {
25 auto groupPeds = group;
26
27 auto pedCnt = static_cast<VIPRA::size>(std::round(selectCount.value(0)));
28
29 bool starved = false;
30 if ( pedCnt > group.size() ) {
31 starved = true;
32 pedCnt = group.size();
33 }
34
35 VIPRA::Log::debug("Selector Exaclty N: Selecting {} Pedestrians", pedCnt);
36
37 std::shuffle(groupPeds.begin(), groupPeds.end(), pack.context.engine);
38 groupPeds.resize(pedCnt);
39
40 return {starved, groupPeds};
41 }
42};
43} // namespace VIPRA::Behaviors
Numeric Values hold runtime VIPRA::f_pnt values taken from Behaviors.
Definition numeric_value.hpp:21
static VIPRA_INLINE void debug(fmt::format_string< param_ts... > message, param_ts &&... params)
Calls the provided Logger with Level DEBUG.
Definition logging.hpp:85
Result of a selection.
Definition subselector.hpp:17