diff options
Diffstat (limited to 'src/Render.cpp')
-rw-r--r-- | src/Render.cpp | 59 |
1 files changed, 28 insertions, 31 deletions
diff --git a/src/Render.cpp b/src/Render.cpp index a20ce21..2e69369 100644 --- a/src/Render.cpp +++ b/src/Render.cpp @@ -8,13 +8,13 @@ #include "AssetManager.hpp" #include "Event.hpp" #include "DebugInfo.hpp" -#include "Game.hpp" #include "World.hpp" #include "GameState.hpp" #include "RendererWorld.hpp" #include "Settings.hpp" #include "Framebuffer.hpp" #include "Plugin.hpp" +#include "Game.hpp" Render::Render(unsigned int windowWidth, unsigned int windowHeight, std::string windowTitle) @@ -228,11 +228,11 @@ void Render::HandleEvents() { case SDL_WINDOWEVENT_FOCUS_LOST: { HasFocus = false; - auto state = GlobalState::GetState(); + State state = GetState(); if (state == State::Inventory || state == State::Playing || state == State::Chat) { - GlobalState::SetState(State::Paused); + SetState(State::Paused); } break; } @@ -244,13 +244,13 @@ void Render::HandleEvents() { case SDL_KEYDOWN: { switch (event.key.keysym.scancode) { case SDL_SCANCODE_ESCAPE: { - auto state = GlobalState::GetState(); + auto state = GetState(); if (state == State::Playing) { - GlobalState::SetState(State::Paused); + SetState(State::Paused); } else if (state == State::Paused || state == State::Inventory || state == State::Chat) { - GlobalState::SetState(State::Playing); + SetState(State::Playing); } else if (state == State::MainMenu) { LOG(INFO) << "Received close event by esc"; PUSH_EVENT("Exit", 0); @@ -260,11 +260,11 @@ void Render::HandleEvents() { } case SDL_SCANCODE_E: { - auto state = GlobalState::GetState(); + auto state = GetState(); if (state == State::Playing) { - GlobalState::SetState(State::Inventory); + SetState(State::Inventory); } else if (state == State::Inventory) { - GlobalState::SetState(State::Playing); + SetState(State::Playing); } break; @@ -273,11 +273,11 @@ void Render::HandleEvents() { case SDL_SCANCODE_SLASH: case SDL_SCANCODE_T: { if (!ImGui::GetIO().WantCaptureKeyboard) { - auto state = GlobalState::GetState(); + auto state = GetState(); if (state == State::Playing) { - GlobalState::SetState(State::Chat); + SetState(State::Chat); } else if (state == State::Chat) { - GlobalState::SetState(State::Playing); + SetState(State::Playing); } } @@ -351,11 +351,8 @@ void Render::SetMouseCapture(bool IsCaptured) { } void Render::Update() { - if (world) - world->UpdateGameState(GlobalState::GetGameState()); - HandleEvents(); - if (HasFocus && GlobalState::GetState() == State::Playing) UpdateKeyboard(); + if (HasFocus && GetState() == State::Playing) UpdateKeyboard(); if (isMouseCaptured) HandleMouseCapture(); glCheckError(); @@ -388,9 +385,9 @@ void Render::RenderGui() { ImGui::Text("FPS: %.1f (%.3fms)", ImGui::GetIO().Framerate, 1000.0f / ImGui::GetIO().Framerate); float gameTime = DebugInfo::gameThreadTime / 100.0f; if (world) { - Entity *playerPtr = world->GameStatePtr()->GetPlayer(); - SelectionStatus selectionStatus = world->GameStatePtr()->GetSelectionStatus(); - const World *worldPtr = &world->GameStatePtr()->GetWorld(); + Entity *playerPtr = GetGameState()->GetPlayer(); + SelectionStatus selectionStatus = GetGameState()->GetSelectionStatus(); + const World *worldPtr = &GetGameState()->GetWorld(); ImGui::Text("TPS: %.1f (%.2fms)", 1000.0f / gameTime, gameTime); ImGui::Text("Sections loaded: %d", (int) DebugInfo::totalSections); @@ -431,7 +428,7 @@ void Render::RenderGui() { ImGui::Text( "Player health: %.1f/%.1f", - world->GameStatePtr()->GetPlayerStatus().health, 20.0f); + GetGameState()->GetPlayerStatus().health, 20.0f); ImGui::Text( "Selected block: %d %d %d : %.1f", @@ -456,7 +453,7 @@ void Render::RenderGui() { ImGui::End(); - switch (GlobalState::GetState()) { + switch (GetState()) { case State::MainMenu: { ImGui::SetNextWindowPosCenter(); ImGui::Begin("Menu", 0, windowFlags); @@ -513,7 +510,7 @@ void Render::RenderGui() { }; ImGui::SetNextWindowPosCenter(); ImGui::Begin("Inventory", 0, windowFlags); - const Window& inventory = world->GameStatePtr()->GetInventory(); + const Window& inventory = GetGameState()->GetInventory(); //Hand and drop slots if (renderSlot(inventory.handSlot, -1)) { @@ -600,7 +597,7 @@ void Render::RenderGui() { ImGui::SetNextWindowPosCenter(); ImGui::Begin("Pause Menu", 0, windowFlags); if (ImGui::Button("Continue")) { - GlobalState::SetState(State::Playing); + SetState(State::Playing); } ImGui::Separator(); @@ -629,7 +626,7 @@ void Render::RenderGui() { if (fieldSensetivity != sensetivity) sensetivity = fieldSensetivity; - world->GameStatePtr()->GetPlayer()->isFlying = fieldFlight; + GetGameState()->GetPlayer()->isFlying = fieldFlight; isWireframe = fieldWireframe; timer.SetDelayLength(std::chrono::duration<double, std::milli>(1.0 / fieldTargetFps * 1000.0)); @@ -675,7 +672,7 @@ void Render::InitEvents() { listener.RegisterHandler("PlayerConnected", [this](const Event&) { stateString = "Loading terrain..."; - world = std::make_unique<RendererWorld>(GlobalState::GetGameState()); + world = std::make_unique<RendererWorld>(); world->MaxRenderingDistance = fieldDistance; PUSH_EVENT("UpdateSectionsRender", 0); }); @@ -683,9 +680,9 @@ void Render::InitEvents() { listener.RegisterHandler("RemoveLoadingScreen", [this](const Event&) { stateString = "Playing"; renderWorld = true; - GlobalState::SetState(State::Playing); + SetState(State::Playing); glClearColor(0, 0, 0, 1.0f); - world->GameStatePtr()->GetPlayer()->isFlying = this->fieldFlight; + GetGameState()->GetPlayer()->isFlying = this->fieldFlight; PUSH_EVENT("SetMinLightLevel", fieldBrightness); }); @@ -693,7 +690,7 @@ void Render::InitEvents() { stateString = "Connection failed: " + eventData.get <std::string>(); renderWorld = false; world.reset(); - GlobalState::SetState(State::MainMenu); + SetState(State::MainMenu); glClearColor(0.8, 0.8, 0.8, 1.0f); }); @@ -701,13 +698,13 @@ void Render::InitEvents() { stateString = "Disconnected: " + eventData.get<std::string>(); renderWorld = false; world.reset(); - GlobalState::SetState(State::MainMenu); + SetState(State::MainMenu); glClearColor(0.8, 0.8, 0.8, 1.0f); }); listener.RegisterHandler("Connecting", [this](const Event&) { stateString = "Connecting to the server..."; - GlobalState::SetState(State::Loading); + SetState(State::Loading); }); listener.RegisterHandler("ChatMessageReceived", [this](const Event& eventData) { @@ -717,7 +714,7 @@ void Render::InitEvents() { }); listener.RegisterHandler("StateUpdated", [this](const Event& eventData) { - switch (GlobalState::GetState()) { + switch (GetState()) { case State::Playing: SetMouseCapture(true); PluginSystem::CallOnChangeState("Playing"); |