Engine.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * author: Patrick-Christopher Mattulat
  3. * e-mail: webmaster@lynarstudios.com
  4. */
  5. #include <cycle/Engine.hpp>
  6. #include <factory/KeyboardFactory.hpp>
  7. #include <factory/WindowApiFactory.hpp>
  8. #include <messaging/StatusCodeOk.hpp>
  9. using ls::atlantis::cycle::Engine;
  10. using ls::atlantis::cycle::EngineParameter;
  11. using ls::atlantis::cycle::EngineRuntimeData;
  12. using ls::atlantis::factory::KeyboardFactory;
  13. using ls::atlantis::factory::WindowApiFactory;
  14. using ls::atlantis::interfaces::AStatusCode;
  15. using ls::atlantis::messaging::StatusCodeOk;
  16. using ::std::make_shared;
  17. using ::std::shared_ptr;
  18. Engine::Engine(const EngineParameter &_parameter)
  19. : data(make_shared<EngineRuntimeData>()),
  20. parameter(_parameter)
  21. {
  22. this->data->setIsUp(true);
  23. }
  24. Engine::~Engine() = default;
  25. void Engine::beginFrame()
  26. {
  27. }
  28. void Engine::endFrame() const
  29. {
  30. this->data->getKeyboard()->reset();
  31. }
  32. shared_ptr<EngineRuntimeData> Engine::getData() const
  33. {
  34. return this->data;
  35. }
  36. shared_ptr<AStatusCode> Engine::init() const
  37. {
  38. shared_ptr<AStatusCode> result = _initWindowApi();
  39. if (result->getCode() == StatusCodeOk().getCode())
  40. {
  41. result = this->_initKeyboard();
  42. }
  43. return result;
  44. }
  45. bool Engine::isRunning() const
  46. {
  47. return this->data->getIsUp();
  48. }
  49. void Engine::quit() const
  50. {
  51. this->data->setIsUp(false);
  52. }
  53. shared_ptr<AStatusCode> Engine::_initKeyboard() const
  54. {
  55. const auto keyboard = KeyboardFactory::build(this->parameter.getWindowApiType());
  56. this->data->setKeyboard(keyboard);
  57. return make_shared<StatusCodeOk>();
  58. }
  59. shared_ptr<AStatusCode> Engine::_initWindowApi() const
  60. {
  61. const auto windowApi = WindowApiFactory::build(this->parameter.getWindowApiType());
  62. this->data->setWindowApi(windowApi);
  63. return windowApi->init();
  64. }