A 2D tile-based sandbox game.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

WorldPlane.h 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #pragma once
  2. #include <vector>
  3. #include <utility>
  4. #include <memory>
  5. #include <map>
  6. #include <set>
  7. #include "common.h"
  8. #include "traits/BodyTrait.h"
  9. #include "util.h"
  10. #include "Chunk.h"
  11. #include "Tile.h"
  12. #include "WorldGen.h"
  13. #include "Entity.h"
  14. namespace Swan {
  15. class World;
  16. class Game;
  17. class WorldPlane {
  18. public:
  19. using ID = uint16_t;
  20. WorldPlane(ID id, World *world, std::shared_ptr<WorldGen> gen):
  21. id_(id), world_(world), gen_(std::move(gen)) {}
  22. Entity *spawnEntity(const std::string &name, const SRF &params);
  23. void despawnEntity(Entity &ent);
  24. Context getContext();
  25. bool hasChunk(ChunkPos pos);
  26. Chunk &getChunk(ChunkPos pos);
  27. void setTileID(TilePos pos, Tile::ID id);
  28. void setTile(TilePos pos, const std::string &name);
  29. Tile::ID getTileID(TilePos pos);
  30. Tile &getTile(TilePos pos);
  31. Iter<Entity *> getEntsInArea(Vec2 center, float radius);
  32. BodyTrait::HasBody *spawnPlayer();
  33. void breakBlock(TilePos pos);
  34. void draw(Win &win);
  35. void update(float dt);
  36. void tick(float dt);
  37. void debugBox(TilePos pos);
  38. ID id_;
  39. World *world_;
  40. std::shared_ptr<WorldGen> gen_;
  41. private:
  42. std::map<std::pair<int, int>, Chunk> chunks_;
  43. std::set<Chunk *> active_chunks_;
  44. std::vector<std::unique_ptr<Entity>> entities_;
  45. std::vector<std::unique_ptr<Entity>> spawn_list_;
  46. std::vector<Entity *> despawn_list_;
  47. std::vector<TilePos> debug_boxes_;
  48. };
  49. }