Chunk.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #pragma once
  2. #include "Block.h"
  3. #include "DoLaterHandler.h"
  4. #include <Vec3.h>
  5. #include <Array.h>
  6. #include <Datei.h>
  7. #include <Punkt.h>
  8. #include <Either.h>
  9. class Chunk : public virtual Framework::ReferenceCounter
  10. {
  11. private:
  12. int dimensionId;
  13. Framework::Punkt location;
  14. Block** blocks;
  15. Chunk* zNeighbours[4];
  16. unsigned short* blockIds;
  17. Framework::Either<Block*, int> zBlockNeighbor(Framework::Vec3<int> location);
  18. bool added;
  19. Framework::Critical cs;
  20. Framework::Array<int> observers;
  21. Framework::Array<int> lightSources;
  22. unsigned char* lightData;
  23. void addLightSource(int index);
  24. void removeLightSource(int index);
  25. void sendLightToClient(Framework::StreamWriter* zWriter);
  26. public:
  27. Chunk(Framework::Punkt location, int dimensionId);
  28. Chunk(Framework::Punkt location, int dimensionId, Framework::StreamReader* zReader);
  29. ~Chunk();
  30. void notifyObservers(NetworkMessage* msg);
  31. void addObserver(Entity* zEntity, DoLaterHandler& laterHandler);
  32. void removeObserver(Entity* zEntity);
  33. void api(Framework::StreamReader* zRequest, Entity* zSource, DoLaterHandler& laterHandler);
  34. void initializeLightning();
  35. Framework::Either<Block*, int> zBlockAt(Framework::Vec3<int> cLocation) const;
  36. const Block* zBlockConst(Framework::Vec3<int> location) const;
  37. void instantiateBlock(Framework::Vec3<int> location);
  38. void generateBlock(Framework::Vec3<int> location);
  39. void putBlockAt(Framework::Vec3<int> location, Block* block);
  40. void putBlockTypeAt(Framework::Vec3<int> location, int type);
  41. void setNeighbor(Direction dir, Chunk* zChunk);
  42. void load(Framework::StreamReader* zReader);
  43. void save(Framework::StreamWriter* zWriter);
  44. void sendToClient(Framework::StreamWriter* zWriter);
  45. void removeUnusedBlocks();
  46. int getDimensionId() const;
  47. Framework::Punkt getCenter() const;
  48. Framework::Vec3<int> getMin() const;
  49. Framework::Vec3<int> getMax() const;
  50. void prepareRemove();
  51. void setAdded();
  52. bool hasObservers() const;
  53. unsigned char* getLightData(Framework::Vec3<int> location) const;
  54. void setLightData(Framework::Vec3<int> location, unsigned char* data, bool foreground);
  55. };