Dimension.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #pragma once
  2. #include <Array.h>
  3. #include <Critical.h>
  4. #include <Model3DCollection.h>
  5. #include <Trie.h>
  6. #include "Chunk.h"
  7. #include "Entity.h"
  8. class World;
  9. class Dimension : public virtual Framework::Model3DCollection
  10. {
  11. private:
  12. int id;
  13. Framework::RCTrie<Chunk>* chunks;
  14. Framework::Array<Chunk*> chunkList;
  15. Framework::RCArray<Entity>* entities;
  16. Framework::ReadWriteLock lock;
  17. void getAddrOf(Framework::Point cPos, char* addr) const;
  18. void getAddrOfWorld(Framework::Point wPos, char* addr) const;
  19. public:
  20. Dimension();
  21. ~Dimension();
  22. void forAll(std::function<void(Model3D*)> f) override;
  23. void render(std::function<void(Model3D*)> f) override;
  24. bool tick(std::function<void(Model3D*)> f, double time) override;
  25. void setId(int id);
  26. void api(char* message);
  27. Block* zBlock(Framework::Vec3<int> location);
  28. Block* getBlock(Framework::Vec3<int> location);
  29. void addEntity(Entity* entity);
  30. void setChunk(Chunk* chunk, Framework::Point center);
  31. bool hasChunck(int x, int y) const;
  32. Chunk* zChunk(Framework::Point wPos) const;
  33. void removeDistantChunks(Framework::Point wPos);
  34. void setBlock(Block* block);
  35. void removeBlock(Block* zBlock);
  36. Entity* zEntity(int id);
  37. Entity* getEntity(int id);
  38. void removeEntity(int id);
  39. int getId() const;
  40. Lock& getReadLock() const;
  41. inline static Framework::Vec3<int> chunkCoordinates(
  42. Framework::Vec3<int> worldLocation)
  43. {
  44. Framework::Vec3<int> result = worldLocation;
  45. result.x = result.x % CHUNK_SIZE;
  46. result.y = result.y % CHUNK_SIZE;
  47. if (result.x < 0) result.x += CHUNK_SIZE;
  48. if (result.y < 0) result.y += CHUNK_SIZE;
  49. return result;
  50. }
  51. };