Skip to content

Commit

Permalink
Added runtime
Browse files Browse the repository at this point in the history
nepp95 committed Apr 10, 2024
1 parent c6fdfa2 commit 336516f
Showing 5 changed files with 109 additions and 35 deletions.
75 changes: 56 additions & 19 deletions EppoEditor/Source/EditorLayer.cpp
Original file line number Diff line number Diff line change
@@ -18,6 +18,10 @@ namespace Eppo

void EditorLayer::OnAttach()
{
// Load resources
m_IconPlay = CreateRef<Texture>(TextureSpecification("Resources/Textures/Icons/PlayButton.png"));
m_IconStop = CreateRef<Texture>(TextureSpecification("Resources/Textures/Icons/StopButton.png"));

// Setup UI panels
m_PanelManager.AddPanel<SceneHierarchyPanel>(SCENE_HIERARCHY_PANEL, true, m_PanelManager);
m_PanelManager.AddPanel<PropertyPanel>(PROPERTY_PANEL, true, m_PanelManager);
@@ -44,8 +48,20 @@ namespace Eppo
m_ViewportRenderer->Resize(m_ViewportWidth, m_ViewportHeight);
}

m_EditorCamera.OnUpdate(timestep);
m_ActiveScene->OnUpdate(timestep);
switch (m_SceneState)
{
case SceneState::Edit:
{
m_EditorCamera.OnUpdate(timestep);
break;
}

case SceneState::Play:
{
m_ActiveScene->OnUpdateRuntime(timestep);
break;
}
}
}

void EditorLayer::Render()
@@ -148,29 +164,30 @@ namespace Eppo

// Performance
m_ViewportRenderer->RenderGui();
/*ImGui::Begin("Performance");

const auto& profileData = Application::Get().GetProfiler()->GetProfileData();
for (const auto& [category, results] : profileData)
{
ImGui::Text("%s", category.c_str());
// Toolbar
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 2));
ImGui::PushStyleVar(ImGuiStyleVar_ItemInnerSpacing, ImVec2(0, 0));
ImGui::Begin("Scene Control", nullptr, ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse);

std::chrono::microseconds totalCategoryTime = std::chrono::microseconds::zero();
float buttonSize = ImGui::GetWindowHeight() - 4.0f;

for (const auto& [tag, time] : results)
{
ImGui::Text(" %s: %.3fms", tag.c_str(), time.count() / 1000.0f);
totalCategoryTime += time;
}
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0, 0));
ImGui::SetCursorPosX((ImGui::GetWindowContentRegionMax().x * 0.5f) - (buttonSize * 0.5f));

ImGui::Text("Total time: %.3fms", totalCategoryTime.count() / 1000.0f);
ImGui::Separator();
if (m_SceneState == SceneState::Edit)
{
if (ImGui::ImageButton("##Play", (ImTextureID)m_IconPlay->GetRendererID(), ImVec2(buttonSize, buttonSize)))
OnScenePlay();
} else if (m_SceneState == SceneState::Play)
{
if (ImGui::ImageButton("##Stop", (ImTextureID)m_IconStop->GetRendererID(), ImVec2(buttonSize, buttonSize)))
OnSceneStop();
}
*/
Application::Get().GetProfiler()->Clear();

//ImGui::End(); // Performance

ImGui::PopStyleVar(3);
ImGui::End(); // Scene Control

ImGui::End(); // DockSpace
}

@@ -210,6 +227,26 @@ namespace Eppo
return false;
}

void EditorLayer::OnScenePlay()
{
if (!m_ActiveScene)
return;

m_SceneState = SceneState::Play;

m_ActiveScene->OnRuntimeStart();
}

void EditorLayer::OnSceneStop()
{
if (!m_ActiveScene)
return;

m_ActiveScene->OnRuntimeStop();

m_SceneState = SceneState::Edit;
}

void EditorLayer::NewScene()
{
m_ActiveScene = CreateRef<Scene>();
21 changes: 18 additions & 3 deletions EppoEditor/Source/EditorLayer.h
Original file line number Diff line number Diff line change
@@ -24,6 +24,9 @@ namespace Eppo
private:
bool OnKeyPressed(KeyPressedEvent& e);

void OnScenePlay();
void OnSceneStop();

void NewScene();
void SaveScene();
void SaveScene(const std::filesystem::path& filepath);
@@ -33,17 +36,29 @@ namespace Eppo
private:
// Scene
Ref<SceneRenderer> m_ViewportRenderer;

Ref<Scene> m_ActiveScene;
std::filesystem::path m_ActiveScenePath;


// Editor
PanelManager& m_PanelManager;
EditorCamera m_EditorCamera;

// Viewport
uint32_t m_ViewportWidth = 0;
uint32_t m_ViewportHeight = 0;
bool m_ViewportFocused = false;
bool m_ViewportHovered = false;

PanelManager& m_PanelManager;
// Scene state
enum class SceneState
{
Edit,
Play
};
SceneState m_SceneState = SceneState::Edit;

// Resources
Ref<Texture> m_IconPlay;
Ref<Texture> m_IconStop;
};
}
32 changes: 20 additions & 12 deletions EppoEditor/imgui.ini
Original file line number Diff line number Diff line change
@@ -9,10 +9,10 @@ Size=400,400
Collapsed=0

[Window][Viewport]
Pos=305,20
Size=976,587
Pos=305,54
Size=976,553
Collapsed=0
DockId=0x00000007,0
DockId=0x0000000A,0

[Window][Scene Hierarchy]
Pos=0,20
@@ -38,14 +38,22 @@ Size=1295,291
Collapsed=0
DockId=0x00000002,0

[Window][Scene Control]
Pos=305,20
Size=976,32
Collapsed=0
DockId=0x00000009,0

[Docking][Data]
DockSpace ID=0x09EF459F Window=0x9A404470 Pos=216,192 Size=1600,880 Split=X
DockNode ID=0x00000005 Parent=0x09EF459F SizeRef=303,881 Split=Y Selected=0x2E9237F7
DockNode ID=0x00000003 Parent=0x00000005 SizeRef=303,441 Selected=0x2E9237F7
DockNode ID=0x00000004 Parent=0x00000005 SizeRef=303,438 Selected=0x199AB496
DockNode ID=0x00000006 Parent=0x09EF459F SizeRef=1295,881 Split=Y
DockNode ID=0x00000001 Parent=0x00000006 SizeRef=1600,588 Split=X
DockNode ID=0x00000007 Parent=0x00000001 SizeRef=976,881 CentralNode=1 Selected=0x13926F0B
DockNode ID=0x00000008 Parent=0x00000001 SizeRef=317,881 Selected=0x60B79D0E
DockNode ID=0x00000002 Parent=0x00000006 SizeRef=1600,291 Selected=0x1A4A3508
DockSpace ID=0x09EF459F Window=0x9A404470 Pos=109,93 Size=1600,880 Split=X
DockNode ID=0x00000005 Parent=0x09EF459F SizeRef=303,881 Split=Y Selected=0x2E9237F7
DockNode ID=0x00000003 Parent=0x00000005 SizeRef=303,441 Selected=0x2E9237F7
DockNode ID=0x00000004 Parent=0x00000005 SizeRef=303,438 Selected=0x199AB496
DockNode ID=0x00000006 Parent=0x09EF459F SizeRef=1295,881 Split=Y
DockNode ID=0x00000001 Parent=0x00000006 SizeRef=1600,588 Split=X
DockNode ID=0x00000007 Parent=0x00000001 SizeRef=976,881 Split=Y Selected=0x13926F0B
DockNode ID=0x00000009 Parent=0x00000007 SizeRef=976,32 HiddenTabBar=1 Selected=0x5811277B
DockNode ID=0x0000000A Parent=0x00000007 SizeRef=976,553 CentralNode=1 Selected=0x13926F0B
DockNode ID=0x00000008 Parent=0x00000001 SizeRef=317,881 Selected=0x60B79D0E
DockNode ID=0x00000002 Parent=0x00000006 SizeRef=1600,291 Selected=0x1A4A3508

5 changes: 5 additions & 0 deletions EppoEngine/Source/Renderer/Texture.h
Original file line number Diff line number Diff line change
@@ -52,6 +52,11 @@ namespace Eppo

uint32_t Width;
uint32_t Height;

TextureSpecification() = default;
TextureSpecification(const std::filesystem::path& filepath)
: Filepath(filepath)
{}
};

class Texture : public Asset
11 changes: 10 additions & 1 deletion EppoEngine/Source/Scene/Scene.h
Original file line number Diff line number Diff line change
@@ -16,16 +16,25 @@ namespace Eppo
Scene() = default;
~Scene() = default;

void OnUpdate(float timestep);
void OnUpdateRuntime(float timestep);
void RenderEditor(const Ref<SceneRenderer>& sceneRenderer, const EditorCamera& editorCamera);

void OnRuntimeStart();
void OnRuntimeStop();

Entity CreateEntity(const std::string& name = std::string());
Entity CreateEntityWithUUID(UUID uuid, const std::string& name);
void DestroyEntity(Entity entity);

private:
void OnPhysicsStart();
void OnPhysicsStop();

private:
entt::registry m_Registry;

bool m_IsRunning = false;

friend class Entity;
friend class SceneHierarchyPanel;
friend class SceneSerializer;

0 comments on commit 336516f

Please sign in to comment.