Dimension.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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::Array<Framework::Vec3<int>> priorizedLightUpdateQueue;
  28. Framework::Critical lightCs;
  29. Framework::Critical prioLightCs;
  30. public:
  31. Dimension(int id);
  32. ~Dimension();
  33. void api(Framework::InMemoryBuffer* zRequest, NetworkMessage* zResponse, Entity* zSource);
  34. void tickEntities();
  35. void thread() override;
  36. Framework::Either<Block*, int> zBlock(Framework::Vec3<int> location);
  37. Block* zRealBlockInstance(Framework::Vec3<int> location);
  38. const Block* zBlockOrDefault(Framework::Vec3<int> location);
  39. void placeBlock(Framework::Vec3<int> location, Framework::Either<Block*, int> block);
  40. void addEntity(Entity* entity);
  41. void setChunk(Chunk* chunk, Framework::Punkt center);
  42. void save(Framework::Text worldDir) const;
  43. int getDimensionId() const;
  44. bool hasChunck(int x, int y) const;
  45. Chunk* zChunk(Framework::Punkt wPos) const;
  46. float getGravity() const;
  47. void removeOldChunks();
  48. Entity* zEntity(int id);
  49. Entity* zNearestEntity(Framework::Vec3<float> pos, std::function<bool(Entity*)> filter);
  50. void removeEntity(int id);
  51. void removeSubscriptions(Entity* zEntity);
  52. void updateLightning(Framework::Vec3<int> location);
  53. void updateLightningWithoutWait(Framework::Vec3<int> location);
  54. void updateLightAtChunkBorders(Framework::Punkt chunkCenter);
  55. };