Chunk.h 2.5 KB

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