Dimension.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #pragma once
  2. #include <Punkt.h>
  3. #include <InMemoryBuffer.h>
  4. #include "Chunk.h"
  5. #include "NetworkMessage.h"
  6. struct RequestQueue
  7. {
  8. Framework::InMemoryBuffer* request;
  9. Framework::Punkt chunkCenter;
  10. int sourceId;
  11. };
  12. class Dimension : public virtual Framework::ReferenceCounter
  13. {
  14. private:
  15. int dimensionId;
  16. float gravity;
  17. Framework::Trie<Chunk>* chunks;
  18. Framework::Array<Chunk*> chunkList;
  19. Framework::RCArray<Entity>* entities;
  20. Framework::Array<RequestQueue> waitingRequests;
  21. Framework::Critical cs;
  22. void getAddrOf(Framework::Punkt cPos, char* addr) const;
  23. void getAddrOfWorld(Framework::Punkt wPos, char* addr) const;
  24. public:
  25. Dimension(int id);
  26. ~Dimension();
  27. void api(Framework::InMemoryBuffer* zRequest, NetworkMessage* zResponse, Entity* zSource);
  28. void tickEntities();
  29. Framework::Either<Block*, int> zBlock(Framework::Vec3<int> location);
  30. Block* zRealBlockInstance(Framework::Vec3<int> location);
  31. void placeBlock(Framework::Vec3<int> location, Framework::Either<Block*, int> block);
  32. void addEntity(Entity* entity);
  33. void setChunk(Chunk* chunk, Framework::Punkt center);
  34. void save(Framework::Text worldDir) const;
  35. int getDimensionId() const;
  36. bool hasChunck(int x, int y) const;
  37. Chunk* zChunk(Framework::Punkt wPos) const;
  38. float getGravity() const;
  39. void removeOldChunks();
  40. Entity* zEntity(int id);
  41. Entity* zNearestEntity(Framework::Vec3<float> pos, std::function<bool(Entity*)> filter);
  42. void removeEntity(int id);
  43. void removeSubscriptions(Entity* zEntity);
  44. };