refactor file structure

This commit is contained in:
2026-10-06 12:07:12 +02:00
parent 6ee6b1482b
commit 18b7df5f0c
14 changed files with 204 additions and 217 deletions
+3 -1
View File
@@ -1,4 +1,6 @@
#include "engine.h"
#include <dangerzone/engine.h>
#include "internal/engine_internal.h"
engine_internal_state_t *internal_state = NULL;
game_state_t *game_state = NULL;
+4 -5
View File
@@ -1,8 +1,7 @@
#include "engine.h"
#include "error.h"
#include <SDL3/SDL_render.h>
#include <SDL3/SDL_video.h>
#include <stdint.h>
#include <dangerzone/engine.h>
#include "internal/engine_internal.h"
#include "internal/util/error.h"
bool
engine_sdl_init_state(
+48
View File
@@ -0,0 +1,48 @@
#include <dangerzone/engine.h>
#include <dangerzone/render/misc.h>
#include <dangerzone/render/rect.h>
#include "internal/util/error.h"
#include <stdint.h>
// alter a pixel at an imaginary x & y coordinates
void
put_pixel(
unsigned int x,
unsigned int y,
uint32_t color
) {
uint16_t w = game_state->width;
uint16_t h = game_state->height;
if (x < 0 || x >= w || y < 0 || y >= h) {
eprintf(
"CRITICAL: attempted buffer overflow in put_pixel\n"
"at x = %d, y = %d", x, y
);
} else {
game_state->framebuffer[game_state->width * y + x]
= color;
mark_dirty_rect(x, y, 1, 1);
}
}
// fill the entire framebuffer with a given color
void
clear_framebuffer(
uint32_t color
) {
for (size_t i = 0;
i < (size_t)game_state->width * game_state->height;
++i) {
game_state->framebuffer[i] = color;
}
mark_dirty_rect(
0,
0,
game_state->width,
game_state->height
);
}
@@ -1,30 +1,9 @@
#include "engine.h"
#include "error.h"
#include <dangerzone/engine.h>
#include <dangerzone/render/misc.h>
#include <dangerzone/render/rect.h>
#include <stdint.h>
// alter a pixel at an imaginary x & y coordinates
void
put_pixel(
unsigned int x,
unsigned int y,
uint32_t color
) {
uint16_t w = game_state->width;
uint16_t h = game_state->height;
if (x < 0 || x >= w || y < 0 || y >= h) {
eprintf(
"CRITICAL: attempted buffer overflow in put_pixel\n"
"at x = %d, y = %d", x, y
);
} else {
game_state->framebuffer[game_state->width * y + x]
= color;
mark_dirty_rect(x, y, 1, 1);
}
}
/**
* draws a rectangle with its left-top corner at (x,y) with
* a width of 'w' and height of 'h' filled with color 'color'
@@ -45,25 +24,6 @@ put_rect(
mark_dirty_rect(x, y, w, h);
}
// fill the entire framebuffer with a given color
void
clear_framebuffer(
uint32_t color
) {
for (size_t i = 0;
i < (size_t)game_state->width * game_state->height;
++i) {
game_state->framebuffer[i] = color;
}
mark_dirty_rect(
0,
0,
game_state->width,
game_state->height
);
}
void
clear_rect(int x, int y, int w, int h, uint32_t color)
{
@@ -1,7 +1,10 @@
// rendering characters in the framebuffer
#include "engine.h"
#include <stdint.h>
#include <dangerzone/engine.h>
#include <dangerzone/render/rect.h>
#include <dangerzone/render/text.h>
#include "internal/engine_internal.h"
/*
* each character has 8 rows