diff --git a/gbuffer.c b/gbuffer.c index 43344c7..639ab13 100644 --- a/gbuffer.c +++ b/gbuffer.c @@ -73,3 +73,8 @@ void gbuffer_fill_subrect(Glyph* gbuffer, Usz f_height, Usz f_width, Usz y, p += f_width; } } + +void mbuffer_clear(Mark* mbuf, Usz height, Usz width) { + Usz cleared_size = height * width; + memset(mbuf, 0, cleared_size); +} diff --git a/gbuffer.h b/gbuffer.h index 1b6b89c..694d445 100644 --- a/gbuffer.h +++ b/gbuffer.h @@ -44,3 +44,49 @@ void gbuffer_copy_subrect(Glyph* src, Glyph* dest, Usz src_grid_h, ORCA_FORCE_NO_INLINE void gbuffer_fill_subrect(Glyph* gbuf, Usz grid_h, Usz grid_w, Usz y, Usz x, Usz height, Usz width, Glyph fill_char); + +typedef enum { + Mark_flag_none = 0, + Mark_flag_input = 1 << 0, + Mark_flag_output = 1 << 1, + Mark_flag_haste_input = 1 << 2, + Mark_flag_lock = 1 << 3, + Mark_flag_sleep = 1 << 4, +} Mark_flags; + +ORCA_OK_IF_UNUSED +static Mark_flags mbuffer_peek(Mark* mbuf, Usz height, Usz width, Usz y, + Usz x) { + (void)height; + return mbuf[y * width + x]; +} + +ORCA_OK_IF_UNUSED +static Mark_flags mbuffer_peek_relative(Mark* mbuf, Usz height, Usz width, + Usz y, Usz x, Isz offs_y, Isz offs_x) { + Isz y0 = (Isz)y + offs_y; + Isz x0 = (Isz)x + offs_x; + if (y0 >= (Isz)height || x0 >= (Isz)width || y0 < 0 || x0 < 0) + return Mark_flag_none; + return mbuf[(Usz)y0 * width + (Usz)x0]; +} + +ORCA_OK_IF_UNUSED +static void mbuffer_poke_flags_or(Mark* mbuf, Usz height, Usz width, Usz y, + Usz x, Mark_flags flags) { + (void)height; + mbuf[y * width + x] |= (Mark)flags; +} + +ORCA_OK_IF_UNUSED +static void mbuffer_poke_relative_flags_or(Mark* mbuf, Usz height, Usz width, + Usz y, Usz x, Isz offs_y, Isz offs_x, + Mark_flags flags) { + Isz y0 = (Isz)y + offs_y; + Isz x0 = (Isz)x + offs_x; + if (y0 >= (Isz)height || x0 >= (Isz)width || y0 < 0 || x0 < 0) + return; + mbuf[(Usz)y0 * width + (Usz)x0] |= (Mark)flags; +} + +void mbuffer_clear(Mark* mbuf, Usz height, Usz width); diff --git a/mark.c b/mark.c index eca1612..d06e6fc 100644 --- a/mark.c +++ b/mark.c @@ -14,8 +14,3 @@ void mbuf_reusable_ensure_size(Mbuf_reusable* mbr, Usz height, Usz width) { } void mbuf_reusable_deinit(Mbuf_reusable* mbr) { free(mbr->buffer); } - -void mbuffer_clear(Mark* mbuf, Usz height, Usz width) { - Usz cleared_size = height * width; - memset(mbuf, 0, cleared_size); -} diff --git a/mark.h b/mark.h index a456bf5..ba58724 100644 --- a/mark.h +++ b/mark.h @@ -1,15 +1,6 @@ #pragma once #include "base.h" -typedef enum { - Mark_flag_none = 0, - Mark_flag_input = 1 << 0, - Mark_flag_output = 1 << 1, - Mark_flag_haste_input = 1 << 2, - Mark_flag_lock = 1 << 3, - Mark_flag_sleep = 1 << 4, -} Mark_flags; - typedef struct Mbuf_reusable { Mark* buffer; Usz capacity; @@ -18,55 +9,3 @@ typedef struct Mbuf_reusable { void mbuf_reusable_init(Mbuf_reusable* mbr); void mbuf_reusable_ensure_size(Mbuf_reusable* mbr, Usz height, Usz width); void mbuf_reusable_deinit(Mbuf_reusable* mbr); - -void mbuffer_clear(Mark* mbuf, Usz height, Usz width); - -ORCA_OK_IF_UNUSED -static Mark_flags mbuffer_peek(Mark* mbuf, Usz height, Usz width, Usz y, Usz x); -ORCA_OK_IF_UNUSED -static Mark_flags mbuffer_peek_relative(Mark* mbuf, Usz height, Usz width, - Usz y, Usz x, Isz offs_y, Isz offs_x); -ORCA_OK_IF_UNUSED -static void mbuffer_poke_flags_or(Mark* mbuf, Usz height, Usz width, Usz y, - Usz x, Mark_flags flags); -ORCA_OK_IF_UNUSED -static void mbuffer_poke_relative_flags_or(Mark* mbuf, Usz height, Usz width, - Usz y, Usz x, Isz offs_y, Isz offs_x, - Mark_flags flags); - -// Inline implementation - -ORCA_OK_IF_UNUSED -static Mark_flags mbuffer_peek(Mark* mbuf, Usz height, Usz width, Usz y, - Usz x) { - (void)height; - return mbuf[y * width + x]; -} - -ORCA_OK_IF_UNUSED -static Mark_flags mbuffer_peek_relative(Mark* mbuf, Usz height, Usz width, - Usz y, Usz x, Isz offs_y, Isz offs_x) { - Isz y0 = (Isz)y + offs_y; - Isz x0 = (Isz)x + offs_x; - if (y0 >= (Isz)height || x0 >= (Isz)width || y0 < 0 || x0 < 0) - return Mark_flag_none; - return mbuf[(Usz)y0 * width + (Usz)x0]; -} - -ORCA_OK_IF_UNUSED -static void mbuffer_poke_flags_or(Mark* mbuf, Usz height, Usz width, Usz y, - Usz x, Mark_flags flags) { - (void)height; - mbuf[y * width + x] |= (Mark)flags; -} - -ORCA_OK_IF_UNUSED -static void mbuffer_poke_relative_flags_or(Mark* mbuf, Usz height, Usz width, - Usz y, Usz x, Isz offs_y, Isz offs_x, - Mark_flags flags) { - Isz y0 = (Isz)y + offs_y; - Isz x0 = (Isz)x + offs_x; - if (y0 >= (Isz)height || x0 >= (Isz)width || y0 < 0 || x0 < 0) - return; - mbuf[(Usz)y0 * width + (Usz)x0] |= (Mark)flags; -} diff --git a/sim.c b/sim.c index b9b5b8e..77e9ea1 100644 --- a/sim.c +++ b/sim.c @@ -1,6 +1,5 @@ #include "sim.h" #include "gbuffer.h" -#include "mark.h" //////// Utilities