Chunk.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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);
  34. void sendToClient(Framework::StreamWriter* zWriter);
  35. void removeUnusedBlocks();
  36. int getDimensionId() const;
  37. Framework::Punkt getCenter() const;
  38. Framework::Vec3<int> getMin() const;
  39. Framework::Vec3<int> getMax() const;
  40. void prepareRemove();
  41. void setAdded();
  42. void addView(Entity* zEntity);
  43. void removeView(Entity* zEntity);
  44. bool hasView(Entity* zEntity);
  45. bool hasViews() const;
  46. };