Skip to content

Commit 050fa9b

Browse files
author
Andreas
committed
Run presenter in the main thread
1 parent 85136da commit 050fa9b

File tree

2 files changed

+32
-17
lines changed

2 files changed

+32
-17
lines changed

libopenage/engine/engine.cpp

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -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

7261
void 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

libopenage/engine/engine.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,11 @@ class Engine {
110110
*/
111111
util::Path root_dir;
112112

113+
/**
114+
* Window settings
115+
*/
116+
const renderer::window_settings window_settings;
117+
113118
/**
114119
* The threads used by the engine.
115120
*/

0 commit comments

Comments
 (0)