From 2bc7dc2837fe5c85f835cb813484765d0091d84c Mon Sep 17 00:00:00 2001 From: cancel Date: Sun, 25 Nov 2018 03:43:13 +0900 Subject: [PATCH] Add field peek/poke --- field.c | 16 ++++++++++++++++ field.h | 2 ++ 2 files changed, 18 insertions(+) diff --git a/field.c b/field.c index 5257b82..47342d5 100644 --- a/field.c +++ b/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) { enum { Line_buffer_count = 4096 }; chtype line_buffer[Line_buffer_count]; diff --git a/field.h b/field.h index 07b8c9a..7a7a5dd 100644 --- a/field.h +++ b/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); 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);