Browse Source

Move mbuffer_* functions out of mark.h to gbuffer.h

They are more similar to the stuff in gbuffer.h. If you want what's in
gbuffer.h, you also probably want the mbuffer_* stuff.
master
cancel 5 years ago
parent
commit
7cd10dd0bf
  1. 5
      gbuffer.c
  2. 46
      gbuffer.h
  3. 5
      mark.c
  4. 61
      mark.h
  5. 1
      sim.c

5
gbuffer.c

@ -73,3 +73,8 @@ void gbuffer_fill_subrect(Glyph* gbuffer, Usz f_height, Usz f_width, Usz y,
p += f_width; p += f_width;
} }
} }
void mbuffer_clear(Mark* mbuf, Usz height, Usz width) {
Usz cleared_size = height * width;
memset(mbuf, 0, cleared_size);
}

46
gbuffer.h

@ -44,3 +44,49 @@ void gbuffer_copy_subrect(Glyph* src, Glyph* dest, Usz src_grid_h,
ORCA_FORCE_NO_INLINE ORCA_FORCE_NO_INLINE
void gbuffer_fill_subrect(Glyph* gbuf, Usz grid_h, Usz grid_w, Usz y, Usz x, void gbuffer_fill_subrect(Glyph* gbuf, Usz grid_h, Usz grid_w, Usz y, Usz x,
Usz height, Usz width, Glyph fill_char); 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);

5
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 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);
}

61
mark.h

@ -1,15 +1,6 @@
#pragma once #pragma once
#include "base.h" #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 { typedef struct Mbuf_reusable {
Mark* buffer; Mark* buffer;
Usz capacity; Usz capacity;
@ -18,55 +9,3 @@ typedef struct Mbuf_reusable {
void mbuf_reusable_init(Mbuf_reusable* mbr); void mbuf_reusable_init(Mbuf_reusable* mbr);
void mbuf_reusable_ensure_size(Mbuf_reusable* mbr, Usz height, Usz width); void mbuf_reusable_ensure_size(Mbuf_reusable* mbr, Usz height, Usz width);
void mbuf_reusable_deinit(Mbuf_reusable* mbr); 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;
}

1
sim.c

@ -1,6 +1,5 @@
#include "sim.h" #include "sim.h"
#include "gbuffer.h" #include "gbuffer.h"
#include "mark.h"
//////// Utilities //////// Utilities

Loading…
Cancel
Save