17
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-10-30 23:40:29 +01:00

refactor(track): reusable segment init, geometry rebuild, cell removal

This commit is contained in:
maj00r
2026-10-01 22:48:39 +02:00
parent 521c4f9ebb
commit e46fe6d06c
5 changed files with 282 additions and 179 deletions

View File

@@ -416,6 +416,40 @@ basic_cell::insert( TMemCell *Memorycell ) {
// NOTE: memory cells are virtual 'points' hence they don't ever expand cell range
}
// removes provided path from the cell
void
basic_cell::erase( TTrack *Path ) {
m_paths.erase(
std::remove( std::begin( m_paths ), std::end( m_paths ), Path ),
std::end( m_paths ) );
// drop the path from the animation list, the cell won't update it anymore
if( tTrackAnim == Path ) {
tTrackAnim = Path->SwitchExtension->pNextAnim;
Path->SwitchExtension->pNextAnim = nullptr;
}
else {
for( auto *track = tTrackAnim; track != nullptr; track = track->SwitchExtension->pNextAnim ) {
if( track->SwitchExtension->pNextAnim == Path ) {
track->SwitchExtension->pNextAnim = Path->SwitchExtension->pNextAnim;
Path->SwitchExtension->pNextAnim = nullptr;
break;
}
}
}
Path->RaOwnerSet( nullptr );
// TODO: update cell bounding area
}
// removes provided path from the lookup directory of the cell
void
basic_cell::unregister_end( TTrack *Path ) {
m_directories.paths.erase(
std::remove( std::begin( m_directories.paths ), std::end( m_directories.paths ), Path ),
std::end( m_directories.paths ) );
}
// removes provided model instance from the cell
void
basic_cell::erase( TAnimModel *Instance ) {

View File

@@ -145,6 +145,12 @@ public:
// registers provided traction piece in the lookup directory of the cell
void
register_end( TTraction *Traction );
// removes provided path from the cell
void
erase( TTrack *Path );
// removes provided path from the lookup directory of the cell
void
unregister_end( TTrack *Path );
// removes provided model instance from the cell
void
erase( TAnimModel *Instance );
@@ -308,6 +314,11 @@ public:
void
register_node( Type_ *Node, glm::dvec3 const &Point ) {
cell( Point ).register_end( Node ); }
// removes provided node from the lookup directory of the section enclosing specified point
template <class Type_>
void
unregister_node( Type_ *Node, glm::dvec3 const &Point ) {
cell( Point ).unregister_end( Node ); }
// find a vehicle located nearest to specified point, within specified radius. reurns: located vehicle and distance
std::tuple<TDynamicObject *, float>
find( glm::dvec3 const &Point, float const Radius, bool const Onlycontrolled, bool const Findbycoupler );
@@ -435,6 +446,14 @@ public:
auto const location{ Node->location() };
if( point_inside( location ) ) {
section( location ).erase( Node ); } }
// removes specified node from the region and from the lookup directories of its ends
template <class Type_>
void
erase_and_unregister( Type_ *Node ) {
for( auto const &point : Node->endpoints() ) {
if( point_inside( point ) ) {
section( point ).unregister_node( Node, point ); } }
erase( Node ); }
// find a vehicle located nearest to specified point, within specified radius. reurns: located vehicle and distance
std::tuple<TDynamicObject *, float>
find_vehicle( glm::dvec3 const &Point, float const Radius, bool const Onlycontrolled, bool const Findbycoupler );