ref: 7bbdeddf1ccd100126dd0baffe905408cc50a906
parent: dfc5a075e578c21a6700ff8bfeffe726d5600012
author: cancel <cancel@cancel.fm>
date: Sat Nov 24 19:31:03 EST 2018
Add start of some basic grid stuff
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,4 @@
-basic_flags := -std=c99 -Wall -Wpedantic -Wextra -pipe
+basic_flags := -std=c99 -pipe -Wall -Wpedantic -Wextra -Werror=implicit-function-declaration
debug_flags := -DDEBUG -O0 -ggdb -feliminate-unused-debug-symbols
release_flags := -DNDEBUG -O2 -s -D_FORTIFY_SOURCE=2 -fstack-protector-strong -fpie -Wl,-pie
library_flags := -lncurses
--- a/main.c
+++ b/main.c
@@ -3,8 +3,50 @@
#include <locale.h>
#include <ncurses.h>
#include <stdbool.h>
+#include <stdint.h>
#include <stdlib.h>
+#include <string.h>
#include <unistd.h>
+
+typedef char Term;
+typedef uint32_t U32;
+typedef int32_t I32;
+
+typedef struct {
+ Term* buffer;
+ U32 height;
+ U32 width;
+} Field;
+
+void field_init_zero(Field* f, U32 height, U32 width) {
+ size_t num_cells = height * width;
+ f->buffer = calloc(num_cells, sizeof(Term));
+ f->height = height;
+ f->width = width;
+}
+
+void field_init_fill(Field* f, U32 height, U32 width, Term fill_char) {
+ size_t num_cells = height * width;
+ f->buffer = malloc(num_cells * sizeof(Term));
+ memset(f->buffer, fill_char, num_cells);
+ f->height = height;
+ f->width = width;
+}
+
+void field_realloc(Field* f, U32 height, U32 width) {
+ size_t cells = height * width;
+ f->buffer = realloc(f->buffer, cells * sizeof(Term));
+ f->height = height;
+ f->width = width;
+}
+
+void field_deinit(Field* f) {
+ assert(f->buffer != NULL);
+ free(f->buffer);
+#ifndef NDEBUG
+ f->buffer = NULL;
+#endif
+}
typedef struct {
chtype* buffer;