16
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-07-19 00:59:18 +02:00

Stream visual scenery in the driver (play starts after infrastructure pass)

Splits the progressive load across modes: the loader runs only the first
(infrastructure) pass and then hands off to the driver, so play begins as soon
as tracks/traction/events/signals/the player train are ready. The deferred
visual nodes (3d models, terrain shapes/lines) then stream in from the driver,
a small budget per frame, so the world fills in without a long up-front wait.

- state_serializer: the infrastructure pass now returns to the caller (instead of
  chaining the visual pass), restarting the twin for the visual pass; the visual
  pass uses a small ~8 ms/frame budget and marks the load done at the end. A
  text/compile load (no twin) stays single-pass and finishes as before.
- state_manager: retains the load state across the loader->driver hand-off and
  exposes loading_visuals()/continue_loading_visuals().
- driver_mode::update(): advances the deferred visual load each frame.

Verified on td.scn (playable in ~2 s, visuals complete a few seconds later, no
duplicate objects) and on the large tomaszewo scenery (flora/terrain/models
deferred while infrastructure loads). Inserts run on the main thread before the
render step, so progressive loading needs no locking.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
maj00r
2026-06-22 23:23:36 +02:00
parent fd8bfdbcf3
commit 512595234f
5 changed files with 46 additions and 6 deletions

View File

@@ -56,7 +56,8 @@ bool is_ready { false };
std::shared_ptr<deserializer_state>
state_manager::deserialize_begin(std::string const &Scenariofile) {
return m_serializer.deserialize_begin( Scenariofile );
m_loadstate = m_serializer.deserialize_begin( Scenariofile );
return m_loadstate;
}
bool
@@ -65,6 +66,26 @@ state_manager::deserialize_continue(std::shared_ptr<deserializer_state> state) {
return m_serializer.deserialize_continue(state);
}
// true while a progressive load still has visual nodes to stream in (driver phase)
bool
state_manager::loading_visuals() const {
return ( m_loadstate && m_loadstate->visualphase && ( false == m_loadstate->done ) );
}
// advances the deferred visual-node load by one budgeted step; clears the state when done.
// called every frame from the driver so the world's visuals fill in after play starts.
void
state_manager::continue_loading_visuals() {
if( false == loading_visuals() ) { return; }
m_serializer.deserialize_continue( m_loadstate );
if( m_loadstate->done ) {
WriteLog( "Progressive visual load complete" );
m_loadstate = nullptr;
}
}
// stores class data in specified file, in legacy (text) format
void
state_manager::export_as_text( std::string const &Scenariofile ) const {