35 namespace engine::events {
59 cloe::EventPtr
clone()
const override {
return std::make_unique<TimeEvent>(name(), time_); }
60 void to_json(cloe::Json& j)
const override {
62 {
"time", cloe::Seconds{time_}.count()},
78 using namespace cloe::schema;
79 static const char* desc =
"absolute number of seconds in simulation time";
91 auto secs = cloe::Seconds{c.
get<
double>(
"time")};
92 return std::make_unique<TimeEvent>(
name(), std::chrono::duration_cast<cloe::Duration>(secs));
95 cloe::EventPtr
make(
const std::string& s)
const override {
97 {
"time", std::stod(s)},
109 cloe::TriggerPtr trigger;
116 TimeCallback(cloe::Logger log, TimeEmplaceHook h) : log_(log), hook_(h) {}
119 auto now = sync.
time();
120 auto when =
dynamic_cast<const TimeEvent&
>(t->event()).time();
123 log_->error(
"Inserting timed trigger for the past!");
124 log_->error(
"> trigger time = {} s", std::chrono::duration_cast<cloe::Seconds>(when).count());
125 log_->error(
"> current time = {} s", std::chrono::duration_cast<cloe::Seconds>(now).count());
127 if (t->is_sticky()) {
128 log_->error(
"Inserting timed trigger that is sticky discards stickiness!");
130 storage_.emplace(std::make_shared<TimeTrigger>(when, std::move(t)));
133 void to_json(cloe::Json& j)
const override {
135 decltype(storage_) st_copy{storage_};
136 while (!st_copy.empty()) {
137 j.push_back(st_copy.top());
143 auto now = sync.
time();
144 while (!storage_.empty() && storage_.top()->time <= now) {
145 auto tt = storage_.top();
147 this->execute(std::move(tt->trigger), sync);
153 TimeEmplaceHook hook_;
159 std::shared_ptr<TimeTrigger>,
160 std::vector<std::shared_ptr<TimeTrigger>>,
161 std::function<bool(
const std::shared_ptr<TimeTrigger>&,
const std::shared_ptr<TimeTrigger>&)>>
162 storage_{[](
const std::shared_ptr<TimeTrigger>& x,
163 const std::shared_ptr<TimeTrigger>& y) ->
bool {
return x->time > y->time; }};
171 using namespace cloe::schema;
172 static const char* desc =
"optional number of seconds from current simulation time";
186 auto secs = cloe::Seconds{c.
get<
double>(
"time")};
187 next_time += std::chrono::duration_cast<cloe::Duration>(secs);
189 return std::make_unique<TimeEvent>(
name(), next_time);
192 std::unique_ptr<cloe::Event>
make(
const std::string& s)
const override {
195 {
"time", std::stod(s)},
204 using cloe::AliasCallback::AliasCallback;
206 auto& time_event =
const_cast<TimeEvent&
>(
dynamic_cast<const TimeEvent&
>(t->event()));
208 time_event.time_ += s.
time();
Definition: trigger.hpp:582
void emplace(TriggerPtr &&t, const Sync &s) override
Definition: trigger.hpp:590
Definition: trigger.hpp:545
friend void to_json(fable::Json &j, const Entity &e)
Definition: entity.hpp:120
void set_name(std::string name)
Definition: entity.cpp:30
const std::string & description() const
Definition: entity.hpp:90
const std::string & name() const
Definition: entity.hpp:67
virtual Duration time() const =0
Definition: trigger.hpp:290
Definition: trigger.hpp:400
Definition: simulation_events.hpp:202
void emplace(cloe::TriggerPtr &&t, const cloe::Sync &s) override
Definition: simulation_events.hpp:205
Definition: simulation_events.hpp:166
std::unique_ptr< cloe::Event > make(const cloe::Conf &c) const override
Definition: simulation_events.hpp:183
std::unique_ptr< cloe::Event > make(const std::string &s) const override
Definition: simulation_events.hpp:192
cloe::TriggerSchema schema() const override
Definition: simulation_events.hpp:170
Definition: simulation_events.hpp:114
void emplace(cloe::TriggerPtr &&t, const cloe::Sync &sync) override
Definition: simulation_events.hpp:118
Definition: simulation_events.hpp:55
cloe::EventPtr clone() const override
Definition: simulation_events.hpp:59
Definition: simulation_events.hpp:73
cloe::EventPtr make(const cloe::Conf &c) const override
Definition: simulation_events.hpp:90
cloe::EventPtr make(const std::string &s) const override
Definition: simulation_events.hpp:95
cloe::TriggerSchema schema() const override
Definition: simulation_events.hpp:77
bool has(const std::string &key) const
Definition: conf.hpp:165
T get() const
Definition: conf.hpp:297
Definition: schema.hpp:173
Definition: number.hpp:36
std::chrono::nanoseconds Duration
Definition: cloe_fwd.hpp:36
#define DEFINE_NIL_EVENT(xName, xname, xdescription)
Definition: nil_event.hpp:58
Definition: trigger.hpp:87
Definition: trigger.hpp:207
Definition: simulation_events.hpp:102