diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/AssetManager.hpp | 3 | ||||
-rw-r--r-- | include/Core.hpp | 25 | ||||
-rw-r--r-- | include/Utility.hpp | 4 | ||||
-rw-r--r-- | include/graphics/RenderSection.hpp | 25 | ||||
-rw-r--r-- | include/world/Section.hpp | 3 | ||||
-rw-r--r-- | include/world/World.hpp | 21 |
6 files changed, 58 insertions, 23 deletions
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<std::string, Block> assetIds; std::map<std::string, TextureCoordinates> assetTextures; + std::map<BlockTextureId,glm::vec4> textureAtlasIndexes; public: AssetManager(); @@ -66,6 +67,8 @@ public: GLuint GetTextureAtlas(); + const std::map<BlockTextureId,glm::vec4> &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 <graphics/RenderSection.hpp> #include <network/NetworkClient.hpp> +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<Vector> toRender; + bool isRendersShouldBeCreated=false; + std::condition_variable waitRendersCreated; + std::vector<Vector> renders; + std::mutex toRenderMutex; std::vector<Vector> toRender; std::map<Vector, RenderSection> availableChunks; + std::mutex availableChunksMutex; - int ChunkDistance = 2; + int ChunkDistance = 1; RenderState renderState; - /*std::map<Vector, std::vector<glm::mat4>> toRenderModels; - std::map<Vector, std::vector<glm::vec2>> 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 <glm/gtx/transform.hpp> #include <easylogging++.h> +#include <AssetManager.hpp> #include <world/Section.hpp> #include <world/World.hpp> @@ -21,21 +22,31 @@ public: class RenderSection { Vector sectionPosition; World *world; - GLuint Vao,VboBlocks,VboModels; + GLuint Vao, VboTextures, VboModels, VboColors; + std::vector<glm::mat4> models; + std::vector<glm::vec4> textures; + std::vector<glm::vec3> colors; - static GLuint VboVertices,VboUvs; - static std::map<GLuint,int> refCounterVbo; - static std::map<GLuint,int> refCounterVao; + static GLuint VboVertices, VboUvs; + static std::map<GLuint, int> refCounterVbo; + static std::map<GLuint, int> 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<BlockTextureId, glm::vec4> &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 <vector> #include <map> #include <condition_variable> +#include <functional> #include <easylogging++.h> @@ -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 <world/Collision.hpp> class World { - //utility vars - World(const World &other); - - World &operator=(const World &other); - - //game vars + std::map<Vector, Section> sections; + std::map<Vector, std::mutex> 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<PacketChunkData> packet); - std::map<Vector, Section> sections; - bool isPlayerCollides(double X, double Y, double Z); + + Block &GetBlock(Vector pos); + + std::vector<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 |