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
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

View File

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

View File

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

View File

@ -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

View File

@ -3,6 +3,13 @@
#include <core.h>
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;

View File

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

View File

@ -1,25 +1,37 @@
#include <engine.h>
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);
}

View File

@ -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) {

View File

@ -1,26 +1,20 @@
#include <engine.h>
#include <rlgl.h>
#include <raymath.h>
//#define RAYGUI_IMPLEMENTATION
//#include <raygui.h>
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);
}

View File

@ -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();
}

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
void GameLoop(const double tick_time) {
__thread static double time = 0;
static double time = 0;
time += GetFrameTime();
if (time >= tick_time) {