diff options
author | LaG1924 <12997935+LaG1924@users.noreply.github.com> | 2018-02-25 13:05:18 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-02-25 13:05:18 +0100 |
commit | 55e432becc8c5a1b8dd6543cc0a26e0213aeb88f (patch) | |
tree | f5d7dea2c6dc5a3d2feb8f4c0413f83beef61793 /src/Render.cpp | |
parent | Raycast debug render (diff) | |
parent | min/max functions (diff) | |
download | AltCraft-55e432becc8c5a1b8dd6543cc0a26e0213aeb88f.tar AltCraft-55e432becc8c5a1b8dd6543cc0a26e0213aeb88f.tar.gz AltCraft-55e432becc8c5a1b8dd6543cc0a26e0213aeb88f.tar.bz2 AltCraft-55e432becc8c5a1b8dd6543cc0a26e0213aeb88f.tar.lz AltCraft-55e432becc8c5a1b8dd6543cc0a26e0213aeb88f.tar.xz AltCraft-55e432becc8c5a1b8dd6543cc0a26e0213aeb88f.tar.zst AltCraft-55e432becc8c5a1b8dd6543cc0a26e0213aeb88f.zip |
Diffstat (limited to '')
-rw-r--r-- | src/Render.cpp | 600 |
1 files changed, 337 insertions, 263 deletions
diff --git a/src/Render.cpp b/src/Render.cpp index 534782e..b5d24b6 100644 --- a/src/Render.cpp +++ b/src/Render.cpp @@ -13,7 +13,9 @@ #include "GameState.hpp" #include "RendererWorld.hpp" -Render::Render(unsigned int windowWidth, unsigned int windowHeight, std::string windowTitle) : timer(std::chrono::milliseconds(16)) { +Render::Render(unsigned int windowWidth, unsigned int windowHeight, + std::string windowTitle) + : timer(std::chrono::milliseconds(16)) { InitEvents(); InitSdl(windowWidth, windowHeight, windowTitle); @@ -34,7 +36,7 @@ Render::~Render() { } void Render::InitSdl(unsigned int WinWidth, unsigned int WinHeight, std::string WinTitle) { - LOG(INFO) << "Creating window: " << WinWidth << "x" << WinHeight << " \"" << WinTitle << "\""; + LOG(INFO) << "Creating window: " << WinWidth << "x" << WinHeight << " \"" << WinTitle << "\""; if (SDL_Init(SDL_INIT_VIDEO) < 0) throw std::runtime_error("SDL initalization failed: " + std::string(SDL_GetError())); @@ -44,7 +46,10 @@ void Render::InitSdl(unsigned int WinWidth, unsigned int WinHeight, std::string SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24); - window = SDL_CreateWindow(WinTitle.c_str(), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, WinWidth, WinHeight, SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE); + window = SDL_CreateWindow( + WinTitle.c_str(), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, + WinWidth, WinHeight, SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE); + if (!window) throw std::runtime_error("Window creation failed: " + std::string(SDL_GetError())); @@ -52,7 +57,7 @@ void Render::InitSdl(unsigned int WinWidth, unsigned int WinHeight, std::string if (!glContext) throw std::runtime_error("OpenGl context creation failed: " + std::string(SDL_GetError())); - SetMouseCapture(false); + SetMouseCapture(false); renderState.WindowWidth = WinWidth; renderState.WindowHeight = WinHeight; @@ -60,34 +65,34 @@ void Render::InitSdl(unsigned int WinWidth, unsigned int WinHeight, std::string } void Render::InitGlew() { - LOG(INFO) << "Initializing GLEW"; - glewExperimental = GL_TRUE; - GLenum glewStatus = glewInit(); - glCheckError(); - if (glewStatus != GLEW_OK) { - LOG(FATAL) << "Failed to initialize GLEW: " << glewGetErrorString(glewStatus); - } + LOG(INFO) << "Initializing GLEW"; + glewExperimental = GL_TRUE; + GLenum glewStatus = glewInit(); + glCheckError(); + if (glewStatus != GLEW_OK) { + LOG(FATAL) << "Failed to initialize GLEW: " << glewGetErrorString(glewStatus); + } int width, height; SDL_GL_GetDrawableSize(window, &width, &height); glViewport(0, 0, width, height); glClearColor(0.8,0.8,0.8, 1.0f); - glEnable(GL_DEPTH_TEST); + glEnable(GL_DEPTH_TEST); - glEnable(GL_CULL_FACE); - glCullFace(GL_BACK); - glFrontFace(GL_CCW); + glEnable(GL_CULL_FACE); + glCullFace(GL_BACK); + glFrontFace(GL_CCW); - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glCheckError(); + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glCheckError(); if (glActiveTexture == nullptr) { throw std::runtime_error("GLEW initialization failed with unknown reason"); } } void Render::PrepareToRendering() { - //TextureAtlas texture - glActiveTexture(GL_TEXTURE0); + //TextureAtlas texture + glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, AssetManager::Instance().GetTextureAtlas()); AssetManager::Instance().GetTextureAtlasIndexes(); @@ -103,13 +108,13 @@ void Render::UpdateKeyboard() { for (auto key : toUpdate) { bool isPressed = kbState[key]; if (!isKeyPressed[key] && isPressed) { - PUSH_EVENT("KeyPressed", key); + PUSH_EVENT("KeyPressed", key); } if (isKeyPressed[key] && isPressed) { //KeyHeld } if (isKeyPressed[key] && !isPressed) { - PUSH_EVENT("KeyReleased", key); + PUSH_EVENT("KeyReleased", key); } isKeyPressed[key] = isPressed; } @@ -141,94 +146,127 @@ void Render::HandleEvents() { ImGui_ImplSdlGL3_ProcessEvent(&event); switch (event.type) { - case SDL_QUIT: - LOG(INFO) << "Received close event by window closing"; - PUSH_EVENT("Exit",0); - break; - case SDL_WINDOWEVENT: { - switch (event.window.event) { - case SDL_WINDOWEVENT_RESIZED: { - int width, height; - SDL_GL_GetDrawableSize(window, &width, &height); - glViewport(0, 0, width, height); - renderState.WindowWidth = width; - renderState.WindowHeight = height; - break; - } - case SDL_WINDOWEVENT_FOCUS_GAINED: - HasFocus = true; - break; - case SDL_WINDOWEVENT_FOCUS_LOST: - HasFocus = false; - if (GlobalState::GetState() == State::Inventory || GlobalState::GetState() == State::Playing || GlobalState::GetState() == State::Chat) - GlobalState::SetState(State::Paused); + case SDL_QUIT: { + LOG(INFO) << "Received close event by window closing"; + PUSH_EVENT("Exit",0); break; } - break; - } - case SDL_KEYDOWN: - switch (event.key.keysym.scancode) { - case SDL_SCANCODE_ESCAPE: - switch (GlobalState::GetState()) { - case State::Playing: - GlobalState::SetState(State::Paused); - break; - case State::Inventory: - GlobalState::SetState(State::Paused); - break; - case State::Paused: - GlobalState::SetState(State::Playing); - break; - case State::MainMenu: - LOG(INFO) << "Received close event by esc"; - PUSH_EVENT("Exit",0); - break; - } - break; - case SDL_SCANCODE_E: - switch (GlobalState::GetState()) { - case State::Playing: - GlobalState::SetState(State::Inventory); - break; - case State::Inventory: - GlobalState::SetState(State::Playing); - break; + + case SDL_WINDOWEVENT: { + switch (event.window.event) { + case SDL_WINDOWEVENT_RESIZED: { + int width, height; + SDL_GL_GetDrawableSize(window, &width, &height); + glViewport(0, 0, width, height); + renderState.WindowWidth = width; + renderState.WindowHeight = height; + break; + } + + case SDL_WINDOWEVENT_FOCUS_GAINED: + HasFocus = true; + break; + + case SDL_WINDOWEVENT_FOCUS_LOST: { + HasFocus = false; + auto state = GlobalState::GetState(); + if (state == State::Inventory || + state == State::Playing || + state == State::Chat) { + GlobalState::SetState(State::Paused); + } + break; + } + } break; - case SDL_SCANCODE_T: - if (!ImGui::GetIO().WantCaptureKeyboard) - switch (GlobalState::GetState()) { - case State::Playing: - GlobalState::SetState(State::Chat); - SetMouseCapture(false); + } + + case SDL_KEYDOWN: { + switch (event.key.keysym.scancode) { + case SDL_SCANCODE_ESCAPE: { + auto state = GlobalState::GetState(); + if (state == State::Playing) { + GlobalState::SetState(State::Paused); + } else if (state == State::Paused || + state == State::Inventory || + state == State::Chat) { + GlobalState::SetState(State::Playing); + } else if (state == State::MainMenu) { + LOG(INFO) << "Received close event by esc"; + PUSH_EVENT("Exit", 0); + } + break; - case State::Chat: - GlobalState::SetState(State::Playing); - SetMouseCapture(true); + } + + case SDL_SCANCODE_E: { + auto state = GlobalState::GetState(); + if (state == State::Playing) { + GlobalState::SetState(State::Inventory); + } else if (state == State::Inventory) { + GlobalState::SetState(State::Playing); + } + break; } + + case SDL_SCANCODE_SLASH: + case SDL_SCANCODE_T: { + if (!ImGui::GetIO().WantCaptureKeyboard) { + auto state = GlobalState::GetState(); + if (state == State::Playing) { + GlobalState::SetState(State::Chat); + } else if (state == State::Chat) { + GlobalState::SetState(State::Playing); + } + } + + break; + } + + default: + break; + } + break; } - break; - case SDL_MOUSEMOTION: - if (isMouseCaptured) { - double deltaX = event.motion.xrel; - double deltaY = event.motion.yrel; - deltaX *= sensetivity; - deltaY *= sensetivity * -1; - PUSH_EVENT("MouseMove", std::make_tuple(deltaX, deltaY)); + + case SDL_MOUSEMOTION: { + if (isMouseCaptured) { + double deltaX = event.motion.xrel; + double deltaY = event.motion.yrel; + deltaX *= sensetivity; + deltaY *= sensetivity * -1; + PUSH_EVENT("MouseMove", std::make_tuple(deltaX, deltaY)); + } + + break; } + + case SDL_MOUSEBUTTONDOWN: { + if (isMouseCaptured && !ImGui::GetIO().WantCaptureMouse) { + if (event.button.button == SDL_BUTTON_LEFT) + PUSH_EVENT("LmbPressed", 0); + else if (event.button.button == SDL_BUTTON_RIGHT) + PUSH_EVENT("RmbPressed", 0); + } + break; - case SDL_MOUSEBUTTONDOWN: - if (event.button.button == SDL_BUTTON_LEFT && !ImGui::GetIO().WantCaptureMouse) - PUSH_EVENT("LmbPressed",0); + } + + case SDL_MOUSEBUTTONUP: { + if (isMouseCaptured && !ImGui::GetIO().WantCaptureMouse) { + if (event.button.button == SDL_BUTTON_LEFT) + PUSH_EVENT("LmbReleased", 0); + else if (event.button.button == SDL_BUTTON_RIGHT) + PUSH_EVENT("RmbReleased", 0); + } break; - case SDL_MOUSEBUTTONUP: - if (event.button.button == SDL_BUTTON_LEFT && !ImGui::GetIO().WantCaptureMouse) - PUSH_EVENT("LmbReleased",0); + } + + default: break; - default: - break; } } } @@ -254,7 +292,6 @@ void Render::SetMouseCapture(bool IsCaptured) { } void Render::Update() { - HandleEvents(); if (HasFocus && GlobalState::GetState() == State::Playing) UpdateKeyboard(); if (isMouseCaptured) HandleMouseCapture(); @@ -272,7 +309,12 @@ void Render::RenderGui() { auto& io = ImGui::GetIO(); io.MousePos = ImVec2(-FLT_MAX, -FLT_MAX); } - const ImGuiWindowFlags windowFlags = ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoSavedSettings; + + const ImGuiWindowFlags windowFlags = ImGuiWindowFlags_NoTitleBar | + ImGuiWindowFlags_NoResize | + ImGuiWindowFlags_NoMove | + ImGuiWindowFlags_AlwaysAutoResize| + ImGuiWindowFlags_NoSavedSettings; //ImGui::ShowTestWindow(); @@ -285,203 +327,235 @@ void Render::RenderGui() { float gameTime = DebugInfo::gameThreadTime / 100.0f; if (world) { ImGui::Text("TPS: %.1f (%.2fms)", 1000.0f / gameTime, gameTime); - ImGui::Text("Sections loaded: %d", (int)DebugInfo::totalSections); - ImGui::Text("SectionsRenderer: %d (%d)", (int)DebugInfo::renderSections, (int)DebugInfo::readyRenderer); - ImGui::Text("Culled sections: %d", (int)DebugInfo::renderSections - world->culledSections); - ImGui::Text("Player pos: %.1f %.1f %.1f OnGround=%d", world->GameStatePtr()->player->pos.x, world->GameStatePtr()->player->pos.y, world->GameStatePtr()->player->pos.z, world->GameStatePtr()->player->onGround); - ImGui::Text("Player vel: %.1f %.1f %.1f", world->GameStatePtr()->player->vel.x, world->GameStatePtr()->player->vel.y, world->GameStatePtr()->player->vel.z); - ImGui::Text("Player health: %.1f/%.1f", world->GameStatePtr()->g_PlayerHealth, 20.0f); - ImGui::Text("Selected block: %d %d %d : %.1f",world->GameStatePtr()->selectedBlock.x,world->GameStatePtr()->selectedBlock.y,world->GameStatePtr()->selectedBlock.z,world->GameStatePtr()->distanceToSelectedBlock); + ImGui::Text("Sections loaded: %d", (int) DebugInfo::totalSections); + ImGui::Text( + "SectionsRenderer: %d (%d)", + (int) DebugInfo::renderSections,(int) DebugInfo::readyRenderer); + + ImGui::Text( + "Culled sections: %d", + (int) DebugInfo::renderSections - world->culledSections); + + ImGui::Text( + "Player pos: %.1f %.1f %.1f OnGround=%d", + world->GameStatePtr()->player->pos.x, + world->GameStatePtr()->player->pos.y, + world->GameStatePtr()->player->pos.z, + world->GameStatePtr()->player->onGround); + + ImGui::Text( + "Player vel: %.1f %.1f %.1f", + world->GameStatePtr()->player->vel.x, + world->GameStatePtr()->player->vel.y, + world->GameStatePtr()->player->vel.z); + + ImGui::Text( + "Player health: %.1f/%.1f", + world->GameStatePtr()->g_PlayerHealth, 20.0f); + + ImGui::Text( + "Selected block: %d %d %d : %.1f", + world->GameStatePtr()->selectedBlock.x, + world->GameStatePtr()->selectedBlock.y, + world->GameStatePtr()->selectedBlock.z, + world->GameStatePtr()->distanceToSelectedBlock); } ImGui::End(); switch (GlobalState::GetState()) { - case State::MainMenu: { - ImGui::SetNextWindowPosCenter(); - ImGui::Begin("Menu", 0, windowFlags); - static char buff[512] = "127.0.0.1"; - static int port = 25565; - static char buffName[512] = "HelloOne"; - if (ImGui::Button("Connect")) { - PUSH_EVENT("ConnectToServer", std::make_tuple(std::string(buff), (unsigned short)port, std::string(buffName))); - } - ImGui::InputText("Username", buffName, 512); - ImGui::InputText("Address", buff, 512); - ImGui::InputInt("Port", &port); - ImGui::Separator(); - if (ImGui::Button("Exit")) - PUSH_EVENT("Exit",0); - ImGui::End(); - break; - } - case State::Loading: - break; - case State::Chat: { - ImGui::SetNextWindowPosCenter(); - ImGui::Begin("Chat", 0, windowFlags); - for (const auto& msg : chatMessages) { - ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(1,1,1,1)); - ImGui::TextWrapped("%s", msg.c_str()); - ImGui::PopStyleColor(); - } - static char buff[256]; - ImGui::InputText("", buff, 256); - ImGui::SameLine(); - if (ImGui::Button("Send")) { - PUSH_EVENT("SendChatMessage", std::string(buff)); + case State::MainMenu: { + ImGui::SetNextWindowPosCenter(); + ImGui::Begin("Menu", 0, windowFlags); + static char buff[512] = "127.0.0.1"; + static int port = 25565; + static char buffName[512] = "HelloOne"; + if (ImGui::Button("Connect")) { + PUSH_EVENT("ConnectToServer", std::make_tuple(std::string(buff), + (unsigned short) port, std::string(buffName))); + } + ImGui::InputText("Username", buffName, 512); + ImGui::InputText("Address", buff, 512); + ImGui::InputInt("Port", &port); + ImGui::Separator(); + if (ImGui::Button("Exit")) + PUSH_EVENT("Exit",0); + ImGui::End(); + break; } - ImGui::End(); - break; - } - case State::Inventory: { - auto renderSlot = [](const SlotDataType &slot, int i) -> bool { - return ImGui::Button(((slot.BlockId == -1 ? " ##" : - AssetManager::Instance().GetAssetNameByBlockId(BlockId{ (unsigned short)slot.BlockId,0 }) + " x" + std::to_string(slot.ItemCount) + "##") - + std::to_string(i)).c_str()); - }; - ImGui::SetNextWindowPosCenter(); - ImGui::Begin("Inventory", 0, windowFlags); - Window& inventory = world->GameStatePtr()->playerInventory; - //Hand and drop slots - if (renderSlot(inventory.handSlot, -1)) { - } - ImGui::SameLine(); - if (ImGui::Button("Drop")) { - inventory.MakeClick(-1, true, true); - } - ImGui::SameLine(); - ImGui::Text("Hand slot and drop mode"); - ImGui::Separator(); - //Crafting - if (renderSlot(inventory.slots[1], 1)) { - inventory.MakeClick(1, true); - } - ImGui::SameLine(); - if (renderSlot(inventory.slots[2], 2)) { - inventory.MakeClick(2, true); - } - //Crafting result - ImGui::SameLine(); - ImGui::Text("Result"); - ImGui::SameLine(); - if (renderSlot(inventory.slots[0], 0)) { - inventory.MakeClick(0, true); - } - //Crafting second line - if (renderSlot(inventory.slots[3], 3)) { - inventory.MakeClick(3, true); - } - ImGui::SameLine(); - if (renderSlot(inventory.slots[4], 4)) { - inventory.MakeClick(4, true); - } - ImGui::Separator(); - //Armor and offhand - for (int i = 5; i < 8 + 1; i++) { - if (renderSlot(inventory.slots[i], i)) { - inventory.MakeClick(i, true); + case State::Loading: + break; + + case State::Chat: { + ImGui::SetNextWindowPosCenter(); + ImGui::Begin("Chat", 0, windowFlags); + for (const auto& msg : chatMessages) { + ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(1,1,1,1)); + ImGui::TextWrapped("%s", msg.c_str()); + ImGui::PopStyleColor(); } + static char buff[256]; + ImGui::InputText("", buff, 256); ImGui::SameLine(); + if (ImGui::Button("Send")) { + PUSH_EVENT("SendChatMessage", std::string(buff)); + } + ImGui::End(); + break; } - if (renderSlot(inventory.slots[45], 45)) { - inventory.MakeClick(45, true); - } - ImGui::SameLine(); - ImGui::Text("Armor and offhand"); - ImGui::Separator(); - for (int i = 36; i < 44 + 1; i++) { - if (renderSlot(inventory.slots[i], i)) { - inventory.MakeClick(i, true); + + case State::Inventory: { + auto renderSlot = [](const SlotDataType &slot, int i) -> bool { + return ImGui::Button(((slot.BlockId == -1 ? " ##" : + AssetManager::Instance().GetAssetNameByBlockId(BlockId{ (unsigned short)slot.BlockId,0 }) + " x" + std::to_string(slot.ItemCount) + "##") + + std::to_string(i)).c_str()); + }; + ImGui::SetNextWindowPosCenter(); + ImGui::Begin("Inventory", 0, windowFlags); + Window& inventory = world->GameStatePtr()->playerInventory; + //Hand and drop slots + if (renderSlot(inventory.handSlot, -1)) { + } ImGui::SameLine(); - } - ImGui::Text("Hotbar"); - ImGui::Separator(); - ImGui::Text("Main inventory"); - for (int i = 9; i < 17 + 1; i++) { - if (renderSlot(inventory.slots[i], i)) { - inventory.MakeClick(i, true); + if (ImGui::Button("Drop")) { + inventory.MakeClick(-1, true, true); } ImGui::SameLine(); - } - ImGui::Text(""); - for (int i = 18; i < 26 + 1; i++) { - if (renderSlot(inventory.slots[i], i)) { - inventory.MakeClick(i, true); + ImGui::Text("Hand slot and drop mode"); + ImGui::Separator(); + //Crafting + if (renderSlot(inventory.slots[1], 1)) { + inventory.MakeClick(1, true); } ImGui::SameLine(); - } - ImGui::Text(""); - for (int i = 27; i < 35 + 1; i++) { - if (renderSlot(inventory.slots[i], i)) { - inventory.MakeClick(i, true); + if (renderSlot(inventory.slots[2], 2)) { + inventory.MakeClick(2, true); } + //Crafting result ImGui::SameLine(); - } - ImGui::End(); + ImGui::Text("Result"); + ImGui::SameLine(); + if (renderSlot(inventory.slots[0], 0)) { + inventory.MakeClick(0, true); + } + //Crafting second line + if (renderSlot(inventory.slots[3], 3)) { + inventory.MakeClick(3, true); + } + ImGui::SameLine(); + if (renderSlot(inventory.slots[4], 4)) { + inventory.MakeClick(4, true); + } + ImGui::Separator(); + //Armor and offhand + for (int i = 5; i < 8 + 1; i++) { + if (renderSlot(inventory.slots[i], i)) { + inventory.MakeClick(i, true); + } + ImGui::SameLine(); + } + if (renderSlot(inventory.slots[45], 45)) { + inventory.MakeClick(45, true); + } + ImGui::SameLine(); + ImGui::Text("Armor and offhand"); + ImGui::Separator(); + for (int i = 36; i < 44 + 1; i++) { + if (renderSlot(inventory.slots[i], i)) { + inventory.MakeClick(i, true); + } + ImGui::SameLine(); + } + ImGui::Text("Hotbar"); + ImGui::Separator(); + ImGui::Text("Main inventory"); + for (int i = 9; i < 17 + 1; i++) { + if (renderSlot(inventory.slots[i], i)) { + inventory.MakeClick(i, true); + } + ImGui::SameLine(); + } + ImGui::Text(""); + for (int i = 18; i < 26 + 1; i++) { + if (renderSlot(inventory.slots[i], i)) { + inventory.MakeClick(i, true); + } + ImGui::SameLine(); + } + ImGui::Text(""); + for (int i = 27; i < 35 + 1; i++) { + if (renderSlot(inventory.slots[i], i)) { + inventory.MakeClick(i, true); + } + ImGui::SameLine(); + } + ImGui::End(); - break; - } - case State::Paused: { - ImGui::SetNextWindowPosCenter(); - ImGui::Begin("Pause Menu", 0, windowFlags); - if (ImGui::Button("Continue")) { - GlobalState::SetState(State::Playing); + break; } - ImGui::Separator(); - static float distance = world->MaxRenderingDistance; - ImGui::SliderFloat("Render distance", &distance, 1.0f, 16.0f); - static float sense = sensetivity; - ImGui::SliderFloat("Sensetivity", &sense, 0.01f, 1.0f); + case State::Paused: { + ImGui::SetNextWindowPosCenter(); + ImGui::Begin("Pause Menu", 0, windowFlags); + if (ImGui::Button("Continue")) { + GlobalState::SetState(State::Playing); + } + ImGui::Separator(); + static float distance = world->MaxRenderingDistance; + ImGui::SliderFloat("Render distance", &distance, 1.0f, 16.0f); - static float targetFps = 60.0f; - ImGui::SliderFloat("Target FPS", &targetFps, 1.0f, 300.0f); + static float sense = sensetivity; + ImGui::SliderFloat("Sensetivity", &sense, 0.01f, 1.0f); - static bool wireframe = isWireframe; + static float targetFps = 60.0f; + ImGui::SliderFloat("Target FPS", &targetFps, 1.0f, 300.0f); - ImGui::Checkbox("Wireframe", &wireframe); + static bool wireframe = isWireframe; - static bool vsync = false; + ImGui::Checkbox("Wireframe", &wireframe); - ImGui::Checkbox("VSync", &vsync); + static bool vsync = false; - if (ImGui::Button("Apply settings")) { - if (distance != world->MaxRenderingDistance) { - world->MaxRenderingDistance = distance; - PUSH_EVENT("UpdateSectionsRender", 0); - } + ImGui::Checkbox("VSync", &vsync); + + if (ImGui::Button("Apply settings")) { + if (distance != world->MaxRenderingDistance) { + world->MaxRenderingDistance = distance; + PUSH_EVENT("UpdateSectionsRender", 0); + } - if (sense != sensetivity) - sensetivity = sense; + if (sense != sensetivity) + sensetivity = sense; - isWireframe = wireframe; - timer.SetDelayLength(std::chrono::duration<double, std::milli>(1.0 / targetFps * 1000.0)); - if (vsync) { - timer.SetDelayLength(std::chrono::milliseconds(0)); - SDL_GL_SetSwapInterval(1); - } else - SDL_GL_SetSwapInterval(0); + isWireframe = wireframe; + timer.SetDelayLength(std::chrono::duration<double, std::milli>(1.0 / targetFps * 1000.0)); + if (vsync) { + timer.SetDelayLength(std::chrono::milliseconds(0)); + SDL_GL_SetSwapInterval(1); + } else + SDL_GL_SetSwapInterval(0); + } + ImGui::Separator(); + + if (ImGui::Button("Disconnect")) { + PUSH_EVENT("Disconnect", std::string("Disconnected by user")); + } + ImGui::End(); + break; } - ImGui::Separator(); - if (ImGui::Button("Disconnect")) { - PUSH_EVENT("Disconnect", std::string("Disconnected by user")); + case State::InitialLoading: + break; + + case State::Playing: { + ImGui::SetNextWindowPosCenter(); + ImGui::Begin("",0,windowFlags); + ImGui::End(); + break; } - ImGui::End(); - break; - } - case State::InitialLoading: - break; - case State::Playing: { - ImGui::SetNextWindowPosCenter(); - ImGui::Begin("",0,windowFlags); - ImGui::End(); - break; - } } ImGui::Render(); |