Chunk.h 2.3 KB

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