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.

World.h 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #pragma once
  2. #include <memory>
  3. #include <vector>
  4. #include <string>
  5. #include "common.h"
  6. #include "Asset.h"
  7. #include "Item.h"
  8. #include "Tile.h"
  9. #include "WorldPlane.h"
  10. #include "WorldGen.h"
  11. #include "Entity.h"
  12. namespace Swan {
  13. class Game;
  14. class World {
  15. public:
  16. World(Game *game): game_(game) {}
  17. WorldPlane &addPlane(std::string gen);
  18. WorldPlane &addPlane() { return addPlane(default_world_gen_); }
  19. void setCurrentPlane(WorldPlane &plane);
  20. void setWorldGen(const std::string &gen);
  21. void spawnPlayer();
  22. void registerTile(std::shared_ptr<Tile> t);
  23. void registerItem(std::shared_ptr<Item> i);
  24. void registerWorldGen(std::shared_ptr<WorldGen::Factory> gen);
  25. void registerEntity(std::shared_ptr<Entity::Factory> ent);
  26. void registerAsset(std::shared_ptr<Asset> asset);
  27. Tile &getTileByID(Tile::ID id);
  28. Tile::ID getTileID(const std::string &name);
  29. Tile &getTile(const std::string &name);
  30. Item &getItem(const std::string &name);
  31. Asset &getAsset(const std::string &name);
  32. void draw(Win &win);
  33. void update(float dt);
  34. void tick();
  35. std::vector<std::shared_ptr<Tile>> tiles_;
  36. std::map<std::string, Tile::ID> tiles_map_;
  37. std::map<std::string, std::shared_ptr<Item>> items_;
  38. std::map<std::string, std::shared_ptr<WorldGen::Factory>> worldgens_;
  39. std::map<std::string, std::shared_ptr<Entity::Factory>> ents_;
  40. std::map<std::string, std::shared_ptr<Asset>> assets_;
  41. Entity *player_;
  42. Game *game_;
  43. private:
  44. class ChunkRenderer {
  45. public:
  46. void tick(WorldPlane &plane, ChunkPos abspos);
  47. };
  48. ChunkRenderer chunk_renderer_;
  49. WorldPlane::ID current_plane_;
  50. std::vector<WorldPlane> planes_;
  51. std::string default_world_gen_;
  52. };
  53. }