5#include "vipra/types/time.hpp"
7#include "vipra/vipra_behaviors/values/numeric_value.hpp"
9namespace VIPRA::Behaviors {
15class TimedLatchCollection {
18 : _duration(std::move(value))
27 void resize(VIPRA::size latchCnt) { _startTimes.resize(latchCnt, -1); }
36 void latch(VIPRA::time_s startTime, VIPRA::idx pedIdx)
38 if ( _startTimes[pedIdx] == -1 ) {
39 _startTimes[pedIdx] = startTime;
43 [[nodiscard]]
auto size() const -> VIPRA::size {
return _startTimes.size(); }
53 auto check(VIPRA::time_s currTime, VIPRA::idx pedIdx) ->
bool
55 if ( _startTimes[pedIdx] == -1 )
return false;
57 VIPRA::f_pnt val = _duration.value(pedIdx);
58 if ( currTime - _startTimes.at(pedIdx) >= val ) {
59 _startTimes.at(pedIdx) = -1;
72 auto get_duration(VIPRA::idx pedIdx) -> VIPRA::f_pnt {
return _duration.value(pedIdx); }
76 std::vector<VIPRA::time_s> _startTimes;
87 static inline constexpr auto in_time_step(VIPRA::time_s currTime,
88 VIPRA::time_s checkTime,
89 VIPRA::delta_t deltaT) ->
bool
91 const VIPRA::delta_t left = checkTime - deltaT;
92 const VIPRA::delta_t right = checkTime + deltaT;
93 return (currTime > left && currTime < right);
Numeric Values hold runtime VIPRA::f_pnt values taken from Behaviors.
Definition numeric_value.hpp:21
auto check(VIPRA::time_s currTime, VIPRA::idx pedIdx) -> bool
Checks if the latches duration time has passed since it was latched.
Definition timed_latch.hpp:53
void latch(VIPRA::time_s startTime, VIPRA::idx pedIdx)
Sets the latch for pedestrian at pedIdx.
Definition timed_latch.hpp:36
auto get_duration(VIPRA::idx pedIdx) -> VIPRA::f_pnt
Returns the duration for a pedestrians latch.
Definition timed_latch.hpp:72
void resize(VIPRA::size latchCnt)
Sets the size of the container.
Definition timed_latch.hpp:27