| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- //
- // universe.h
- // engine_base
- //
- // Created by Sam Jaffe on 3/15/23.
- //
- #pragma once
- #include <memory>
- #include <string>
- #include <engine/forwards.h>
- namespace engine {
- class Universe {
- private:
- std::shared_ptr<Mailbox> mailbox_;
- // The universe is not a shared object, so by convention we use unique_ptr
- // to store everything that does not need to be shared.
- std::unique_ptr<env::Config> config_;
- std::unique_ptr<random_number_generator> random_;
- // The cache is, by definition, a shared object and so uses shared_ptr
- std::shared_ptr<serializer::SharedCache> serialcache_;
- std::unique_ptr<serializer::Jsonizer> jsonizer_;
- public:
- Mailbox & mailbox() const { return *mailbox_; }
- env::Config const & config() const { return *config_; }
- serializer::Jsonizer & jsonizer() const { return *jsonizer_; }
- random_number_generator const & random() const { return *random_; }
- /**
- * @brief Construct a universe with all necessary components
- * @param cfg The config object generated from reading a config file or JSON
- * @param cache A serializer cache
- * @param rng A random number generator's underlying implementation. This
- * exists for dependency injection's sake. If rng is null, then random_ will
- * be constructed with the default random device.
- */
- Universe(std::shared_ptr<Mailbox> mailbox, env::Config const & cfg,
- std::shared_ptr<serializer::SharedCache> cache,
- std::shared_ptr<detail::random_impl> rng);
- ~Universe();
- protected:
- template <typename T>
- void load(std::string const & name, std::string const & fallback = "");
- /**
- * @deprecated This exists solely for the purpose of needing to initialize
- * the singleton.
- */
- [[deprecated]] Universe();
- Universe(Universe &&) = default;
- Universe & operator=(Universe &&) = default;
- };
- }
|