shithub: orca

Download patch

ref: 2bc7dc2837fe5c85f835cb813484765d0091d84c
parent: 433de277b359edb9e43120ab1532601233c530a1
author: cancel <cancel@cancel.fm>
date: Sat Nov 24 22:43:13 EST 2018

Add field peek/poke

--- a/field.c
+++ b/field.c
@@ -112,6 +112,22 @@
   }
 }
 
+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) {
   enum { Line_buffer_count = 4096 };
   chtype line_buffer[Line_buffer_count];
--- a/field.h
+++ b/field.h
@@ -15,4 +15,6 @@
                         U32 dest_y, U32 dest_x, U32 height, U32 width);
 void field_fill_subrect(Field* f, U32 y, U32 x, U32 height, U32 width,
                         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);