implement game configuration file

this integrates https://github.com/cktan/tomlc99 into the repo as a dependency
This commit is contained in:
2024-09-30 21:13:58 -03:00
committed by veclavtalica
parent ec15d8ec4b
commit 57fe5e8946
165 changed files with 4797 additions and 92 deletions

View File

@ -104,7 +104,7 @@ void use_2d_pipeline(void) {
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, RENDER_BASE_WIDTH, RENDER_BASE_HEIGHT, 0, -1, 1);
glOrtho(0, (double)ctx.base_render_width, (double)ctx.base_render_height, 0, -1, 1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

View File

@ -106,9 +106,9 @@ void render(void) {
/* fit rendering context onto the resizable screen */
if (ctx.game.window_size_has_changed) {
if ((float)ctx.game.window_w / (float)ctx.game.window_h > RENDER_BASE_RATIO) {
float ratio = (float)ctx.game.window_h / (float)RENDER_BASE_HEIGHT;
int w = (int)((float)RENDER_BASE_WIDTH * ratio);
if ((float)ctx.game.window_w / (float)ctx.game.window_h > (float)(ctx.base_render_width / ctx.base_render_height)) {
float ratio = (float)ctx.game.window_h / (float)ctx.base_render_height;
int w = (int)((float)ctx.base_render_width * ratio);
setup_viewport(
ctx.game.window_w / 2 - w / 2,
0,
@ -116,8 +116,8 @@ void render(void) {
ctx.game.window_h
);
} else {
float ratio = (float)ctx.game.window_w / (float)RENDER_BASE_WIDTH;
int h = (int)((float)RENDER_BASE_HEIGHT * ratio);
float ratio = (float)ctx.game.window_w / (float)ctx.base_render_width;
int h = (int)((float)ctx.base_render_height * ratio);
setup_viewport(
0,
ctx.game.window_h / 2 - h / 2,

View File

@ -99,7 +99,7 @@ static FontData *text_load_font_data(const char *path, int height_px) {
font_data->file_path = path;
font_data->height_px = height_px;
unsigned char* bitmap = ccalloc(TEXT_FONT_TEXTURE_SIZE * TEXT_FONT_TEXTURE_SIZE, 1);
unsigned char* bitmap = ccalloc(ctx.font_texture_size * ctx.font_texture_size, 1);
{
unsigned char *buf = NULL;
@ -121,19 +121,19 @@ static FontData *text_load_font_data(const char *path, int height_px) {
font_data->line_gap = (int)((float)font_data->line_gap * font_data->scale_factor);
stbtt_pack_context pctx;
stbtt_PackBegin(&pctx, bitmap, TEXT_FONT_TEXTURE_SIZE, TEXT_FONT_TEXTURE_SIZE, 0, 1, NULL);
stbtt_PackSetOversampling(&pctx, TEXT_FONT_OVERSAMPLING, TEXT_FONT_OVERSAMPLING);
stbtt_PackBegin(&pctx, bitmap, (int)ctx.font_texture_size, (int)ctx.font_texture_size, 0, 1, NULL);
stbtt_PackSetOversampling(&pctx, (unsigned int)ctx.font_oversampling, (unsigned int)ctx.font_oversampling);
stbtt_PackFontRange(&pctx, buf, 0, (float)height_px, ASCII_START, NUM_DISPLAY_ASCII, font_data->char_data);
stbtt_PackEnd(&pctx);
}
font_data->texture = create_gpu_texture(TEXT_FONT_FILTERING, true);
font_data->texture = create_gpu_texture(ctx.font_filtering, true);
upload_gpu_texture(
font_data->texture,
bitmap,
1,
TEXT_FONT_TEXTURE_SIZE,
TEXT_FONT_TEXTURE_SIZE
(int)ctx.font_texture_size,
(int)ctx.font_texture_size
);
SDL_free(bitmap);
@ -169,8 +169,8 @@ static void text_draw_with(FontData* font_data, char* text, Vec2 position, Color
stbtt_aligned_quad quad;
stbtt_GetPackedQuad(
font_data->char_data,
TEXT_FONT_TEXTURE_SIZE,
TEXT_FONT_TEXTURE_SIZE,
(int)ctx.font_texture_size,
(int)ctx.font_texture_size,
c - ASCII_START,
&position.x,
&position.y,