From: matthew Date: Sat, 4 Aug 2018 14:03:26 +0000 (+0100) Subject: implemented clamping for tile's z coord to prevent output errors in nogl build X-Git-Url: https://git.owens.tech/assets/static/gitweb.js/assets/static/gitweb.js/git?a=commitdiff_plain;h=4de3366e51e74fb8a22e41525d16b5089f515b43;p=csrpg.git implemented clamping for tile's z coord to prevent output errors in nogl build --- diff --git a/common/tile.c b/common/tile.c index 4833414..fdf1e43 100644 --- a/common/tile.c +++ b/common/tile.c @@ -1,5 +1,9 @@ #include "tile.h" #include +#include +#include + +#define CLAMPERR "Tile init error! z-coord must be 0-9, clamping to %d\n" typedef struct { @@ -12,8 +16,22 @@ static const char repr[] = {'X', '.', '^', '\'', '~', '#', '*', '|', '0'}; Tile *tile_init(Point3i pos, enum Terrain ter) { Tile_t *t = malloc(sizeof(Tile_t)); + bool clamped = false; + t->position = pos; t->terrain = ter; + if(pos.z < 0){ + clamped = true; + t->position.z = 0; + } else if (pos.z > 9) { + clamped = true; + t->position.z = 9; + } + if(clamped == true){ + //TODO: err output + //fprintf(stderr, CLAMPERR, t->position.z); + } + return (Tile *) t; }