Merge branch 'nodecloner' into sim

This commit is contained in:
milek7
2019-03-15 01:18:07 +01:00
23 changed files with 396 additions and 157 deletions

View File

@@ -956,7 +956,7 @@ state_serializer::transform( glm::dvec3 Location, scene::scratch_data const &Scr
// stores class data in specified file, in legacy (text) format
void
state_serializer::export_as_text( std::string const &Scenariofile ) const {
state_serializer::export_as_text(std::string const &Scenariofile) const {
if( Scenariofile == "$.scn" ) {
ErrorLog( "Bad file: scenery export not supported for file \"$.scn\"" );
@@ -965,66 +965,79 @@ state_serializer::export_as_text( std::string const &Scenariofile ) const {
WriteLog( "Scenery data export in progress..." );
}
auto filename { Scenariofile };
while( filename[ 0 ] == '$' ) {
auto filename { Scenariofile };
while( filename[ 0 ] == '$' ) {
// trim leading $ char rainsted utility may add to the base name for modified .scn files
filename.erase( 0, 1 );
filename.erase( 0, 1 );
}
erase_extension( filename );
filename = Global.asCurrentSceneryPath + filename + "_export";
erase_extension( filename );
auto absfilename = Global.asCurrentSceneryPath + filename + "_export";
std::ofstream scmfile { filename + ".scm" };
// groups
scmfile << "// groups\n";
scene::Groups.export_as_text( scmfile );
// tracks
scmfile << "// paths\n";
for( auto const *path : Paths.sequence() ) {
if( path->group() == null_handle ) {
path->export_as_text( scmfile );
}
}
// traction
scmfile << "// traction\n";
for( auto const *traction : Traction.sequence() ) {
if( traction->group() == null_handle ) {
traction->export_as_text( scmfile );
}
}
// power grid
scmfile << "// traction power sources\n";
for( auto const *powersource : Powergrid.sequence() ) {
if( powersource->group() == null_handle ) {
powersource->export_as_text( scmfile );
}
}
// models
scmfile << "// instanced models\n";
for( auto const *instance : Instances.sequence() ) {
if( instance->group() == null_handle ) {
instance->export_as_text( scmfile );
}
}
// sounds
// NOTE: sounds currently aren't included in groups
scmfile << "// sounds\n";
Region->export_as_text( scmfile );
std::ofstream scmdirtyfile { absfilename + "_dirty.scm" };
export_nodes_to_stream(scmdirtyfile, true);
std::ofstream ctrfile { filename + ".ctr" };
// mem cells
ctrfile << "// memory cells\n";
for( auto const *memorycell : Memory.sequence() ) {
if( ( true == memorycell->is_exportable )
&& ( memorycell->group() == null_handle ) ) {
memorycell->export_as_text( ctrfile );
}
}
// events
Events.export_as_text( ctrfile );
std::ofstream scmfile { absfilename + ".scm" };
export_nodes_to_stream(scmfile, false);
// sounds
// NOTE: sounds currently aren't included in groups
scmfile << "// sounds\n";
Region->export_as_text( scmfile );
scmfile << "// modified objects\ninclude " << filename << "_export_dirty.scm\n";
std::ofstream ctrfile { absfilename + ".ctr" };
// mem cells
ctrfile << "// memory cells\n";
for( auto const *memorycell : Memory.sequence() ) {
if( ( true == memorycell->is_exportable )
&& ( memorycell->group() == null_handle ) ) {
memorycell->export_as_text( ctrfile );
}
}
// events
Events.export_as_text( ctrfile );
WriteLog( "Scenery data export done." );
}
void
state_serializer::export_nodes_to_stream(std::ostream &scmfile, bool Dirty) const {
// groups
scmfile << "// groups\n";
scene::Groups.export_as_text( scmfile, Dirty );
// tracks
scmfile << "// paths\n";
for( auto const *path : Paths.sequence() ) {
if( path->dirty() == Dirty && path->group() == null_handle ) {
path->export_as_text( scmfile );
}
}
// traction
scmfile << "// traction\n";
for( auto const *traction : Traction.sequence() ) {
if( traction->dirty() == Dirty && traction->group() == null_handle ) {
traction->export_as_text( scmfile );
}
}
// power grid
scmfile << "// traction power sources\n";
for( auto const *powersource : Powergrid.sequence() ) {
if( powersource->dirty() == Dirty && powersource->group() == null_handle ) {
powersource->export_as_text( scmfile );
}
}
// models
scmfile << "// instanced models\n";
for( auto const *instance : Instances.sequence() ) {
if( instance && instance->dirty() == Dirty && instance->group() == null_handle ) {
instance->export_as_text( scmfile );
}
}
}
} // simulation
//---------------------------------------------------------------------------