Chunk.h 1.9 KB

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