Ver código fonte

Add engine runtime data

Patrick-Christopher Mattulat 6 dias atrás
pai
commit
83ab65833c

+ 5 - 5
README.md

@@ -36,11 +36,11 @@ conan create . -o "ls-std/*:shared=True" -s build_type=Release
 
 In Process: It contains the following modules:
 
-| Name                  | Description                                                                                                                                 |
-|-----------------------|---------------------------------------------------------------------------------------------------------------------------------------------|
-| ls-atlantis-cycle     | This module provides functionalities like engine setup, game loop logic and engine run time information.                                    |
-| ls-atlantis-interface | This module provides all interfaces all other engine modules can implement. This would avoid circular dependencies through out the project. |
-| ls-atlantis-window    | This module provides functionalities for window creation and handling.                                                                      |
+| Name                  | Description                                                                                                                                                                                                                                         |
+|-----------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
+| ls-atlantis-cycle     | This module provides functionalities like engine setup, game loop logic and engine run time information.                                                                                                                                            |
+| ls-atlantis-interface | __Consumer:__ This module provides all interfaces all other engine modules can implement. This would avoid circular dependencies through out the project. This module can be imported. This module must not import any library dependencies itself. |
+| ls-atlantis-window    | This module provides functionalities for window creation and handling.                                                                                                                                                                              |
 
 ## Dependencies
 

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

@@ -9,6 +9,8 @@
 ################################
 
 set(ATLANTIS_CYCLE_TEST_SOURCES
+        ${CMAKE_CURRENT_SOURCE_DIR}/test/cycle/mock/WindowApiMock.cpp
+        ${CMAKE_CURRENT_SOURCE_DIR}/test/cycle/EngineRuntimeDataTest.cpp
         ${CMAKE_CURRENT_SOURCE_DIR}/test/cycle/StatusCodeOkTest.cpp
         ${CMAKE_CURRENT_SOURCE_DIR}/test/cycle/StatusCodeWindowApiLoadingFailedTest.cpp
         ${CMAKE_CURRENT_SOURCE_DIR}/test/cycle/StatusCodeWindowCreationFailedTest.cpp

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

@@ -9,6 +9,7 @@
 ################################
 
 set(ATLANTIS_CYCLE_SOURCES
+        ${CMAKE_CURRENT_SOURCE_DIR}/source/cycle/EngineRuntimeData.cpp
         ${CMAKE_CURRENT_SOURCE_DIR}/source/cycle/StatusCodeOk.cpp
         ${CMAKE_CURRENT_SOURCE_DIR}/source/cycle/StatusCodeWindowApiLoadingFailed.cpp
         ${CMAKE_CURRENT_SOURCE_DIR}/source/cycle/StatusCodeWindowCreationFailed.cpp

+ 31 - 0
include/cycle/EngineRuntimeData.hpp

@@ -0,0 +1,31 @@
+/*
+ * author: Patrick-Christopher Mattulat
+ * e-mail: webmaster@lynarstudios.com
+ */
+
+#ifndef LS_ATLANTIS_ENGINE_CYCLE_ENGINE_RUNTIME_DATA_HPP
+#define LS_ATLANTIS_ENGINE_CYCLE_ENGINE_RUNTIME_DATA_HPP
+
+#include <Export.hpp>
+#include <interface/IWindowApi.hpp>
+#include <memory>
+
+namespace ls::atlantis::cycle
+{
+  class LS_ATLANTIS_DYNAMIC_GOAL EngineRuntimeData
+  {
+    public:
+
+      EngineRuntimeData();
+      ~EngineRuntimeData();
+
+      [[nodiscard]] ::std::shared_ptr<ls::atlantis::interfaces::IWindowApi> getWindowApi() const;
+      void setWindowApi(const ::std::shared_ptr<ls::atlantis::interfaces::IWindowApi> &_windowApi);
+
+    private:
+
+      ::std::shared_ptr<ls::atlantis::interfaces::IWindowApi> windowApi{};
+  };
+}
+
+#endif

+ 27 - 0
source/cycle/EngineRuntimeData.cpp

@@ -0,0 +1,27 @@
+/*
+ * author: Patrick-Christopher Mattulat
+ * e-mail: webmaster@lynarstudios.com
+ */
+
+#include <cycle/EngineRuntimeData.hpp>
+#include <ls-std/core/evaluator/NullPointerArgumentEvaluator.hpp>
+
+using ls::atlantis::cycle::EngineRuntimeData;
+using ls::atlantis::interfaces::IWindowApi;
+using ls::std::core::NullPointerArgumentEvaluator;
+using ::std::shared_ptr;
+
+EngineRuntimeData::EngineRuntimeData() = default;
+
+EngineRuntimeData::~EngineRuntimeData() = default;
+
+shared_ptr<IWindowApi> EngineRuntimeData::getWindowApi() const
+{
+  return this->windowApi;
+}
+
+void EngineRuntimeData::setWindowApi(const shared_ptr<IWindowApi> &_windowApi)
+{
+  NullPointerArgumentEvaluator(_windowApi).evaluate();
+  this->windowApi = _windowApi;
+}

+ 43 - 0
test/cycle/EngineRuntimeDataTest.cpp

@@ -0,0 +1,43 @@
+/*
+ * author: Patrick-Christopher Mattulat
+ * e-mail: webmaster@lynarstudios.com
+ */
+
+#include <cycle/EngineRuntimeData.hpp>
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+#include <ls-std/core/exception/IllegalArgumentException.hpp>
+#include <test/cycle/mock/WindowApiMock.hpp>
+
+using ls::atlantis::cycle::EngineRuntimeData;
+using ls::atlantis::cycle::test::WindowApiMock;
+using ls::std::core::IllegalArgumentException;
+using ::std::make_shared;
+using ::std::shared_ptr;
+using ::testing::Test;
+
+namespace
+{
+  class EngineRuntimeDataTest : public Test
+  {
+    public:
+
+      EngineRuntimeDataTest() = default;
+      ~EngineRuntimeDataTest() override = default;
+
+      shared_ptr<WindowApiMock> windowApiMock = make_shared<WindowApiMock>();
+  };
+
+  TEST_F(EngineRuntimeDataTest, setWindowApi_nullPointer)
+  {
+    ASSERT_THROW(EngineRuntimeData().setWindowApi(nullptr), IllegalArgumentException);
+  }
+
+  TEST_F(EngineRuntimeDataTest, getWindowApi)
+  {
+    EngineRuntimeData engineRuntimeData{};
+    engineRuntimeData.setWindowApi(windowApiMock);
+
+    ASSERT_EQ(windowApiMock, engineRuntimeData.getWindowApi());
+  }
+}

+ 22 - 0
test/cycle/mock/WindowApiMock.cpp

@@ -0,0 +1,22 @@
+/*
+ * author: Patrick-Christopher Mattulat
+ * e-mail: webmaster@lynarstudios.com
+ */
+
+#include <cycle/StatusCodeOk.hpp>
+#include <test/cycle/mock/WindowApiMock.hpp>
+
+using ls::atlantis::cycle::StatusCodeOk;
+using ls::atlantis::cycle::test::WindowApiMock;
+using ls::atlantis::interfaces::AStatusCode;
+using ::std::make_shared;
+using ::std::shared_ptr;
+
+WindowApiMock::WindowApiMock() = default;
+
+WindowApiMock::~WindowApiMock() = default;
+
+shared_ptr<AStatusCode> WindowApiMock::init()
+{
+  return make_shared<StatusCodeOk>();
+}

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

@@ -0,0 +1,24 @@
+/*
+ * author: Patrick-Christopher Mattulat
+ * e-mail: webmaster@lynarstudios.com
+ */
+
+#ifndef LS_ATLANTIS_ENGINE_CYCLE_TEST_WINDOW_API_MOCK_HPP
+#define LS_ATLANTIS_ENGINE_CYCLE_TEST_WINDOW_API_MOCK_HPP
+
+#include <interface/IWindowApi.hpp>
+
+namespace ls::atlantis::cycle::test
+{
+  class WindowApiMock : public ls::atlantis::interfaces::IWindowApi
+  {
+    public:
+
+      WindowApiMock();
+      ~WindowApiMock() override;
+
+      [[nodiscard]] ::std::shared_ptr<ls::atlantis::interfaces::AStatusCode> init() override;
+  };
+}
+
+#endif