moved tile_repr() to tile_renderer
authormatthew <matthew@owens.tech>
Tue, 7 Aug 2018 17:34:17 +0000 (17:34 +0000)
committermatthew <matthew@owens.tech>
Tue, 7 Aug 2018 17:34:17 +0000 (17:34 +0000)
common/tile.c
common/tile.h
nogl/tile_renderer.c [new file with mode: 0644]
nogl/tile_renderer.h [new file with mode: 0644]

index fdf1e43..1e2a950 100644 (file)
@@ -1,4 +1,5 @@
 #include "tile.h"
+#include "err.h"
 #include <stdlib.h>
 #include <stdio.h>
 #include <stdbool.h>
@@ -11,12 +12,12 @@ typedef struct
        enum Terrain terrain;
 } Tile_t;
 
-static const char repr[] = {'X', '.', '^', '\'', '~', '#', '*', '|', '0'};
 
 Tile *tile_init(Point3i pos, enum Terrain ter)
 {
        Tile_t *t = malloc(sizeof(Tile_t));
        bool clamped = false;
+       char msg[80];
 
        t->position = pos;
        t->terrain = ter;
@@ -28,8 +29,8 @@ Tile *tile_init(Point3i pos, enum Terrain ter)
                t->position.z = 9;
        }
        if(clamped == true){
-               //TODO: err output
-               //fprintf(stderr, CLAMPERR, t->position.z);
+               sprintf(msg, CLAMPERR, t->position.z);
+               err_output(msg);
        }
 
        return (Tile *) t;
index 943c9be..89241f6 100644 (file)
@@ -8,7 +8,6 @@ enum Terrain{
        MOUNTAIN,
        S_WATER,
        D_WATER,
-       WALL,
        FLOOR,
        ROAD,
        LAST
@@ -21,7 +20,4 @@ Tile *tile_init(Point3i pos, enum Terrain ter);
 void tile_cleanup(Tile *t);
 Point3i tile_position(Tile *t);
 enum Terrain tile_terrain(Tile *t);
-
-// TODO: move to nogl output c file
-char tile_repr(enum Terrain t);
 #endif//TILE_H
diff --git a/nogl/tile_renderer.c b/nogl/tile_renderer.c
new file mode 100644 (file)
index 0000000..19fcdfe
--- /dev/null
@@ -0,0 +1,27 @@
+#include "tile_renderer.h"
+#include "board.h"
+
+static Board *b = NULL;
+static const char repr[] = {'X', '.', '^', '\'', '~', '*', '|', '0'};
+const static char col_repr = '#';
+const static char air_repr = ' ';
+const static char unk_repr = '?';
+
+char trndr_repr(Tile *t, int dlayer)
+{
+       if(b == NULL || t == NULL)
+               return unk_repr;
+
+       int tlayer = tile_position(t).z;
+       int terrain;
+
+       if(t < 0; || t > LAST){
+               return unk_repr;
+       } else {
+               if(tlayer < dlayer) { return col_repr; }
+               else if(tlayer > dlayer) { return air_repr; }
+               else return repr[tile_terrain(t)];
+       }
+}
+
+void trendr_set_board(Board *board) { b = board; }
diff --git a/nogl/tile_renderer.h b/nogl/tile_renderer.h
new file mode 100644 (file)
index 0000000..3d685e8
--- /dev/null
@@ -0,0 +1,7 @@
+#ifndef TILE_RENDERER
+#define TILE_RENDERER
+#include "tile.h"
+
+char trndr_repr(enum Terrain t, int layer);
+void trenr_set_board(Board *board);
+#endif//TILE_RENDERER