From f6f5333007d03b31be3716c2fe7c5e575425e968 Mon Sep 17 00:00:00 2001 From: "Emilia(SleepeeSoftware)" Date: Fri, 20 Feb 2026 20:09:55 +0100 Subject: [PATCH] Advancing, changed and loaded correclty assets fonts registry and render, need to work on gui now --- Makefile | 14 ++++--- include/core.h | 8 ++-- include/damage.h | 2 +- include/engine.h | 27 +++----------- include/render.h | 20 ++++++++++ include/skill.h | 1 + source/client_assets.c | 42 +++++++++++++-------- source/client_gui.c | 2 +- source/client_main.c | 16 +++----- source/client_render.c | 85 ++++++++++++++++++++++++++++-------------- source/core_registry.c | 25 ------------- source/game_loop.c | 2 +- 12 files changed, 132 insertions(+), 112 deletions(-) delete mode 100644 source/core_registry.c diff --git a/Makefile b/Makefile index c7e239c..ec5c04b 100644 --- a/Makefile +++ b/Makefile @@ -1,15 +1,19 @@ NAME := MarhaEngine -OBJ := $(SRC:source/%.c=obj/%.o) -SRC := source/client.c +SRC := source/client_render.c +SRC += source/game_loop.c +SRC += source/client_gui.c +SRC += source/client_assets.c +SRC += source/client_main.c #$(wildcard source/*.c) +OBJ := $(SRC:source/%.c=obj/%.o) + CC := gcc CFLAG := -ggdb -Wall -Wextra -Werror -Wpedantic -I include -O0 -std=c99 ifeq ($(OS), Windows_NT) -CFLAG += -I C:\raylibs\include -LFLAG := -lraylib -lopengl32 -lgdi32 -lwinmm -lpthread +LFLAG := -lopengl32 -lgdi32 -lwinmm -lpthread -lm endif ifeq ($(shell uname -s), Linux) LFLAG := -lraylib -lGL -lm -lpthread -ldl -lrt -lX11 @@ -21,7 +25,7 @@ obj/%.o : source/%.c | makedir $(CC) $(CFLAG) -c $< -o $@ $(NAME): $(OBJ) - $(CC) $(OBJ) $(LFLAG) -o build/$(NAME) + $(CC) $(OBJ) ./lib/libraylib.a $(LFLAG) -o build/$(NAME) makedir: mkdir -p obj diff --git a/include/core.h b/include/core.h index 56a22ae..7487305 100644 --- a/include/core.h +++ b/include/core.h @@ -15,10 +15,10 @@ #include #include -#include -#include -#include -#include +#include +#include +#include +#include //#include //#include diff --git a/include/damage.h b/include/damage.h index bd976c3..953386d 100644 --- a/include/damage.h +++ b/include/damage.h @@ -7,7 +7,7 @@ typedef enum { } DAMAGE_TYPE; typedef struct { - + int id; } Damage; #endif diff --git a/include/engine.h b/include/engine.h index 81fabb8..8ec5a83 100644 --- a/include/engine.h +++ b/include/engine.h @@ -17,7 +17,6 @@ typedef enum { CRITICAL_SUCCESS, } CHECK_STATE; - typedef enum { SPLASH_SCREEN, GAMELOOP_SCREEN, @@ -28,14 +27,6 @@ typedef enum { DEBUG_SCREEN, } ENGINE_STATE_E; - -typedef enum { - DENDRITIC_VOLTAGE, - LAZENBYCOMP_LIQUID, - LAZENBYCOMP_SMOOTH, - POTRA, -} FONTS_ENUM; - typedef struct { int key[4];//should be the number of action in PLAYER_ACTION union { @@ -54,14 +45,6 @@ typedef struct { Assets assets; } Context; - -typedef struct { - Font fonts[4];// - Texture textures;// - Model models;// - Sound sound; -} Assets; - //cities //hideout //tiles @@ -86,20 +69,20 @@ typedef struct { // void *(*effect)(int e, Event ev); //} physicalRule; -# ifndef ENGINE_PROTOTYPE -# define ENGINE_PROTOTYPE - //Render +Assets LoadAssets(void); +void UnloadAssets(const Assets *assets); + void LoadPipeline(); void UnloadPipeline(); +void RenderingDeferred3D(const Scene* scene, const ModelRegistry *models, const AnimationRegistry *animations, const TextureRegistry *textures, const FontRegistry *fonts); //UI void UserInterface(const Player *player); //void Menu(); void EngineStateSwitch(ENGINE_STATE_E engine_state); - -# endif +void GameLoop(const double tick_time); //other stuff here diff --git a/include/render.h b/include/render.h index 65c4a61..a40c516 100644 --- a/include/render.h +++ b/include/render.h @@ -3,6 +3,13 @@ #include +typedef enum { + DENDRITIC_VOLTAGE, + LAZENBYCOMP_LIQUID, + LAZENBYCOMP_SMOOTH, + POTRA, +} FONTS_ENUM; + typedef enum { R_ENTITY_STATIC, R_ENTITY_ANIMATED, @@ -52,6 +59,19 @@ typedef struct { int count; } FontRegistry; +typedef struct { + Sound *font; + int count; +} SoundRegistry; + +typedef struct { + FontRegistry fonts; + TextureRegistry textures; + AnimationRegistry animations; + ModelRegistry models; + SoundRegistry sound; +} Assets; + typedef struct { Shader gbuffer; Shader deferred; diff --git a/include/skill.h b/include/skill.h index 13bfaa1..a873168 100644 --- a/include/skill.h +++ b/include/skill.h @@ -14,6 +14,7 @@ typedef enum { } SKILL_TYPE; typedef struct { + int id; } Skill; #endif diff --git a/source/client_assets.c b/source/client_assets.c index beeb56f..a36ace5 100644 --- a/source/client_assets.c +++ b/source/client_assets.c @@ -1,25 +1,37 @@ #include -Assets* LoadAssets() { - Assets *asset = (Assets *)calloc(sizeof(Assets), 1); - assert(asset); +Assets LoadAssets(void) { + Assets assets = { 0 }; //Font - asset->fonts[DENDRITIC_VOLTAGE] = LoadFont("assets/font/Dendritic_Voltage.ttf"); - asset->fonts[LAZENBYCOMP_LIQUID] = LoadFont("assets/font/LazenbyCompLiquid.ttf"); - asset->fonts[LAZENBYCOMP_SMOOTH] = LoadFont("assets/font/LazenbyCompSmooth.ttf"); - asset->fonts[POTRA] = LoadFont("assets/font/Potra.ttf"); + assets.fonts.count = 4; + assets.fonts.font = calloc(4, sizeof(Font)); + assert(assets.fonts.font); + assets.fonts.font[DENDRITIC_VOLTAGE] = LoadFont("assets/font/Dendritic_Voltage.ttf"); + assets.fonts.font[LAZENBYCOMP_LIQUID] = LoadFont("assets/font/LazenbyCompLiquid.ttf"); + assets.fonts.font[LAZENBYCOMP_SMOOTH] = LoadFont("assets/font/LazenbyCompSmooth.ttf"); + assets.fonts.font[POTRA] = LoadFont("assets/font/Potra.ttf"); + SetTextureFilter(assets.fonts.font[DENDRITIC_VOLTAGE].texture, TEXTURE_FILTER_BILINEAR); + SetTextureFilter(assets.fonts.font[LAZENBYCOMP_LIQUID].texture, TEXTURE_FILTER_BILINEAR); + SetTextureFilter(assets.fonts.font[LAZENBYCOMP_SMOOTH].texture, TEXTURE_FILTER_BILINEAR); + SetTextureFilter(assets.fonts.font[POTRA].texture, TEXTURE_FILTER_BILINEAR); + //asset.textures.count = 4; + //asset.textures.textures = calloc(4, sizeof(Font)); + //assert(asset.fonts.font); //Textures //Models //Sound - //Data + //Animation TraceLog(LOG_INFO, "Assets Loaded"); - return (asset); + return (assets); } -void UnloadAssets(Assets *asset) { - UnloadFont(asset->fonts[DENDRITIC_VOLTAGE]); - UnloadFont(asset->fonts[LAZENBYCOMP_LIQUID]); - UnloadFont(asset->fonts[LAZENBYCOMP_SMOOTH]); - UnloadFont(asset->fonts[POTRA]); - free(asset); +void UnloadAssets(const Assets *assets) { + for (int i = 0; i < assets->fonts.count; i++) { + UnloadFont(assets->fonts.font[i]); + } + UnloadFont(assets->fonts.font[DENDRITIC_VOLTAGE]); + UnloadFont(assets->fonts.font[LAZENBYCOMP_LIQUID]); + UnloadFont(assets->fonts.font[LAZENBYCOMP_SMOOTH]); + UnloadFont(assets->fonts.font[POTRA]); + free(assets->fonts.font); } diff --git a/source/client_gui.c b/source/client_gui.c index 598a9b7..8c3f4d2 100644 --- a/source/client_gui.c +++ b/source/client_gui.c @@ -25,7 +25,7 @@ void UserInterface(const Player *player) { //player state and aliement //health and other metric //DrawTextureRec(); - DrawText(player->entity.body.health, 0, 0, 16, RED); + DrawText(TextFormat("%i", player->entity.body.health), 0, 0, 16, RED); } void EngineStateSwitch(ENGINE_STATE_E engine_state) { diff --git a/source/client_main.c b/source/client_main.c index 57cb24c..ddc322b 100644 --- a/source/client_main.c +++ b/source/client_main.c @@ -1,26 +1,20 @@ #include -#include -#include -//#define RAYGUI_IMPLEMENTATION -//#include - int main(void) { double tick_time = 0.4; ENGINE_STATE_E engine_state = SPLASH_SCREEN; SetTraceLogLevel(LOG_ALL); LoadPipeline(); - Assets *assets = LoadAssets(); - SetExitKey(KEY_NULL); + Assets assets = LoadAssets(); + //SetExitKey(KEY_NULL); while (!WindowShouldClose()) { EngineStateSwitch(engine_state); //UpdateInput(); //ComputeIntent(); - //GameLoop(tick_time); - //Rendering(); + GameLoop(tick_time); + RenderingDeferred3D(NULL, NULL, NULL, NULL, &assets.fonts); } - UnloadAssets(assets); - assets = NULL;//to remember to not use it after + UnloadAssets(&assets); UnloadPipeline(); return (0); } diff --git a/source/client_render.c b/source/client_render.c index 59e092d..4952e51 100644 --- a/source/client_render.c +++ b/source/client_render.c @@ -2,10 +2,33 @@ RenderCtx r_ctx; +// Possible window flags +/* +FLAG_VSYNC_HINT +FLAG_FULLSCREEN_MODE -> not working properly -> wrong scaling! +FLAG_WINDOW_RESIZABLE +FLAG_WINDOW_UNDECORATED +FLAG_WINDOW_TRANSPARENT +FLAG_WINDOW_HIDDEN +FLAG_WINDOW_MINIMIZED -> Not supported on window creation +FLAG_WINDOW_MAXIMIZED -> Not supported on window creation +FLAG_WINDOW_UNFOCUSED +FLAG_WINDOW_TOPMOST +FLAG_WINDOW_HIGHDPI -> errors after minimize-resize, fb size is recalculated +FLAG_WINDOW_ALWAYS_RUN +FLAG_MSAA_4X_HINT +*/ + void LoadPipeline() { r_ctx.width = 800; r_ctx.height = 480; + r_ctx.camera3d.position = (Vector3){ 10.0f, 10.0f, 10.0f }; // Camera position + r_ctx.camera3d.target = (Vector3){ 0.0f, 0.0f, 0.0f }; // Camera looking at point + r_ctx.camera3d.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target) + r_ctx.camera3d.fovy = 45.0f; // Camera field-of-view Y + r_ctx.camera3d.projection = CAMERA_PERSPECTIVE; // Camera projection type + r_ctx.hud_on = true; r_ctx.debug_on = true; InitWindow(r_ctx.width, r_ctx.height, "GAME!!"); @@ -46,6 +69,7 @@ void LoadPipeline() { rlEnableBackfaceCulling(); TraceLog(LOG_INFO, "Render Pipeline Built"); SetTargetFPS(120);//may change + DisableCursor(); } void UnloadPipeline() { @@ -70,7 +94,13 @@ void LoadCameraMode(int mode) { } //need to work on a way to structurize my data for the scene to be rendered -void RenderingDeferred3D(Scene* scene, ModelRegistry *models, AnimationRegistry *animation) { +void RenderingDeferred3D(const Scene* scene, const ModelRegistry *models, const AnimationRegistry *animations, const TextureRegistry *textures, const FontRegistry *fonts) { + (void)scene; + (void)models; + (void)animations; + (void)textures; + UpdateCamera(&r_ctx.camera3d, CAMERA_FREE); + if (IsKeyPressed(KEY_Z)) r_ctx.camera3d.target = (Vector3){ 0.0f, 0.0f, 0.0f }; BeginDrawing(); ClearBackground(BLACK); rlEnableDepthMask(); @@ -78,28 +108,28 @@ void RenderingDeferred3D(Scene* scene, ModelRegistry *models, AnimationRegistry rlEnableShader(r_ctx.shader.gbuffer.id); BeginMode3D(r_ctx.camera3d); //MainGeamoetry; - for (int i = 0; i < scene->count; i++) { - RenderEntity *e = &scene->entities[i]; - Model m = models->models[e->modelId]; + //for (int i = 0; i < scene->count; i++) { + // RenderEntity *e = &scene->entities[i]; + // Model m = models->models[e->modelId]; - switch (e->type) { - case R_ENTITY_STATIC: - DrawModel(m, (Vector3){0}, 1.0f, WHITE); - break; + // switch (e->type) { + // case R_ENTITY_STATIC: + // DrawModel(m, (Vector3){0}, 1.0f, WHITE); + // break; - case R_ENTITY_ANIMATED: - UpdateModelAnimation(m, animation->animations[e->data.anim.activeAnim], e->data.anim.time); - DrawModel(m, (Vector3){0}, 1.0f, WHITE); - break; + // case R_ENTITY_ANIMATED: + // UpdateModelAnimation(m, animation->animations[e->data.anim.activeAnim], e->data.anim.time); + // DrawModel(m, (Vector3){0}, 1.0f, WHITE); + // break; - case R_ENTITY_INSTANCED: - // Note: Raylib's DrawMeshInstanced handles the instancing buffer - for (int j = 0; j < m.meshCount; j++) { - DrawMeshInstanced(m.meshes[j], m.materials[0], e->data.instancing.transforms, e->data.instancing.instanceCount); - } - break; - } - } + // case R_ENTITY_INSTANCED: + // // Note: Raylib's DrawMeshInstanced handles the instancing buffer + // for (int j = 0; j < m.meshCount; j++) { + // DrawMeshInstanced(m.meshes[j], m.materials[0], e->data.instancing.transforms, e->data.instancing.instanceCount); + // } + // break; + // } + //} EndMode3D(); rlDisableShader(); rlDisableFramebuffer(); @@ -109,15 +139,16 @@ void RenderingDeferred3D(Scene* scene, ModelRegistry *models, AnimationRegistry //Light Pass and forward pass; //I should build a shader that take every light in the scene and make a 3D heightmap of lighting then compute it once for all static light allowing to cheat computing everylight //light could be computed into a scalar field - //Light Pass - + BeginMode3D(r_ctx.camera3d); + DrawCube(Vector3Zero(), 1, 1, 1, GREEN); + EndMode3D(); //Screen Filter Pass - BeginShaderMode(r_ctx.shader.filter);//may be good to have this disabled for accessibility - //DrawTextureRec(); - EndShaderMode(); - + //BeginShaderMode(r_ctx.shader.filter);//may be good to have this disabled for accessibility + ////DrawTextureRec(); + //EndShaderMode(); + DrawFPS(10, 10); + DrawTextEx(fonts->font[DENDRITIC_VOLTAGE] , "Hello", (Vector2){40, 40}, 16, 1, RED); //render ui EndDrawing(); } - diff --git a/source/core_registry.c b/source/core_registry.c deleted file mode 100644 index 0488d72..0000000 --- a/source/core_registry.c +++ /dev/null @@ -1,25 +0,0 @@ -#include - -void RegistryAdd() { - -} - -void RegistryRemove() { - -} - -void RegistryCreate() { - -} - -void RegistryDestroy() { - -} - -void RegistrySort() { - -} - -void RegistrySearch() { - -} diff --git a/source/game_loop.c b/source/game_loop.c index 917c890..3a289b0 100644 --- a/source/game_loop.c +++ b/source/game_loop.c @@ -2,7 +2,7 @@ //may be able to dispatch it void GameLoop(const double tick_time) { - __thread static double time = 0; + static double time = 0; time += GetFrameTime(); if (time >= tick_time) {