/*____________________________________________________________________________
TILE engine
by Martin Robinson
collection of function and macro that simplify and boost tile based engine
______________________________________________________________________________
todo:
    pathfinding
    serialization
______________________________________________________________________________
game:
    tetris
    sort of rpg roguelike
    onomatopeiaous game
    three little bear
    sand game
preprocessor________________________________________________________________*/

#pragma once
#ifndef _TILE
#define _TILE

/*2D ARRAY____________________________________________________________________
pair of coordinate cant be blobed in a 
single index that match it's position
in a single dimension array. 
Can be considered as 2d vector in an integer________________________________*/
#ifdef W
    #define index(COL,ROW)  (COL+ROW*W)
    #define col(INDEX)      (index%W)
    #define row(INDEX)      (index/W)
#else
    #define index(COL,ROW,W)  (COL+ROW*W)
    #define col(INDEX,W)      (index%W)
    #define row(INDEX,W)      (index/W)
#endif

/*NEIGHBOR____________________________________________________________________
pathfinding and some other recursive algo
will appreciate have some left/right/up/down macro
and some control is welcomed________________________________________________*/
#ifdef W
    #define haveUp(INDEX) (INDEX>W-1)
    #ifdef H
        #define haveDown(INDEX) (INDEX<W*H-W)
    #else
        #define haveDown(INDEX,H) (INDEX<W*H-W)
    #endif
    #define haveLeft(INDEX) (INDEX%W>0)
    #define haveRight(INDEX) (INDEX>W-1)
    #define up(INDEX) (INDEX-W)
    #define down(INDEX) (INDEX+W)
    #define left(INDEX) (INDEX-1)
    #define right(INDEX) (INDEX+1)
#else
    #define haveUp(INDEX,W,H) (INDEX>W-1)
    #define haveDown(INDEX,W,H) (INDEX<W*H-W)
    #define haveLeft(INDEX,W,H) (INDEX%W>0)
    #define haveRight(INDEX,W,H) (INDEX%W<W-1)
    #define up(INDEX,W,H) (INDEX-W)
    #define down(INDEX,W,H) (INDEX+W)
    #define left(INDEX,W,H) (INDEX-1)
    #define right(INDEX,W,H) (INDEX+1)
#endif

/*WINDOWS_SYSTEM______________________________________________________________
only a feature that allow to capture a portion of the tile array instead of
whole, a simple traduction of x,y,w,h rectangle in a bigger array
____________________________________________________________________________*/

/*ENGINE_design_______________________________________________________________
on a big array, by value of the cell you can determine if the cell can move
(there is permutation involved by setting new cell and reseting old one)
the drawback is that you need to scan all the array for any movable cell
that is why we need a dual stack swap
____________________________________________________________________________*/



#endif


