Skip to content

Commit

Permalink
Partial rooms diff
Browse files Browse the repository at this point in the history
  • Loading branch information
chreden committed Jan 13, 2025
1 parent 6a8a933 commit 03f0aec
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 9 deletions.
62 changes: 53 additions & 9 deletions trview.app/Windows/Diff/DiffWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "../../Elements/ITrigger.h"
#include "../../Elements/ILight.h"
#include "../../Elements/SoundSource/ISoundSource.h"
#include "../../Elements/IRoom.h"

namespace trview
{
Expand Down Expand Up @@ -302,6 +303,24 @@ namespace trview
return results;
}

std::vector<DiffDetail> get_details(const std::shared_ptr<IRoom>& left, const std::shared_ptr<IRoom>& right)
{
std::vector<DiffDetail> results;
// left->bounding_box() == right->bounding_box() &&
// info
add_if_changed(results, "Alternate Group", left->alternate_group(), right->alternate_group());
add_if_changed(results, "Alternate Mode", left->alternate_mode(), right->alternate_mode());
add_if_changed(results, "Ambient", left->ambient(), right->ambient());
add_if_changed(results, "Ambient Intensity 1", left->ambient_intensity_1(), right->ambient_intensity_1());
add_if_changed(results, "Ambient Intensity 2", left->ambient_intensity_2(), right->ambient_intensity_2());
add_if_changed(results, "Centre", left->centre() * 1024, right->centre() * 1024);
add_if_changed(results, "Flags", left->flags(), right->flags());
add_if_changed(results, "Light Mode", left->light_mode(), right->light_mode());
add_if_changed(results, "X Sectors", left->num_x_sectors(), right->num_x_sectors());
add_if_changed(results, "Z Sectors", left->num_z_sectors(), right->num_z_sectors());
return results;
}

template <typename T>
void show_details(const std::shared_ptr<T>& left, const std::shared_ptr<T>& right)
{
Expand Down Expand Up @@ -596,14 +615,34 @@ namespace trview
left->sample() == right->sample();
});

// Rooms:
const auto rooms_results = get_results<IRoom>(left->rooms(), right->rooms(),
[](auto&& left, auto&& right)
{
return
left->alternate_group() == right->alternate_group() &&
left->ambient() == right->ambient() &&
left->ambient_intensity_1() == right->ambient_intensity_1() &&
left->ambient_intensity_2() == right->ambient_intensity_2() &&
left->alternate_mode() == right->alternate_mode() &&
// left->bounding_box() == right->bounding_box() &&
left->centre() == right->centre() &&
left->flags() == right->flags() &&
// info
left->light_mode() == right->light_mode()&&
left->num_x_sectors() == right->num_x_sectors() &&
left->num_z_sectors() == right->num_z_sectors();
});

return Diff
{
.items = item_results,
.triggers = trigger_results,
.lights = light_results,
.camera_sinks = camera_sink_results,
.static_meshes = static_results,
.sound_sources = sound_source_results
.sound_sources = sound_source_results,
.rooms = rooms_results
};
}

Expand Down Expand Up @@ -633,12 +672,14 @@ namespace trview

if (ImGui::BeginTabBar("TabBar"))
{
const bool any_items = std::ranges::any_of(_diff->diff.items, [](auto&& i) { return i.type != Diff::Type::None; });
const bool any_triggers = std::ranges::any_of(_diff->diff.items, [](auto&& t) { return t.type != Diff::Type::None; });
const bool any_lights = std::ranges::any_of(_diff->diff.lights, [](auto&& l) { return l.type != Diff::Type::None; });
const bool any_camera_sink = std::ranges::any_of(_diff->diff.camera_sinks, [](auto&& c) { return c.type != Diff::Type::None; });
const bool any_statics = std::ranges::any_of(_diff->diff.static_meshes, [](auto&& c) { return c.type != Diff::Type::None; });
const bool any_sounds = std::ranges::any_of(_diff->diff.sound_sources, [](auto&& c) { return c.type != Diff::Type::None; });
const auto any_diff = [](auto&& range) { return std::ranges::any_of(range, [](auto&& e) { return e.type != Diff::Type::None; }); };
const bool any_items = any_diff(_diff->diff.items);
const bool any_triggers = any_diff(_diff->diff.triggers);
const bool any_lights = any_diff(_diff->diff.lights);
const bool any_camera_sink = any_diff(_diff->diff.camera_sinks);
const bool any_statics = any_diff(_diff->diff.static_meshes);
const bool any_sounds = any_diff(_diff->diff.sound_sources);
const bool any_rooms = any_diff(_diff->diff.rooms);

const auto show_table = [this](
const std::string& table_name,
Expand Down Expand Up @@ -751,8 +792,11 @@ namespace trview
ImGui::EndTabItem();
}

// TODO:
// Rooms...
if (ImGui::BeginTabItem(std::format("Rooms{}", any_rooms ? "*" : "").c_str()))
{
show_table("Rooms List", _diff->diff.rooms, on_room_selected, [](auto&&) { return "Room"; });
ImGui::EndTabItem();
}

ImGui::EndTabBar();
}
Expand Down
1 change: 1 addition & 0 deletions trview.app/Windows/Diff/DiffWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ namespace trview
std::vector<Item<ICameraSink>> camera_sinks;
std::vector<Item<IStaticMesh>> static_meshes;
std::vector<Item<ISoundSource>> sound_sources;
std::vector<Item<IRoom>> rooms;
};
private:
struct LoadOperation
Expand Down
1 change: 1 addition & 0 deletions trview.app/Windows/Diff/DiffWindowManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ namespace trview
window->on_camera_sink_selected += on_camera_sink_selected;
window->on_static_mesh_selected += on_static_mesh_selected;
window->on_sound_source_selected += on_sound_source_selected;
window->on_room_selected += on_room_selected;
return add_window(window);
}

Expand Down
2 changes: 2 additions & 0 deletions trview.app/Windows/Diff/IDiffWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace trview
struct ILight;
struct ISoundSource;
struct ITrigger;
struct IRoom;

struct IDiffWindow
{
Expand All @@ -31,5 +32,6 @@ namespace trview
Event<std::weak_ptr<ICameraSink>> on_camera_sink_selected;
Event<std::weak_ptr<IStaticMesh>> on_static_mesh_selected;
Event<std::weak_ptr<ISoundSource>> on_sound_source_selected;
Event<std::weak_ptr<IRoom>> on_room_selected;
};
}
2 changes: 2 additions & 0 deletions trview.app/Windows/Diff/IDiffWindowManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ namespace trview
struct ISoundSource;
struct IStaticMesh;
struct ITrigger;
struct IRoom;

struct IDiffWindowManager
{
Expand All @@ -28,5 +29,6 @@ namespace trview
Event<std::weak_ptr<ICameraSink>> on_camera_sink_selected;
Event<std::weak_ptr<IStaticMesh>> on_static_mesh_selected;
Event<std::weak_ptr<ISoundSource>> on_sound_source_selected;
Event<std::weak_ptr<IRoom>> on_room_selected;
};
}
1 change: 1 addition & 0 deletions trview.app/Windows/Windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ namespace trview
_diff_windows->on_camera_sink_selected += on_camera_sink_selected;
_diff_windows->on_static_mesh_selected += on_static_selected;
_diff_windows->on_sound_source_selected += on_sound_source_selected;
_diff_windows->on_room_selected += on_room_selected;

_token_store += _items_windows->on_add_to_route += [this](auto item)
{
Expand Down

0 comments on commit 03f0aec

Please sign in to comment.