17
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-10-17 05:09:20 +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

@@ -344,9 +344,14 @@ editor_mode::editor_mode() {
m_orthophoto.ground_source([](glm::dvec2 const &Min, glm::dvec2 const &Max, std::vector<world_triangle> &Out) {
gather_ground_triangles(Min, Max, true, 50.0f, Out);
});
infra_hooks();
editor_track::observe(this);
}
editor_mode::~editor_mode()
{
editor_track::observe(nullptr);
}
editor_ui *editor_mode::ui() const
{
return static_cast<editor_ui *>(m_userinterface.get());

View File

@@ -34,12 +34,13 @@ http://mozilla.org/MPL/2.0/.
class TAnimModel;
class TTrack;
class editor_mode : public application_mode
class editor_mode : public application_mode, private editor_track::observer
{
public:
// constructors
editor_mode();
~editor_mode() override;
// methods
// initializes internal data structures of the mode. returns: true on success, false otherwise
bool init() override;
@@ -576,7 +577,6 @@ class editor_mode : public application_mode
bool m_bindings_loaded{false};
std::vector<infra::object_state> m_infra_buffer; // states of the objects before the change in progress
bool m_infra_suspended{false};
void infra_hooks();
void infra_load();
void infra_store();
std::vector<TTrack *> infra_scope() const;
@@ -587,9 +587,11 @@ class editor_mode : public application_mode
infra::object_state infra_state_of(infra::binding const &Binding) const;
void infra_restore_state(infra::object_state const &State);
void infra_buffer(infra::binding const &Binding, bool const Refresh);
void infra_capture(TTrack const &Track);
void infra_follow(std::vector<TTrack *> const &Tracks);
void infra_split(TTrack &Original, TTrack &Created, segment_data const &First);
// editor_track::observer
void track_captured(TTrack const &Track) override;
void tracks_committed(std::vector<TTrack *> const &Tracks) override;
void track_retired(TTrack &Track) override;
void track_split(TTrack &Original, TTrack &Created, segment_data const &First) override;
void infra_move(infra::binding &Binding);
void infra_attach(EditorSnapshot &Snapshot);
void render_infra_window();

View File

@@ -461,14 +461,6 @@ double turn_of(infra::binding const &Binding, double const Yaw)
} // namespace
void editor_mode::infra_hooks()
{
editor_track::on_capture = [this](TTrack const &Track) { infra_capture(Track); };
editor_track::on_commit = [this](std::vector<TTrack *> const &Tracks) { infra_follow(Tracks); };
editor_track::on_retire = [this](TTrack &) { infra_follow({}); };
editor_track::on_split = [this](TTrack &Original, TTrack &Created, segment_data const &First) { infra_split(Original, Created, First); };
}
// format of the lines, coordinates in the space of the file:
// <kind> <category> <x y z of the object> <file or name, - if none> <turns 0/1> <anchor count> { <path> <start x y z> <end x y z> }
// the object is the model, the include (position from its parameters), the traction piece (its first point), the memory
@@ -908,7 +900,7 @@ void editor_mode::infra_buffer(infra::binding const &Binding, bool const Refresh
m_infra_buffer.push_back(infra_state_of(Binding));
}
void editor_mode::infra_capture(TTrack const &Track)
void editor_mode::track_captured(TTrack const &Track)
{
if (m_infra_suspended || false == m_infra.follow)
return;
@@ -948,7 +940,7 @@ void editor_mode::infra_capture(TTrack const &Track)
}
}
void editor_mode::infra_follow(std::vector<TTrack *> const &Tracks)
void editor_mode::tracks_committed(std::vector<TTrack *> const &Tracks)
{
if (m_infra_suspended || false == m_infra.follow)
return;
@@ -1027,7 +1019,12 @@ void editor_mode::infra_follow(std::vector<TTrack *> const &Tracks)
}
}
void editor_mode::infra_split(TTrack &Original, TTrack &Created, segment_data const &First)
void editor_mode::track_retired(TTrack &)
{
tracks_committed({});
}
void editor_mode::track_split(TTrack &Original, TTrack &Created, segment_data const &First)
{
if (m_infra_suspended || Created.m_paths.empty())
return;