minor refactor
This commit is contained in:
parent
32120d8af4
commit
62ef230af6
@ -155,26 +155,32 @@ void Engine::mainloop() {
|
|||||||
screen->update(delta);
|
screen->update(delta);
|
||||||
|
|
||||||
if (!Window::isIconified()) {
|
if (!Window::isIconified()) {
|
||||||
|
renderFrame(batch);
|
||||||
|
}
|
||||||
|
Window::swapInterval(Window::isIconified() ? 1 : settings.display.swapInterval);
|
||||||
|
|
||||||
|
processPostRunnables();
|
||||||
|
|
||||||
|
Window::swapBuffers();
|
||||||
|
Events::pollEvents();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Engine::renderFrame(Batch2D& batch) {
|
||||||
screen->draw(delta);
|
screen->draw(delta);
|
||||||
|
|
||||||
Viewport viewport(Window::width, Window::height);
|
Viewport viewport(Window::width, Window::height);
|
||||||
GfxContext ctx(nullptr, viewport, &batch);
|
GfxContext ctx(nullptr, viewport, &batch);
|
||||||
gui->draw(&ctx, assets.get());
|
gui->draw(&ctx, assets.get());
|
||||||
|
|
||||||
Window::swapInterval(settings.display.swapInterval);
|
|
||||||
} else {
|
|
||||||
Window::swapInterval(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Engine::processPostRunnables() {
|
||||||
|
std::lock_guard<std::recursive_mutex> lock(postRunnablesMutex);
|
||||||
while (!postRunnables.empty()) {
|
while (!postRunnables.empty()) {
|
||||||
postRunnables.front()();
|
postRunnables.front()();
|
||||||
postRunnables.pop();
|
postRunnables.pop();
|
||||||
}
|
}
|
||||||
scripting::process_post_runnables();
|
scripting::process_post_runnables();
|
||||||
|
|
||||||
Window::swapBuffers();
|
|
||||||
Events::pollEvents();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Engine::~Engine() {
|
Engine::~Engine() {
|
||||||
@ -203,6 +209,7 @@ inline const std::string checkPacks(
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: refactor this
|
||||||
void Engine::loadContent() {
|
void Engine::loadContent() {
|
||||||
auto resdir = paths->getResources();
|
auto resdir = paths->getResources();
|
||||||
ContentBuilder contentBuilder;
|
ContentBuilder contentBuilder;
|
||||||
@ -322,5 +329,6 @@ std::shared_ptr<Screen> Engine::getScreen() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Engine::postRunnable(runnable callback) {
|
void Engine::postRunnable(runnable callback) {
|
||||||
|
std::lock_guard<std::recursive_mutex> lock(postRunnablesMutex);
|
||||||
postRunnables.push(callback);
|
postRunnables.push(callback);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,11 +16,13 @@
|
|||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
class Level;
|
class Level;
|
||||||
class Screen;
|
class Screen;
|
||||||
class EnginePaths;
|
class EnginePaths;
|
||||||
class ResPaths;
|
class ResPaths;
|
||||||
|
class Batch2D;
|
||||||
|
|
||||||
namespace fs = std::filesystem;
|
namespace fs = std::filesystem;
|
||||||
|
|
||||||
@ -43,6 +45,7 @@ class Engine {
|
|||||||
std::unique_ptr<Content> content = nullptr;
|
std::unique_ptr<Content> content = nullptr;
|
||||||
std::unique_ptr<ResPaths> resPaths = nullptr;
|
std::unique_ptr<ResPaths> resPaths = nullptr;
|
||||||
std::queue<runnable> postRunnables;
|
std::queue<runnable> postRunnables;
|
||||||
|
std::recursive_mutex postRunnablesMutex;
|
||||||
|
|
||||||
uint64_t frame = 0;
|
uint64_t frame = 0;
|
||||||
double lastTime = 0.0;
|
double lastTime = 0.0;
|
||||||
@ -52,6 +55,8 @@ class Engine {
|
|||||||
|
|
||||||
void updateTimers();
|
void updateTimers();
|
||||||
void updateHotkeys();
|
void updateHotkeys();
|
||||||
|
void renderFrame(Batch2D& batch);
|
||||||
|
void processPostRunnables();
|
||||||
public:
|
public:
|
||||||
Engine(EngineSettings& settings, EnginePaths* paths);
|
Engine(EngineSettings& settings, EnginePaths* paths);
|
||||||
~Engine();
|
~Engine();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user