Chunk.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 lock();
  38. void unlock();
  39. void tick(TickQueue* zQueue) override;
  40. void postTick() override;
  41. void notifyObservers(NetworkMessage* msg);
  42. void addObserver(Entity* zEntity, DoLaterHandler& laterHandler);
  43. void removeObserver(Entity* zEntity);
  44. void api(Framework::StreamReader* zRequest,
  45. Entity* zSource,
  46. DoLaterHandler& laterHandler);
  47. void initializeLightning();
  48. Framework::Either<Block*, int> zBlockAt(
  49. Framework::Vec3<int> cLocation) const;
  50. const Block* zBlockConst(Framework::Vec3<int> location) const;
  51. void instantiateBlock(Framework::Vec3<int> location);
  52. void generateBlock(Framework::Vec3<int> location);
  53. void putBlockAt(Framework::Vec3<int> location, Block* block);
  54. void putBlockTypeAt(Framework::Vec3<int> location, int type);
  55. void sendBlockInfo(Framework::Vec3<int> location);
  56. void setNeighbor(Direction dir, Chunk* zChunk);
  57. void load(Framework::StreamReader* zReader);
  58. void save(Framework::StreamWriter* zWriter);
  59. void sendToClient(Framework::StreamWriter* zWriter);
  60. void removeUnusedBlocks();
  61. int getDimensionId() const;
  62. void onLoaded();
  63. void onUnloaded();
  64. Framework::Punkt getCenter() const;
  65. Framework::Vec3<int> getMin() const;
  66. Framework::Vec3<int> getMax() const;
  67. void prepareRemove();
  68. void setAdded();
  69. bool hasObservers() const;
  70. unsigned char* getLightData(Framework::Vec3<int> location) const;
  71. void setLightData(
  72. Framework::Vec3<int> location, unsigned char* data, bool foreground);
  73. };