#pragma once #include "xe_model.hpp" #include "xe_engine.hpp" #include "xe_image.hpp" #include "PerlinNoise.hpp" #include #include #include #include #include #include #include #define INVALID -1 #define AIR 0 #define DIRT 1 #define GRASS 2 #define DIRT_TEXTURE "res/image/dirt.png" #define GRASS_TEXTURE "res/image/grass.png" #define GRASS_TOP_TEXTURE "res/image/grass_top.png" namespace app { struct Block { uint32_t textures[6]; }; class Chunk { public: static void load(); static void unload(); static std::vector& getTextures(); static Chunk* newChunk(int32_t gridX, int32_t gridZ, uint32_t world_seed); static Chunk* getChunk(int32_t gridX, int32_t gridZ); static void createMesh(Chunk* c); static void createMeshAsync(Chunk* c); xe::Model* getMesh(); uint8_t getBlock(int32_t x, int32_t y, int32_t z); void setBlock(int32_t x, int32_t y, int32_t z, uint8_t block); const int32_t gridX, gridZ; const uint32_t world_seed, chunk_seed; private: Chunk(int32_t gridX, int32_t gridZ, uint32_t world_seed); ~Chunk(); void generate(); static void addVerticies(Chunk* c, uint8_t side, int32_t x, int32_t y, int32_t z, uint8_t block); bool reloadRequired{false}; bool working{false}; xe::Model* chunkMesh; xe::Model::Data vertexData; std::vector cubes; std::thread worker; }; const float px[36][3] = { // POS X {0.5f,0.5f,0.5f}, {0.5f,-0.5f,0.5f}, {0.5f,-0.5f,-0.5f}, {0.5f,-0.5f,-0.5f}, {0.5f,0.5f,-0.5f}, {0.5f,0.5f,0.5f}, // NEG X {-0.5f,0.5f,-0.5f}, {-0.5f,-0.5f,-0.5f}, {-0.5f,-0.5f,0.5f}, {-0.5f,-0.5f,0.5f}, {-0.5f,0.5f,0.5f}, {-0.5f,0.5f,-0.5f}, // POS Y {0.5f,0.5f,-0.5f}, {-0.5f,0.5f,-0.5f}, {-0.5f,0.5f,0.5f}, {-0.5f,0.5f,0.5f}, {0.5f,0.5f,0.5f}, {0.5f,0.5f,-0.5f}, // NEG Y {-0.5f,-0.5f,0.5f}, {-0.5f,-0.5f,-0.5f}, {0.5f,-0.5f,-0.5f}, {0.5f,-0.5f,-0.5f}, {0.5f,-0.5f,0.5f}, {-0.5f,-0.5f,0.5f}, // POS Z {-0.5f,0.5f,0.5f}, {-0.5f,-0.5f,0.5f}, {0.5f,-0.5f,0.5f}, {0.5f,-0.5f,0.5f}, {0.5f,0.5f,0.5f}, {-0.5f,0.5f,0.5f}, // NEG Z {0.5f,0.5f,-0.5f}, {0.5f,-0.5f,-0.5f}, {-0.5f,-0.5f,-0.5f}, {-0.5f,-0.5f,-0.5f}, {-0.5f,0.5f,-0.5f}, {0.5f,0.5f,-0.5f} }; const float nm[6][3] = { {1.f,0.f,0.f}, {-1.f,0.f,0.f}, {0.f,1.f,0.f}, {0.f,-1.f,0.f}, {0.f,0.f,1.f}, {0.f,0.f,-1.f} }; const float uv[6][2] = { {1.f,0.f}, {1.f,1.f}, {0.f,1.f}, {0.f,1.f}, {0.f,0.f}, {1.f,0.f} }; }