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<int> observers;
  20. public:
  21. Chunk(Framework::Punkt location, int dimensionId);
  22. Chunk(Framework::Punkt location, int dimensionId, Framework::StreamReader* zReader);
  23. ~Chunk();
  24. void notifyObservers(NetworkMessage& msg);
  25. void addObserver(Entity* zEntity);
  26. void removeObserver(Entity* zEntity);
  27. void api(Framework::StreamReader* zRequest, Entity* zSource);
  28. Framework::Either<Block*, int> zBlockAt(Framework::Vec3<int> cLocation) const;
  29. const Block* zBlockConst(Framework::Vec3<int> location) const;
  30. void instantiateBlock(Framework::Vec3<int> location);
  31. void generateBlock(Framework::Vec3<int> location);
  32. void putBlockAt(Framework::Vec3<int> location, Block* block);
  33. void putBlockTypeAt(Framework::Vec3<int> location, int type);
  34. void setNeighbor(Direction dir, Chunk* zChunk);
  35. void load(Framework::StreamReader* zReader);
  36. void save(Framework::StreamWriter* zWriter);
  37. void sendToClient(Framework::StreamWriter* zWriter);
  38. void removeUnusedBlocks();
  39. int getDimensionId() const;
  40. Framework::Punkt getCenter() const;
  41. Framework::Vec3<int> getMin() const;
  42. Framework::Vec3<int> getMax() const;
  43. void prepareRemove();
  44. void setAdded();
  45. bool hasObservers() const;
  46. };