Skip to content

Draft: feat: make environment stepable

Karl Schrab requested to merge khbner/mantle-api:environment-step into main

This merge request picks up discussion from issue #31.

From our perspective, the environment should be stepable, meaning that the environment implements the simulator part as well. Calling Step() on the environment would therefore advance the simulation state one step ahead. This should (from a callers perspective) be aligned with IScenarioEngine#Step(), by convention.

A usual process of combining environment and scenario engine therefore would look as follows:

environment_->Init();
scenario_engine_->Init();

auto scenario_info = scenario_engine_->GetScenarioInfo();
environment_->LoadEnvironment(scenario_info); // loads the map, but maybe also other resources
scenario_engine_->SetupDynamicContent();

In simulation loop:

environment_->PreStep();
scenario_engine_->PreStep();

environment_->Step();
scenario_engine_->Step();

environment_->PostStep();
scenario_engine_->PostStep();

From looking into gtgen-core it seems that there already are similar concepts used as proposed here. We also could to this solely on implementation side, but from our pov it would improve interchangeability of the environment if it provides the additional step methods.

We also should define via documentation, in which order these calls should be done (scenario_engine or environment first?). We currently use environment-first, gtgen-core calls scenario-engine first, we just need to decide.

I omitted an additional interface IStepable, as it was already decided in #31 that the additional methods should be better added directly to the existing interfaces.

In this draft I also added PreStep() and PostStep() to provide the possibility for resource management between the calls of environment/scenario_engine within one simulation step. We should discuss if implementation of these methods should be optional, or if they should be pure virtual.

Furthermore I replaced the CreateMap(path) method with a more general LoadEnvironment(scenario_info), allowing to pass more information from the scenario engine to the environment which might be required for loading the environment.

image

Edited by Karl Schrab

Merge request reports