Init and destroy components

This commit is contained in:
MrLetsplay 2022-11-08 20:12:36 +01:00
parent 6725f5eb20
commit bdfa5f16dd
7 changed files with 36 additions and 17 deletions

View File

@ -147,4 +147,8 @@ void init() {
//UI::addElement(options);
}
void destroy() {
}
}

View File

@ -23,6 +23,7 @@
#include "defaults.h"
#include "ui.h"
#include "uielements.h"
#include "physics.h"
#include "internal.h"
#include "internal/ui.h"
@ -120,11 +121,28 @@ int init() {
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
glClearColor(0.1f, 0.3f, 0.1f, 0.0f);
glfwSwapInterval(0);
stbi_set_flip_vertically_on_load(true);
if(Resource::init() != KEK_SUCCESS) {
glfwTerminate();
return KEK_ERROR;
}
FT_Error error = FT_Init_FreeType(&kekData.freetype);
if(error) {
ErrorDialog::showError("Failed to initialize FreeType: " + std::string(FT_Error_String(error)));
glfwTerminate();
return KEK_ERROR;
}
UI::init();
Input::init();
Physics::init();
Defaults::init();
MemoryBuffer *buf = Resource::loadResource("image/icon.png");
if(buf) {
int width, height, nrChannels;
@ -147,21 +165,6 @@ int init() {
glfwSetCharCallback(kekData.window, Input::onKeyCharCallback);
glfwSetMouseButtonCallback(kekData.window, Input::onMouseButtonCallback);
glClearColor(0.1f, 0.3f, 0.1f, 0.0f);
glfwSwapInterval(0);
stbi_set_flip_vertically_on_load(true);
FT_Error error = FT_Init_FreeType(&kekData.freetype);
if(error) {
ErrorDialog::showError("Failed to initialize FreeType: " + std::string(FT_Error_String(error)));
glfwTerminate();
return KEK_ERROR;
}
UI::init();
Defaults::init();
fpsText = new TextElement(uiPx(0), uiPx(0));
UI::addElement(fpsText);
@ -292,6 +295,15 @@ int start() {
return KEK_SUCCESS;
}
void exit() {
FT_Done_FreeType(kekData.freetype);
Defaults::destroy();
Physics::destroy();
Input::destroy();
UI::destroy();
Resource::destroy();
}
void setActiveScene(Scene *scene) {
kekData.activeScene = scene;
}

View File

@ -19,7 +19,7 @@ int init() {
return KEK_SUCCESS;
}
void exit() {
void destroy() {
mtar_close(&resources);
}

View File

@ -3,5 +3,6 @@
namespace kek::Defaults {
void init();
void destroy();
}

View File

@ -5,8 +5,8 @@
namespace kek::Engine {
int init();
int start();
void exit();
void setActiveScene(Scene *scene);

View File

@ -12,6 +12,7 @@
#include "mesh.h"
#include "object.h"
#include "objparser.h"
#include "physics.h"
#include "resource.h"
#include "scene.h"
#include "shader.h"

View File

@ -8,6 +8,7 @@
namespace kek::Resource {
int init();
void destroy();
MemoryBuffer *loadResource(std::string path);