Dimension.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #pragma once
  2. #include <Punkt.h>
  3. #include <InMemoryBuffer.h>
  4. #include <Thread.h>
  5. #include "Chunk.h"
  6. #include "NetworkMessage.h"
  7. struct RequestQueue
  8. {
  9. Framework::InMemoryBuffer* request;
  10. Framework::Punkt chunkCenter;
  11. int sourceId;
  12. };
  13. class Dimension : public Framework::Thread
  14. {
  15. private:
  16. int dimensionId;
  17. float gravity;
  18. Framework::Trie<Chunk>* chunks;
  19. Framework::Array<Chunk*> chunkList;
  20. Framework::Critical chunkCs;
  21. Framework::RCArray<Entity>* entities;
  22. Framework::Array<RequestQueue> waitingRequests;
  23. Framework::Critical cs;
  24. void getAddrOf(Framework::Punkt cPos, char* addr) const;
  25. void getAddrOfWorld(Framework::Punkt wPos, char* addr) const;
  26. Framework::Array<Framework::Vec3<int>> lightUpdateQueue;
  27. Framework::Critical lightCs;
  28. public:
  29. Dimension(int id);
  30. ~Dimension();
  31. void api(Framework::InMemoryBuffer* zRequest, NetworkMessage* zResponse, Entity* zSource);
  32. void tickEntities();
  33. void thread() override;
  34. Framework::Either<Block*, int> zBlock(Framework::Vec3<int> location);
  35. Block* zRealBlockInstance(Framework::Vec3<int> location);
  36. const Block* zBlockOrDefault(Framework::Vec3<int> location);
  37. void placeBlock(Framework::Vec3<int> location, Framework::Either<Block*, int> block);
  38. void addEntity(Entity* entity);
  39. void setChunk(Chunk* chunk, Framework::Punkt center);
  40. void save(Framework::Text worldDir) const;
  41. int getDimensionId() const;
  42. bool hasChunck(int x, int y) const;
  43. Chunk* zChunk(Framework::Punkt wPos) const;
  44. float getGravity() const;
  45. void removeOldChunks();
  46. Entity* zEntity(int id);
  47. Entity* zNearestEntity(Framework::Vec3<float> pos, std::function<bool(Entity*)> filter);
  48. void removeEntity(int id);
  49. void removeSubscriptions(Entity* zEntity);
  50. void updateLightning(Framework::Vec3<int> location);
  51. void updateLightAtChunkBorders(Framework::Punkt chunkCenter);
  52. };