Browse Source

Add start of some basic grid stuff

master
cancel 6 years ago
parent
commit
7bbdeddf1c
  1. 2
      Makefile
  2. 42
      main.c

2
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

42
main.c

@ -3,9 +3,51 @@
#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;
int size_y;

Loading…
Cancel
Save