implemented clamping for tile's z coord to prevent output errors in nogl build
authormatthew <matthew@owens.tech>
Sat, 4 Aug 2018 14:03:26 +0000 (15:03 +0100)
committermatthew <matthew@owens.tech>
Sat, 4 Aug 2018 14:03:26 +0000 (15:03 +0100)
common/tile.c

index 4833414..fdf1e43 100644 (file)
@@ -1,5 +1,9 @@
 #include "tile.h"
 #include <stdlib.h>
+#include <stdio.h>
+#include <stdbool.h>
+
+#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;
 }