@@ -484,50 +484,54 @@ void TerrainObjectManager::ProcessGrass(
484
484
#endif // USE_PAGED
485
485
}
486
486
487
- void TerrainObjectManager::MoveObjectVisuals (const String& instancename, const Ogre::Vector3& pos)
487
+ void TerrainObjectManager::moveObjectVisuals (const String& instancename, const Ogre::Vector3& pos)
488
488
{
489
- if (m_static_objects.find (instancename) == m_static_objects.end ())
489
+ // Obsolete function kept for backwards-compatibility; does the same as `TerrainEditorObject::setPosition()`
490
+ // -------------------------------------------------------------------------------------------------------
491
+
492
+ TerrainEditorObjectID_t id = FindEditorObjectByInstanceName (instancename);
493
+ if (id == TERRAINEDITOROBJECTID_INVALID)
490
494
{
491
- LOG (instancename+ " not found!" );
495
+ LOG (fmt::format ( " [RoR] `moveObjectVisuals()`: instance name '{}' not found!" , instancename) );
492
496
return ;
493
497
}
494
498
495
- StaticObject obj = m_static_objects[instancename];
496
-
497
- if (!obj.enabled )
498
- return ;
499
-
500
- obj.sceneNode ->setPosition (pos);
499
+ m_editor_objects[id]->setPosition (pos);
501
500
}
502
501
503
- void TerrainObjectManager::unloadObject (const String& instancename)
502
+ void TerrainObjectManager::destroyObject (const String& instancename)
504
503
{
505
- if (m_static_objects.find (instancename) == m_static_objects.end ())
504
+ TerrainEditorObjectID_t id = FindEditorObjectByInstanceName (instancename);
505
+ if (id == -1 )
506
506
{
507
- LOG (" unable to unload object: " + instancename);
507
+ LOG (fmt::format ( " [RoR] `destroyObject()`: instance name '{}' not found! " , instancename) );
508
508
return ;
509
509
}
510
510
511
- StaticObject obj = m_static_objects[instancename];
512
-
513
- if (!obj.enabled )
514
- return ;
515
-
516
- for (auto tri : obj.collTris )
511
+ for (int tri : m_editor_objects[id]->static_collision_tris )
517
512
{
518
513
terrainManager->GetCollisions ()->removeCollisionTri (tri);
519
514
}
520
- for (auto box : obj. collBoxes )
515
+ for (int box : m_editor_objects[id]-> static_collision_boxes )
521
516
{
522
517
terrainManager->GetCollisions ()->removeCollisionBox (box);
523
518
}
524
519
525
- obj.sceneNode ->detachAllObjects ();
526
- obj.sceneNode ->setVisible (false );
527
- obj.enabled = false ;
520
+ // Destroy the scene node and everything attached to it.
521
+ for (Ogre::MovableObject* mova : m_editor_objects[id]->node ->getAttachedObjects ())
522
+ {
523
+ App::GetGfxScene ()->GetSceneManager ()->destroyMovableObject (mova);
524
+ }
525
+ App::GetGfxScene ()->GetSceneManager ()->destroySceneNode (m_editor_objects[id]->node );
528
526
529
- m_editor_objects.erase (std::remove_if (m_editor_objects.begin (), m_editor_objects.end (),
530
- [instancename](TerrainEditorObjectPtr& e) { return e->instance_name == instancename; }), m_editor_objects.end ());
527
+ // Release the object from editor, if active.
528
+ if (id == App::GetGameContext ()->GetTerrain ()->GetTerrainEditor ()->GetSelectedObjectID ())
529
+ {
530
+ App::GetGameContext ()->GetTerrain ()->GetTerrainEditor ()->ClearSelection ();
531
+ }
532
+
533
+ // Forget the object ever existed.
534
+ m_editor_objects.erase (m_editor_objects.begin () + id);
531
535
}
532
536
533
537
ODefDocument* TerrainObjectManager::FetchODef (std::string const & odef_name)
@@ -633,13 +637,6 @@ bool TerrainObjectManager::LoadTerrainObject(const Ogre::String& name, const Ogr
633
637
tenode->pitch (Degree (-90 ));
634
638
tenode->setVisible (true );
635
639
636
- // register in map
637
- StaticObject* obj = &m_static_objects[instancename];
638
- obj->instanceName = instancename;
639
- obj->enabled = true ;
640
- obj->sceneNode = tenode;
641
- obj->collTris .clear ();
642
-
643
640
TerrainEditorObjectPtr object = new TerrainEditorObject ();
644
641
object->name = name;
645
642
object->instance_name = instancename;
@@ -722,7 +719,7 @@ bool TerrainObjectManager::LoadTerrainObject(const Ogre::String& name, const Ogr
722
719
m_map_entities.push_back (SurveyMapEntity (object->type , caption, fmt::format (" icon_{}.dds" , object->type ), /* resource_group:*/ " " , object->position , Ogre::Radian (0 ), -1 ));
723
720
}
724
721
725
- this ->ProcessODefCollisionBoxes (obj , odef, object, race_event);
722
+ this ->ProcessODefCollisionBoxes (object , odef, object, race_event);
726
723
727
724
for (ODefCollisionMesh& cmesh : odef->collision_meshes )
728
725
{
@@ -736,7 +733,7 @@ bool TerrainObjectManager::LoadTerrainObject(const Ogre::String& name, const Ogr
736
733
terrainManager->GetCollisions ()->addCollisionMesh (
737
734
odefname,
738
735
cmesh.mesh_name , pos, tenode->getOrientation (),
739
- cmesh.scale , gm, &(obj-> collTris ));
736
+ cmesh.scale , gm, &(object-> static_collision_tris ));
740
737
}
741
738
742
739
for (ODefParticleSys& psys : odef->particle_systems )
@@ -761,7 +758,7 @@ bool TerrainObjectManager::LoadTerrainObject(const Ogre::String& name, const Ogr
761
758
pAff = pParticleSys->getAffector (i);
762
759
if (pAff->getType () == " ExtinguishableFire" )
763
760
{
764
- ((ExtinguishableFireAffector*)pAff)->setInstanceName (obj-> instanceName );
761
+ ((ExtinguishableFireAffector*)pAff)->setInstanceName (object-> instance_name );
765
762
}
766
763
}
767
764
#endif // USE_ANGELSCRIPT
@@ -1018,7 +1015,7 @@ bool TerrainObjectManager::UpdateTerrainObjects(float dt)
1018
1015
return true ;
1019
1016
}
1020
1017
1021
- void TerrainObjectManager::ProcessODefCollisionBoxes (StaticObject* obj, ODefDocument* odef, const TerrainEditorObjectPtr& params, bool race_event)
1018
+ void TerrainObjectManager::ProcessODefCollisionBoxes (TerrainEditorObjectPtr obj, ODefDocument* odef, const TerrainEditorObjectPtr& params, bool race_event)
1022
1019
{
1023
1020
for (ODefCollisionBox& cbox : odef->collision_boxes )
1024
1021
{
@@ -1046,7 +1043,7 @@ void TerrainObjectManager::ProcessODefCollisionBoxes(StaticObject* obj, ODefDocu
1046
1043
params->instance_name , cbox.force_cam_pos , cbox.cam_pos ,
1047
1044
cbox.scale , cbox.direction , cbox.event_filter , params->script_handler );
1048
1045
1049
- obj->collBoxes .push_back (boxnum);
1046
+ obj->static_collision_boxes .push_back (boxnum);
1050
1047
}
1051
1048
}
1052
1049
}
@@ -1066,3 +1063,18 @@ Ogre::SceneNode* TerrainObjectManager::getGroupingSceneNode()
1066
1063
return App::GetGfxScene ()->GetSceneManager ()->getRootSceneNode ();
1067
1064
}
1068
1065
1066
+ TerrainEditorObjectID_t TerrainObjectManager::FindEditorObjectByInstanceName (std::string const & needle_instance_name)
1067
+ {
1068
+ // Is this the right 'ModernC++' approach? :/
1069
+ auto itor = std::find_if (m_editor_objects.begin (), m_editor_objects.end (),
1070
+ [needle_instance_name](TerrainEditorObjectPtr& obj) { return obj->instance_name == needle_instance_name; });
1071
+ if (itor != m_editor_objects.end ())
1072
+ {
1073
+ return static_cast <int >(std::distance (m_editor_objects.begin (), itor));
1074
+ }
1075
+ else
1076
+ {
1077
+ return TERRAINEDITOROBJECTID_INVALID;
1078
+ }
1079
+ }
1080
+
0 commit comments