Browse Source

Add field peek/poke

master
cancel 6 years ago
parent
commit
2bc7dc2837
  1. 16
      field.c
  2. 2
      field.h

16
field.c

@ -112,6 +112,22 @@ void field_fill_subrect(Field* f, U32 y, U32 x, U32 height, U32 width,
} }
} }
Term field_peek(Field* f, U32 y, U32 x) {
size_t f_height = f->height;
size_t f_width = f->width;
assert(y < f_height && x < f_width);
if (y >= f_height || x >= f_width) return '\0';
return f->buffer[y * f_width + x];
}
void field_poke(Field* f, U32 y, U32 x, Term term) {
size_t f_height = f->height;
size_t f_width = f->width;
assert(y < f_height && x < f_width);
if (y >= f_height || x >= f_width) return;
f->buffer[y * f_width + x] = term;
}
void field_debug_draw(Field* f, int offset_y, int offset_x) { void field_debug_draw(Field* f, int offset_y, int offset_x) {
enum { Line_buffer_count = 4096 }; enum { Line_buffer_count = 4096 };
chtype line_buffer[Line_buffer_count]; chtype line_buffer[Line_buffer_count];

2
field.h

@ -15,4 +15,6 @@ void field_copy_subrect(Field* src, Field* dest, U32 src_y, U32 src_x,
U32 dest_y, U32 dest_x, U32 height, U32 width); U32 dest_y, U32 dest_x, U32 height, U32 width);
void field_fill_subrect(Field* f, U32 y, U32 x, U32 height, U32 width, void field_fill_subrect(Field* f, U32 y, U32 x, U32 height, U32 width,
Term fill_char); Term fill_char);
Term field_peek(Field* f, U32 y, U32 x);
void field_poke(Field* f, U32 y, U32 x, Term term);
void field_debug_draw(Field* f, int offset_y, int offset_x); void field_debug_draw(Field* f, int offset_y, int offset_x);

Loading…
Cancel
Save