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

improvements

This commit is contained in:
milek7
2019-02-23 23:41:25 +01:00
parent 37dc56a8d8
commit 41548af003
7 changed files with 94 additions and 59 deletions

View File

@@ -300,6 +300,7 @@ editor_mode::on_mouse_button( int const Button, int const Action, int const Mods
if (!cloned) if (!cloned)
return; return;
cloned->mark_dirty();
cloned->location(Camera.Pos + GfxRenderer.Mouse_Position()); cloned->location(Camera.Pos + GfxRenderer.Mouse_Position());
simulation::Instances.insert(cloned); simulation::Instances.insert(cloned);
simulation::Region->insert(cloned); simulation::Region->insert(cloned);

View File

@@ -40,6 +40,7 @@ basic_editor::translate( scene::basic_node *Node, glm::dvec3 const &Location, bo
// NOTE: bit of a waste for single nodes, for the sake of less varied code down the road // NOTE: bit of a waste for single nodes, for the sake of less varied code down the road
auto const translation { targetlocation - initiallocation }; auto const translation { targetlocation - initiallocation };
Node->mark_dirty();
if( Node->group() == null_handle ) { if( Node->group() == null_handle ) {
translate_node( Node, Node->location() + translation ); translate_node( Node, Node->location() + translation );
} }

View File

@@ -345,6 +345,10 @@ public:
group( scene::group_handle Group ); group( scene::group_handle Group );
scene::group_handle scene::group_handle
group() const; group() const;
void
mark_dirty() { m_dirty = true; }
bool
dirty() const { return m_dirty; }
protected: protected:
// members // members
@@ -354,6 +358,7 @@ protected:
double m_rangesquaredmax { 0.0 }; // visibility range, max double m_rangesquaredmax { 0.0 }; // visibility range, max
bool m_visible { true }; // visibility flag bool m_visible { true }; // visibility flag
std::string m_name; std::string m_name;
bool m_dirty { false };
private: private:
// methods // methods

View File

@@ -119,24 +119,38 @@ node_groups::insert( scene::group_handle const Group, basic_event *Event ) {
// sends basic content of the class in legacy (text) format to provided stream // sends basic content of the class in legacy (text) format to provided stream
void void
node_groups::export_as_text( std::ostream &Output ) const { node_groups::export_as_text( std::ostream &Output, bool Dirty ) const {
for( auto const &group : m_groupmap ) { for( auto const &group : m_groupmap ) {
bool any = false;
Output << "group\n";
for( auto *node : group.second.nodes ) { for( auto *node : group.second.nodes ) {
if (node->dirty() != Dirty)
continue;
// HACK: auto-generated memory cells aren't exported, so we check for this // HACK: auto-generated memory cells aren't exported, so we check for this
// TODO: is_exportable as basic_node method // TODO: is_exportable as basic_node method
if( ( typeid( *node ) == typeid( TMemCell ) ) if( ( typeid( *node ) == typeid( TMemCell ) )
&& ( false == static_cast<TMemCell *>( node )->is_exportable ) ) { && ( false == static_cast<TMemCell *>( node )->is_exportable ) ) {
continue; continue;
} }
if (!any)
Output << "group\n";
any = true;
node->export_as_text( Output ); node->export_as_text( Output );
} }
for( auto *event : group.second.events ) { for( auto *event : group.second.events ) {
if (Dirty)
continue;
if (!any)
Output << "group\n";
any = true;
event->export_as_text( Output ); event->export_as_text( Output );
} }
Output << "endgroup\n"; if (any)
Output << "endgroup\n";
} }
} }

View File

@@ -48,7 +48,7 @@ public:
return m_groupmap[ Group ]; } return m_groupmap[ Group ]; }
// sends basic content of the class in legacy (text) format to provided stream // sends basic content of the class in legacy (text) format to provided stream
void void
export_as_text( std::ostream &Output ) const; export_as_text(std::ostream &Output , bool Dirty) const;
private: private:
// types // types

View File

@@ -952,7 +952,7 @@ state_serializer::transform( glm::dvec3 Location, scene::scratch_data const &Scr
// stores class data in specified file, in legacy (text) format // stores class data in specified file, in legacy (text) format
void void
state_serializer::export_as_text( std::string const &Scenariofile ) const { state_serializer::export_as_text(std::string const &Scenariofile) const {
if( Scenariofile == "$.scn" ) { if( Scenariofile == "$.scn" ) {
ErrorLog( "Bad file: scenery export not supported for file \"$.scn\"" ); ErrorLog( "Bad file: scenery export not supported for file \"$.scn\"" );
@@ -961,66 +961,79 @@ state_serializer::export_as_text( std::string const &Scenariofile ) const {
WriteLog( "Scenery data export in progress..." ); WriteLog( "Scenery data export in progress..." );
} }
auto filename { Scenariofile }; auto filename { Scenariofile };
while( filename[ 0 ] == '$' ) { while( filename[ 0 ] == '$' ) {
// trim leading $ char rainsted utility may add to the base name for modified .scn files // 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 ); erase_extension( filename );
filename = Global.asCurrentSceneryPath + filename + "_export"; auto absfilename = Global.asCurrentSceneryPath + filename + "_export";
std::ofstream scmfile { filename + ".scm" }; std::ofstream scmdirtyfile { absfilename + "_dirty.scm" };
// groups export_nodes_to_stream(scmdirtyfile, true);
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 ctrfile { filename + ".ctr" }; std::ofstream scmfile { absfilename + ".scm" };
// mem cells export_nodes_to_stream(scmfile, false);
ctrfile << "// memory cells\n";
for( auto const *memorycell : Memory.sequence() ) { // sounds
if( ( true == memorycell->is_exportable ) // NOTE: sounds currently aren't included in groups
&& ( memorycell->group() == null_handle ) ) { scmfile << "// sounds\n";
memorycell->export_as_text( ctrfile ); Region->export_as_text( scmfile );
}
} scmfile << "// modified objects\ninclude " << filename << "_export_dirty.scm\n";
// events
Events.export_as_text( ctrfile ); 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." ); 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 } // simulation
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------

View File

@@ -40,7 +40,7 @@ public:
deserialize_continue(std::shared_ptr<deserializer_state> state); deserialize_continue(std::shared_ptr<deserializer_state> state);
// stores class data in specified file, in legacy (text) format // stores class data in specified file, in legacy (text) format
void void
export_as_text( std::string const &Scenariofile ) const; export_as_text(std::string const &Scenariofile) const;
// temporary public for editor // temporary public for editor
TAnimModel * deserialize_model( cParser &Input, scene::scratch_data &Scratchpad, scene::node_data const &Nodedata ); TAnimModel * deserialize_model( cParser &Input, scene::scratch_data &Scratchpad, scene::node_data const &Nodedata );
@@ -79,6 +79,7 @@ private:
void skip_until( cParser &Input, std::string const &Token ); void skip_until( cParser &Input, std::string const &Token );
// transforms provided location by specifed rotation and offset // transforms provided location by specifed rotation and offset
glm::dvec3 transform( glm::dvec3 Location, scene::scratch_data const &Scratchpad ); glm::dvec3 transform( glm::dvec3 Location, scene::scratch_data const &Scratchpad );
void export_nodes_to_stream(std::ostream &, bool Dirty) const;
}; };
} // simulation } // simulation