// Copyright (c) 2021 Dominic Masters
// 
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT

#pragma once
#include "../../libs.h"
#include "../../display/primitive.h"
#include "tile.h"

/** When loading a chunk, how many chars to offset (ASCII char to byte) */
#define CHUNK_TILE_LOAD_ASCII 48

/** Width (in tiles) of chunks. */
#define CHUNK_WIDTH 16
/** Height (in tiles) of chunks. */
#define CHUNK_HEIGHT 16
/** Depth (in tiles) of chunks. */
#define CHUNK_DEPTH 8
/** Count of tiles in the chunk. */
#define CHUNK_TILE_COUNT CHUNK_WIDTH * CHUNK_HEIGHT * CHUNK_DEPTH

/** Representation of a chunk, a group of tiles that can be buffered around. */
typedef struct {
  /** Position (in absolute chunk coordinates) of this chunk */
  int32_t x, y, z;
  
  /** Array of tiles within the chunk */
  tileid_t tiles[CHUNK_TILE_COUNT];

  /** Ready to be rendered chunk 3d primitive */
  primitive_t *primitive;
} chunk_t;