hibiscus/core/engine/engine.cpp

56 lines
1.5 KiB
C++

#include "enginever.hpp"
#include "engine.hpp"
#include <pragmautil.hpp>
#include <core/graphics/drawable.hpp>
namespace hibis {
Engine::Engine(Renderer* renderer, LoggerCallback logger) {
this->renderer = renderer;
loggerCallback = logger;
previousProcessTick = std::chrono::steady_clock::now();
previousPhysicsProcessTick = std::chrono::steady_clock::now();
//watch.start();
this->loggerCallback(Information, "Started Hibis [using v" + (std::string)getEngineVersion() + "]!");
}
Engine::~Engine() {
//watch.stop();
}
void Engine::runNodeProcesses() {
TODO("check if delta calc is correct")
const std::chrono::time_point<std::chrono::steady_clock> current = std::chrono::steady_clock::now();
auto delta = std::chrono::duration<float>(current - previousProcessTick);
for (Node* node : nodeList) {
node->process(delta.count());
}
previousProcessTick = std::chrono::steady_clock::now();
}
void Engine::runNodePhysicsProcesses() {
const std::chrono::time_point<std::chrono::steady_clock> current = std::chrono::steady_clock::now();
auto delta = std::chrono::duration<float>(current - previousProcessTick);
for (Node* node : nodeList) {
node->physicsProcess(delta.count());
}
previousProcessTick = std::chrono::steady_clock::now();
}
void Engine::drawNodes() {
TODO("check if this works")
for (Node* node : nodeList) {
if (Drawable* drawNode = (Drawable*)&node) {
drawNode->draw(renderer);
}
}
}
const char* Engine::getEngineVersion() { return HIBIS_VERSION; }
}