Game state switching now uses commands

This commit is contained in:
Antoine Pilote
2024-04-28 01:09:55 -04:00
parent a39c86d9ae
commit 2e19fabdef
4 changed files with 38 additions and 5 deletions

View File

@@ -16,4 +16,21 @@ namespace NuakeEditor
return true;
}
bool SetGameState::Execute()
{
GameState gameState = Engine::GetGameState();
if (gameState == GameState::Stopped && mGameState == GameState::Playing)
{
Engine::EnterPlayMode();
}
else if (mGameState == GameState::Stopped)
{
Engine::ExitPlayMode();
}
Engine::SetGameState(mGameState);
return true;
}
}

View File

@@ -5,7 +5,7 @@
#include <src/Core/Core.h>
#include <src/Scene/Scene.h>
#include <src/Resource/Project.h>
#include <Engine.h>
namespace NuakeEditor {
using namespace Nuake;
@@ -32,4 +32,18 @@ namespace NuakeEditor {
bool Execute() override;
};
// GameState
class SetGameState : public ICommand
{
private:
GameState mGameState;
public:
SetGameState(GameState gameState) :
mGameState(gameState)
{
}
bool Execute() override;
};
}

View File

@@ -344,7 +344,8 @@ namespace Nuake {
{
if (Engine::GetGameState() == GameState::Paused)
{
Engine::SetGameState(GameState::Playing);
PushCommand(SetGameState(GameState::Playing));
std::string statusMessage = ICON_FA_RUNNING + std::string(" Playing...");
SetStatusMessage(statusMessage.c_str(), { 97.0 / 255.0, 0, 1, 1 });
}
@@ -363,7 +364,8 @@ namespace Nuake {
JobSystem::Get().Dispatch(job, [this]()
{
SetStatusMessage("Entering play mode...");
Engine::EnterPlayMode();
PushCommand(SetGameState(GameState::Playing));
std::string statusMessage = ICON_FA_RUNNING + std::string(" Playing...");
SetStatusMessage(statusMessage.c_str(), { 97.0 / 255.0, 0, 1, 1 });

View File

@@ -83,7 +83,7 @@ namespace Nuake
s_LastFrameTime = (float)glfwGetTime();; // Reset timestep timer.
// Dont trigger init if already in player mode.
if (s_GameState == GameState::Playing)
if (GetGameState() == GameState::Playing)
{
Logger::Log("Cannot enter play mode if is already in play mode.", "engine", WARNING);
return;
@@ -91,7 +91,7 @@ namespace Nuake
if (GetCurrentScene()->OnInit())
{
s_GameState = GameState::Playing;
SetGameState(GameState::Playing);
}
else
{