Chunk.h 1.8 KB

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