hibiscus/core/engine/engine.cpp

57 lines
1.6 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->mRenderer = renderer;
mLoggerCallback = logger;
mPreviousProcessTick = std::chrono::steady_clock::now();
mPreviousPhysicsProcessTick = std::chrono::steady_clock::now();
//watch.start();
this->mLoggerCallback(Information, "Started Hibis [using v" + (std::string)getEngineVersion() + "]!");
}
Engine::~Engine() {
//watch.stop();
}
void Engine::runNodeProcesses() {
TODO("check if delta calc is correct")
TODO("get workaround for MSVC being fucking stupid (std::chrono + std::this_thread)")
const std::chrono::time_point<std::chrono::steady_clock> current = std::chrono::steady_clock::now();
auto delta = std::chrono::duration<float>(current - mPreviousProcessTick);
for (Node* node : mNodeList) {
node->process(delta.count());
}
mPreviousProcessTick = 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 - mPreviousProcessTick);
for (Node* node : mNodeList) {
node->physicsProcess(delta.count());
}
mPreviousProcessTick = std::chrono::steady_clock::now();
}
void Engine::drawNodes() {
TODO("check if this works")
for (Node* node : mNodeList) {
if (Drawable* drawNode = (Drawable*)&node) {
drawNode->draw(mRenderer);
}
}
}
const char* Engine::getEngineVersion() { return HIBIS_VERSION; }
}