mirror of
https://github.com/antopilo/Nuake.git
synced 2026-09-15 20:08:54 +03:00
Cleanup Engine.h and made IsPlayMode a method
This commit is contained in:
@@ -183,7 +183,7 @@ int main(int argc, char* argv[])
|
||||
camera = currentScene->m_EditorCamera;
|
||||
}
|
||||
|
||||
if (currentScene && !Nuake::Engine::IsPlayMode && editor.ShouldDrawAxis())
|
||||
if (currentScene && !Nuake::Engine::IsPlayMode() && editor.ShouldDrawAxis())
|
||||
{
|
||||
gizmoDrawer.DrawGizmos(currentScene);
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ namespace Nuake {
|
||||
float needed = half - used;
|
||||
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0, 0));
|
||||
if (ImGui::Button(ICON_FA_PLAY, ImVec2(30, 30)) || (Input::IsKeyPressed(GLFW_KEY_F5) && !Engine::IsPlayMode))
|
||||
if (ImGui::Button(ICON_FA_PLAY, ImVec2(30, 30)) || (Input::IsKeyPressed(GLFW_KEY_F5) && !Engine::IsPlayMode()))
|
||||
{
|
||||
SceneSnapshot = Engine::GetCurrentScene()->Copy();
|
||||
Engine::EnterPlayMode();
|
||||
@@ -172,14 +172,14 @@ namespace Nuake {
|
||||
ImGuizmo::AllowAxisFlip(true);
|
||||
ImGuizmo::SetRect(imagePos.x + 8.0, imagePos.y + 30.0, viewportPanelSize.x, viewportPanelSize.y);
|
||||
|
||||
if (m_DrawGrid && !Engine::IsPlayMode)
|
||||
if (m_DrawGrid && !Engine::IsPlayMode())
|
||||
{
|
||||
ImGuizmo::DrawGrid(glm::value_ptr(Engine::GetCurrentScene()->GetCurrentCamera()->GetTransform()),
|
||||
glm::value_ptr(Engine::GetCurrentScene()->GetCurrentCamera()->GetPerspective()),
|
||||
glm::value_ptr(glm::identity<glm::mat4>()), 100.f);
|
||||
}
|
||||
|
||||
if (Selection.Type == EditorSelectionType::Entity && !Engine::IsPlayMode)
|
||||
if (Selection.Type == EditorSelectionType::Entity && !Engine::IsPlayMode())
|
||||
{
|
||||
TransformComponent& tc = Selection.Entity.GetComponent<TransformComponent>();
|
||||
ParentComponent& parent = Selection.Entity.GetComponent<ParentComponent>();
|
||||
@@ -1498,7 +1498,7 @@ namespace Nuake {
|
||||
|
||||
void EditorInterface::Update(float ts)
|
||||
{
|
||||
if (!Engine::GetCurrentScene() || Engine::IsPlayMode)
|
||||
if (!Engine::GetCurrentScene() || Engine::IsPlayMode())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -15,16 +15,16 @@
|
||||
|
||||
namespace Nuake
|
||||
{
|
||||
Ref<Project> Engine::CurrentProject;
|
||||
Ref<Window> Engine::CurrentWindow;
|
||||
Ref<Project> Engine::s_CurrentProject;
|
||||
Ref<Window> Engine::s_CurrentWindow;
|
||||
|
||||
float Engine::m_LastFrameTime = 0.0f;
|
||||
float Engine::m_FixedUpdateRate = 1.0f / 90.0f;
|
||||
float Engine::m_FixedUpdateDifference = 0.f;
|
||||
float Engine::m_Time = 0.f;
|
||||
Timestep Engine::m_TimeStep = 0.f;
|
||||
bool Engine::s_IsPlayMode = false;
|
||||
|
||||
bool Engine::IsPlayMode = false;
|
||||
float Engine::s_LastFrameTime = 0.0f;
|
||||
float Engine::s_FixedUpdateRate = 1.0f / 90.0f;
|
||||
float Engine::s_FixedUpdateDifference = 0.f;
|
||||
float Engine::s_Time = 0.f;
|
||||
Timestep Engine::s_TimeStep = 0.f;
|
||||
|
||||
void Engine::Init()
|
||||
{
|
||||
@@ -39,7 +39,7 @@ namespace Nuake
|
||||
Logger::Log("Physics initialized");
|
||||
|
||||
// Creates the window
|
||||
CurrentWindow = Window::Get();
|
||||
s_CurrentWindow = Window::Get();
|
||||
Logger::Log("Window initialized");
|
||||
|
||||
Input::Init();
|
||||
@@ -52,33 +52,33 @@ namespace Nuake
|
||||
|
||||
void Engine::Tick()
|
||||
{
|
||||
m_Time = (float)glfwGetTime();
|
||||
m_TimeStep = m_Time - m_LastFrameTime;
|
||||
m_LastFrameTime = m_Time;
|
||||
s_Time = (float)glfwGetTime();
|
||||
s_TimeStep = s_Time - s_LastFrameTime;
|
||||
s_LastFrameTime = s_Time;
|
||||
|
||||
m_TimeStep = std::min((float)m_TimeStep, 0.5f);
|
||||
s_TimeStep = std::min((float)s_TimeStep, 0.5f);
|
||||
|
||||
// Dont update if no scene is loaded.
|
||||
if (CurrentWindow->GetScene())
|
||||
if (s_CurrentWindow->GetScene())
|
||||
{
|
||||
CurrentWindow->Update(m_TimeStep);
|
||||
s_CurrentWindow->Update(s_TimeStep);
|
||||
|
||||
// Play mode update all the entities, Editor does not.
|
||||
if (Engine::IsPlayMode)
|
||||
if (Engine::IsPlayMode())
|
||||
{
|
||||
m_FixedUpdateDifference += m_TimeStep;
|
||||
s_FixedUpdateDifference += s_TimeStep;
|
||||
|
||||
// Fixed update
|
||||
while (m_FixedUpdateDifference >= m_FixedUpdateRate)
|
||||
while (s_FixedUpdateDifference >= s_FixedUpdateRate)
|
||||
{
|
||||
CurrentWindow->FixedUpdate(m_FixedUpdateDifference);
|
||||
s_CurrentWindow->FixedUpdate(s_FixedUpdateDifference);
|
||||
|
||||
m_FixedUpdateDifference -= m_FixedUpdateRate;
|
||||
s_FixedUpdateDifference -= s_FixedUpdateRate;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
GetCurrentScene()->EditorUpdate(m_TimeStep);
|
||||
GetCurrentScene()->EditorUpdate(s_TimeStep);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,7 +88,7 @@ namespace Nuake
|
||||
void Engine::EnterPlayMode()
|
||||
{
|
||||
// Dont trigger init if already in player mode.
|
||||
if (IsPlayMode)
|
||||
if (IsPlayMode())
|
||||
{
|
||||
Logger::Log("Cannot enter play mode if is already in play mode.", WARNING);
|
||||
return;
|
||||
@@ -96,7 +96,7 @@ namespace Nuake
|
||||
|
||||
if (GetCurrentScene()->OnInit())
|
||||
{
|
||||
IsPlayMode = true;
|
||||
s_IsPlayMode = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -108,11 +108,11 @@ namespace Nuake
|
||||
void Engine::ExitPlayMode()
|
||||
{
|
||||
// Dont trigger exit if already not in play mode.
|
||||
if (IsPlayMode)
|
||||
if (IsPlayMode())
|
||||
{
|
||||
GetCurrentScene()->OnExit();
|
||||
Input::ShowMouse();
|
||||
IsPlayMode = false;
|
||||
s_IsPlayMode = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -141,24 +141,24 @@ namespace Nuake
|
||||
|
||||
Ref<Scene> Engine::GetCurrentScene()
|
||||
{
|
||||
return CurrentWindow->GetScene();
|
||||
return s_CurrentWindow->GetScene();
|
||||
}
|
||||
|
||||
bool Engine::LoadScene(Ref<Scene> scene)
|
||||
{
|
||||
return CurrentWindow->SetScene(scene);
|
||||
return s_CurrentWindow->SetScene(scene);
|
||||
}
|
||||
|
||||
Ref<Project> Engine::GetProject()
|
||||
{
|
||||
return CurrentProject;
|
||||
return s_CurrentProject;
|
||||
}
|
||||
|
||||
bool Engine::LoadProject(Ref<Project> project)
|
||||
{
|
||||
CurrentProject = project;
|
||||
s_CurrentProject = project;
|
||||
|
||||
if (!Engine::LoadScene(CurrentProject->DefaultScene))
|
||||
if (!Engine::LoadScene(s_CurrentProject->DefaultScene))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -169,6 +169,6 @@ namespace Nuake
|
||||
|
||||
Ref<Window> Engine::GetCurrentWindow()
|
||||
{
|
||||
return CurrentWindow;
|
||||
return s_CurrentWindow;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,20 +17,22 @@
|
||||
// Welcome to the Nuake source code.
|
||||
namespace Nuake
|
||||
{
|
||||
class Engine {
|
||||
class Engine
|
||||
{
|
||||
private:
|
||||
static Ref<Window> CurrentWindow;
|
||||
static Ref<Project> CurrentProject;
|
||||
static Ref<Scene> CurrentScene;
|
||||
static Ref<Window> s_CurrentWindow;
|
||||
static Ref<Project> s_CurrentProject;
|
||||
static Ref<Scene> s_CurrentScene;
|
||||
|
||||
static bool s_IsPlayMode;
|
||||
|
||||
static float s_LastFrameTime;
|
||||
static float s_FixedUpdateRate;
|
||||
static float s_FixedUpdateDifference;
|
||||
static float s_Time;
|
||||
static Timestep s_TimeStep;
|
||||
|
||||
static float m_LastFrameTime;
|
||||
static float m_FixedUpdateRate;
|
||||
static float m_FixedUpdateDifference;
|
||||
static float m_Time;
|
||||
static Timestep m_TimeStep;
|
||||
public:
|
||||
static bool IsPlayMode; // Is currently in runtime..
|
||||
|
||||
static void Init(); // Initialize the engine.
|
||||
static void Tick(); // Updates everything, called everyframe.
|
||||
static void Close(); // Shutdown the engine.
|
||||
@@ -41,8 +43,12 @@ namespace Nuake
|
||||
// Custom drawing should happen in between these two
|
||||
static void Draw(); // Start new frame
|
||||
static void EndDraw(); // Swap buffer
|
||||
static inline float GetTime() { return m_Time; }
|
||||
static inline Timestep GetTimestep() { return m_TimeStep; }
|
||||
|
||||
static bool IsPlayMode() { return s_IsPlayMode; }
|
||||
|
||||
static inline float GetTime() { return s_Time; }
|
||||
static inline Timestep GetTimestep() { return s_TimeStep; }
|
||||
|
||||
static Ref<Window> GetCurrentWindow();
|
||||
|
||||
static bool LoadScene(Ref<Scene> scene);
|
||||
|
||||
@@ -244,7 +244,7 @@ namespace Nuake {
|
||||
|
||||
Ref<Camera> Scene::GetCurrentCamera()
|
||||
{
|
||||
if (Engine::IsPlayMode)
|
||||
if (Engine::IsPlayMode())
|
||||
{
|
||||
Ref<Camera> cam = nullptr;
|
||||
{
|
||||
|
||||
@@ -50,8 +50,10 @@ namespace Nuake
|
||||
|
||||
void PhysicsSystem::Update(Timestep ts)
|
||||
{
|
||||
if (!Engine::IsPlayMode)
|
||||
if (!Engine::IsPlayMode())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
auto brushes = m_Scene->m_Registry.view<TransformComponent, BSPBrushComponent>();
|
||||
for (auto e : brushes)
|
||||
@@ -114,7 +116,7 @@ namespace Nuake
|
||||
|
||||
void PhysicsSystem::FixedUpdate(Timestep ts)
|
||||
{
|
||||
if (!Engine::IsPlayMode)
|
||||
if (!Engine::IsPlayMode())
|
||||
return;
|
||||
|
||||
PhysicsManager::Get().Step(ts);
|
||||
|
||||
@@ -40,7 +40,7 @@ namespace Nuake {
|
||||
|
||||
void ScriptingSystem::Update(Timestep ts)
|
||||
{
|
||||
if (!Engine::IsPlayMode)
|
||||
if (!Engine::IsPlayMode())
|
||||
return;
|
||||
|
||||
auto entities = m_Scene->m_Registry.view<WrenScriptComponent>();
|
||||
|
||||
Reference in New Issue
Block a user