Dimension.h 2.3 KB

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