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); //UI::addElement(options);
} }
void destroy() {
}
} }

View File

@ -23,6 +23,7 @@
#include "defaults.h" #include "defaults.h"
#include "ui.h" #include "ui.h"
#include "uielements.h" #include "uielements.h"
#include "physics.h"
#include "internal.h" #include "internal.h"
#include "internal/ui.h" #include "internal/ui.h"
@ -120,11 +121,28 @@ int init() {
glEnable(GL_CULL_FACE); glEnable(GL_CULL_FACE);
glCullFace(GL_BACK); 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) { if(Resource::init() != KEK_SUCCESS) {
glfwTerminate(); glfwTerminate();
return KEK_ERROR; 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"); MemoryBuffer *buf = Resource::loadResource("image/icon.png");
if(buf) { if(buf) {
int width, height, nrChannels; int width, height, nrChannels;
@ -147,21 +165,6 @@ int init() {
glfwSetCharCallback(kekData.window, Input::onKeyCharCallback); glfwSetCharCallback(kekData.window, Input::onKeyCharCallback);
glfwSetMouseButtonCallback(kekData.window, Input::onMouseButtonCallback); 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)); fpsText = new TextElement(uiPx(0), uiPx(0));
UI::addElement(fpsText); UI::addElement(fpsText);
@ -292,6 +295,15 @@ int start() {
return KEK_SUCCESS; return KEK_SUCCESS;
} }
void exit() {
FT_Done_FreeType(kekData.freetype);
Defaults::destroy();
Physics::destroy();
Input::destroy();
UI::destroy();
Resource::destroy();
}
void setActiveScene(Scene *scene) { void setActiveScene(Scene *scene) {
kekData.activeScene = scene; kekData.activeScene = scene;
} }

View File

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

View File

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

View File

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

View File

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

View File

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