From ba2e09672bf88ed1016fc82bd88ac87df0a5b3a1 Mon Sep 17 00:00:00 2001 From: LaG1924 <12997935+LaG1924@users.noreply.github.com> Date: Tue, 20 Jun 2017 19:25:21 +0500 Subject: 2017-06-20 --- src/core/Core.cpp | 67 +++++++++---------------------------------------------- src/core/Core.hpp | 6 ++--- 2 files changed, 12 insertions(+), 61 deletions(-) (limited to 'src/core') diff --git a/src/core/Core.cpp b/src/core/Core.cpp index bb5bc12..50bcd81 100644 --- a/src/core/Core.cpp +++ b/src/core/Core.cpp @@ -182,11 +182,12 @@ void Core::Exec() { gameState->g_PlayerVelocityZ); toWindow << std::setprecision(2) << std::fixed; toWindow << "Pos: " << camPos.x << ", " << camPos.y - 1.12 << ", " << camPos.z << "; "; - toWindow << "Health: " << gameState->g_PlayerHealth<<"; "; + toWindow << "Health: " << gameState->g_PlayerHealth << "; "; //toWindow << "OG: " << gameState->g_OnGround << "; "; toWindow << "Vel: " << velPos.x << ", " << velPos.y << ", " << velPos.z << "; "; toWindow << "FPS: " << (1.0f / deltaTime) << " "; - toWindow << " (" << deltaTime * 1000 << "ms) "; + toWindow << " (" << deltaTime * 1000 << "ms); "; + toWindow << "Tickrate: " << tickRate << " (" << (1.0 / tickRate * 1000) << "ms); "; window->setTitle(toWindow.str()); HandleEvents(); @@ -288,13 +289,6 @@ void Core::HandleEvents() { case sf::Keyboard::T: SetMouseCapture(!isMouseCaptured); break; - case sf::Keyboard::M: - std::sort(toRender.begin(), toRender.end(), [this](const Vector &lhs, const Vector &rhs) { - return glm::length((glm::vec3) lhs - gameState->Position()) < - glm::length((glm::vec3) rhs - gameState->Position()); - }); - LOG(WARNING) << "Render list is optimized"; - break; case sf::Keyboard::L: ChunkDistance++; LOG(INFO) << "Increased render distance: " << ChunkDistance; @@ -350,11 +344,8 @@ void Core::RenderWorld() { shader->Use(); glCheckError(); - GLint modelLoc = glGetUniformLocation(shader->Program, "model"); GLint projectionLoc = glGetUniformLocation(shader->Program, "projection"); GLint viewLoc = glGetUniformLocation(shader->Program, "view"); - GLint blockLoc = glGetUniformLocation(shader->Program, "Block"); - GLint stateLoc = glGetUniformLocation(shader->Program, "State"); GLint timeLoc = glGetUniformLocation(shader->Program, "time"); glm::mat4 projection = glm::perspective(45.0f, (float) width() / (float) height(), 0.1f, 10000000.0f); glm::mat4 view = gameState->GetViewMatrix(); @@ -367,7 +358,7 @@ void Core::RenderWorld() { glBindVertexArray(VAO); for (auto §ionPos : toRender) { - Section §ion = gameState->world.sections.find(sectionPos)->second; + //Section §ion = gameState->world.sections.find(sectionPos)->second; std::vector sectionCorners = { Vector(0, 0, 0), @@ -521,15 +512,10 @@ void Core::PrepareToWorldRendering() { glBindBufferBase(GL_UNIFORM_BUFFER, bp1, UBO); glBufferData(GL_UNIFORM_BUFFER, sizeof(glm::vec4) + sizeof(glm::vec4) * 1023, NULL, GL_STATIC_DRAW); glBufferSubData(GL_UNIFORM_BUFFER, 0, sizeof(GLint), &totalTextures); //copy totalTextures - for (int i = 0; i < indexes.size(); i++) { + for (size_t i = 0; i < indexes.size(); i++) { size_t baseOffset = sizeof(glm::vec4); size_t itemOffset = sizeof(glm::vec4); size_t offset = baseOffset + i * itemOffset; - /*int index = indexes[i]; - int side = (index & 0x70000) >> 16; - int id = (index & 0xFF0) >> 4; - int state = index & 0xF; - LOG(WARNING) << "Copying " << indexes[i] << " at " << offset<<" side is "<Update(deltaTime); - + const double targetDelta = 1 / 60.0; + std::chrono::duration> timeToSleep(targetDelta - delta.getElapsedTime().asSeconds()); + std::this_thread::sleep_for(timeToSleep); + tickRate = 1 / delta.getElapsedTime().asSeconds(); } LOG(INFO) << "GameState thread is stopped"; -} - -void Core::DrawLine(glm::vec3 from, glm::vec3 to, glm::vec3 color) { - shader2->Use(); - glm::mat4 projection = glm::perspective(45.0f, (float) width() / (float) height(), 0.1f, 10000000.0f); - glm::mat4 view = gameState->GetViewMatrix(); - glUniformMatrix4fv(glGetUniformLocation(shader2->Program, "projection"), 1, GL_FALSE, - glm::value_ptr(projection)); - glUniformMatrix4fv(glGetUniformLocation(shader2->Program, "view"), 1, GL_FALSE, glm::value_ptr(view)); - - /*GLfloat data[6]; - data[0] = from[0]; - data[1] = from[1]; - data[2] = to[2]; - data[3] = to[0]; - data[4] = to[1]; - data[5] = from[2];*/ - GLfloat data[] = {0.5f, 0.5f, 0.0f, - 0.5f, -0.5f, 0.0f, - -0.5f, 0.5f, 0.0f, - - 0.5f, -0.5f, 0.0f, - -0.5f, -0.5f, 0.0f, - -0.5f, 0.5f, 0.0f,}; - - glUniform3f(glGetUniformLocation(shader2->Program, "color"), color[0], color[1], color[2]); - - glDisable(GL_DEPTH_TEST); - glBindVertexArray(VAO2); - glBindBuffer(GL_ARRAY_BUFFER, VBO5); - glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * 18, data, GL_DYNAMIC_DRAW); - glBindBuffer(GL_ARRAY_BUFFER, 0); - glDrawArrays(GL_TRIANGLES, 0, 3); - glBindVertexArray(0); - glEnable(GL_DEPTH_TEST); -} - +} \ No newline at end of file diff --git a/src/core/Core.hpp b/src/core/Core.hpp index cc355db..4cc334c 100644 --- a/src/core/Core.hpp +++ b/src/core/Core.hpp @@ -9,10 +9,8 @@ #include "../gamestate/GameState.hpp" #include "../network/NetworkClient.hpp" #include "../gui/Gui.hpp" -#include "../graphics/Camera3D.hpp" #include "../graphics/Shader.hpp" #include "AssetManager.hpp" -#include "../graphics/Frustrum.hpp" class Core { GameState *gameState; @@ -57,8 +55,6 @@ class Core { void UpdateGameState(); - void DrawLine(glm::vec3 from, glm::vec3 to, glm::vec3 color); - std::thread gameStateLoopThread; Shader *shader,*shader2; @@ -73,6 +69,8 @@ class Core { std::map> toRenderBlocks; //std::map, std::vector > > sectionsRenderingData; + double tickRate=0; + public: Core(); -- cgit v1.2.3