@@ -20,6 +20,7 @@ Engine::Engine(mode mode,
2020 running{true },
2121 run_mode{mode},
2222 root_dir{root_dir},
23+ window_settings{window_settings},
2324 threads{} {
2425 log::log (INFO
2526 << " launching engine with root directory"
@@ -53,31 +54,40 @@ Engine::Engine(mode mode,
5354 this ->time_loop .reset ();
5455 });
5556
56- // if presenter is used, run it in a separate thread
57- if (this ->run_mode == mode::FULL) {
58- this ->threads .emplace_back ([&]() {
59- this ->presenter ->run (window_settings);
60-
61- // Make sure that the presenter gets destructed in the same thread
62- // otherwise OpenGL complains about missing contexts
63- this ->presenter .reset ();
64- this ->running = false ;
65- });
66- }
67-
6857 log::log (INFO << " Using " << this ->threads .size () + 1 << " threads "
6958 << " (" << std::jthread::hardware_concurrency () << " available)" );
7059}
7160
7261void Engine::loop () {
73- // Run the main game simulation loop:
74- this ->simulation ->run ();
7562
76- // After stopping, clean up the simulation
77- this ->simulation .reset ();
78- if (this ->run_mode != mode::FULL) {
63+ // if presenter is used, run the simulation in a separate thread
64+ if (this ->run_mode == mode::FULL) {
65+
66+ this ->threads .emplace_back ([&]() {
67+ // Run the main game simulation loop:
68+ this ->simulation ->run ();
69+ // After stopping, clean up the simulation
70+ this ->simulation .reset ();
71+ if (this ->run_mode != mode::FULL) {
72+ this ->running = false ;
73+ }
74+ });
75+
76+ this ->presenter ->run (this ->window_settings );
77+ // Make sure that the presenter gets destructed in the same thread
78+ // otherwise OpenGL complains about missing contexts
79+ this ->presenter .reset ();
7980 this ->running = false ;
8081 }
82+ else {
83+ // Run the main game simulation loop:
84+ this ->simulation ->run ();
85+ // After stopping, clean up the simulation
86+ this ->simulation .reset ();
87+ if (this ->run_mode != mode::FULL) {
88+ this ->running = false ;
89+ }
90+ }
8191}
8292
8393} // namespace openage::engine
0 commit comments