first commit

This commit is contained in:
2023-08-11 01:51:06 -04:00
commit 68746a654f
194 changed files with 33308 additions and 0 deletions

18
src/game/GAME_COMMON.h Normal file
View File

@ -0,0 +1,18 @@
#pragma once
#include "../engine/event.h"
#include "../engine/renderer.h"
#include "../engine/window.h"
#include "../engine/sdl.h"
#include "../engine/tick.h"
#include "ecs/ECS_COMMON.h"
typedef struct Game
{
Renderer renderer;
Window window;
Event event;
Tick tick;
ECS ecs;
} Game;

51
src/game/ecs/ECS_COMMON.h Normal file
View File

@ -0,0 +1,51 @@
#pragma once
#include "../../COMMON.h"
#define ECS_FUNCTION_COUNT ECS_FUNCTION_DRAW + 1
typedef enum ECSFunctionType
{
ECS_FUNCTION_ADD,
ECS_FUNCTION_DELETE,
ECS_FUNCTION_TICK,
ECS_FUNCTION_DRAW
} ECSFunctionType;
#define ECS_COMPONENT_COUNT ECS_COMPONENT_SPRITE + 1
typedef enum ECSComponentType
{
ECS_COMPONENT_SPRITE
} ECSComponentType;
typedef struct ECS;
typedef struct Game;
typedef void (*ECSRegister)(ECS);
typedef void (*ECSFunction)(ECS, void*);
typedef struct ECSsystem
{
ECSFunction functions[ECS_FUNCTION_COUNT];
} ECSSystem;
typedef struct ECSComponentInfo
{
ECSSystem system;
ECSComponentType type;
size_t size;
};
typedef struct ECSComponentList
{
ECSSustem system;
ECSComponentType type;
void* components; /* dynamic array */
};
typedef struct ECS
{
Game* game;
ECSComponentList lists[ECS_COMPONENT_COUNT];
u32 nextID;
} ECS;

View File

@ -0,0 +1,47 @@
#include "component_sprite.h"
/* Initializes sprite component. */
void
component_sprite_init
(
)
{
}
/* Ticks sprite component. */
void
component_sprite_tick(ComponentSprite* self, ECS* ecs)
{
}
/* Draws sprite component. */
void
component_sprite_draw(ComponentSprite* self, ECS* ecs)
{
}

View File

@ -0,0 +1,24 @@
#pragma once
#include "../../GAME_COMMON.h"
typedef struct ComponentSprite
{
u32 id;
vec2 size;
vec3 offset;
vec3 position;
vec4 color;
f32 scale;
f32 rotation;
} ComponentSprite;
static const ECSComponentInfo COMPONENT_SPRITE_INFO =
{
.system =
{
.functions = { NULL, NULL, NULL, NULL}
},
.type = ECS_COMPONENT_SPRITE,
.size = sizeof(ComponentSprite)
};

50
src/game/ecs/ecs.c Normal file
View File

@ -0,0 +1,50 @@
#include "ecs.h"
static void _ecs_function(ECS* self, ECSFunctionType type);
/* Executes a function upon an ECS. */
/* If a component does not have the function specfied, skips. */
static void
_ecs_function(ECS* self, ECSFunctionType type)
{
for (s32 i = 0; i < ECS_COMPONENT_COUNT; i++)
{
ECSFunction function;
struct ECSComponentList* list;
list = &game.ecs.lists[i];
function = list->system.functions[type];
if (function)
ecs_component_function(list, function);
}
}
/* Ticks the ECS. */
void
ecs_tick(ECS* self)
{
_ecs_function(self, ECS_FUNCTION_TICK);
}
/* Draws the ECS. */
void
ecs_draw(ECS* self)
{
_ecs_function(self, ECS_FUNCTION_DRAW);
}
/* Initializes ECS. */
void
ecs_init(ECS* self, Game* game)
{
self->game = game;
}
/* Frees ECS. */
void
ecs_free(ECS* self)
{
}

View File

@ -0,0 +1,10 @@
#include "ecs_component.h"
/* Executes a function on a component. */
void
ecs_component_function(ECSComponentList* self, ECSFunction function)
{
}

78
src/game/game.c Normal file
View File

@ -0,0 +1,78 @@
#include "game.h"
Game game;
static void _game_tick(Game* self);
static void _game_draw(Game* self);
static void _game_quit(Game* self);
/* Quits game. */
static void
_game_quit(Game* self)
{
window_free(&self->window);
sdl_quit();
memset(self, '\0', sizeof(Game));
exit(EXIT_SUCCESS);
}
/* Main game tick function. */
static void
_game_tick(Game* self)
{
renderer_update(&self->renderer);
event_update(&self->event);
if (event_press(&self->event, EVENT_QUIT))
_game_quit(self);
}
/* Main game draw function. */
static void
_game_draw(Game* self)
{
renderer_present(&self->renderer);
renderer_clear(&self->renderer);
}
/* Initializes game. */
void
game_init(Game* self)
{
memset(self, '\0', sizeof(Game));
sdl_init();
window_init
(
&self->window,
WINDOW_TITLE,
(s32*)WINDOW_SIZE,
WINDOW_FLAGS
);
renderer_init(&self->renderer, &self->window);
renderer_clear_color_set(&self->renderer, (f32*)RENDERER_CLEAR_COLOR);
}
/* Main game loop. */
void
game_loop(Game* self)
{
tick_update(&self->tick);
while (self->tick.cum > 16)
{
_game_tick(self);
self->tick.cum -= 16;
}
_game_draw(self);
}

14
src/game/game.h Normal file
View File

@ -0,0 +1,14 @@
#pragma once
#include "ecs/ecs.h"
#define WINDOW_TITLE "Sneed"
#define WINDOW_FLAGS SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE
static const ivec2 WINDOW_SIZE = {800, 600};
static const vec4 RENDERER_CLEAR_COLOR = {0.0f, 0.0f, 0.0f, 1.0f};
void game_init(Game* game);
void game_loop(Game* game);
extern Game game;