#pragma once #include #include #include #include #include #include #include "Area.h" #include "Block.h" #include "BlockAnimation.h" #include "Constants.h" #include "FactoryCraftModel.h" #include "ChunkModelBuilder.h" class Chunk : public Framework::ReferenceCounter { public: class CombinedModels { public: static const int GROUND = 1; static const int FLUID = 2; static const int TRANSPARENT_GROUND = 4; }; private: Framework::Punkt location; // TODO: use native array for bedder performance? Block** blocks; Framework::Array visibleBlocks; Framework::RCArray modelBuilders; bool isLoading; Framework::Critical cs; Framework::Critical vcs; Framework::Critical acs; Framework::RCArray animations; int lightChanged; int modelChanged; void appendAnimation( Block* zB, int boneId, double time, Vec3 pos, Vec3 rot); void load(Framework::StreamReader* zReader); void buildModel(ChunkModelBuilder *builder); void updateLight(ChunkModelBuilder *builder); public: Chunk(Framework::Punkt location); Chunk(Framework::Punkt location, Framework::StreamReader* zReader); ~Chunk(); void renderSolid(std::function f); void renderTransparent(std::function f); bool tick(std::function f, double time); void destroy(); void api(char* message); Block* zBlockAt(Framework::Vec3 cLocation); void setBlock(Block* block); void removeBlock(Block* zBlock); void blockVisibilityChanged(Block* zB); Framework::Punkt getCenter() const; Framework::Vec3 getMin() const; Framework::Vec3 getMax() const; void setModelChanged(int modelType); void setLightChanged(int modelType); inline static int index(Framework::Vec3 localLocation) { return (localLocation.x * CHUNK_SIZE + localLocation.y) * WORLD_HEIGHT + localLocation.z; } friend ChunkModelBuilder; };