From 9e56348975dbdaf1cce9dd688129208a61fd4eb5 Mon Sep 17 00:00:00 2001 From: LaG1924 <12997935+LaG1924@users.noreply.github.com> Date: Fri, 21 Jul 2017 19:49:56 +0500 Subject: 2017-07-21 --- include/AssetManager.hpp | 3 +++ include/Core.hpp | 25 ++++++++++++++++++------- include/Utility.hpp | 4 ++++ include/graphics/RenderSection.hpp | 25 ++++++++++++++++++------- include/world/Section.hpp | 3 +++ include/world/World.hpp | 21 ++++++++++++--------- 6 files changed, 58 insertions(+), 23 deletions(-) (limited to 'include') diff --git a/include/AssetManager.hpp b/include/AssetManager.hpp index f91c722..26c7eca 100644 --- a/include/AssetManager.hpp +++ b/include/AssetManager.hpp @@ -53,6 +53,7 @@ class AssetManager { Texture *textureAtlas; std::map assetIds; std::map assetTextures; + std::map textureAtlasIndexes; public: AssetManager(); @@ -66,6 +67,8 @@ public: GLuint GetTextureAtlas(); + const std::map &GetTextureAtlasIndexes(); + void LoadIds(); TextureCoordinates GetTextureByBlock(BlockTextureId block); diff --git a/include/Core.hpp b/include/Core.hpp index 64fab4e..8d60ff6 100644 --- a/include/Core.hpp +++ b/include/Core.hpp @@ -15,6 +15,14 @@ #include #include +struct MyMutex { + std::mutex mtx; + std::string str; + MyMutex(std::string name); + void lock(); + void unlock(); +}; + class Core { GameState *gameState; NetworkClient *client; @@ -56,24 +64,27 @@ class Core { void UpdateGameState(); + void UpdateSections(); + std::thread gameStateLoopThread; + std::thread sectionUpdateLoopThread; Shader *shader; //Cube verticies, Cube VAO, Cube UVs, TextureIndexes UboTextureIndexes, TextureData UboTextureIndexes, TextureData2 UboTextureIndexes, Blocks VBO, Models VBO, Line VAO, Lines VBO - //GLuint VBO, VAO, VBO2, UboTextureIndexes, UboTextureData, VBO3, VBO4, VAO2, VBO5; - GLuint UboTextureIndexes, UboTextureData; - //std::vector toRender; + bool isRendersShouldBeCreated=false; + std::condition_variable waitRendersCreated; + std::vector renders; + std::mutex toRenderMutex; std::vector toRender; std::map availableChunks; + std::mutex availableChunksMutex; - int ChunkDistance = 2; + int ChunkDistance = 1; RenderState renderState; - /*std::map> toRenderModels; - std::map> toRenderBlocks;*/ - double tickRate = 0; + double sectionRate = 0; public: Core(); diff --git a/include/Utility.hpp b/include/Utility.hpp index 92e924f..11b4ff7 100644 --- a/include/Utility.hpp +++ b/include/Utility.hpp @@ -47,6 +47,10 @@ inline GLenum glCheckError_(const char *file, int line) { error = "INVALID_FRAMEBUFFER_OPERATION"; break; } + static int t = 0; + t++; + if (t>10) + LOG(FATAL); LOG(ERROR) << "OpenGL error: " << error << " at " << file << ":" << line; } return errorCode; diff --git a/include/graphics/RenderSection.hpp b/include/graphics/RenderSection.hpp index 6a2f3ce..58c4acf 100644 --- a/include/graphics/RenderSection.hpp +++ b/include/graphics/RenderSection.hpp @@ -7,6 +7,7 @@ #include #include +#include #include #include @@ -21,21 +22,31 @@ public: class RenderSection { Vector sectionPosition; World *world; - GLuint Vao,VboBlocks,VboModels; + GLuint Vao, VboTextures, VboModels, VboColors; + std::vector models; + std::vector textures; + std::vector colors; - static GLuint VboVertices,VboUvs; - static std::map refCounterVbo; - static std::map refCounterVao; + static GLuint VboVertices, VboUvs; + static std::map refCounterVbo; + static std::map refCounterVao; - size_t numOfBlocks; + size_t numOfFaces = 0; + bool isEnabled = true; + + size_t hash = 0; public: RenderSection(World *world, Vector position); RenderSection(const RenderSection &other); ~RenderSection(); - void UpdateState(); + void UpdateState(const std::map &textureAtlas); void Render(RenderState &state); - Section* GetSection(); + void SetEnabled(bool isEnabled); + + Section *GetSection(); + + bool IsNeedUpdate(); }; \ No newline at end of file diff --git a/include/world/Section.hpp b/include/world/Section.hpp index 139b5b5..2df0cfe 100644 --- a/include/world/Section.hpp +++ b/include/world/Section.hpp @@ -3,6 +3,7 @@ #include #include #include +#include #include @@ -45,4 +46,6 @@ public: Section(const Section &other); Vector GetPosition(); + + size_t GetHash(); }; \ No newline at end of file diff --git a/include/world/World.hpp b/include/world/World.hpp index 6e5eedb..6b09f1f 100644 --- a/include/world/World.hpp +++ b/include/world/World.hpp @@ -11,17 +11,14 @@ #include class World { - //utility vars - World(const World &other); - - World &operator=(const World &other); - - //game vars + std::map sections; + std::map sectionMutexes; int dimension = 0; - //game methods Section ParseSection(StreamInput *data, Vector position); + World(const World &other); + World &operator=(const World &other); public: World(); @@ -29,7 +26,13 @@ public: void ParseChunkData(std::shared_ptr packet); - std::map sections; - bool isPlayerCollides(double X, double Y, double Z); + + Block &GetBlock(Vector pos); + + std::vector GetSectionsList(); + + Section &GetSection(Vector sectionPos); + + glm::vec3 Raycast(glm::vec3 position, glm::vec3 direction, float maxLength = 1000.0f, float minPrecision = 0.01f); }; \ No newline at end of file -- cgit v1.2.3