aboutsummaryrefslogtreecommitdiff
path: root/mwe/events/src/loopManager.cpp
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-11-05 16:12:47 +0100
committerLoek Le Blansch <loek@pipeframe.xyz>2024-11-05 16:12:47 +0100
commite36ea050972fcaaf3d85d672755bad4ebb2dcd80 (patch)
tree5145e0b66650eea1df301106b7d197a586be65f3 /mwe/events/src/loopManager.cpp
parent333b07775be1ef20fdb5909672c1e4dcabec1b40 (diff)
parentb770475741b7c33d57331f3139c55a3f237ad274 (diff)
merge `master` into `loek/savemgr`
Diffstat (limited to 'mwe/events/src/loopManager.cpp')
-rw-r--r--mwe/events/src/loopManager.cpp67
1 files changed, 42 insertions, 25 deletions
diff --git a/mwe/events/src/loopManager.cpp b/mwe/events/src/loopManager.cpp
index 8ecb932..0b7d888 100644
--- a/mwe/events/src/loopManager.cpp
+++ b/mwe/events/src/loopManager.cpp
@@ -1,22 +1,27 @@
#include "loopManager.h"
-LoopManager::LoopManager() {}
+LoopManager::LoopManager() : inputSystem(std::make_unique<InputSystem>()) {
+ shutdownHandler
+ = [this](const ShutDownEvent & event) { this->onShutdown(event); };
+ subscribe(shutdownHandler);
+}
void LoopManager::processInput() {
- SDL_Event event;
- SDL_PollEvent(&event);
- switch (event.type) {
- case SDL_QUIT:
- gameRunning = false;
- break;
- case SDL_KEYDOWN:
- triggerEvent(KeyPressedEvent(getCustomKey(event.key.keysym.sym)));
- break;
- case SDL_MOUSEBUTTONDOWN:
- int x, y;
- SDL_GetMouseState(&x, &y);
- triggerEvent(MousePressedEvent(x, y));
- break;
- }
+ inputSystem->processInput();
+ // SDL_Event event;
+ // SDL_PollEvent(&event);
+ // switch (event.type) {
+ // case SDL_QUIT:
+ // gameRunning = false;
+ // break;
+ // case SDL_KEYDOWN:
+ // triggerEvent(KeyPressedEvent(getCustomKey(event.key.keysym.sym)));
+ // break;
+ // case SDL_MOUSEBUTTONDOWN:
+ // int x, y;
+ // SDL_GetMouseState(&x, &y);
+ // triggerEvent(MousePressedEvent(x, y));
+ // break;
+ // }
}
void LoopManager::setRunning(bool running) { this->gameRunning = running; }
void LoopManager::fixedUpdate() {
@@ -28,9 +33,8 @@ void LoopManager::loop() {
while (gameRunning) {
timer.update();
-
+ processInput();
while (timer.getLag() >= timer.getFixedDeltaTime()) {
- processInput();
fixedUpdate();
timer.advanceFixedUpdate();
}
@@ -66,22 +70,35 @@ void LoopManager::setup() {
}
};
subscribe<KeyPressedEvent>(closeWindowCallback, false);
+ Button * testButton = new Button(200, 200);
+ testButton->color = {100, 0, 100};
+ testButton->onClick
+ = []() { std::cout << "Button was clicked" << std::endl; };
+ testButton->x = 200;
+ testButton->y = 200;
+ inputSystem->registerButton(testButton);
+
+ window.addUIObject(testButton);
+
+ TextInput * testInput = new TextInput(200, 200);
+ testInput->x = 100;
+ testInput->y = 100;
+ testInput->backgroundColor = {20, 50, 80};
+ inputSystem->registerTextInput(testInput);
+ window.addUIObject(testInput);
}
void LoopManager::render() {
//fprintf(stderr, "**********render********** \n");
if (gameRunning) {
- //window.render(objectList);
+ window.renderUIObjects();
}
}
-
+void LoopManager::onShutdown(const ShutDownEvent & e) {
+ this->gameRunning = false;
+}
void LoopManager::update() {
//fprintf(stderr, "**********normal update********** \n");
LoopTimer & timer = LoopTimer::getInstance();
float delta = timer.getDeltaTime();
-
- // for (int i = 0; i < objectList.size(); i++) {
- // objectList[i]->setX(objectList[i]->getX() + 50 * delta);
- // objectList[i]->setY(objectList[i]->getY() + 50 * delta);
- // }
}