universe.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. //
  2. // universe.h
  3. // engine_base
  4. //
  5. // Created by Sam Jaffe on 3/15/23.
  6. //
  7. #pragma once
  8. #include <memory>
  9. #include <string>
  10. #include <engine/forwards.h>
  11. #include <random/random.h>
  12. #include <serializer/jsonizer.h>
  13. namespace engine {
  14. class Universe {
  15. private:
  16. std::shared_ptr<Mailbox> mailbox_;
  17. std::shared_ptr<env::Config const> config_;
  18. random::Random random_;
  19. serializer::Jsonizer jsonizer_;
  20. public:
  21. Mailbox & mailbox() const { return *mailbox_; }
  22. env::Config const & config() const { return *config_; }
  23. serializer::Jsonizer const & jsonizer() const { return jsonizer_; }
  24. random::Random const & random() const { return random_; }
  25. /**
  26. * @brief Construct a universe with all necessary components
  27. * @param cfg The config object generated from reading a config file or JSON
  28. * @param cache A serializer cache. If null, then we construct a default cache
  29. * @param rng A random number generator's underlying implementation. This
  30. * exists for dependency injection's sake. If rng is null, then random_ will
  31. * be constructed with the default random device.
  32. */
  33. Universe(std::shared_ptr<Mailbox> mailbox, env::Config const & cfg,
  34. std::shared_ptr<serializer::SharedCache> cache,
  35. std::shared_ptr<random::Device> rng);
  36. void set_random(random::Random const &random) { random_ = random; }
  37. protected:
  38. template <typename T>
  39. void load(std::string const & name, std::string const & fallback = "");
  40. };
  41. }