Restructure/refactor of main.c
This commit is contained in:
@@ -17,22 +17,23 @@ typedef struct BzAppDesc {
|
||||
BzAppInitFunc init;
|
||||
BzAppUpdateFunc update;
|
||||
BzAppRenderFunc render;
|
||||
BzAppRenderFunc imguiRender;
|
||||
BzAppDeinitFunc deinit;
|
||||
|
||||
bool useNuklear;
|
||||
bool useFlecs;
|
||||
|
||||
void *userData;
|
||||
} BzAppDesc;
|
||||
|
||||
extern struct nk_context *NK;
|
||||
typedef struct ecs_world_t ecs_world_t;
|
||||
extern ecs_world_t *ECS;
|
||||
|
||||
extern bool bzMain(BzAppDesc *appDesc, int argc, const char **argv);
|
||||
|
||||
#ifdef BZ_ENTRYPOINT
|
||||
#include <flecs.h>
|
||||
#include <rlImGui.h>
|
||||
|
||||
struct nk_context *NK = NULL;
|
||||
ecs_world_t *ECS = NULL;
|
||||
|
||||
// https://www.raylib.com/examples/core/loader.html?name=core_custom_logging
|
||||
@@ -93,9 +94,10 @@ int main(int argc, const char **argv) {
|
||||
SetTargetFPS(appDesc.fps);
|
||||
// Initialize modules
|
||||
|
||||
if (appDesc.useFlecs) {
|
||||
if (appDesc.useFlecs)
|
||||
ECS = ecs_init();
|
||||
}
|
||||
if (appDesc.imguiRender)
|
||||
rlImGuiSetup(true);
|
||||
|
||||
// User initialize
|
||||
if (appDesc.init && !appDesc.init(appDesc.userData)) {
|
||||
@@ -113,6 +115,12 @@ int main(int argc, const char **argv) {
|
||||
BeginDrawing();
|
||||
if (appDesc.render)
|
||||
appDesc.render(dt, appDesc.userData);
|
||||
|
||||
if (appDesc.imguiRender) {
|
||||
rlImGuiBegin();
|
||||
appDesc.imguiRender(dt, appDesc.userData);
|
||||
rlImGuiEnd();
|
||||
}
|
||||
EndDrawing();
|
||||
}
|
||||
|
||||
@@ -121,6 +129,8 @@ int main(int argc, const char **argv) {
|
||||
appDesc.deinit(appDesc.userData);
|
||||
|
||||
// Deinitialize modules
|
||||
if (appDesc.imguiRender)
|
||||
rlImGuiShutdown();
|
||||
if (ECS) {
|
||||
ecs_fini(ECS);
|
||||
ECS = NULL;
|
||||
|
||||
Reference in New Issue
Block a user