Chunk.h 2.4 KB

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