add pausing and stepping
This commit is contained in:
@ -42,7 +42,9 @@ namespace Hazel
|
|||||||
m_CheckerBoardTexture = Texture2D::Create("assets/textures/Checkerboard.png");
|
m_CheckerBoardTexture = Texture2D::Create("assets/textures/Checkerboard.png");
|
||||||
|
|
||||||
m_IconPlay = Texture2D::Create("Resources/Icons/PlayButton.png");
|
m_IconPlay = Texture2D::Create("Resources/Icons/PlayButton.png");
|
||||||
m_IconStop = Texture2D::Create("Resources/Icons/PauseButton.png");
|
m_IconPause = Texture2D::Create("Resources/Icons/PauseButton.png");
|
||||||
|
m_IconStep = Texture2D::Create("Resources/Icons/StepButton.png");
|
||||||
|
m_IconStop = Texture2D::Create("Resources/Icons/StopButton.png");
|
||||||
m_IconSimulate = Texture2D::Create("Resources/Icons/SimulateButton.png");
|
m_IconSimulate = Texture2D::Create("Resources/Icons/SimulateButton.png");
|
||||||
|
|
||||||
m_EditorScene = CreateRef<Scene>();
|
m_EditorScene = CreateRef<Scene>();
|
||||||
@ -76,12 +78,13 @@ namespace Hazel
|
|||||||
// reset Renderer Draw Stats
|
// reset Renderer Draw Stats
|
||||||
Renderer2D::ResetStats();
|
Renderer2D::ResetStats();
|
||||||
|
|
||||||
|
m_ActiveScene->OnViewportResize((uint32_t)m_ViewPortSize.x, (uint32_t)m_ViewPortSize.y);
|
||||||
|
|
||||||
if (const auto& spec = m_FrameBuffer->GetSpecification();
|
if (const auto& spec = m_FrameBuffer->GetSpecification();
|
||||||
spec.Width != m_ViewPortSize.x || spec.Height != m_ViewPortSize.y)
|
spec.Width != m_ViewPortSize.x || spec.Height != m_ViewPortSize.y)
|
||||||
{
|
{
|
||||||
m_FrameBuffer->Resize((uint32_t)m_ViewPortSize.x, (uint32_t)m_ViewPortSize.y);
|
m_FrameBuffer->Resize((uint32_t)m_ViewPortSize.x, (uint32_t)m_ViewPortSize.y);
|
||||||
m_CameraController.OnResize(m_ViewPortSize.x, m_ViewPortSize.y);
|
m_CameraController.OnResize(m_ViewPortSize.x, m_ViewPortSize.y);
|
||||||
|
|
||||||
m_EditorCamera.SetViewPortSize(m_ViewPortSize.x, m_ViewPortSize.y);
|
m_EditorCamera.SetViewPortSize(m_ViewPortSize.x, m_ViewPortSize.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -594,6 +597,10 @@ namespace Hazel
|
|||||||
m_SceneHierachyPanel.SetContext(m_ActiveScene);
|
m_SceneHierachyPanel.SetContext(m_ActiveScene);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void EditorLayer::OnScenePause()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
void EditorLayer::OnSceneSimulation()
|
void EditorLayer::OnSceneSimulation()
|
||||||
{
|
{
|
||||||
if (m_SceneState == SceneState::Simulate)
|
if (m_SceneState == SceneState::Simulate)
|
||||||
@ -684,6 +691,12 @@ namespace Hazel
|
|||||||
ImGui::SetCursorPosX(ImGui::GetWindowContentRegionMax().x * 0.5f - size * 0.5f);
|
ImGui::SetCursorPosX(ImGui::GetWindowContentRegionMax().x * 0.5f - size * 0.5f);
|
||||||
ImGui::SetCursorPosX(ImGui::GetWindowContentRegionMax().x * 0.5f - (size * 0.5f));
|
ImGui::SetCursorPosX(ImGui::GetWindowContentRegionMax().x * 0.5f - (size * 0.5f));
|
||||||
|
|
||||||
|
bool hasPlayButton = m_SceneState == SceneState::Play || m_SceneState == SceneState::Edit;
|
||||||
|
bool hasSimulateButton = m_SceneState == SceneState::Simulate || m_SceneState == SceneState::Edit;
|
||||||
|
bool hasPauseButton = m_SceneState != SceneState::Edit;
|
||||||
|
|
||||||
|
if (hasPlayButton)
|
||||||
|
{
|
||||||
Ref<Texture2D> icon = (m_SceneState == SceneState::Edit || m_SceneState == SceneState::Simulate)? m_IconPlay : m_IconStop;
|
Ref<Texture2D> icon = (m_SceneState == SceneState::Edit || m_SceneState == SceneState::Simulate)? m_IconPlay : m_IconStop;
|
||||||
if (ImGui::ImageButton("toolbar-play-edit", icon->GetRendererID(), ImVec2{size, size}, ImVec2{0, 0}, ImVec2{1, 1}))
|
if (ImGui::ImageButton("toolbar-play-edit", icon->GetRendererID(), ImVec2{size, size}, ImVec2{0, 0}, ImVec2{1, 1}))
|
||||||
{
|
{
|
||||||
@ -692,9 +705,13 @@ namespace Hazel
|
|||||||
else if (m_SceneState == SceneState::Play)
|
else if (m_SceneState == SceneState::Play)
|
||||||
OnSceneStop();
|
OnSceneStop();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ImGui::SameLine();
|
if (hasSimulateButton)
|
||||||
{
|
{
|
||||||
|
if (hasPlayButton)
|
||||||
|
ImGui::SameLine();
|
||||||
|
|
||||||
Ref<Texture2D> icon = (m_SceneState == SceneState::Edit || m_SceneState == SceneState::Play)? m_IconSimulate : m_IconStop;
|
Ref<Texture2D> icon = (m_SceneState == SceneState::Edit || m_SceneState == SceneState::Play)? m_IconSimulate : m_IconStop;
|
||||||
if (ImGui::ImageButton("toolbar-simulate", icon->GetRendererID(), ImVec2{size, size}, ImVec2{0, 0}, ImVec2{1, 1}))
|
if (ImGui::ImageButton("toolbar-simulate", icon->GetRendererID(), ImVec2{size, size}, ImVec2{0, 0}, ImVec2{1, 1}))
|
||||||
{
|
{
|
||||||
@ -705,6 +722,32 @@ namespace Hazel
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (hasPauseButton)
|
||||||
|
{
|
||||||
|
bool isPaused = m_ActiveScene->IsPaused();
|
||||||
|
ImGui::SameLine();
|
||||||
|
{
|
||||||
|
Ref<Texture2D> icon = m_IconPause;
|
||||||
|
if (ImGui::ImageButton("toolbar-pause", icon->GetRendererID(), ImVec2{size, size}, ImVec2{0, 0}, ImVec2{1, 1}))
|
||||||
|
{
|
||||||
|
m_ActiveScene->SetPaused(!isPaused);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isPaused)
|
||||||
|
{
|
||||||
|
ImGui::SameLine();
|
||||||
|
{
|
||||||
|
Ref<Texture2D> icon = m_IconStep;
|
||||||
|
if (ImGui::ImageButton("toolbar-step", icon->GetRendererID(), ImVec2{size, size}, ImVec2{0, 0}, ImVec2{1, 1}))
|
||||||
|
{
|
||||||
|
m_ActiveScene->Step();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ImGui::PopStyleVar(2);
|
ImGui::PopStyleVar(2);
|
||||||
ImGui::PopStyleColor(3);
|
ImGui::PopStyleColor(3);
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
|
|||||||
@ -29,6 +29,7 @@ namespace Hazel
|
|||||||
void OnScenePlay();
|
void OnScenePlay();
|
||||||
void OnSceneSimulation();
|
void OnSceneSimulation();
|
||||||
void OnSceneStop();
|
void OnSceneStop();
|
||||||
|
void OnScenePause();
|
||||||
|
|
||||||
|
|
||||||
void SaveSceneAs() const;
|
void SaveSceneAs() const;
|
||||||
@ -84,7 +85,7 @@ namespace Hazel
|
|||||||
|
|
||||||
SceneState m_SceneState = SceneState::Edit;
|
SceneState m_SceneState = SceneState::Edit;
|
||||||
|
|
||||||
Ref<Texture2D> m_IconPlay, m_IconStop, m_IconSimulate;
|
Ref<Texture2D> m_IconPlay, m_IconPause, m_IconStep, m_IconStop, m_IconSimulate;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -143,6 +143,11 @@ namespace Hazel
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Scene::Step(const int frames)
|
||||||
|
{
|
||||||
|
m_StepFrame = frames;
|
||||||
|
}
|
||||||
|
|
||||||
void Scene::OnPhysics2DStart()
|
void Scene::OnPhysics2DStart()
|
||||||
{
|
{
|
||||||
b2WorldDef worldDef = b2DefaultWorldDef();
|
b2WorldDef worldDef = b2DefaultWorldDef();
|
||||||
@ -284,6 +289,8 @@ namespace Hazel
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Scene::OnUpdateRuntime(TimeStep& ts)
|
void Scene::OnUpdateRuntime(TimeStep& ts)
|
||||||
|
{
|
||||||
|
if (!m_IsPaused || m_StepFrame-- > 0)
|
||||||
{
|
{
|
||||||
// Update scripts
|
// Update scripts
|
||||||
{
|
{
|
||||||
@ -330,6 +337,7 @@ namespace Hazel
|
|||||||
transform.Rotation.z = angle;
|
transform.Rotation.z = angle;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Renderer 2D
|
// Renderer 2D
|
||||||
Camera* mainCamera = nullptr;
|
Camera* mainCamera = nullptr;
|
||||||
@ -379,6 +387,8 @@ namespace Hazel
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Scene::OnUpdateSimulation(TimeStep& ts, const EditorCamera& camera)
|
void Scene::OnUpdateSimulation(TimeStep& ts, const EditorCamera& camera)
|
||||||
|
{
|
||||||
|
if (!m_IsPaused || m_StepFrame-- > 0)
|
||||||
{
|
{
|
||||||
// Physics
|
// Physics
|
||||||
{
|
{
|
||||||
@ -400,6 +410,7 @@ namespace Hazel
|
|||||||
transform.Rotation.z = angle;
|
transform.Rotation.z = angle;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Render
|
// Render
|
||||||
RenderScene(camera);
|
RenderScene(camera);
|
||||||
|
|||||||
@ -49,6 +49,10 @@ namespace Hazel
|
|||||||
Entity GetEntityByUUID(UUID uuid);
|
Entity GetEntityByUUID(UUID uuid);
|
||||||
|
|
||||||
bool IsRunning() const {return m_IsRunning; }
|
bool IsRunning() const {return m_IsRunning; }
|
||||||
|
bool IsPaused() const {return m_IsPaused; }
|
||||||
|
|
||||||
|
void SetPaused(const bool pause) {m_IsPaused = pause; }
|
||||||
|
void Step(int frames = 1);
|
||||||
|
|
||||||
template<typename... Components>
|
template<typename... Components>
|
||||||
auto GetAllEntitiesWith()
|
auto GetAllEntitiesWith()
|
||||||
@ -73,6 +77,8 @@ namespace Hazel
|
|||||||
b2WorldId* m_PhysicsWorld = nullptr;
|
b2WorldId* m_PhysicsWorld = nullptr;
|
||||||
|
|
||||||
bool m_IsRunning = false;
|
bool m_IsRunning = false;
|
||||||
|
bool m_IsPaused = false;
|
||||||
|
int m_StepFrame = 0;
|
||||||
|
|
||||||
std::unordered_map<UUID, entt::entity> m_EnttMap;
|
std::unordered_map<UUID, entt::entity> m_EnttMap;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user