VIPRA Documentation
Loading...
Searching...
No Matches
selector_percent.hpp
1#pragma once
2
3#include "vipra/logging/logging.hpp"
4
5#include "vipra/vipra_behaviors/selectors/subselector.hpp"
6
7namespace VIPRA::Behaviors {
12struct SelectorPercent {
13 NON_DEFAULT_CONSTRUCTIBLE(SelectorPercent)
14 COPYABLE(SelectorPercent)
15 MOVEABLE(SelectorPercent)
16
17 explicit SelectorPercent(VIPRA::f_pnt pnt) : percentage(pnt) {}
18
19 VIPRA::f_pnt percentage;
20 auto operator()(std::vector<VIPRA::idx> const& fullGroup,
21 std::vector<VIPRA::idx> const& group, auto pack) const -> SelectorResult
22 {
23 auto groupPeds = group;
24
25 auto count = static_cast<VIPRA::size>(
26 std::floor(percentage * static_cast<VIPRA::f_pnt>(fullGroup.size())));
27
28 bool starved = false;
29 if ( count > group.size() ) {
30 starved = true;
31 count = group.size();
32 }
33
34 VIPRA::Log::debug("Selector Percent: Selecting {} Pedestrians", count);
35
36 std::shuffle(groupPeds.begin(), groupPeds.end(), pack.context.engine);
37 groupPeds.resize(count);
38
39 return {starved, groupPeds};
40 }
41};
42
43} // namespace VIPRA::Behaviors
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