From a2fd708de4ede7427589125e680f3fb339926f4e Mon Sep 17 00:00:00 2001 From: LaG1924 <12997935+LaG1924@users.noreply.github.com> Date: Sun, 17 Feb 2019 21:24:52 +0500 Subject: Refactored lua-api --- src/Render.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'src/Render.cpp') diff --git a/src/Render.cpp b/src/Render.cpp index cf108e4..f86e5ec 100644 --- a/src/Render.cpp +++ b/src/Render.cpp @@ -14,6 +14,7 @@ #include "RendererWorld.hpp" #include "Settings.hpp" #include "Framebuffer.hpp" +#include "Plugin.hpp" Render::Render(unsigned int windowWidth, unsigned int windowHeight, std::string windowTitle) @@ -71,7 +72,9 @@ Render::~Render() { Settings::WriteDouble("brightness", fieldBrightness); Settings::WriteDouble("resolutionScale", fieldResolutionScale); Settings::Save(); - + + PluginSystem::Init(); + framebuffer.reset(); ImGui_ImplSdlGL3_Shutdown(); SDL_GL_DeleteContext(glContext); @@ -717,13 +720,25 @@ void Render::InitEvents() { switch (GlobalState::GetState()) { case State::Playing: SetMouseCapture(true); + PluginSystem::CallOnChangeState("Playing"); break; case State::InitialLoading: + PluginSystem::CallOnChangeState("InitialLoading"); + break; case State::MainMenu: + PluginSystem::CallOnChangeState("MainMenu"); + break; case State::Loading: + PluginSystem::CallOnChangeState("Loading"); + break; case State::Paused: + PluginSystem::CallOnChangeState("Paused"); + break; case State::Inventory: + PluginSystem::CallOnChangeState("Inventory"); + break; case State::Chat: + PluginSystem::CallOnChangeState("Chat"); SetMouseCapture(false); break; } -- cgit v1.2.3 From d4e9d6bbc0abe66acb149a358a25c9a0f385ce74 Mon Sep 17 00:00:00 2001 From: LaG1924 <12997935+LaG1924@users.noreply.github.com> Date: Sun, 21 Apr 2019 18:06:55 +0500 Subject: Renamed GlobalState to Game --- src/Render.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Render.cpp') diff --git a/src/Render.cpp b/src/Render.cpp index f86e5ec..a20ce21 100644 --- a/src/Render.cpp +++ b/src/Render.cpp @@ -8,7 +8,7 @@ #include "AssetManager.hpp" #include "Event.hpp" #include "DebugInfo.hpp" -#include "GlobalState.hpp" +#include "Game.hpp" #include "World.hpp" #include "GameState.hpp" #include "RendererWorld.hpp" -- cgit v1.2.3 From 9d9a415b9a6e4a9ad75256e10f68e4ce55dd5f95 Mon Sep 17 00:00:00 2001 From: LaG1924 <12997935+LaG1924@users.noreply.github.com> Date: Sun, 21 Apr 2019 19:04:53 +0500 Subject: Basic single-threaded implementation --- src/Render.cpp | 59 ++++++++++++++++++++++++++++------------------------------ 1 file changed, 28 insertions(+), 31 deletions(-) (limited to 'src/Render.cpp') 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(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(GlobalState::GetGameState()); + world = std::make_unique(); 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 (); 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(); 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"); -- cgit v1.2.3 From 0d78332f2b82438a4cc47df4a4f923c2b23a7a38 Mon Sep 17 00:00:00 2001 From: LaG1924 <12997935+LaG1924@users.noreply.github.com> Date: Mon, 22 Apr 2019 00:34:40 +0500 Subject: Second iteration of changing to single-threaded model --- src/Render.cpp | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'src/Render.cpp') diff --git a/src/Render.cpp b/src/Render.cpp index 2e69369..00daf99 100644 --- a/src/Render.cpp +++ b/src/Render.cpp @@ -8,17 +8,16 @@ #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) - : timer(std::chrono::milliseconds(16)) { + std::string windowTitle) { InitEvents(); Settings::Load(); @@ -48,9 +47,9 @@ Render::Render(unsigned int windowWidth, unsigned int windowHeight, if (fieldSensetivity != sensetivity) sensetivity = fieldSensetivity; isWireframe = fieldWireframe; - timer.SetDelayLength(std::chrono::duration(1.0 / fieldTargetFps * 1000.0)); + GetTime()->SetDelayLength(std::chrono::duration(1.0 / fieldTargetFps * 1000.0)); if (fieldVsync) { - timer.SetDelayLength(std::chrono::milliseconds(0)); + GetTime()->SetDelayLength(std::chrono::milliseconds(0)); SDL_GL_SetSwapInterval(1); } else @@ -191,7 +190,7 @@ void Render::RenderFrame() { RenderGui(); if (world) { - world->Update(timer.RemainTimeMs()); + world->Update(GetTime()->RemainTimeMs()); } SDL_GL_SwapWindow(window); @@ -358,7 +357,6 @@ void Render::Update() { RenderFrame(); listener.HandleAllEvents(); - timer.Update(); } void Render::RenderGui() { @@ -629,9 +627,9 @@ void Render::RenderGui() { GetGameState()->GetPlayer()->isFlying = fieldFlight; isWireframe = fieldWireframe; - timer.SetDelayLength(std::chrono::duration(1.0 / fieldTargetFps * 1000.0)); + GetTime()->SetDelayLength(std::chrono::duration(1.0 / fieldTargetFps * 1000.0)); if (fieldVsync) { - timer.SetDelayLength(std::chrono::milliseconds(0)); + GetTime()->SetDelayLength(std::chrono::milliseconds(0)); SDL_GL_SetSwapInterval(1); } else SDL_GL_SetSwapInterval(0); @@ -721,18 +719,23 @@ void Render::InitEvents() { break; case State::InitialLoading: PluginSystem::CallOnChangeState("InitialLoading"); + SetMouseCapture(false); break; case State::MainMenu: PluginSystem::CallOnChangeState("MainMenu"); + SetMouseCapture(false); break; case State::Loading: PluginSystem::CallOnChangeState("Loading"); + SetMouseCapture(false); break; case State::Paused: PluginSystem::CallOnChangeState("Paused"); + SetMouseCapture(false); break; case State::Inventory: PluginSystem::CallOnChangeState("Inventory"); + SetMouseCapture(false); break; case State::Chat: PluginSystem::CallOnChangeState("Chat"); -- cgit v1.2.3 From 868ba6279a20e4d1412c2d576c67400167de6694 Mon Sep 17 00:00:00 2001 From: LaG1924 <12997935+LaG1924@users.noreply.github.com> Date: Tue, 30 Apr 2019 16:12:35 +0500 Subject: Integrated Optick profiler --- src/Render.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src/Render.cpp') diff --git a/src/Render.cpp b/src/Render.cpp index 00daf99..6218740 100644 --- a/src/Render.cpp +++ b/src/Render.cpp @@ -2,6 +2,7 @@ #include #include +#include #include "imgui_impl_sdl_gl3.h" #include "Shader.hpp" @@ -173,6 +174,7 @@ void Render::UpdateKeyboard() { } void Render::RenderFrame() { + OPTICK_EVENT(); framebuffer->Clear(); Framebuffer::GetDefault().Clear(); @@ -193,7 +195,9 @@ void Render::RenderFrame() { world->Update(GetTime()->RemainTimeMs()); } - SDL_GL_SwapWindow(window); + + OPTICK_EVENT("VSYNC"); + SDL_GL_SwapWindow(window); } void Render::HandleEvents() { @@ -350,6 +354,7 @@ void Render::SetMouseCapture(bool IsCaptured) { } void Render::Update() { + OPTICK_EVENT(); HandleEvents(); if (HasFocus && GetState() == State::Playing) UpdateKeyboard(); if (isMouseCaptured) HandleMouseCapture(); @@ -360,6 +365,7 @@ void Render::Update() { } void Render::RenderGui() { + OPTICK_EVENT(); ImGui_ImplSdlGL3_NewFrame(window); if (isMouseCaptured) { -- cgit v1.2.3 From 37fbb814cb277fe5ce53240a3d02aa996000be1d Mon Sep 17 00:00:00 2001 From: LaG1924 <12997935+LaG1924@users.noreply.github.com> Date: Mon, 20 May 2019 14:06:25 +0500 Subject: Completely removed hardcoded list of blockstates --- src/Render.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/Render.cpp') diff --git a/src/Render.cpp b/src/Render.cpp index 6218740..128c877 100644 --- a/src/Render.cpp +++ b/src/Render.cpp @@ -451,8 +451,8 @@ void Render::RenderGui() { AssetManager::GetAssetNameByBlockId(BlockId{ worldPtr->GetBlockId(selectionStatus.selectedBlock).id,0 }).c_str()); ImGui::Text("Selected block variant: %s:%s", - TransformBlockIdToBlockStateName(worldPtr->GetBlockId(selectionStatus.selectedBlock)).first.c_str(), - TransformBlockIdToBlockStateName(worldPtr->GetBlockId(selectionStatus.selectedBlock)).second.c_str()); + GetBlockInfo(worldPtr->GetBlockId(selectionStatus.selectedBlock)).blockstate.c_str(), + GetBlockInfo(worldPtr->GetBlockId(selectionStatus.selectedBlock)).variant.c_str()); } ImGui::End(); -- cgit v1.2.3