#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();

		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() + "]!");
	}

	Engine::~Engine() {
		//watch.stop();
	}

	float Engine::calculateDelta(bool isPhysics) {
		const std::chrono::time_point<std::chrono::steady_clock> current = std::chrono::steady_clock::now();
		if (isPhysics) {
			auto delta = std::chrono::duration<float>(current - mPreviousPhysicsProcessTick);

			return delta.count();
		} else {
			auto delta = std::chrono::duration<float>(current - mPreviousProcessTick);

			return delta.count();
		}
	}

	void Engine::updateDelta(bool isPhysics) {
		if (isPhysics) {
			mPreviousPhysicsProcessTick = std::chrono::steady_clock::now();
		} else {
			mPreviousProcessTick = std::chrono::steady_clock::now();
		}
	}

	const char* Engine::getEngineVersion() { return HIBIS_VERSION; }
}