Dimension.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #pragma once
  2. #include <InMemoryBuffer.h>
  3. #include <Punkt.h>
  4. #include <Thread.h>
  5. #include "Chunk.h"
  6. #include "MultiblockStructure.h"
  7. #include "NetworkMessage.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. bool stop;
  37. public:
  38. Dimension(int id);
  39. ~Dimension();
  40. void api(Framework::InMemoryBuffer* zRequest,
  41. NetworkMessage* zResponse,
  42. Entity* zSource);
  43. void tickEntities();
  44. void thread() override;
  45. Framework::Either<Block*, int> zBlock(Framework::Vec3<int> location);
  46. Block* zRealBlockInstance(Framework::Vec3<int> location);
  47. const Block* zBlockOrDefault(Framework::Vec3<int> location);
  48. void placeBlock(
  49. Framework::Vec3<int> location, Framework::Either<Block*, int> block);
  50. void sendBlockInfo(Framework::Vec3<int> location);
  51. void addEntity(Entity* entity);
  52. void setChunk(Chunk* chunk, Framework::Punkt center);
  53. void save(Framework::Text worldDir) const;
  54. int getDimensionId() const;
  55. bool hasChunck(int x, int y);
  56. bool reviveChunk(int x, int y);
  57. Chunk* zChunk(Framework::Punkt wPos) const;
  58. float getGravity() const;
  59. void removeOldChunks();
  60. Entity* zEntity(int id);
  61. Entity* zNearestEntity(
  62. Framework::Vec3<float> pos, std::function<bool(Entity*)> filter);
  63. void removeEntity(int id);
  64. void removeSubscriptions(Entity* zEntity);
  65. void updateLightning(Framework::Vec3<int> location);
  66. void updateLightningWithoutWait(Framework::Vec3<int> location);
  67. void updateLightAtChunkBorders(Framework::Punkt chunkCenter);
  68. __int64 getNextStructureId();
  69. void addStructure(MultiblockStructure* structure);
  70. MultiblockStructure* zStructureByPosition(
  71. Framework::Vec3<int> uniquePosition);
  72. MultiblockStructure* zStructureById(__int64 id);
  73. void requestStopAndWait();
  74. };