Dimension.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #pragma once
  2. #include <Array.h>
  3. #include <Critical.h>
  4. #include <Trie.h>
  5. #include "Chunk.h"
  6. #include "Entity.h"
  7. class World;
  8. class Dimension : public virtual Framework::Model3DCollection
  9. {
  10. private:
  11. int id;
  12. float gravity;
  13. Framework::RCTrie<Chunk>* chunks;
  14. Framework::Array<Chunk*> chunkList;
  15. Framework::RCArray<Entity>* entities;
  16. Framework::Critical cs;
  17. void getAddrOf(Framework::Punkt cPos, char* addr) const;
  18. void getAddrOfWorld(Framework::Punkt 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::Punkt center);
  31. bool hasChunck(int x, int y) const;
  32. Chunk* zChunk(Framework::Punkt wPos) const;
  33. void removeDistantChunks(Framework::Punkt 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. float getGravity() 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. };