17
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-10-17 03:59:19 +02:00

refactor(editor): track observer instead of the function hooks

This commit is contained in:
maj00r
2026-10-04 00:37:26 +02:00
parent 7b8d809078
commit c85a52d5b1
5 changed files with 43 additions and 35 deletions

View File

@@ -122,15 +122,12 @@ bool adjoining_direction(TTrack const *Neighbour, glm::dvec3 const &Joint, bool
}
std::function<void(TTrack const &)> editor_track::on_capture;
std::function<void(std::vector<TTrack *> const &)> editor_track::on_commit;
std::function<void(TTrack &)> editor_track::on_retire;
std::function<void(TTrack &, TTrack &, segment_data const &)> editor_track::on_split;
editor_track::observer *editor_track::s_observer{nullptr};
editor_track::state editor_track::capture(TTrack const &Track)
{
if (on_capture)
on_capture(Track);
if (s_observer != nullptr)
s_observer->track_captured(Track);
state result;
result.paths = Track.m_paths;
result.velocity = Track.fVelocity;
@@ -240,8 +237,8 @@ void editor_track::commit(std::vector<TTrack *> const &Tracks)
for (auto *track : affected)
for (auto *vehicle : track->Dynamics)
vehicle->Move(0.000001);
if (on_commit)
on_commit(Tracks);
if (s_observer != nullptr)
s_observer->tracks_committed(Tracks);
}
void editor_track::commit_parameters(TTrack &Track)
@@ -2219,8 +2216,8 @@ TTrack *editor_track::split_path(TTrack &Track, double const T)
second.rolls[0] = roll;
auto *created{create_path(Track, second)};
Track.m_paths.front() = first;
if (on_split)
on_split(Track, *created, first);
if (s_observer != nullptr)
s_observer->track_split(Track, *created, first);
commit({&Track, created});
return created;
}
@@ -2257,8 +2254,8 @@ void editor_track::retire(TTrack &Track)
update_transition(*neighbour);
rebuild_geometry(*neighbour);
}
if (on_retire)
on_retire(Track);
if (s_observer != nullptr)
s_observer->track_retired(Track);
}
void editor_track::rebuild_geometry(TTrack &Track)