mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-19 04:05:58 +01:00
feat(simulation): test mode, --test runs a scenery unattended and exits with the result (eu07/maszyna#541)
eu07 --test -s <scenery> [--test-timeout <s>] runs the scenery in ghostview with
the null renderer (models loaded, no textures), a hidden window, no sound,
network or python, and in fixed steps of 0.03 s of simulation time per frame
(three 10 ms physics steps) as fast as it can. Without -seed it uses a fixed
seed, so two runs give byte-identical physicslogs.
The scenery reports its result to the __test.result memory cell, which the
simulator always creates: value 1 passes once every vehicle has stood still for
1 s, value 0 fails at once. The run ends with exit code
0 pass, 1 fail,
2 a train passed a signal at stop (SetVelocity 0 0, as seen in its driver's
speed table; SetVelocity 0 x on automatic block doesn't count),
3 timeout (test.timeout, default 3600 s of simulation time),
4 standstill (every vehicle still for test.standstill s, default 300, with no
result; a pass with test.pass_on_standstill yes),
5 error (no -s, the scenery didn't load or has no vehicles, an exception).
The test.* keys go in the scenery's config block; test.fail_if_stop_overran no
only logs a signal passed at danger. Outside the test mode a signal passed at
danger is logged.
The null renderer gets a ui backend which draws nothing, hands out the null
texture and material instead of throwing, and ends the ui frame. A GL context
is still made for the hidden window, without asking for a version, as parts
of the ui create textures with gl calls of their own. No crash dialog or
message box in test mode; the window code no longer needs a monitor.
This commit is contained in:
@@ -35,7 +35,18 @@ private:
|
||||
release_() override { /* null implementation, nothing to do */ }
|
||||
};
|
||||
|
||||
// user interface backend which draws nothing: imgui still builds its frames, so the ui code runs as usual
|
||||
class null_imgui_renderer : public imgui_renderer {
|
||||
public:
|
||||
bool Init() override { return true; }
|
||||
void Shutdown() override { /* null implementation, nothing to do */ }
|
||||
// imgui wants its font atlas built before a frame starts; that's done on the cpu, no texture is made of it
|
||||
void BeginFrame() override;
|
||||
void Render() override { /* null implementation, nothing to do */ }
|
||||
};
|
||||
|
||||
// bare-bones render controller, in lack of anything better yet
|
||||
// it's the renderer of the test mode (--test): models are loaded for the physics, textures aren't
|
||||
class null_renderer : public gfx_renderer {
|
||||
|
||||
public:
|
||||
@@ -49,7 +60,7 @@ public:
|
||||
Init( GLFWwindow *Window ) override { return true; }
|
||||
// main draw call. returns false on error
|
||||
bool
|
||||
Render() override { return true; }
|
||||
Render() override;
|
||||
void
|
||||
SwapBuffers() override { /* null implementation, nothing to do */ }
|
||||
inline
|
||||
@@ -105,20 +116,22 @@ public:
|
||||
void
|
||||
Bind_Material( material_handle const Material, TSubModel const *sm = nullptr, lighting_data const *lighting = nullptr ) override { /* null implementation, nothing to do */ }
|
||||
IMaterial const *
|
||||
Material( material_handle const Material ) const override { return m_materials.at(Material - 1).get(); }
|
||||
Material( material_handle const Material ) const override {
|
||||
return ( Material > 0 && static_cast<std::size_t>( Material ) <= m_materials.size() ? m_materials[ Material - 1 ].get() : IMaterial::null_material() ); }
|
||||
// shader methods
|
||||
auto Fetch_Shader( std::string const &name ) -> std::shared_ptr<gl::program> override { throw std::runtime_error("not impl"); }
|
||||
// texture methods
|
||||
// no textures are loaded; whoever asks gets the null texture
|
||||
texture_handle
|
||||
Fetch_Texture( std::string const &Filename, bool const Loadnow = true, GLint format_hint = GL_SRGB_ALPHA ) override { throw std::runtime_error("not impl"); }
|
||||
Fetch_Texture( std::string const &Filename, bool const Loadnow = true, GLint format_hint = GL_SRGB_ALPHA ) override { return null_handle; }
|
||||
void
|
||||
Bind_Texture( texture_handle const Texture ) override { /* null implementation, nothing to do */ }
|
||||
void
|
||||
Bind_Texture( std::size_t const Unit, texture_handle const Texture ) override { /* null implementation, nothing to do */ }
|
||||
opengl_texture &
|
||||
Texture( texture_handle const Texture ) override { throw std::runtime_error("not impl"); }
|
||||
opengl_texture const &
|
||||
Texture( texture_handle const Texture ) const override { throw std::runtime_error("not impl"); }
|
||||
ITexture &
|
||||
Texture( texture_handle const Texture ) override { return *ITexture::null_texture(); }
|
||||
ITexture const &
|
||||
Texture( texture_handle const Texture ) const override { return *ITexture::null_texture(); }
|
||||
// utility methods
|
||||
void
|
||||
Pick_Control_Callback( std::function<void( TSubModel const *, const glm::vec2 )> Callback ) override { /* null implementation, nothing to do */ }
|
||||
@@ -152,11 +165,12 @@ public:
|
||||
|
||||
imgui_renderer *GetImguiRenderer() override
|
||||
{
|
||||
return nullptr;
|
||||
return &m_imgui;
|
||||
}
|
||||
|
||||
private:
|
||||
std::string empty_str;
|
||||
null_imgui_renderer m_imgui;
|
||||
gfx::geometrybank_manager m_geometry;
|
||||
std::vector<std::shared_ptr<opengl_material>> m_materials;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user