Skip to content

Commit

Permalink
Set visibility of static mesh directly
Browse files Browse the repository at this point in the history
  • Loading branch information
chreden committed May 21, 2024
1 parent c0399f7 commit 187b0d2
Show file tree
Hide file tree
Showing 14 changed files with 19 additions and 37 deletions.
20 changes: 1 addition & 19 deletions trview.app/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ namespace trview
for (const auto& light : _level->lights()) { set_light_visibility(light, true); }
for (const auto& room : _level->rooms()) { set_room_visibility(room, true); }
for (const auto& camera_sink : _level->camera_sinks()) { set_camera_sink_visibility(camera_sink, true); }
for (const auto& static_mesh : _level->static_meshes()) { set_static_mesh_visibility(static_mesh, true); }
for (const auto& static_mesh : _level->static_meshes()) { if (auto stat = static_mesh.lock()) { stat->set_visible(true); } };
};
}

Expand Down Expand Up @@ -295,7 +295,6 @@ namespace trview
}
};
_token_store += _viewer->on_font += [this](auto&& name, auto&& font) { _new_font = { name, font }; };
_token_store += _viewer->on_static_mesh_visibility += [this](const auto& static_mesh, bool value) { set_static_mesh_visibility(static_mesh, value); };
_token_store += _viewer->on_static_mesh_selected += [this](const auto& static_mesh) { select_static_mesh(static_mesh); };

_viewer->set_settings(_settings);
Expand Down Expand Up @@ -658,22 +657,6 @@ namespace trview
}
}

void Application::set_static_mesh_visibility(const std::weak_ptr<IStaticMesh>& static_mesh, bool visible)
{
if (!_level)
{
return;
}

if (const auto static_mesh_ptr = static_mesh.lock())
{
if (static_mesh_ptr->visible() != visible)
{
_level->set_static_mesh_visibility(static_mesh_ptr->number(), visible);
}
}
}

void Application::select_sector(const std::weak_ptr<ISector>& sector)
{
_viewer->select_sector(sector);
Expand Down Expand Up @@ -926,7 +909,6 @@ namespace trview
void Application::setup_statics_window()
{
_token_store += _statics_windows->on_static_selected += [this](const auto& stat) { select_static_mesh(stat); };
_token_store += _statics_windows->on_static_visibility += [this](const auto& stat, bool value) { set_static_mesh_visibility(stat, value); };
}

void Application::save_window_placement()
Expand Down
1 change: 0 additions & 1 deletion trview.app/Application.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ namespace trview
void set_light_visibility(const std::weak_ptr<ILight>& light, bool visible);
void set_room_visibility(const std::weak_ptr<IRoom>& room, bool visible);
void set_camera_sink_visibility(const std::weak_ptr<ICameraSink>& camera_sink, bool visible);
void set_static_mesh_visibility(const std::weak_ptr<IStaticMesh>& static_mesh, bool visible);
void select_sector(const std::weak_ptr<ISector>& sector);
bool is_rando_route() const;
bool should_discard_changes();
Expand Down
1 change: 0 additions & 1 deletion trview.app/Elements/ILevel.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ namespace trview
virtual void set_light_visibility(uint32_t index, bool state) = 0;
virtual void set_room_visibility(uint32_t index, bool state) = 0;
virtual void set_camera_sink_visibility(uint32_t index, bool state) = 0;
virtual void set_static_mesh_visibility(uint32_t index, bool state) = 0;
virtual bool show_camera_sinks() const = 0;
virtual bool show_geometry() const = 0;
virtual bool show_lighting() const = 0;
Expand Down
3 changes: 3 additions & 0 deletions trview.app/Elements/IStaticMesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <trlevel/trtypes.h>
#include <trview.app/Camera/ICamera.h>
#include <trview.app/Geometry/IMesh.h>
#include <trview.common/Event.h>

namespace trview
{
Expand Down Expand Up @@ -42,6 +43,8 @@ namespace trview
virtual bool breakable() const = 0;
virtual bool visible() const = 0;
virtual void set_visible(bool value) = 0;

Event<> on_changed;
};

constexpr std::string to_string(IStaticMesh::Type type) noexcept;
Expand Down
11 changes: 4 additions & 7 deletions trview.app/Elements/Level.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1315,6 +1315,7 @@ namespace trview
{
if (auto stat_ptr = stat.lock())
{
_token_store += stat_ptr->on_changed += [this]() { content_changed(); };
stat_ptr->set_number(index);
}
++index;
Expand All @@ -1327,14 +1328,10 @@ namespace trview
return _static_meshes;
}

void Level::set_static_mesh_visibility(uint32_t index, bool state)
void Level::content_changed()
{
if (auto mesh = static_mesh(index).lock())
{
mesh->set_visible(state);
_regenerate_transparency = true;
on_level_changed();
}
_regenerate_transparency = true;
on_level_changed();
}

std::weak_ptr<IStaticMesh> Level::static_mesh(uint32_t index) const
Expand Down
2 changes: 1 addition & 1 deletion trview.app/Elements/Level.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ namespace trview
const ILight::Source& light_source,
const ICameraSink::Source& camera_sink_source);
std::vector<std::weak_ptr<IStaticMesh>> static_meshes() const override;
void set_static_mesh_visibility(uint32_t index, bool state) override;
std::weak_ptr<IStaticMesh> static_mesh(uint32_t index) const override;
private:
void generate_rooms(const trlevel::ILevel& level, const IRoom::Source& room_source, const IMeshStorage& mesh_storage);
Expand Down Expand Up @@ -161,6 +160,7 @@ namespace trview
void deduplicate_triangles();
void record_models(const trlevel::ILevel& level);
void record_static_meshes();
void content_changed();

std::shared_ptr<graphics::IDevice> _device;
std::vector<std::shared_ptr<IRoom>> _rooms;
Expand Down
6 changes: 5 additions & 1 deletion trview.app/Elements/StaticMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,11 @@ namespace trview

void StaticMesh::set_visible(bool value)
{
_visible = value;
if (value != _visible)
{
_visible = value;
on_changed();
}
}

uint32_t static_mesh_room(const std::shared_ptr<IStaticMesh>& static_mesh)
Expand Down
1 change: 0 additions & 1 deletion trview.app/Mocks/Elements/ILevel.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ namespace trview
MOCK_METHOD(std::optional<uint32_t>, selected_camera_sink, (), (const, override));
MOCK_METHOD(std::weak_ptr<IStaticMesh>, static_mesh, (uint32_t), (const, override));
MOCK_METHOD(std::vector<std::weak_ptr<IStaticMesh>>, static_meshes, (), (const));
MOCK_METHOD(void, set_static_mesh_visibility, (uint32_t, bool), (override));

std::shared_ptr<MockLevel> with_version(trlevel::LevelVersion version)
{
Expand Down
1 change: 0 additions & 1 deletion trview.app/Windows/IViewer.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ namespace trview

Event<std::string, FontSetting> on_font;

Event<std::weak_ptr<IStaticMesh>, bool> on_static_mesh_visibility;
Event<std::weak_ptr<IStaticMesh>> on_static_mesh_selected;

virtual CameraMode camera_mode() const = 0;
Expand Down
1 change: 0 additions & 1 deletion trview.app/Windows/Statics/IStaticsWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,5 @@ namespace trview

Event<> on_window_closed;
Event<std::weak_ptr<IStaticMesh>> on_static_selected;
Event<std::weak_ptr<IStaticMesh>, bool> on_static_visibility;
};
}
1 change: 0 additions & 1 deletion trview.app/Windows/Statics/IStaticsWindowManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,5 @@ namespace trview
virtual void select_static(const std::weak_ptr<IStaticMesh>& static_mesh) = 0;

Event<std::weak_ptr<IStaticMesh>> on_static_selected;
Event<std::weak_ptr<IStaticMesh>, bool> on_static_visibility;
};
}
2 changes: 1 addition & 1 deletion trview.app/Windows/Statics/StaticsWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ namespace trview
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0, 0));
if (ImGui::Checkbox(std::format("##hide-{}", stat_ptr->number()).c_str(), &hidden))
{
on_static_visibility(stat, !hidden);
stat_ptr->set_visible(!hidden);
}
ImGui::PopStyleVar();
}
Expand Down
1 change: 0 additions & 1 deletion trview.app/Windows/Statics/StaticsWindowManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ namespace trview
auto window = _source();
window->set_statics(_statics);
window->on_static_selected += on_static_selected;
window->on_static_visibility += on_static_visibility;
return add_window(window);
}

Expand Down
5 changes: 4 additions & 1 deletion trview.app/Windows/Viewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,10 @@ namespace trview
}
else if (_context_pick.type == PickResult::Type::StaticMesh)
{
on_static_mesh_visibility(level->static_mesh(_context_pick.index), false);
if (auto mesh = level->static_mesh(_context_pick.index).lock())
{
mesh->set_visible(false);
}
}
}
};
Expand Down

0 comments on commit 187b0d2

Please sign in to comment.