Dimension.h 2.4 KB

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