Browse Source

- added SetUp configuration

lynarstudios 3 years ago
parent
commit
33543c53a6

+ 1 - 1
CMakeLists.txt

@@ -415,6 +415,6 @@ add_executable(LynarMoonEngineProject
     LynarMoonTest/tests/engine/Module/ModelModule/ModelModule_getTexturePosition.cpp
     LynarMoonTest/tests/engine/Module/ModelModule/ModelModule_setTexturePosition.cpp
     LynarMoonTest/tests/engine/ModuleLayer/Model/Model_getTexturePosition.cpp
-    LynarMoonTest/tests/engine/ModuleLayer/Model/Model_setTexturePosition.cpp)
+    LynarMoonTest/tests/engine/ModuleLayer/Model/Model_setTexturePosition.cpp LynarMoon/engine/SetUp/SetUp.cpp LynarMoon/engine/SetUp/SetUp.h)
 
 target_link_libraries(LynarMoonEngineProject atomic lynarmath dirhandler tfhandler clock gtest gtest_main SDL2 SDL2main SDL2_mixer SDL2_ttf SDL2_image)

+ 5 - 2
LynarMoon/engine/LynarMoon.cpp

@@ -12,6 +12,7 @@
 #include "../tools/File/FileCreator.h"
 #include "../tools/File/LogFileHandler.h"
 #include "Module/Module.h"
+#include "SetUp/SetUp.h"
 
 #include <iostream>
 #include <SDL.h>
@@ -39,7 +40,9 @@ numberOfSoundChannels(0),
 operatingSystem(OS_NOT_SELECTED),
 timestamp(0),
 timestep(0.0f)
-{}
+{
+  this->setup = SetUp("../SetUp.txt");
+}
 
 LynarMoon::~LynarMoon()
 {
@@ -504,7 +507,7 @@ int LynarMoon::init(const std::string applicationName, uint8_t os)
   // log file / Error Handler
 
   this->createPreferencePath();
-  engineLogFileHandler = std::make_shared<LogFileHandler>();
+  engineLogFileHandler = std::make_shared<LogFileHandler>(this->setup.getConfiguration("ENGINE_PATH"));
   this->logFileName = engineLogFileHandler->createLogFile(this->prefPath);
   logFilePathStream << this->prefPath << "logging/" << this->logFileName;
   logFilePath = logFilePathStream.str();

+ 2 - 0
LynarMoon/engine/LynarMoon.h

@@ -29,6 +29,7 @@
 #include "Module/PointModule.h"
 #include "Module/TextModule.h"
 #include "Module/ModelModule.h"
+#include "SetUp/SetUp.h"
 
 class LynarMoon : Mouse, Keyboard
 {
@@ -331,6 +332,7 @@ class LynarMoon : Mouse, Keyboard
     std::shared_ptr<SmartList<PointModule>> pointModuleList;
     std::string prefPath;
     std::shared_ptr<SDL_Renderer> renderer;
+    SetUp setup;
     std::shared_ptr<SmartList<TextModule>> textModuleList;
     std::atomic<uint32_t> timestamp;
     std::atomic<double> timestep;

+ 46 - 0
LynarMoon/engine/SetUp/SetUp.cpp

@@ -0,0 +1,46 @@
+/*
+ * author:            Patrick-Christopher Mattulat
+ * dev-tools:         JetBrains CLion
+ * created:           01.09.2018
+ * last updated:      01.09.2018
+ */
+
+#include <TextFileHandler.h>
+#include "SetUp.h"
+
+//////////////////////////////////////////////////
+//////////////////////////////////////////////////
+//// constructor / destructor
+//////////////////////////////////////////////////
+//////////////////////////////////////////////////
+
+SetUp::SetUp() = default;
+
+SetUp::SetUp(const std::string& file)
+{
+  TextFileHandler textFileHandler;
+  std::vector<std::string> lineList;
+
+  if(textFileHandler.open(file)) {
+    lineList = textFileHandler.read();
+
+    if(!lineList.empty()) {
+      for(std::string& line : lineList) {
+        this->setupConfigurations.insert(this->setupConfigurations.begin(), std::pair<std::string, std::string>(line.substr(0, line.find('=')), line.substr(line.find('=') + 1)));
+      }
+    }
+  }
+}
+
+SetUp::~SetUp() = default;
+
+//////////////////////////////////////////////////
+//////////////////////////////////////////////////
+//// public
+//////////////////////////////////////////////////
+//////////////////////////////////////////////////
+
+const std::string SetUp::getConfiguration(const std::string& configurationName)
+{
+  return this->setupConfigurations.at(configurationName);
+}

+ 29 - 0
LynarMoon/engine/SetUp/SetUp.h

@@ -0,0 +1,29 @@
+/*
+ * author:            Patrick-Christopher Mattulat
+ * dev-tools:         JetBrains CLion
+ * created:           01.09.2018
+ * last updated:      01.09.2018
+ */
+
+#ifndef SETUP_H
+#define SETUP_H
+
+#include <string>
+#include <map>
+
+class SetUp
+{
+  private:
+
+    std::map<std::string, std::string> setupConfigurations;
+
+  public:
+
+    SetUp();
+    explicit SetUp(const std::string&);
+    ~SetUp();
+
+    const std::string getConfiguration(const std::string&);
+};
+
+#endif

+ 10 - 3
LynarMoon/tools/File/LogFileHandler.cpp

@@ -2,7 +2,7 @@
  * author:            Patrick-Christopher Mattulat
  * dev-tools:         JetBrains CLion
  * created:           12.08.2018
- * last updated:      23.08.2018
+ * last updated:      01.09.2018
  */
 
 #include <sstream>
@@ -23,7 +23,10 @@
 //////////////////////////////////////////////////
 //////////////////////////////////////////////////
 
-LogFileHandler::LogFileHandler() = default;
+LogFileHandler::LogFileHandler(const std::string& engineDirectory)
+{
+  this->engineDirectory = engineDirectory;
+}
 
 LogFileHandler::~LogFileHandler() = default;
 
@@ -39,9 +42,13 @@ void LogFileHandler::createHtmlFile(const std::string& filePath, ClockImage cloc
   TextFileHandler templateFileHandler;
   std::vector<std::string> templateFileLines;
   std::stringstream headline;
+  std::stringstream templatePath;
+  std::string templatePathStr;
 
   fileHandler.open(filePath);
-  templateFileHandler.open("../LynarMoon/resources/templates/log_template.htm");
+  templatePath << this->engineDirectory << "resources/templates/log_template.htm";
+  templatePathStr = templatePath.str();
+  templateFileHandler.open(templatePathStr);
 
   templateFileLines = templateFileHandler.read();
 

+ 3 - 2
LynarMoon/tools/File/LogFileHandler.h

@@ -2,7 +2,7 @@
  * author:            Patrick-Christopher Mattulat
  * dev-tools:         JetBrains CLion
  * created:           12.08.2018
- * last updated:      23.08.2018
+ * last updated:      01.09.2018
  */
 
 #ifndef ENGINELOGFILEHANDLER_H
@@ -16,13 +16,14 @@ class LogFileHandler
 {
   private:
 
+    std::string engineDirectory;
     std::mutex mtx;
 
     void createHtmlFile(const std::string&, ClockImage);
 
   public:
 
-    LogFileHandler();
+    explicit LogFileHandler(const std::string&);
     ~LogFileHandler();
 
     void cleanUpOldFiles(const std::string&);

+ 1 - 0
SetUp.txt

@@ -0,0 +1 @@
+ENGINE_PATH=../LynarMoon/