Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

diff #1335

Draft
wants to merge 28 commits into
base: master
Choose a base branch
from
Draft

diff #1335

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
45dd58a
Create empty diff window and manager
chreden Dec 30, 2024
2d7a152
Update tests, simplify Di
chreden Dec 30, 2024
2623a31
Loading file from the diff window
chreden Dec 30, 2024
96b779f
Start on diff for items
chreden Jan 1, 2025
7ffe982
Semi-functional diff window
chreden Jan 1, 2025
8f8a506
Show item numbers
chreden Jan 1, 2025
a3c9971
Compare more attributes, string/colour for move
chreden Jan 1, 2025
33a2da5
Rename move to reindex, sort
chreden Jan 1, 2025
855d813
Item selection in diff window
chreden Jan 3, 2025
6546984
Re-diff when level changes
chreden Jan 3, 2025
b931211
Show compare file
chreden Jan 3, 2025
c729a0d
Add trigger diff
chreden Jan 5, 2025
7e2f852
Start passing diff level around
chreden Jan 6, 2025
4f0cb30
Use level from thing being selected
chreden Jan 6, 2025
3c0cdb0
Fix some tests
chreden Jan 6, 2025
ef9f8b1
Update application tests
chreden Jan 6, 2025
af5eebb
Simplify details, add * on changed, show A:B
chreden Jan 7, 2025
d1b4692
Add lights to diff
chreden Jan 8, 2025
cbb4884
Add camera/sinks
chreden Jan 9, 2025
d8261bb
Tidy up diffs, to_string
chreden Jan 9, 2025
c36e597
Reuse code for items diff
chreden Jan 9, 2025
94f872d
Statics in diff window
chreden Jan 10, 2025
6a8a933
Add sound diff
chreden Jan 10, 2025
03f0aec
Partial rooms diff
chreden Jan 13, 2025
f0fe934
Start on imgui file menu
chreden Jan 19, 2025
66dc8f1
Update mocks
chreden Jan 20, 2025
4d567ea
Recent file in diff menu
chreden Jan 20, 2025
c028083
Fix diff recent files save/load
chreden Jan 21, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion trlevel/tr_lights.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ namespace trlevel
return 0;
}

std::string light_type_name(LightType type)
std::string to_string(LightType type)
{
switch (type)
{
Expand Down
2 changes: 1 addition & 1 deletion trlevel/tr_lights.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace trlevel
float density() const;
};

std::string light_type_name(LightType type);
std::string to_string(LightType type);

std::vector<tr_x_room_light> convert_lights(std::vector<tr_room_light> lights);
std::vector<tr_x_room_light> convert_lights(std::vector<tr_room_light_psx> lights);
Expand Down
178 changes: 93 additions & 85 deletions trview.app.tests/ApplicationTests.cpp

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions trview.app.tests/Elements/StaticMeshTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ TEST(StaticMesh, BoundingBoxRendered)
auto bounding_mesh = mock_shared<MockMesh>();
EXPECT_CALL(*bounding_mesh, render(A<const Matrix&>(), A<const ILevelTextureStorage&>(), A<const Color&>(), A<float>(), A<Vector3>(), A<bool>(), A<bool>())).Times(1);

StaticMesh mesh({}, {}, actual_mesh, {}, bounding_mesh);
StaticMesh mesh({}, {}, actual_mesh, {}, {}, bounding_mesh);
mesh.render_bounding_box(NiceMock<MockCamera>{}, NiceMock<MockLevelTextureStorage>{}, Colour::White);
}

TEST(StaticMesh, OnChangedRaised)
{
StaticMesh mesh({}, {}, mock_shared<MockMesh>(), {}, mock_shared<MockMesh>());
StaticMesh mesh({}, {}, mock_shared<MockMesh>(), {}, {}, mock_shared<MockMesh>());
bool raised = false;
auto token = mesh.on_changed += [&] (){ raised = true; };
mesh.set_visible(false);
Expand All @@ -31,14 +31,14 @@ TEST(StaticMesh, OnChangedRaised)

TEST(StaticMesh, HasCollision)
{
StaticMesh collision_mesh({}, { .Flags = 0 }, mock_shared<MockMesh>(), {}, mock_shared<MockMesh>());
StaticMesh collision_mesh({}, { .Flags = 0 }, mock_shared<MockMesh>(), {}, {}, mock_shared<MockMesh>());
ASSERT_EQ(collision_mesh.has_collision(), true);
StaticMesh no_collision_mesh({}, { .Flags = 1 }, mock_shared<MockMesh>(), {}, mock_shared<MockMesh>());
StaticMesh no_collision_mesh({}, { .Flags = 1 }, mock_shared<MockMesh>(), {}, {}, mock_shared<MockMesh>());
ASSERT_EQ(no_collision_mesh.has_collision(), false);
}

TEST(StaticMesh, SpriteNoCollision)
{
StaticMesh collision_mesh({}, {}, {}, mock_shared<MockMesh>(), {});
StaticMesh collision_mesh({}, {}, {}, mock_shared<MockMesh>(), {}, {});
ASSERT_EQ(collision_mesh.has_collision(), false);
}
13 changes: 11 additions & 2 deletions trview.app.tests/Windows/WindowsTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <trview.app/Mocks/Windows/IAboutWindowManager.h>
#include <trview.app/Mocks/Windows/ICameraSinkWindowManager.h>
#include <trview.app/Mocks/Windows/IConsoleManager.h>
#include <trview.app/Mocks/Windows/IDiffWindowManager.h>
#include <trview.app/Mocks/Windows/IItemsWindowManager.h>
#include <trview.app/Mocks/Windows/ILightsWindowManager.h>
#include <trview.app/Mocks/Windows/ILogWindowManager.h>
Expand Down Expand Up @@ -42,7 +43,8 @@ namespace
std::unique_ptr<IAboutWindowManager> about_window{ mock_unique<MockAboutWindowManager>() };
std::unique_ptr<ICameraSinkWindowManager> camera_sinks{ mock_unique<MockCameraSinkWindowManager>() };
std::unique_ptr<IConsoleManager> console_manager{ mock_unique<MockConsoleManager>() };
std::unique_ptr<IItemsWindowManager> items{ mock_unique<MockItemsWindowManager>() };
std::unique_ptr<IDiffWindowManager> diffs{ mock_unique<MockDiffWindowManager>() };
std::shared_ptr<IItemsWindowManager> items{ mock_shared<MockItemsWindowManager>() };
std::unique_ptr<ILogWindowManager> log{ mock_unique<MockLogWindowManager>() };
std::unique_ptr<ILightsWindowManager> lights{ mock_unique<MockLightsWindowManager>() };
std::unique_ptr<IPluginsWindowManager> plugins{ mock_unique<MockPluginsWindowManager>() };
Expand All @@ -59,7 +61,8 @@ namespace
std::move(about_window),
std::move(camera_sinks),
std::move(console_manager),
std::move(items),
std::move(diffs),
items,
std::move(lights),
std::move(log),
std::move(plugins),
Expand All @@ -83,6 +86,12 @@ namespace
return *this;
}

test_module& with_diffs(std::unique_ptr<IDiffWindowManager> manager)
{
diffs = std::move(manager);
return *this;
}

test_module& with_items(std::unique_ptr<IItemsWindowManager> manager)
{
items = std::move(manager);
Expand Down
108 changes: 63 additions & 45 deletions trview.app/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@ namespace trview
fonts.add_font("Default", { .name = "Arial", .filename = "arial.ttf", .size = 12 });
fonts.add_font("Console", { .name = "Consolas", .filename = "consola.ttf", .size = 12 });
}

template <typename T>
std::tuple<std::shared_ptr<T>, std::shared_ptr<ILevel>> get_entity_and_level(const std::weak_ptr<T>& entity)
{
if (const auto entity_ptr = entity.lock())
{
const auto level_ptr = entity_ptr->level().lock();
return { entity_ptr, level_ptr };
}
return { nullptr, nullptr };
}
}

IApplication::~IApplication()
Expand All @@ -27,7 +38,6 @@ namespace trview
Application::Application(const Window& application_window,
std::unique_ptr<IUpdateChecker> update_checker,
std::shared_ptr<ISettingsLoader> settings_loader,
const trlevel::ILevel::Source& trlevel_source,
std::unique_ptr<IFileMenu> file_menu,
std::shared_ptr<IViewer> viewer,
const IRoute::Source& route_source,
Expand All @@ -43,8 +53,8 @@ namespace trview
std::unique_ptr<IWindows> windows,
LoadMode load_mode)
: MessageHandler(application_window), _instance(GetModuleHandle(nullptr)),
_file_menu(std::move(file_menu)), _update_checker(std::move(update_checker)), _view_menu(window()), _settings_loader(settings_loader), _trlevel_source(trlevel_source),
_viewer(viewer), _route_source(route_source), _shortcuts(shortcuts), _level_source(level_source), _dialogs(dialogs), _files(files), _timer(default_time_source()),
_file_menu(std::move(file_menu)), _update_checker(std::move(update_checker)), _view_menu(window()), _settings_loader(settings_loader), _viewer(viewer),
_route_source(route_source), _shortcuts(shortcuts), _level_source(level_source), _dialogs(dialogs), _files(files), _timer(default_time_source()),
_imgui_backend(std::move(imgui_backend)), _plugins(plugins), _randomizer_route_source(randomizer_route_source), _fonts(fonts), _load_mode(load_mode),
_windows(std::move(windows))
{
Expand Down Expand Up @@ -81,6 +91,18 @@ namespace trview
_token_store += _windows->on_new_randomizer_route += [&]() { if (should_discard_changes()) { set_route(_randomizer_route_source(std::nullopt)); } };
_token_store += _windows->on_static_selected += [this](const auto& stat) { select_static_mesh(stat); };
_token_store += _windows->on_sound_source_selected += [this](const auto& sound) { select_sound_source(sound); };
_token_store += _windows->on_diff_level_selected += [this](auto&& level) { open_diff_level(level); };
_token_store += _windows->on_settings += [this](auto&& settings)
{
_settings = settings;
_viewer->set_settings(_settings);
_windows->set_settings(settings);
lua::set_settings(settings);
if (_level)
{
_level->set_map_colours(settings.map_colours);
}
};

_windows->setup(_settings);
setup_viewer(*startup_options);
Expand Down Expand Up @@ -340,48 +362,44 @@ namespace trview

void Application::select_item(std::weak_ptr<IItem> item)
{
if (!_level)
{
return;
}

auto item_ptr = item.lock();
if (!item_ptr)
const auto [item_ptr, level] = get_entity_and_level(item);
if (!item_ptr || !level)
{
return;
}

_viewer->open(level, ILevel::OpenMode::Reload);
select_room(item_ptr->room());
_level->set_selected_item(item);
level->set_selected_item(item);
_viewer->select_item(item);
_windows->select(item);
}

void Application::select_room(std::weak_ptr<IRoom> room)
{
if (_level)
const auto [room_ptr, level] = get_entity_and_level(room);
if (!room_ptr || !level)
{
_level->set_selected_room(room);
return;
}

level->set_selected_room(room);
_viewer->open(level, ILevel::OpenMode::Reload);
_viewer->select_room(room);
_windows->set_room(room);
}

void Application::select_trigger(const std::weak_ptr<ITrigger>& trigger)
{
if (!_level)
{
return;
}

auto trigger_ptr = trigger.lock();
if (!trigger_ptr)
const auto [trigger_ptr, level] = get_entity_and_level(trigger);
if (!trigger_ptr || !level)
{
return;
}

_viewer->open(level, ILevel::OpenMode::Reload);
select_room(trigger_ptr->room());
_level->set_selected_trigger(trigger_ptr->number());
level->set_selected_trigger(trigger_ptr->number());
_viewer->select_trigger(trigger);
_windows->select(trigger);
}
Expand Down Expand Up @@ -420,19 +438,15 @@ namespace trview

void Application::select_light(const std::weak_ptr<ILight>& light)
{
if (!_level)
{
return;
}

auto light_ptr = light.lock();
if (!light_ptr)
const auto [light_ptr, level] = get_entity_and_level(light);
if (!light_ptr || !level)
{
return;
}

_viewer->open(level, ILevel::OpenMode::Reload);
select_room(light_ptr->room());
_level->set_selected_light(light_ptr->number());
level->set_selected_light(light_ptr->number());
_viewer->select_light(light);
_windows->select(light);
}
Expand Down Expand Up @@ -771,19 +785,15 @@ namespace trview

void Application::select_camera_sink(const std::weak_ptr<ICameraSink>& camera_sink)
{
if (!_level)
{
return;
}

auto camera_sink_ptr = camera_sink.lock();
if (!camera_sink_ptr)
const auto [camera_sink_ptr, level] = get_entity_and_level(camera_sink);
if (!camera_sink_ptr || !level)
{
return;
}

_viewer->open(level, ILevel::OpenMode::Reload);
select_room(actual_room(*camera_sink_ptr));
_level->set_selected_camera_sink(camera_sink_ptr->number());
level->set_selected_camera_sink(camera_sink_ptr->number());
_viewer->select_camera_sink(camera_sink);
_windows->select(camera_sink);
}
Expand All @@ -796,7 +806,7 @@ namespace trview
std::shared_ptr<ILevel> Application::load(const std::string& filename)
{
_progress = std::format("Loading {}", filename);
auto level = _level_source(_trlevel_source(filename),
auto level = _level_source(filename,
{
.on_progress_callback = [&](auto&& p) { _progress = p; }
});
Expand Down Expand Up @@ -918,24 +928,27 @@ namespace trview

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

auto static_mesh_ptr = static_mesh.lock();
if (!static_mesh_ptr)
const auto [static_mesh_ptr, level] = get_entity_and_level(static_mesh);
if (!static_mesh_ptr || !level)
{
return;
}

_viewer->open(level, ILevel::OpenMode::Reload);
select_room(static_mesh_ptr->room());
_viewer->select_static_mesh(static_mesh_ptr);
_windows->select(static_mesh_ptr);
}

void Application::select_sound_source(const std::weak_ptr<ISoundSource>& sound_source)
{
const auto [sound_source_ptr, level] = get_entity_and_level(sound_source);
if (!sound_source_ptr || !level)
{
return;
}

_viewer->open(level, ILevel::OpenMode::Reload);
_viewer->select_sound_source(sound_source);
_windows->select(sound_source);
}
Expand Down Expand Up @@ -967,4 +980,9 @@ namespace trview
_viewer->set_settings(_settings);
set_current_level(op.level, op.open_mode, false);
}

void Application::open_diff_level(const std::weak_ptr<ILevel>& level)
{
_diff_level = level;
}
}
7 changes: 3 additions & 4 deletions trview.app/Application.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
#include <trview.common/Timer.h>
#include <trview.common/TokenStore.h>

#include <trlevel/ILevel.h>

#include "Elements/ITypeInfoLookup.h"
#include <trview.app/Menus/IFileMenu.h>
#include <trview.app/Menus/IUpdateChecker.h>
Expand Down Expand Up @@ -57,7 +55,6 @@ namespace trview
const Window& application_window,
std::unique_ptr<IUpdateChecker> update_checker,
std::shared_ptr<ISettingsLoader> settings_loader,
const trlevel::ILevel::Source& trlevel_source,
std::unique_ptr<IFileMenu> file_menu,
std::shared_ptr<IViewer> viewer,
const IRoute::Source& route_source,
Expand Down Expand Up @@ -127,13 +124,14 @@ namespace trview
void select_static_mesh(const std::weak_ptr<IStaticMesh>& static_mesh);
void select_sound_source(const std::weak_ptr<ISoundSource>& sound_source);
void check_load();
void open_diff_level(const std::weak_ptr<ILevel>& level);


TokenStore _token_store;

// Window message related components.
std::shared_ptr<ISettingsLoader> _settings_loader;
UserSettings _settings;
trlevel::ILevel::Source _trlevel_source;
std::unique_ptr<IFileMenu> _file_menu;
std::unique_ptr<IUpdateChecker> _update_checker;
ViewMenu _view_menu;
Expand Down Expand Up @@ -177,6 +175,7 @@ namespace trview
std::future<LoadOperation> _load;
LoadMode _load_mode;
std::string _progress;
std::weak_ptr<ILevel> _diff_level;
};

std::unique_ptr<IApplication> create_application(HINSTANCE hInstance, int command_show, const std::wstring& command_line);
Expand Down
Loading