Chunk.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #pragma once
  2. #include "Block.h"
  3. #include <Vec3.h>
  4. #include <Array.h>
  5. #include <Datei.h>
  6. #include <Punkt.h>
  7. #include <Either.h>
  8. class Chunk : public virtual Framework::ReferenceCounter
  9. {
  10. private:
  11. int dimensionId;
  12. Framework::Punkt location;
  13. Block** blocks;
  14. Chunk* zNeighbours[ 4 ];
  15. unsigned short* blockIds;
  16. Framework::Either<Block*, int> zBlockNeighbor( Framework::Vec3<int> location );
  17. bool added;
  18. Framework::Critical cs;
  19. Framework::Array<Entity*> views;
  20. public:
  21. Chunk( Framework::Punkt location, int dimensionId );
  22. Chunk( Framework::Punkt location, int dimensionId, Framework::StreamReader* zReader );
  23. ~Chunk();
  24. void api( Framework::StreamReader* zRequest, NetworkResponse* zResponse );
  25. Framework::Either<Block*, int> zBlockAt( Framework::Vec3<int> cLocation ) const;
  26. const Block* zBlockConst( Framework::Vec3<int> location ) const;
  27. void instantiateBlock( Framework::Vec3<int> location );
  28. void generateBlock( Framework::Vec3<int> location );
  29. void putBlockAt( Framework::Vec3<int> location, Block* block );
  30. void putBlockTypeAt( Framework::Vec3<int> location, int type );
  31. void setNeighbor( Direction dir, Chunk* zChunk );
  32. void load( Framework::StreamReader* zReader );
  33. void save( Framework::StreamWriter* zWriter, StreamTarget target );
  34. void removeUnusedBlocks();
  35. int getDimensionId() const;
  36. Framework::Punkt getCenter() const;
  37. Framework::Vec3<int> getMin() const;
  38. Framework::Vec3<int> getMax() const;
  39. void prepareRemove();
  40. void setAdded();
  41. void addView( Entity* zEntity );
  42. void removeView( Entity* zEntity );
  43. bool hasView( Entity* zEntity );
  44. bool hasViews() const;
  45. };