Chunk.h 2.1 KB

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