Advancing, changed and loaded correclty assets fonts registry and render, need to work on gui now

This commit is contained in:
Emilia(SleepeeSoftware) 2026-02-20 20:09:55 +01:00
parent 7b503e1ed2
commit f6f5333007
12 changed files with 132 additions and 112 deletions

View File

@ -1,15 +1,19 @@
NAME := MarhaEngine NAME := MarhaEngine
OBJ := $(SRC:source/%.c=obj/%.o) SRC := source/client_render.c
SRC := source/client.c SRC += source/game_loop.c
SRC += source/client_gui.c
SRC += source/client_assets.c
SRC += source/client_main.c
#$(wildcard source/*.c) #$(wildcard source/*.c)
OBJ := $(SRC:source/%.c=obj/%.o)
CC := gcc CC := gcc
CFLAG := -ggdb -Wall -Wextra -Werror -Wpedantic -I include -O0 -std=c99 CFLAG := -ggdb -Wall -Wextra -Werror -Wpedantic -I include -O0 -std=c99
ifeq ($(OS), Windows_NT) ifeq ($(OS), Windows_NT)
CFLAG += -I C:\raylibs\include LFLAG := -lopengl32 -lgdi32 -lwinmm -lpthread -lm
LFLAG := -lraylib -lopengl32 -lgdi32 -lwinmm -lpthread
endif endif
ifeq ($(shell uname -s), Linux) ifeq ($(shell uname -s), Linux)
LFLAG := -lraylib -lGL -lm -lpthread -ldl -lrt -lX11 LFLAG := -lraylib -lGL -lm -lpthread -ldl -lrt -lX11
@ -21,7 +25,7 @@ obj/%.o : source/%.c | makedir
$(CC) $(CFLAG) -c $< -o $@ $(CC) $(CFLAG) -c $< -o $@
$(NAME): $(OBJ) $(NAME): $(OBJ)
$(CC) $(OBJ) $(LFLAG) -o build/$(NAME) $(CC) $(OBJ) ./lib/libraylib.a $(LFLAG) -o build/$(NAME)
makedir: makedir:
mkdir -p obj mkdir -p obj

View File

@ -15,10 +15,10 @@
#include <math.h> #include <math.h>
#include <unistd.h> #include <unistd.h>
#include <raylib.h> #include <extern/raylib.h>
#include <rlgl.h> #include <extern/rlgl.h>
#include <raymath.h> #include <extern/raymath.h>
#include <raygui.h> #include <extern/raygui.h>
//#include <extern/toml.h> //#include <extern/toml.h>
//#include <extern/FastNoiseLite.h> //#include <extern/FastNoiseLite.h>

View File

@ -7,7 +7,7 @@ typedef enum {
} DAMAGE_TYPE; } DAMAGE_TYPE;
typedef struct { typedef struct {
int id;
} Damage; } Damage;
#endif #endif

View File

@ -17,7 +17,6 @@ typedef enum {
CRITICAL_SUCCESS, CRITICAL_SUCCESS,
} CHECK_STATE; } CHECK_STATE;
typedef enum { typedef enum {
SPLASH_SCREEN, SPLASH_SCREEN,
GAMELOOP_SCREEN, GAMELOOP_SCREEN,
@ -28,14 +27,6 @@ typedef enum {
DEBUG_SCREEN, DEBUG_SCREEN,
} ENGINE_STATE_E; } ENGINE_STATE_E;
typedef enum {
DENDRITIC_VOLTAGE,
LAZENBYCOMP_LIQUID,
LAZENBYCOMP_SMOOTH,
POTRA,
} FONTS_ENUM;
typedef struct { typedef struct {
int key[4];//should be the number of action in PLAYER_ACTION int key[4];//should be the number of action in PLAYER_ACTION
union { union {
@ -54,14 +45,6 @@ typedef struct {
Assets assets; Assets assets;
} Context; } Context;
typedef struct {
Font fonts[4];//
Texture textures;//
Model models;//
Sound sound;
} Assets;
//cities //cities
//hideout //hideout
//tiles //tiles
@ -86,20 +69,20 @@ typedef struct {
// void *(*effect)(int e, Event ev); // void *(*effect)(int e, Event ev);
//} physicalRule; //} physicalRule;
# ifndef ENGINE_PROTOTYPE
# define ENGINE_PROTOTYPE
//Render //Render
Assets LoadAssets(void);
void UnloadAssets(const Assets *assets);
void LoadPipeline(); void LoadPipeline();
void UnloadPipeline(); void UnloadPipeline();
void RenderingDeferred3D(const Scene* scene, const ModelRegistry *models, const AnimationRegistry *animations, const TextureRegistry *textures, const FontRegistry *fonts);
//UI //UI
void UserInterface(const Player *player); void UserInterface(const Player *player);
//void Menu(); //void Menu();
void EngineStateSwitch(ENGINE_STATE_E engine_state); void EngineStateSwitch(ENGINE_STATE_E engine_state);
void GameLoop(const double tick_time);
# endif
//other stuff here //other stuff here

View File

@ -3,6 +3,13 @@
#include <core.h> #include <core.h>
typedef enum {
DENDRITIC_VOLTAGE,
LAZENBYCOMP_LIQUID,
LAZENBYCOMP_SMOOTH,
POTRA,
} FONTS_ENUM;
typedef enum { typedef enum {
R_ENTITY_STATIC, R_ENTITY_STATIC,
R_ENTITY_ANIMATED, R_ENTITY_ANIMATED,
@ -52,6 +59,19 @@ typedef struct {
int count; int count;
} FontRegistry; } FontRegistry;
typedef struct {
Sound *font;
int count;
} SoundRegistry;
typedef struct {
FontRegistry fonts;
TextureRegistry textures;
AnimationRegistry animations;
ModelRegistry models;
SoundRegistry sound;
} Assets;
typedef struct { typedef struct {
Shader gbuffer; Shader gbuffer;
Shader deferred; Shader deferred;

View File

@ -14,6 +14,7 @@ typedef enum {
} SKILL_TYPE; } SKILL_TYPE;
typedef struct { typedef struct {
int id;
} Skill; } Skill;
#endif #endif

View File

@ -1,25 +1,37 @@
#include <engine.h> #include <engine.h>
Assets* LoadAssets() { Assets LoadAssets(void) {
Assets *asset = (Assets *)calloc(sizeof(Assets), 1); Assets assets = { 0 };
assert(asset);
//Font //Font
asset->fonts[DENDRITIC_VOLTAGE] = LoadFont("assets/font/Dendritic_Voltage.ttf"); assets.fonts.count = 4;
asset->fonts[LAZENBYCOMP_LIQUID] = LoadFont("assets/font/LazenbyCompLiquid.ttf"); assets.fonts.font = calloc(4, sizeof(Font));
asset->fonts[LAZENBYCOMP_SMOOTH] = LoadFont("assets/font/LazenbyCompSmooth.ttf"); assert(assets.fonts.font);
asset->fonts[POTRA] = LoadFont("assets/font/Potra.ttf"); 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 //Textures
//Models //Models
//Sound //Sound
//Data //Animation
TraceLog(LOG_INFO, "Assets Loaded"); TraceLog(LOG_INFO, "Assets Loaded");
return (asset); return (assets);
} }
void UnloadAssets(Assets *asset) { void UnloadAssets(const Assets *assets) {
UnloadFont(asset->fonts[DENDRITIC_VOLTAGE]); for (int i = 0; i < assets->fonts.count; i++) {
UnloadFont(asset->fonts[LAZENBYCOMP_LIQUID]); UnloadFont(assets->fonts.font[i]);
UnloadFont(asset->fonts[LAZENBYCOMP_SMOOTH]); }
UnloadFont(asset->fonts[POTRA]); UnloadFont(assets->fonts.font[DENDRITIC_VOLTAGE]);
free(asset); UnloadFont(assets->fonts.font[LAZENBYCOMP_LIQUID]);
UnloadFont(assets->fonts.font[LAZENBYCOMP_SMOOTH]);
UnloadFont(assets->fonts.font[POTRA]);
free(assets->fonts.font);
} }

View File

@ -25,7 +25,7 @@ void UserInterface(const Player *player) {
//player state and aliement //player state and aliement
//health and other metric //health and other metric
//DrawTextureRec(); //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) { void EngineStateSwitch(ENGINE_STATE_E engine_state) {

View File

@ -1,26 +1,20 @@
#include <engine.h> #include <engine.h>
#include <rlgl.h>
#include <raymath.h>
//#define RAYGUI_IMPLEMENTATION
//#include <raygui.h>
int main(void) { int main(void) {
double tick_time = 0.4; double tick_time = 0.4;
ENGINE_STATE_E engine_state = SPLASH_SCREEN; ENGINE_STATE_E engine_state = SPLASH_SCREEN;
SetTraceLogLevel(LOG_ALL); SetTraceLogLevel(LOG_ALL);
LoadPipeline(); LoadPipeline();
Assets *assets = LoadAssets(); Assets assets = LoadAssets();
SetExitKey(KEY_NULL); //SetExitKey(KEY_NULL);
while (!WindowShouldClose()) { while (!WindowShouldClose()) {
EngineStateSwitch(engine_state); EngineStateSwitch(engine_state);
//UpdateInput(); //UpdateInput();
//ComputeIntent(); //ComputeIntent();
//GameLoop(tick_time); GameLoop(tick_time);
//Rendering(); RenderingDeferred3D(NULL, NULL, NULL, NULL, &assets.fonts);
} }
UnloadAssets(assets); UnloadAssets(&assets);
assets = NULL;//to remember to not use it after
UnloadPipeline(); UnloadPipeline();
return (0); return (0);
} }

View File

@ -2,10 +2,33 @@
RenderCtx r_ctx; 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() { void LoadPipeline() {
r_ctx.width = 800; r_ctx.width = 800;
r_ctx.height = 480; 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.hud_on = true;
r_ctx.debug_on = true; r_ctx.debug_on = true;
InitWindow(r_ctx.width, r_ctx.height, "GAME!!"); InitWindow(r_ctx.width, r_ctx.height, "GAME!!");
@ -46,6 +69,7 @@ void LoadPipeline() {
rlEnableBackfaceCulling(); rlEnableBackfaceCulling();
TraceLog(LOG_INFO, "Render Pipeline Built"); TraceLog(LOG_INFO, "Render Pipeline Built");
SetTargetFPS(120);//may change SetTargetFPS(120);//may change
DisableCursor();
} }
void UnloadPipeline() { 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 //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(); BeginDrawing();
ClearBackground(BLACK); ClearBackground(BLACK);
rlEnableDepthMask(); rlEnableDepthMask();
@ -78,28 +108,28 @@ void RenderingDeferred3D(Scene* scene, ModelRegistry *models, AnimationRegistry
rlEnableShader(r_ctx.shader.gbuffer.id); rlEnableShader(r_ctx.shader.gbuffer.id);
BeginMode3D(r_ctx.camera3d); BeginMode3D(r_ctx.camera3d);
//MainGeamoetry; //MainGeamoetry;
for (int i = 0; i < scene->count; i++) { //for (int i = 0; i < scene->count; i++) {
RenderEntity *e = &scene->entities[i]; // RenderEntity *e = &scene->entities[i];
Model m = models->models[e->modelId]; // Model m = models->models[e->modelId];
switch (e->type) { // switch (e->type) {
case R_ENTITY_STATIC: // case R_ENTITY_STATIC:
DrawModel(m, (Vector3){0}, 1.0f, WHITE); // DrawModel(m, (Vector3){0}, 1.0f, WHITE);
break; // break;
case R_ENTITY_ANIMATED: // case R_ENTITY_ANIMATED:
UpdateModelAnimation(m, animation->animations[e->data.anim.activeAnim], e->data.anim.time); // UpdateModelAnimation(m, animation->animations[e->data.anim.activeAnim], e->data.anim.time);
DrawModel(m, (Vector3){0}, 1.0f, WHITE); // DrawModel(m, (Vector3){0}, 1.0f, WHITE);
break; // break;
case R_ENTITY_INSTANCED: // case R_ENTITY_INSTANCED:
// Note: Raylib's DrawMeshInstanced handles the instancing buffer // // Note: Raylib's DrawMeshInstanced handles the instancing buffer
for (int j = 0; j < m.meshCount; j++) { // for (int j = 0; j < m.meshCount; j++) {
DrawMeshInstanced(m.meshes[j], m.materials[0], e->data.instancing.transforms, e->data.instancing.instanceCount); // DrawMeshInstanced(m.meshes[j], m.materials[0], e->data.instancing.transforms, e->data.instancing.instanceCount);
} // }
break; // break;
} // }
} //}
EndMode3D(); EndMode3D();
rlDisableShader(); rlDisableShader();
rlDisableFramebuffer(); rlDisableFramebuffer();
@ -109,15 +139,16 @@ void RenderingDeferred3D(Scene* scene, ModelRegistry *models, AnimationRegistry
//Light Pass and forward pass; //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 //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 could be computed into a scalar field
//Light Pass //Light Pass
BeginMode3D(r_ctx.camera3d);
DrawCube(Vector3Zero(), 1, 1, 1, GREEN);
EndMode3D();
//Screen Filter Pass //Screen Filter Pass
BeginShaderMode(r_ctx.shader.filter);//may be good to have this disabled for accessibility //BeginShaderMode(r_ctx.shader.filter);//may be good to have this disabled for accessibility
//DrawTextureRec(); ////DrawTextureRec();
EndShaderMode(); //EndShaderMode();
DrawFPS(10, 10);
DrawTextEx(fonts->font[DENDRITIC_VOLTAGE] , "Hello", (Vector2){40, 40}, 16, 1, RED);
//render ui //render ui
EndDrawing(); EndDrawing();
} }

View File

@ -1,25 +0,0 @@
#include <engine.h>
void RegistryAdd() {
}
void RegistryRemove() {
}
void RegistryCreate() {
}
void RegistryDestroy() {
}
void RegistrySort() {
}
void RegistrySearch() {
}

View File

@ -2,7 +2,7 @@
//may be able to dispatch it //may be able to dispatch it
void GameLoop(const double tick_time) { void GameLoop(const double tick_time) {
__thread static double time = 0; static double time = 0;
time += GetFrameTime(); time += GetFrameTime();
if (time >= tick_time) { if (time >= tick_time) {