Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add loop event to engine #199

Merged
merged 1 commit into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions engine/src/simulation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@ StateId SimulationMachine::Connect::impl(SimulationContext& ctx) {
ctx.coordinator->enroll(r);

// Events:
ctx.callback_loop = r.register_event<events::LoopFactory>();
cassava marked this conversation as resolved.
Show resolved Hide resolved
ctx.callback_start = r.register_event<events::StartFactory>();
ctx.callback_stop = r.register_event<events::StopFactory>();
ctx.callback_success = r.register_event<events::SuccessFactory>();
Expand Down Expand Up @@ -808,6 +809,7 @@ StateId SimulationMachine::StepBegin::impl(SimulationContext& ctx) {
ctx.server->refresh_buffer();

// Run time-based triggers
ctx.callback_loop->trigger(ctx.sync);
ctx.callback_time->trigger(ctx.sync);

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

Expand Down
2 changes: 2 additions & 0 deletions engine/src/simulation_context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ DEFINE_NIL_EVENT(Failure, "failure", "simulation failure")
DEFINE_NIL_EVENT(Reset, "reset", "reset of simulation")
DEFINE_NIL_EVENT(Pause, "pause", "pausation of simulation")
DEFINE_NIL_EVENT(Resume, "resume", "resumption of simulation after pause")
DEFINE_NIL_EVENT(Loop, "loop", "begin of inner simulation loop each cycle")

} // namespace events

Expand Down Expand Up @@ -355,6 +356,7 @@ struct SimulationContext {
bool pause_execution{false};

// Events
std::shared_ptr<events::LoopCallback> callback_loop;
cassava marked this conversation as resolved.
Show resolved Hide resolved
std::shared_ptr<events::PauseCallback> callback_pause;
std::shared_ptr<events::ResumeCallback> callback_resume;
std::shared_ptr<events::StartCallback> callback_start;
Expand Down