Dimension.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 addEntity(Entity* entity);
  51. void setChunk(Chunk* chunk, Framework::Punkt center);
  52. void save(Framework::Text worldDir) const;
  53. int getDimensionId() const;
  54. bool hasChunck(int x, int y);
  55. bool reviveChunk(int x, int y);
  56. Chunk* zChunk(Framework::Punkt wPos) const;
  57. float getGravity() const;
  58. void removeOldChunks();
  59. Entity* zEntity(int id);
  60. Entity* zNearestEntity(
  61. Framework::Vec3<float> pos, std::function<bool(Entity*)> filter);
  62. void removeEntity(int id);
  63. void removeSubscriptions(Entity* zEntity);
  64. void updateLightning(Framework::Vec3<int> location);
  65. void updateLightningWithoutWait(Framework::Vec3<int> location);
  66. void updateLightAtChunkBorders(Framework::Punkt chunkCenter);
  67. __int64 getNextStructureId();
  68. void addStructure(MultiblockStructure* structure);
  69. MultiblockStructure* zStructureByPosition(
  70. Framework::Vec3<int> uniquePosition);
  71. MultiblockStructure* zStructureById(__int64 id);
  72. void requestStopAndWait();
  73. };