2023-05-26 21:41:51 +00:00
|
|
|
#include "enginever.hpp"
|
|
|
|
#include "engine.hpp"
|
2023-05-30 14:20:34 +00:00
|
|
|
#include "../pragmautil.hpp"
|
2023-05-27 17:11:46 +00:00
|
|
|
#include <core/graphics/drawable.hpp>
|
2023-05-26 21:41:51 +00:00
|
|
|
|
|
|
|
namespace hibis {
|
|
|
|
Engine::Engine(Renderer* renderer, LoggerCallback logger) {
|
2023-05-27 19:47:34 +00:00
|
|
|
this->mRenderer = renderer;
|
|
|
|
mLoggerCallback = logger;
|
|
|
|
mPreviousProcessTick = std::chrono::steady_clock::now();
|
|
|
|
mPreviousPhysicsProcessTick = std::chrono::steady_clock::now();
|
2023-05-26 21:41:51 +00:00
|
|
|
|
|
|
|
//watch.start();
|
|
|
|
|
2023-06-01 17:27:14 +00:00
|
|
|
mLoggerCallback(Information, "Starting FreeType2 library...");
|
|
|
|
int err = FT_Init_FreeType(&mFreeTypeLibrary);
|
|
|
|
if (err) {
|
|
|
|
mLoggerCallback(Fatal, "Failed to init FreeType2");
|
|
|
|
}
|
|
|
|
|
|
|
|
mLoggerCallback(Information, "Started Hibis [using v" + (std::string)getEngineVersion() + "]!");
|
2023-05-26 21:41:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Engine::~Engine() {
|
|
|
|
//watch.stop();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Engine::runNodeProcesses() {
|
2023-05-27 17:11:46 +00:00
|
|
|
TODO("check if delta calc is correct")
|
2023-05-27 23:14:27 +00:00
|
|
|
TODO("get workaround for MSVC being fucking stupid (std::chrono + std::this_thread)")
|
2023-05-27 17:11:46 +00:00
|
|
|
const std::chrono::time_point<std::chrono::steady_clock> current = std::chrono::steady_clock::now();
|
2023-05-27 19:47:34 +00:00
|
|
|
auto delta = std::chrono::duration<float>(current - mPreviousProcessTick);
|
2023-05-26 21:41:51 +00:00
|
|
|
|
2023-05-27 19:47:34 +00:00
|
|
|
for (Node* node : mNodeList) {
|
2023-05-27 17:11:46 +00:00
|
|
|
node->process(delta.count());
|
2023-05-26 21:41:51 +00:00
|
|
|
}
|
|
|
|
|
2023-05-27 19:47:34 +00:00
|
|
|
mPreviousProcessTick = std::chrono::steady_clock::now();
|
2023-05-26 21:41:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Engine::runNodePhysicsProcesses() {
|
2023-05-27 17:11:46 +00:00
|
|
|
const std::chrono::time_point<std::chrono::steady_clock> current = std::chrono::steady_clock::now();
|
2023-05-27 19:47:34 +00:00
|
|
|
auto delta = std::chrono::duration<float>(current - mPreviousProcessTick);
|
2023-05-26 21:41:51 +00:00
|
|
|
|
2023-05-27 19:47:34 +00:00
|
|
|
for (Node* node : mNodeList) {
|
2023-05-27 17:11:46 +00:00
|
|
|
node->physicsProcess(delta.count());
|
2023-05-26 21:41:51 +00:00
|
|
|
}
|
|
|
|
|
2023-05-27 19:47:34 +00:00
|
|
|
mPreviousProcessTick = std::chrono::steady_clock::now();
|
2023-05-26 21:41:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Engine::drawNodes() {
|
2023-05-27 17:11:46 +00:00
|
|
|
TODO("check if this works")
|
2023-05-27 19:47:34 +00:00
|
|
|
for (Node* node : mNodeList) {
|
2023-05-27 17:11:46 +00:00
|
|
|
if (Drawable* drawNode = (Drawable*)&node) {
|
2023-05-27 19:47:34 +00:00
|
|
|
drawNode->draw(mRenderer);
|
2023-05-27 17:11:46 +00:00
|
|
|
}
|
|
|
|
}
|
2023-05-26 21:41:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const char* Engine::getEngineVersion() { return HIBIS_VERSION; }
|
|
|
|
}
|