55#include < Tails/Debug.hpp>
66#include < Tails/Vector2.hpp>
77#include < Tails/LevelSettings.hpp>
8+ #include < Tails/EngineSettings.hpp>
89
910#include < SFML/Graphics/Sprite.hpp>
1011#include < SFML/Graphics/RenderWindow.hpp>
@@ -18,73 +19,57 @@ namespace tails
1819{
1920 std::string SWindowProperties::toString () const
2021 {
21- return " Window properties:\n Title - " + title + " \n Resolution - " + SVector2u::toString (resolution);
22+ return " Window properties:\n Title - \" " + title + " \ "\n Resolution - " + SVector2u::toString (resolution);
2223 }
2324
2425 std::string SRenderProperties::toString () const
2526 {
2627 return " Render properties:\n Resolution - " + SVector2u::toString (resolution);
2728 }
2829
29- // removed make_unique for engine registry here because it was causing compile errors
30- // to do with unique_ptr's deleted copy-constructor (I think). Couldn't fix it.
31- CEngine::CEngine () : CEngine(" engine.json" , {})
30+ CEngine::CEngine () : CEngine(nullptr )
3231 {
3332 }
3433
35- CEngine::CEngine (const std::string& engineSetupFile,
36- std::vector<std::unique_ptr<CClassRegistry>>&& registries)
37- : m_registries(std::move(registries))
34+ CEngine::CEngine (std::unique_ptr<SEngineSettings> engineSettings)
35+ : m_settings(std::move(engineSettings))
3836 {
39- // TODO - replace the above paramters with some SEngineSettings struct:
40- /*
41- * struct SEngineSettings
42- * {
43- * string setupFile;
44- * registries;
45- * levelSettings;??
46- * }
47- *
48- * And maybe a templated constructor for this? or just take in a unique_ptr?
49- * so clients can derive the struct to add their own stuff. how would they use
50- * that stuff? no idea lol. maybe not. Would be nice to have a custom levelsettings
51- * struct though!
52- */
53- if (!getRegistry<CEngineRegistry>())
54- m_registries.emplace_back (std::make_unique<CEngineRegistry>());
37+ // If input engine settings is null, use default
38+ if (!engineSettings)
39+ m_settings = std::make_unique<SEngineSettings>();
5540
5641 // Setup world
5742 m_world.outer = this ;
5843
59- CDebug::print (" Loading " , engineSetupFile );
44+ CDebug::print (" Loading " , m_settings-> getSetupFilePath () );
6045
61- std::ifstream setupFile {engineSetupFile };
46+ std::ifstream setupFile {m_settings-> getSetupFilePath () };
6247 if (!setupFile.is_open ())
6348 {
64- CDebug::print (" Failed to find " , engineSetupFile);
65- initInternalRender ();
66- m_world.openLevel (" " );
49+ CDebug::print (" Failed to find " , m_settings->getSetupFilePath ());
50+ initMembers ();
6751 return ;
6852 }
6953
7054 nlohmann::json setupJson = nlohmann::json::parse (setupFile);
7155
7256 if (setupJson.is_null ())
7357 {
74- CDebug::print (" Failed to load " , engineSetupFile);
75- initInternalRender ();
76- m_world.openLevel (" " );
58+ CDebug::print (" Failed to load " , m_settings->getSetupFilePath ());
59+ initMembers ();
7760 return ;
7861 }
7962
8063 CDebug::print (std::string (" JSON is a valid " ), setupJson.type_name ());
64+ CDebug::print ();
8165
8266 /* DIRECTORIES */
8367
8468 if (const auto & dirJson = setupJson[" dirs" ]; !dirJson.is_null ())
8569 CDirectories::loadDirectories (dirJson);
8670 else
8771 CDebug::print (" Failed to load directories, using default" );
72+ CDebug::print ();
8873
8974 /* RENDER SETTINGS */
9075
@@ -111,15 +96,15 @@ namespace tails
11196 /* WORLD AND LEVEL */
11297
11398 if (const auto & defaultLevelJson = setupJson[" default_level" ]; !defaultLevelJson.is_null ())
114- m_world. openLevel (defaultLevelJson.get <std::string>());
99+ initWorldLevel (defaultLevelJson.get <std::string>());
115100 else
116101 {
117102 CDebug::print (" Failed to open default level, opening blank level" );
118- m_world. openLevel (" " );
103+ initWorldLevel (" " );
119104 }
120105
121106 if (const auto level = m_world.getLevel (0 ))
122- CDebug::print (" Opened level - " , level->getSettings ().name );
107+ CDebug::print (" Opened level - \" " , level->getSettings ().name , " \" " );
123108 else
124109 CDebug::error (" Created level is invalid!" );
125110 CDebug::print ();
@@ -148,7 +133,7 @@ namespace tails
148133 CDebug::print (m_windowProperties.toString ());
149134 CDebug::print ();
150135
151- CDebug::print (engineSetupFile , " loaded" );
136+ CDebug::print (m_settings-> getSetupFilePath () , " loaded" );
152137 CDebug::print ();
153138 }
154139
@@ -160,6 +145,7 @@ namespace tails
160145
161146 void CEngine::run ()
162147 {
148+ CDebug::print ();
163149 CDebug::print (" Initialising final render target" );
164150 // Set default render target as window if it has not already been set
165151 if (!m_renderTarget)
@@ -170,6 +156,7 @@ namespace tails
170156 ),
171157 m_windowProperties.title
172158 );
159+ CDebug::print ();
173160
174161 sf::Clock clock;
175162 const auto window = dynamic_cast <sf::RenderWindow*>(m_renderTarget.get ());
@@ -258,6 +245,12 @@ namespace tails
258245 m_world.postTick ();
259246 }
260247
248+ void CEngine::initMembers ()
249+ {
250+ initInternalRender ();
251+ initWorldLevel (" " );
252+ }
253+
261254 void CEngine::initInternalRender ()
262255 {
263256 CDebug::print (" Initialising internal render target" );
@@ -272,6 +265,11 @@ namespace tails
272265 m_renderView.setCenter (m_renderView.getSize () * 0 .5f );
273266 }
274267
268+ void CEngine::initWorldLevel (std::string path)
269+ {
270+ m_world.openLevel (std::move (path), &m_settings->getLevelSettings ());
271+ }
272+
275273 void CEngine::calculateInternalAspectRatio (sf::Vector2u windowSize)
276274 {
277275 const sf::Vector2f ratio {
0 commit comments