Эх сурвалжийг харах

Add basic window event implementation

Patrick-Christopher Mattulat 5 өдөр өмнө
parent
commit
eaa6b5a4fa

+ 1 - 0
cmake/ls-atlantis-cycle-tests.cmake

@@ -10,6 +10,7 @@
 
 set(ATLANTIS_CYCLE_TEST_SOURCES
         ${CMAKE_CURRENT_SOURCE_DIR}/test/cycle/mock/KeyboardMock.cpp
+        ${CMAKE_CURRENT_SOURCE_DIR}/test/cycle/mock/WindowApiEventManagerMock.cpp
         ${CMAKE_CURRENT_SOURCE_DIR}/test/cycle/mock/WindowApiMock.cpp
         ${CMAKE_CURRENT_SOURCE_DIR}/test/cycle/EngineParameterTest.cpp
         ${CMAKE_CURRENT_SOURCE_DIR}/test/cycle/EngineRuntimeDataTest.cpp

+ 1 - 0
cmake/ls-atlantis-factory-tests.cmake

@@ -10,6 +10,7 @@
 
 set(ATLANTIS_FACTORY_TEST_SOURCES
         ${CMAKE_CURRENT_SOURCE_DIR}/test/factory/KeyboardFactoryTest.cpp
+        ${CMAKE_CURRENT_SOURCE_DIR}/test/factory/WindowApiEventManagerFactoryTest.cpp
         ${CMAKE_CURRENT_SOURCE_DIR}/test/factory/WindowApiFactoryTest.cpp
 )
 

+ 1 - 0
cmake/ls-atlantis-factory.cmake

@@ -10,6 +10,7 @@
 
 set(ATLANTIS_FACTORY_SOURCES
         ${CMAKE_CURRENT_SOURCE_DIR}/source/factory/KeyboardFactory.cpp
+        ${CMAKE_CURRENT_SOURCE_DIR}/source/factory/WindowApiEventManagerFactory.cpp
         ${CMAKE_CURRENT_SOURCE_DIR}/source/factory/WindowApiFactory.cpp
 )
 

+ 2 - 1
include/cycle/Engine.hpp

@@ -21,7 +21,7 @@ namespace ls::atlantis::cycle
       explicit Engine(const ls::atlantis::cycle::EngineParameter &_parameter);
       ~Engine();
 
-      void beginFrame();
+      void beginFrame() const;
       void endFrame() const;
       [[nodiscard]] ::std::shared_ptr<ls::atlantis::cycle::EngineRuntimeData> getData() const;
       [[nodiscard]] ::std::shared_ptr<ls::atlantis::interfaces::AStatusCode> init() const;
@@ -33,6 +33,7 @@ namespace ls::atlantis::cycle
       ::std::shared_ptr<ls::atlantis::cycle::EngineRuntimeData> data{};
       ls::atlantis::cycle::EngineParameter parameter{};
 
+      [[nodiscard]] ::std::shared_ptr<ls::atlantis::interfaces::AStatusCode> _initEventManager() const;
       [[nodiscard]] ::std::shared_ptr<ls::atlantis::interfaces::AStatusCode> _initKeyboard() const;
       [[nodiscard]] ::std::shared_ptr<ls::atlantis::interfaces::AStatusCode> _initWindowApi() const;
   };

+ 4 - 0
include/cycle/EngineRuntimeData.hpp

@@ -9,6 +9,7 @@
 #include <Export.hpp>
 #include <interface/IKeyboard.hpp>
 #include <interface/IWindowApi.hpp>
+#include <interface/IWindowApiEventManager.hpp>
 #include <memory>
 
 namespace ls::atlantis::cycle
@@ -23,15 +24,18 @@ namespace ls::atlantis::cycle
       [[nodiscard]] ::std::shared_ptr<ls::atlantis::interfaces::IKeyboard> getKeyboard() const;
       [[nodiscard]] bool getIsUp() const;
       [[nodiscard]] ::std::shared_ptr<ls::atlantis::interfaces::IWindowApi> getWindowApi() const;
+      [[nodiscard]] ::std::shared_ptr<ls::atlantis::interfaces::IWindowApiEventManager> getWindowApiEventManager() const;
       void setIsUp(bool _isUp);
       void setKeyboard(const ::std::shared_ptr<ls::atlantis::interfaces::IKeyboard> &_keyboard);
       void setWindowApi(const ::std::shared_ptr<ls::atlantis::interfaces::IWindowApi> &_windowApi);
+      void setWindowApiEventManager(const ::std::shared_ptr<ls::atlantis::interfaces::IWindowApiEventManager> &_windowApiEventManager);
 
     private:
 
       bool isUp{};
       ::std::shared_ptr<ls::atlantis::interfaces::IKeyboard> keyboard{};
       ::std::shared_ptr<ls::atlantis::interfaces::IWindowApi> windowApi{};
+      ::std::shared_ptr<ls::atlantis::interfaces::IWindowApiEventManager> windowApiEventManager{};
   };
 }
 

+ 1 - 1
include/factory/KeyboardFactory.hpp

@@ -21,7 +21,7 @@ namespace ls::atlantis::factory
       KeyboardFactory();
       ~KeyboardFactory();
 
-      [[nodiscard]] static ::std::shared_ptr<ls::atlantis::interfaces::IKeyboard> build(const ls::atlantis::glossary::WindowApiTypes &_windowApis);
+      [[nodiscard]] static ::std::shared_ptr<ls::atlantis::interfaces::IKeyboard> build(const ls::atlantis::glossary::WindowApiTypes &_windowApi);
 
     private:
 

+ 27 - 0
include/factory/WindowApiEventManagerFactory.hpp

@@ -0,0 +1,27 @@
+/*
+ * author: Patrick-Christopher Mattulat
+ * e-mail: webmaster@lynarstudios.com
+ */
+
+#ifndef LS_ATLANTIS_ENGINE_FACTORY_WINDOW_API_EVENT_MANAGER_FACTORY_HPP
+#define LS_ATLANTIS_ENGINE_FACTORY_WINDOW_API_EVENT_MANAGER_FACTORY_HPP
+
+#include <Export.hpp>
+#include <glossary/WindowApiTypes.hpp>
+#include <interface/IWindowApiEventManager.hpp>
+#include <memory>
+
+namespace ls::atlantis::factory
+{
+  class LS_ATLANTIS_DYNAMIC_GOAL WindowApiEventManagerFactory
+  {
+    public:
+
+      WindowApiEventManagerFactory();
+      ~WindowApiEventManagerFactory();
+
+      [[nodiscard]] static ::std::shared_ptr<ls::atlantis::interfaces::IWindowApiEventManager> build(const ls::atlantis::glossary::WindowApiTypes &_windowApi);
+  };
+}
+
+#endif

+ 1 - 1
include/factory/WindowApiFactory.hpp

@@ -20,7 +20,7 @@ namespace ls::atlantis::factory
       WindowApiFactory();
       ~WindowApiFactory();
 
-      [[nodiscard]] static ::std::shared_ptr<ls::atlantis::interfaces::IWindowApi> build(const ls::atlantis::glossary::WindowApiTypes &_windowApis);
+      [[nodiscard]] static ::std::shared_ptr<ls::atlantis::interfaces::IWindowApi> build(const ls::atlantis::glossary::WindowApiTypes &_windowApi);
   };
 }
 

+ 17 - 2
source/cycle/Engine.cpp

@@ -5,6 +5,7 @@
 
 #include <cycle/Engine.hpp>
 #include <factory/KeyboardFactory.hpp>
+#include <factory/WindowApiEventManagerFactory.hpp>
 #include <factory/WindowApiFactory.hpp>
 #include <messaging/StatusCodeOk.hpp>
 
@@ -12,6 +13,7 @@ using ls::atlantis::cycle::Engine;
 using ls::atlantis::cycle::EngineParameter;
 using ls::atlantis::cycle::EngineRuntimeData;
 using ls::atlantis::factory::KeyboardFactory;
+using ls::atlantis::factory::WindowApiEventManagerFactory;
 using ls::atlantis::factory::WindowApiFactory;
 using ls::atlantis::interfaces::AStatusCode;
 using ls::atlantis::messaging::StatusCodeOk;
@@ -27,9 +29,9 @@ Engine::Engine(const EngineParameter &_parameter)
 
 Engine::~Engine() = default;
 
-void Engine::beginFrame()
+void Engine::beginFrame() const
 {
-
+  this->data->getWindowApiEventManager()->manage();
 }
 
 void Engine::endFrame() const
@@ -51,6 +53,11 @@ shared_ptr<AStatusCode> Engine::init() const
     result = this->_initKeyboard();
   }
 
+  if (result->getCode() == StatusCodeOk().getCode())
+  {
+    result = this->_initEventManager();
+  }
+
   return result;
 }
 
@@ -64,6 +71,14 @@ void Engine::quit() const
   this->data->setIsUp(false);
 }
 
+shared_ptr<AStatusCode> Engine::_initEventManager() const
+{
+  const auto eventManager = WindowApiEventManagerFactory::build(this->parameter.getWindowApiType());
+  this->data->setWindowApiEventManager(eventManager);
+
+  return make_shared<StatusCodeOk>();
+}
+
 shared_ptr<AStatusCode> Engine::_initKeyboard() const
 {
   const auto keyboard = KeyboardFactory::build(this->parameter.getWindowApiType());

+ 12 - 0
source/cycle/EngineRuntimeData.cpp

@@ -9,6 +9,7 @@
 using ls::atlantis::cycle::EngineRuntimeData;
 using ls::atlantis::interfaces::IKeyboard;
 using ls::atlantis::interfaces::IWindowApi;
+using ls::atlantis::interfaces::IWindowApiEventManager;
 using ls::std::core::NullPointerArgumentEvaluator;
 using ::std::shared_ptr;
 
@@ -31,6 +32,11 @@ shared_ptr<IWindowApi> EngineRuntimeData::getWindowApi() const
   return this->windowApi;
 }
 
+shared_ptr<IWindowApiEventManager> EngineRuntimeData::getWindowApiEventManager() const
+{
+  return this->windowApiEventManager;
+}
+
 void EngineRuntimeData::setIsUp(const bool _isUp)
 {
   this->isUp = _isUp;
@@ -47,3 +53,9 @@ void EngineRuntimeData::setWindowApi(const shared_ptr<IWindowApi> &_windowApi)
   NullPointerArgumentEvaluator(_windowApi).evaluate();
   this->windowApi = _windowApi;
 }
+
+void EngineRuntimeData::setWindowApiEventManager(const shared_ptr<IWindowApiEventManager> &_windowApiEventManager)
+{
+  NullPointerArgumentEvaluator(_windowApiEventManager).evaluate();
+  this->windowApiEventManager = _windowApiEventManager;
+}

+ 2 - 2
source/factory/KeyboardFactory.cpp

@@ -22,11 +22,11 @@ KeyboardFactory::KeyboardFactory() = default;
 
 KeyboardFactory::~KeyboardFactory() = default;
 
-shared_ptr<IKeyboard> KeyboardFactory::build(const WindowApiTypes &_windowApis)
+shared_ptr<IKeyboard> KeyboardFactory::build(const WindowApiTypes &_windowApi)
 {
   shared_ptr<IKeyboard> keyboard{};
 
-  switch (_windowApis)
+  switch (_windowApi)
   {
     case WindowApiTypes::NONE_SELECTED:
     {

+ 39 - 0
source/factory/WindowApiEventManagerFactory.cpp

@@ -0,0 +1,39 @@
+/*
+ * author: Patrick-Christopher Mattulat
+ * e-mail: webmaster@lynarstudios.com
+ */
+
+#include <factory/WindowApiEventManagerFactory.hpp>
+#include <ls-std/core/exception/IllegalArgumentException.hpp>
+#include <window/SdlWindowApiEventManager.hpp>
+
+using ls::atlantis::factory::WindowApiEventManagerFactory;
+using ls::atlantis::glossary::WindowApiTypes;
+using ls::atlantis::interfaces::IWindowApiEventManager;
+using ls::atlantis::window::SdlWindowApiEventManager;
+using ls::std::core::IllegalArgumentException;
+using ::std::make_shared;
+using ::std::shared_ptr;
+
+WindowApiEventManagerFactory::WindowApiEventManagerFactory() = default;
+
+WindowApiEventManagerFactory::~WindowApiEventManagerFactory() = default;
+
+shared_ptr<IWindowApiEventManager> WindowApiEventManagerFactory::build(const WindowApiTypes &_windowApi)
+{
+  shared_ptr<IWindowApiEventManager> eventManager{};
+
+  switch (_windowApi)
+  {
+    case WindowApiTypes::NONE_SELECTED:
+    {
+      throw IllegalArgumentException{};
+    }
+    case WindowApiTypes::SDL_WINDOW_API:
+    {
+      eventManager = make_shared<SdlWindowApiEventManager>();
+    } break;
+  }
+
+  return eventManager;
+}

+ 2 - 2
source/factory/WindowApiFactory.cpp

@@ -19,11 +19,11 @@ WindowApiFactory::WindowApiFactory() = default;
 
 WindowApiFactory::~WindowApiFactory() = default;
 
-shared_ptr<IWindowApi> WindowApiFactory::build(const WindowApiTypes &_windowApis)
+shared_ptr<IWindowApi> WindowApiFactory::build(const WindowApiTypes &_windowApi)
 {
   shared_ptr<IWindowApi> windowApi{};
 
-  switch (_windowApis)
+  switch (_windowApi)
   {
     case WindowApiTypes::NONE_SELECTED:
     {

+ 16 - 0
test/cycle/EngineRuntimeDataTest.cpp

@@ -8,10 +8,12 @@
 #include <gtest/gtest.h>
 #include <ls-std/core/exception/IllegalArgumentException.hpp>
 #include <test/cycle/mock/KeyboardMock.hpp>
+#include <test/cycle/mock/WindowApiEventManagerMock.hpp>
 #include <test/cycle/mock/WindowApiMock.hpp>
 
 using ls::atlantis::cycle::EngineRuntimeData;
 using ls::atlantis::cycle::test::KeyboardMock;
+using ls::atlantis::cycle::test::WindowApiEventManagerMock;
 using ls::atlantis::cycle::test::WindowApiMock;
 using ls::std::core::IllegalArgumentException;
 using ::std::make_shared;
@@ -28,6 +30,7 @@ namespace
       ~EngineRuntimeDataTest() override = default;
 
       shared_ptr<KeyboardMock> keyboardMock = make_shared<KeyboardMock>();
+      shared_ptr<WindowApiEventManagerMock> windowApiEventManagerMock = make_shared<WindowApiEventManagerMock>();
       shared_ptr<WindowApiMock> windowApiMock = make_shared<WindowApiMock>();
   };
 
@@ -44,6 +47,19 @@ namespace
     ASSERT_EQ(keyboardMock, engineRuntimeData.getKeyboard());
   }
 
+  TEST_F(EngineRuntimeDataTest, setWindowApiEventManager_nullPointer)
+  {
+    ASSERT_THROW(EngineRuntimeData().setWindowApiEventManager(nullptr), IllegalArgumentException);
+  }
+
+  TEST_F(EngineRuntimeDataTest, getWindowApiEventManager)
+  {
+    EngineRuntimeData engineRuntimeData{};
+    engineRuntimeData.setWindowApiEventManager(windowApiEventManagerMock);
+
+    ASSERT_EQ(windowApiEventManagerMock, engineRuntimeData.getWindowApiEventManager());
+  }
+
   TEST_F(EngineRuntimeDataTest, setWindowApi_nullPointer)
   {
     ASSERT_THROW(EngineRuntimeData().setWindowApi(nullptr), IllegalArgumentException);

+ 15 - 0
test/cycle/mock/WindowApiEventManagerMock.cpp

@@ -0,0 +1,15 @@
+/*
+ * author: Patrick-Christopher Mattulat
+ * e-mail: webmaster@lynarstudios.com
+ */
+
+#include <test/cycle/mock/WindowApiEventManagerMock.hpp>
+
+using ls::atlantis::cycle::test::WindowApiEventManagerMock;
+
+WindowApiEventManagerMock::WindowApiEventManagerMock() = default;
+
+WindowApiEventManagerMock::~WindowApiEventManagerMock() = default;
+
+void WindowApiEventManagerMock::manage()
+{}

+ 24 - 0
test/cycle/mock/WindowApiEventManagerMock.hpp

@@ -0,0 +1,24 @@
+/*
+ * author: Patrick-Christopher Mattulat
+ * e-mail: webmaster@lynarstudios.com
+ */
+
+#ifndef LS_ATLANTIS_ENGINE_CYCLE_TEST_WINDOW_API_EVENT_MANAGER_MOCK_HPP
+#define LS_ATLANTIS_ENGINE_CYCLE_TEST_WINDOW_API_EVENT_MANAGER_MOCK_HPP
+
+#include <interface/IWindowApiEventManager.hpp>
+
+namespace ls::atlantis::cycle::test
+{
+  class WindowApiEventManagerMock : public ls::atlantis::interfaces::IWindowApiEventManager
+  {
+    public:
+
+      WindowApiEventManagerMock();
+      ~WindowApiEventManagerMock() override;
+
+      void manage() override;
+  };
+}
+
+#endif

+ 30 - 0
test/factory/WindowApiEventManagerFactoryTest.cpp

@@ -0,0 +1,30 @@
+/*
+ * author: Patrick-Christopher Mattulat
+ * e-mail: webmaster@lynarstudios.com
+ */
+
+#include <factory/WindowApiEventManagerFactory.hpp>
+#include <glossary/WindowApiTypes.hpp>
+#include <gtest/gtest.h>
+#include <ls-std/core/exception/IllegalArgumentException.hpp>
+
+using ls::atlantis::factory::WindowApiEventManagerFactory;
+using ls::atlantis::glossary::WindowApiTypes;
+using ls::std::core::IllegalArgumentException;
+using ::testing::Test;
+
+namespace
+{
+  class WindowApiEventManagerFactoryTest : public Test
+  {
+    public:
+
+      WindowApiEventManagerFactoryTest() = default;
+      ~WindowApiEventManagerFactoryTest() override = default;
+  };
+
+  TEST_F(WindowApiEventManagerFactoryTest, build_noneSelected)
+  {
+    ASSERT_THROW(static_cast<void>(WindowApiEventManagerFactory::build(WindowApiTypes::NONE_SELECTED)), IllegalArgumentException);
+  }
+}