summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMitya Selivanov <automainint@guattari.tech>2025-04-15 08:11:38 +0200
committerMitya Selivanov <automainint@guattari.tech>2025-04-15 08:11:38 +0200
commit01ea5ec5aeb50ed9801a457a7ced1c541d63f7c8 (patch)
treeacbdc0ace86b40328fa15d199c625a1bc60366c9
parentaf8c9212a029ddaf8e7eef66cecaa762263ca0c5 (diff)
downloadreduced_system_layer-01ea5ec5aeb50ed9801a457a7ced1c541d63f7c8.zip
Update docs; Add key repeat flag; Fix fill rectangle
-rwxr-xr-xgraphics.c51
-rw-r--r--index.htm12
-rwxr-xr-xreduced_system_layer.c16
-rwxr-xr-xstackless_coroutine.c5
-rw-r--r--test.c2
5 files changed, 64 insertions, 22 deletions
diff --git a/graphics.c b/graphics.c
index 79e3a6c..287b248 100755
--- a/graphics.c
+++ b/graphics.c
@@ -7,6 +7,8 @@
#/
#/ (C) 2025 Mitya Selivanov <guattari.tech>
#/
+#/ Any use of this code is prohibited.
+#/
#/ ================================================================
#/
#/ Self-testing shell script
@@ -20,6 +22,9 @@ gcc \
-Wno-missing-braces \
-Wno-old-style-declaration \
-Wno-overlength-strings \
+ -Wno-unused-parameter \
+ -Wno-unused-variable \
+ -Wno-unused-but-set-variable \
-O3 -D NDEBUG \
-D ENABLE_WAYLAND=0 \
-D GRAPHICS_TEST_SUITE \
@@ -93,7 +98,6 @@ typedef struct {
} Box;
enum {
- GRAPHICS_NOOP = 0,
GRAPHICS_DRAW_PIXELS,
GRAPHICS_FILL_RECTANGLE,
GRAPHICS_FILL_TRIANGLE,
@@ -173,9 +177,9 @@ typedef struct {
//
// ================================================================
-Box external_font_text_area(i32 font, vec2 scale, i64 num_chars, c32 *text);
+Box font_text_area_dispatch(i32 font, vec2 scale, i64 num_chars, c32 *text);
-void external_font_render_to_buffer(Pixel_Buffer dst, i32 font, vec4_f32 color, vec2 position, vec2 scale, i64 num_chars, c32 *text);
+void font_render_to_buffer_dispatch(Pixel_Buffer dst, i32 font, vec4_f32 color, vec2 position, vec2 scale, i64 num_chars, c32 *text);
// ================================================================
@@ -244,6 +248,7 @@ void draw_text_area (i32 font, vec4_f32 color, Box area, vec2 max_size, i64 num
void draw_text_cursor(i32 font, vec4_f32 color, Box area, vec2 max_size, i64 num_chars, c32 *text, i64 cursor, i64 selection);
void perform_graphics_request(Graphics_Context context, Graphics_Request req);
+void clean_graphics_requests_cache(i64 amount);
#endif // GRAPHICS_HEADER_GUARD_
@@ -335,16 +340,18 @@ void draw_pixels_to_buffer(Pixel_Buffer dst, Box area, Pixel_Buffer src) {
PROFILER_begin(PROFILE_DRAW_PIXELS);
- i64 i0 = (i64) floor(area.x);
- i64 i1 = (i64) floor(area.x + area.width);
- i64 j0 = (i64) floor(area.y);
- i64 j1 = (i64) floor(area.y + area.height);
+ i64 i0 = (i64) floor(area.x + 0.5);
+ i64 i1 = (i64) floor(area.x + area.width + 0.5);
+ i64 j0 = (i64) floor(area.y + 0.5);
+ i64 j1 = (i64) floor(area.y + area.height + 0.5);
if (i0 < 0) i0 = 0;
if (i1 > dst.width) i1 = dst.width;
if (j0 < 0) j0 = 0;
if (j1 > dst.height) j1 = dst.height;
+ // FIXME, PERF: Use integer arithmetic.
+
f64 di = src.width / area.width;
f64 dj = src.height / area.height;
f64 jj = (j0 - area.y) * dj + dj * .5;
@@ -365,10 +372,10 @@ void draw_pixels_to_buffer(Pixel_Buffer dst, Box area, Pixel_Buffer src) {
void fill_rectangle_to_buffer(Pixel_Buffer dst, vec4_f32 color, Box area) {
PROFILER_begin(PROFILE_FILL_RECTANGLE);
- i64 i0 = (i64) floor(area.x);
- i64 i1 = (i64) floor(area.x + area.width);
- i64 j0 = (i64) floor(area.y);
- i64 j1 = (i64) floor(area.y + area.height);
+ i64 i0 = (i64) floor(area.x + 0.5);
+ i64 i1 = (i64) floor(area.x + area.width + 0.5);
+ i64 j0 = (i64) floor(area.y + 0.5);
+ i64 j1 = (i64) floor(area.y + area.height + 0.5);
if (i0 < 0) i0 = 0;
if (i1 > dst.width) i1 = dst.width;
@@ -815,8 +822,8 @@ static void draw_text_(Pixel_Buffer dst, vec4_f32 color, f64 x0, f64 y0, f64 sca
}
}
-#if !defined(GRAPHICS_ENABLE_EXTERNAL_FONT)
-Box external_font_text_area(i32 font, vec2 scale, i64 num_chars, c32 *text) {
+#if !defined(GRAPHICS_ENABLE_FONT_CUSTOM_DISPATCH)
+Box font_text_area_dispatch(i32 font, vec2 scale, i64 num_chars, c32 *text) {
// TODO
(void) font;
@@ -827,7 +834,7 @@ Box external_font_text_area(i32 font, vec2 scale, i64 num_chars, c32 *text) {
return (Box) {0};
}
-void external_font_render_to_buffer(Pixel_Buffer dst, i32 font, vec4_f32 color, vec2 position, vec2 scale, i64 num_chars, c32 *text) {
+void font_render_to_buffer_dispatch(Pixel_Buffer dst, i32 font, vec4_f32 color, vec2 position, vec2 scale, i64 num_chars, c32 *text) {
// TODO
(void) dst;
@@ -838,7 +845,7 @@ void external_font_render_to_buffer(Pixel_Buffer dst, i32 font, vec4_f32 color,
(void) num_chars;
(void) text;
}
-#endif // !defined(GRAPHICS_ENABLE_EXTERNAL_FONT)
+#endif // !defined(GRAPHICS_ENABLE_FONT_CUSTOM_DISPATCH)
void draw_text_area_to_buffer(Pixel_Buffer dst, i32 font, vec4_f32 color, Box area, vec2 max_size, i64 num_chars, c32 *text) {
if (text == NULL || num_chars <= 0 || max_size.x < EPSILON || max_size.y < EPSILON)
@@ -2141,15 +2148,17 @@ void perform_graphics_request(Graphics_Context context, Graphics_Request req) {
scale_and_perform_graphics_request_(graphics_context_defaults_(context), req);
}
-void graphics_refresh_frame(void) {
- Graphics_Cache_Slot_ *s = _graphics_cache + _graphics_cache_gc_index;
+void clean_graphics_requests_cache(i64 amount) {
+ for (; amount > 0; --amount) {
+ Graphics_Cache_Slot_ *s = _graphics_cache + _graphics_cache_gc_index;
- i64 required_len = !s->occupied ? 0 : s->width * s->height;
+ i64 required_len = !s->occupied ? 0 : s->width * s->height;
- if (s->buffer_len > required_len)
- resize_dynamic_array_exact(&s->buffer_len, (void **) &s->buffer, sizeof *s->buffer, required_len);
+ if (s->buffer_len > required_len)
+ resize_dynamic_array_exact(&s->buffer_len, (void **) &s->buffer, sizeof *s->buffer, required_len);
- _graphics_cache_gc_index = (_graphics_cache_gc_index + 1) % GRAPHICS_CACHE_SIZE;
+ _graphics_cache_gc_index = (_graphics_cache_gc_index + 1) % GRAPHICS_CACHE_SIZE;
+ }
}
// ================================================================
diff --git a/index.htm b/index.htm
index 5079362..170acef 100644
--- a/index.htm
+++ b/index.htm
@@ -1,3 +1,15 @@
+<!--================================================================
+//
+// index.htm
+//
+// ----------------------------------------------------------------
+//
+// (C) 2025 Mitya Selivanov <guattari.tech>
+//
+// Any use of this code is prohibited.
+//
+// ================================================================
+// -->
<!DOCTYPE html>
<html style="height: 100%; overflow: hidden; overflow-x: hidden;">
<head>
diff --git a/reduced_system_layer.c b/reduced_system_layer.c
index 131ee5c..63f647b 100755
--- a/reduced_system_layer.c
+++ b/reduced_system_layer.c
@@ -161,6 +161,8 @@
#/
#/ (C) 2025 Mitya Selivanov <guattari.tech>
#/
+#/ Any use of this code is prohibited.
+#/
#/ ================================================================
#/
#/ Self-testing shell script
@@ -174,6 +176,9 @@ gcc \
-Wno-missing-braces \
-Wno-old-style-declaration \
-Wno-overlength-strings \
+ -Wno-unused-parameter \
+ -Wno-unused-variable \
+ -Wno-unused-but-set-variable \
-O3 -D NDEBUG \
-fsanitize=undefined,address,leak \
-D REDUCED_SYSTEM_LAYER_TEST_SUITE \
@@ -594,6 +599,7 @@ typedef struct {
b8 num : 1;
b8 scroll : 1;
b8 meta : 1;
+ b8 repeat : 1;
u16 key;
c32 c;
} Input_Key;
@@ -1509,9 +1515,14 @@ void PROFILER_init(u32 slot, c8 *name) {
}
void PROFILER_begin(u32 slot) {
- if ((i64) (u64) slot >= _profiler_num_slots)
+ if ((i64) (u64) slot >= _profiler_num_slots && slot == PROFILE_MEMORY)
return;
+ if ((i64) (u64) slot >= _profiler_num_slots) {
+ LOG_ERROR("Invalid slot: %d", (i32) slot);
+ return;
+ }
+
if (_profiler_slots[slot].count < 0) {
LOG_ERROR("Sanity");
return;
@@ -3533,6 +3544,7 @@ i32 handle_main_window_events(void) {
.num = !!(ev.xkey.state & Mod2Mask),
.scroll = !!(ev.xkey.state & Mod3Mask),
.meta = !!(ev.xkey.state & Mod4Mask),
+ .repeat = _key_repeat[k],
.key = k,
.c = 0,
};
@@ -3548,6 +3560,7 @@ i32 handle_main_window_events(void) {
.num = !!(ev.xkey.state & Mod2Mask),
.scroll = !!(ev.xkey.state & Mod3Mask),
.meta = !!(ev.xkey.state & Mod4Mask),
+ .repeat = _key_repeat[k],
.key = k,
.c = utf8_read(len, buf).code,
};
@@ -3566,6 +3579,7 @@ i32 handle_main_window_events(void) {
g_platform.key_down[MOD_CTRL] = !!(ev.xkey.state & ControlMask);
g_platform.key_down[MOD_SHIFT] = !!(ev.xkey.state & ShiftMask);
+ .repeat = ,
g_platform.key_down[MOD_ALT] = !!(ev.xkey.state & Mod1Mask);
g_platform.key_down[MOD_CAPS] = !!(ev.xkey.state & LockMask);
g_platform.key_down[MOD_NUM] = !!(ev.xkey.state & Mod2Mask);
diff --git a/stackless_coroutine.c b/stackless_coroutine.c
index 6efb1c9..cb169e1 100755
--- a/stackless_coroutine.c
+++ b/stackless_coroutine.c
@@ -7,6 +7,8 @@
#/
#/ (C) 2025 Mitya Selivanov <guattari.tech>
#/
+#/ Any use of this code is prohibited.
+#/
#/ ================================================================
#/
#/ Self-testing shell script
@@ -19,6 +21,9 @@ gcc \
-Wno-missing-braces \
-Wno-old-style-declaration \
-Wno-overlength-strings \
+ -Wno-unused-parameter \
+ -Wno-unused-variable \
+ -Wno-unused-but-set-variable \
-O3 -D NDEBUG \
-D STACKLESS_COROUTINE_TEST_SUITE \
-o $BIN $SRC && \
diff --git a/test.c b/test.c
index 9d61923..6d9c4bb 100644
--- a/test.c
+++ b/test.c
@@ -45,6 +45,8 @@
//
// (C) 2025 Mitya Selivanov <guattari.tech>
//
+// Any use of this code is prohibited.
+//
// ================================================================
#if !defined(__wasm__)