Dimension.h 2.0 KB

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