Skip to content

Commit

Permalink
Improved Editor usability with new shortcuts and mode for camera test…
Browse files Browse the repository at this point in the history
…ing.

Increased camera move speed for terrain testing.
  • Loading branch information
MStachowicz committed Oct 24, 2024
1 parent da77ac7 commit f13c134
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 17 deletions.
1 change: 1 addition & 0 deletions source/System/SceneSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ namespace System
camera_transform.m_position = {0.f, 7.f, 12.5f};
auto camera = Component::FirstPersonCamera(glm::vec3(0.f, -0.5f, 0.5f), true);
camera.look_at(glm::vec3(0.f), camera_transform.m_position);
camera.m_move_speed = 300.f; // 300 good for testing large terrain.

p_scene.m_entities.add_entity(
camera_transform,
Expand Down
51 changes: 36 additions & 15 deletions source/UI/Editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,14 @@ namespace UI
}
break;
}
case Platform::Key::C:
{
if (p_action == Platform::Action::Release)
{
set_state(m_state == State::CameraTesting ? State::Editing : State::CameraTesting);
}
break;
}
case Platform::Key::G:
{
if (p_action == Platform::Action::Release)
Expand Down Expand Up @@ -223,7 +231,12 @@ namespace UI
case Platform::Key::Escape:
{
if (p_action == Platform::Action::Release)
m_window.request_close();
{
if (m_state == State::Playing || m_state == State::CameraTesting)
set_state(State::Editing);
else
m_window.request_close();
}
break;
}
case Platform::Key::Space:
Expand Down Expand Up @@ -285,11 +298,12 @@ namespace UI
case State::Editing:
{
m_input.set_cursor_mode(Platform::CursorMode::Normal);
m_window.m_show_menu_bar = true;
m_window.m_show_menu_bar = true;
m_physics_system.m_bool_apply_kinematic = false;
m_show_primary_camera_frustrum = false;

if (m_scene_before_play)
m_scene_system.set_current_scene(*m_scene_before_play);

break;
}
case State::Playing:
Expand All @@ -305,6 +319,17 @@ namespace UI
play_scene = m_scene_system.get_current_scene();
m_scene_system.set_current_scene(play_scene);
m_physics_system.m_bool_apply_kinematic = true;
m_show_primary_camera_frustrum = false;
break;
}
case State::CameraTesting:
{
m_input.set_cursor_mode(Platform::CursorMode::Captured);
m_window.m_show_menu_bar = true;
m_physics_system.m_bool_apply_kinematic = false;
m_show_primary_camera_frustrum = true;
if (m_scene_before_play && m_state == State::Playing) // Only reset the scene if the user was playing before entering camera testing.
m_scene_system.set_current_scene(*m_scene_before_play);
break;
}
default: break;
Expand All @@ -314,7 +339,7 @@ namespace UI
}
Component::ViewInformation* Editor::get_editor_view_info()
{
if (m_state == State::Editing)
if (m_state == State::Editing || m_state == State::CameraTesting)
{
m_view_info = m_camera.view_information(m_window.aspect_ratio());
return &m_view_info;
Expand All @@ -325,19 +350,10 @@ namespace UI

void Editor::draw(const DeltaTime& p_duration_since_last_draw)
{
if (m_state != State::Editing)
if (m_state == State::Playing)
return;
m_duration_between_draws.push_back(p_duration_since_last_draw);

{// Draw a play button in the middle top of the screen.
const auto button_size = ImVec2(50.f, 50.f);
const auto button_pos = ImVec2((m_window.size().x - button_size.x) / 2.f, button_size.y / 2.f);
ImGui::SetNextWindowPos(button_pos);
ImGui::Begin("Play", nullptr, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoBackground | ImGuiWindowFlags_NoSavedSettings);
if (ImGui::Button("Play"))
set_state(State::Playing);
ImGui::End();
}
m_duration_between_draws.push_back(p_duration_since_last_draw);

if (ImGui::BeginMenuBar())
{
Expand Down Expand Up @@ -397,6 +413,11 @@ namespace UI
ImGui::MenuItem("Graphics", NULL, &m_windows_to_display.Graphics_Debug);
ImGui::MenuItem("Physics", NULL, &m_windows_to_display.Physics_Debug);
ImGui::MenuItem("ImGui Metrics/Debugger", NULL, &m_windows_to_display.ImGuiMetrics);
ImGui::Separator();
if (ImGui::MenuItem("Play"))
set_state(State::Playing);
if (ImGui::MenuItem("Camera Test"))
set_state(State::CameraTesting);
ImGui::EndMenu();
}
if (m_windows_to_display.FPSTimer)
Expand Down
5 changes: 3 additions & 2 deletions source/UI/Editor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ namespace UI
{
enum class State
{
Editing, // The editor is active and the user is interacting with the scene.
Playing // The editor is inactive and the scene is running.
Editing, // The editor is active and the user is interacting with the scene.
Playing, // The editor is inactive and the scene is running.
CameraTesting // The editor is active and the cursor is captured.
};

struct Windows
Expand Down

0 comments on commit f13c134

Please sign in to comment.