Skip to content

Commit

Permalink
[Editor] Moved editor ticking (including child windows) before engine…
Browse files Browse the repository at this point in the history
… ticking, this enliminates any latency between user input an on screen presentation
  • Loading branch information
PanosK92 committed Jul 13, 2023
1 parent d13ad71 commit 8c38444
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 37 deletions.
74 changes: 39 additions & 35 deletions editor/Editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

//= INCLUDES ====================================
#include "Editor.h"
#include "Core/Event.h"
#include "Core/Engine.h"
#include "Core/Settings.h"
#include "Core/Window.h"
#include "ImGui/ImGuiExtension.h"
#include "ImGui/Implementation/ImGui_RHI.h"
#include "ImGui/Implementation/imgui_impl_sdl2.h"
Expand All @@ -39,7 +37,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "Widgets/ResourceViewer.h"
#include "Widgets/Profiler.h"
#include "Widgets/RenderOptions.h"
#include "Widgets/TextureViewer.h"
//===============================================

//= NAMESPACES =====
Expand Down Expand Up @@ -235,50 +232,57 @@ void Editor::Tick()
{
bool render_editor = !Spartan::Window::IsFullScreen();

// ImGui - Begin
if (render_editor)
// Editor
{
ImGui_ImplSDL2_NewFrame();
ImGui::NewFrame();
}

// Engine - Tick
Spartan::Engine::Tick();

// Editor - Tick/End
if (render_editor)
{
// Editor - Begin
BeginWindow();
// Begin
if (render_editor)
{
ImGui_ImplSDL2_NewFrame();
ImGui::NewFrame();
}

// Editor - Tick
for (shared_ptr<Widget>& widget : m_widgets)
// Tick
if (render_editor)
{
widget->Tick();
// Begin window
BeginWindow();

// Tick widgets
for (shared_ptr<Widget>& widget : m_widgets)
{
widget->Tick();
}

// End window
if (m_editor_begun)
{
ImGui::End();
}

// Render
ImGui::Render();
ImGui::RHI::Render(ImGui::GetDrawData());
}

// Editor - End
if (m_editor_begun)
// Child windows
if (render_editor && ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
{
ImGui::End();
ImGui::UpdatePlatformWindows();
ImGui::RenderPlatformWindowsDefault();
}

// ImGui - End/Render
ImGui::Render();
ImGui::RHI::Render(ImGui::GetDrawData());
}

// Present
if (!Spartan::Window::IsMinimised())
// Engine
{
Spartan::Renderer::Present();
}
// Tick
Spartan::Engine::Tick();

// ImGui - Child windows
if (render_editor && ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
{
ImGui::UpdatePlatformWindows();
ImGui::RenderPlatformWindowsDefault();
// Present
if (!Spartan::Window::IsMinimised())
{
Spartan::Renderer::Present();
}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions editor/WidgetsDeferred/FileDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ void FileDialog::ShowTop(bool* is_visible, Editor* editor)
{
if (m_is_window)
{
ImGui::SetNextWindowPos(editor->GetWidget<Viewport>()->GetCenter(), ImGuiCond_Always, ImVec2(0.5f, 0.5f));
ImGui::SetNextWindowPos(editor->GetWidget<Viewport>()->GetCenter(), ImGuiCond_FirstUseEver, ImVec2(0.5f, 0.5f));
ImGui::SetNextWindowSizeConstraints(ImVec2(350, 250), ImVec2(FLT_MAX, FLT_MAX));
ImGui::Begin(m_title.c_str(), is_visible, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoDocking);
ImGui::Begin(m_title.c_str(), is_visible, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoDocking);
ImGui::SetWindowFocus();
}

Expand Down

0 comments on commit 8c38444

Please sign in to comment.