Skip to content

Commit 9a288f7

Browse files
committed
engine: Add loop event
1 parent 808ead9 commit 9a288f7

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

engine/src/simulation.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,7 @@ StateId SimulationMachine::Connect::impl(SimulationContext& ctx) {
387387
ctx.coordinator->enroll(r);
388388

389389
// Events:
390+
ctx.callback_loop = r.register_event<events::LoopFactory>();
390391
ctx.callback_start = r.register_event<events::StartFactory>();
391392
ctx.callback_stop = r.register_event<events::StopFactory>();
392393
ctx.callback_success = r.register_event<events::SuccessFactory>();
@@ -808,6 +809,7 @@ StateId SimulationMachine::StepBegin::impl(SimulationContext& ctx) {
808809
ctx.server->refresh_buffer();
809810

810811
// Run time-based triggers
812+
ctx.callback_loop->trigger(ctx.sync);
811813
ctx.callback_time->trigger(ctx.sync);
812814

813815
// Determine whether to continue simulating or stop
@@ -1040,6 +1042,7 @@ StateId SimulationMachine::Pause::impl(SimulationContext& ctx) {
10401042
// TODO(ben): Process triggers that come in so we can also conclude.
10411043
// What kind of triggers do we want to allow? Should we also be processing
10421044
// NEXT trigger events? How after pausing do we resume?
1045+
ctx.callback_loop->trigger(ctx.sync);
10431046
ctx.callback_pause->trigger(ctx.sync);
10441047
std::this_thread::sleep_for(ctx.config.engine.polling_interval);
10451048

engine/src/simulation_context.hpp

+2
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@ DEFINE_NIL_EVENT(Failure, "failure", "simulation failure")
322322
DEFINE_NIL_EVENT(Reset, "reset", "reset of simulation")
323323
DEFINE_NIL_EVENT(Pause, "pause", "pausation of simulation")
324324
DEFINE_NIL_EVENT(Resume, "resume", "resumption of simulation after pause")
325+
DEFINE_NIL_EVENT(Loop, "loop", "begin of inner simulation loop each cycle")
325326

326327
} // namespace events
327328

@@ -355,6 +356,7 @@ struct SimulationContext {
355356
bool pause_execution{false};
356357

357358
// Events
359+
std::shared_ptr<events::LoopCallback> callback_loop;
358360
std::shared_ptr<events::PauseCallback> callback_pause;
359361
std::shared_ptr<events::ResumeCallback> callback_resume;
360362
std::shared_ptr<events::StartCallback> callback_start;

0 commit comments

Comments
 (0)