Skip to content

Instantly share code, notes, and snippets.

@eddietree
Created December 3, 2013 06:53
Show Gist options
  • Save eddietree/7764967 to your computer and use it in GitHub Desktop.
Save eddietree/7764967 to your computer and use it in GitHub Desktop.
auto-tiling done manually!!! #sigh
void TileBlocksManager::UpdateGridPos( funk::v2i a_grid_pos )
{
const uint32_t neighbor_mask = GetTileBlockNeighborMask( a_grid_pos );
v2i silhouette_tilesheet_grid_pos = v2i(-1);
switch( neighbor_mask )
{
// right nub
case TB_L:
case TB_L | TB_TL:
case TB_L | TB_BL:
case TB_L | TB_TL | TB_BL:
case TB_L | TB_TL | TB_BL | TB_TR:
case TB_L | TB_TL | TB_BL | TB_BR:
case TB_L | TB_TL | TB_BL | TB_BR | TB_TR:
case TB_L | TB_TR:
case TB_L | TB_BR:
case TB_L | TB_BR | TB_TR:
case TB_L | TB_TL | TB_TR:
case TB_L | TB_TL | TB_BR:
case TB_L | TB_TL | TB_BR | TB_TR:
case TB_L | TB_BL | TB_TR:
case TB_L | TB_BL | TB_BR:
case TB_L | TB_BL | TB_BR | TB_TR:
silhouette_tilesheet_grid_pos = v2i(3,4);
break;
// left nub
case TB_R:
case TB_R | TB_TR:
case TB_R | TB_BR:
case TB_R | TB_TR | TB_BR:
case TB_R | TB_TR | TB_BR | TB_TL:
case TB_R | TB_TR | TB_BR | TB_BL:
case TB_R | TB_TR | TB_BR | TB_BL | TB_TL:
case TB_R | TB_TL:
case TB_R | TB_BL:
case TB_R | TB_BL | TB_TL:
case TB_R | TB_TR | TB_TL:
case TB_R | TB_TR | TB_BL:
case TB_R | TB_TR | TB_BL | TB_TL:
case TB_R | TB_BR | TB_TL:
case TB_R | TB_BR | TB_BL:
case TB_R | TB_BR | TB_BL | TB_TL:
silhouette_tilesheet_grid_pos = v2i(3,6);
break;
// bottom nub
case TB_T:
case TB_T | TB_BL:
case TB_T | TB_BR:
case TB_T | TB_BL | TB_BR:
case TB_T | TB_TL:
case TB_T | TB_TL | TB_BL:
case TB_T | TB_TL | TB_BR:
case TB_T | TB_TL | TB_BL | TB_BR:
case TB_T | TB_TR:
case TB_T | TB_TR | TB_BL:
case TB_T | TB_TR | TB_BR:
case TB_T | TB_TR | TB_BL | TB_BR:
case TB_T | TB_TL | TB_TR:
case TB_T | TB_TL | TB_TR | TB_BL:
case TB_T | TB_TL | TB_TR | TB_BR:
case TB_T | TB_TL | TB_TR | TB_BL | TB_BR:
silhouette_tilesheet_grid_pos = v2i(3,7);
break;
// top nub
case TB_B:
case TB_B | TB_TL:
case TB_B | TB_TR:
case TB_B | TB_TL | TB_TR:
case TB_B | TB_BL:
case TB_B | TB_BL | TB_TL:
case TB_B | TB_BL | TB_TR:
case TB_B | TB_BL | TB_TL | TB_TR:
case TB_B | TB_BR:
case TB_B | TB_BR | TB_TL:
case TB_B | TB_BR | TB_TR:
case TB_B | TB_BR | TB_TL | TB_TR:
case TB_B | TB_BL | TB_BR:
case TB_B | TB_BL | TB_BR | TB_TL:
case TB_B | TB_BL | TB_BR | TB_TR:
case TB_B | TB_BL | TB_BR | TB_TL | TB_TR:
silhouette_tilesheet_grid_pos = v2i(3,5);
break;
// straight line - horiz
case TB_L | TB_R:
case TB_L | TB_R | TB_TL:
case TB_L | TB_R | TB_TR:
case TB_L | TB_R | TB_BL:
case TB_L | TB_R | TB_BR:
case TB_L | TB_R | TB_TL | TB_TR:
case TB_L | TB_R | TB_TL | TB_BL:
case TB_L | TB_R | TB_TL | TB_BR:
case TB_L | TB_R | TB_TR | TB_BL:
case TB_L | TB_R | TB_TR | TB_BR:
case TB_L | TB_R | TB_BL | TB_BR:
case TB_L | TB_R | TB_TL | TB_TR | TB_BL:
case TB_L | TB_R | TB_TL | TB_TR | TB_BR:
case TB_L | TB_R | TB_BL | TB_BR | TB_TL:
case TB_L | TB_R | TB_BL | TB_BR | TB_TR:
case TB_L | TB_R | TB_BL | TB_BR | TB_TR | TB_TL:
silhouette_tilesheet_grid_pos = v2i(2,7);
break;
// straight line - vertical
case TB_T | TB_B:
case TB_T | TB_B | TB_TL:
case TB_T | TB_B | TB_TR:
case TB_T | TB_B | TB_BL:
case TB_T | TB_B | TB_BR:
case TB_T | TB_B | TB_TL | TB_TR:
case TB_T | TB_B | TB_TL | TB_BL:
case TB_T | TB_B | TB_TL | TB_BR:
case TB_T | TB_B | TB_TR | TB_BL:
case TB_T | TB_B | TB_TR | TB_BR:
case TB_T | TB_B | TB_BL | TB_BR:
case TB_T | TB_B | TB_TL | TB_TR | TB_BL:
case TB_T | TB_B | TB_TL | TB_TR | TB_BR:
case TB_T | TB_B | TB_BL | TB_BR | TB_TL:
case TB_T | TB_B | TB_BL | TB_BR | TB_TR:
case TB_T | TB_B | TB_BL | TB_BR | TB_TR | TB_TL:
silhouette_tilesheet_grid_pos = v2i(2,6);
break;
// botton-right gap
case TB_TL | TB_T | TB_TR | TB_R | TB_L | TB_BL | TB_B:
silhouette_tilesheet_grid_pos = v2i(4,5);
break;
// botton-left gap
case TB_TR | TB_T | TB_TL | TB_L | TB_R | TB_BR | TB_B:
silhouette_tilesheet_grid_pos = v2i(4,4);
break;
// top-left gap
case TB_BR | TB_B | TB_BL | TB_T | TB_R | TB_TR | TB_L:
silhouette_tilesheet_grid_pos = v2i(4,7);
break;
// top-right gap
case TB_BL | TB_B | TB_BR | TB_TL | TB_L | TB_T | TB_R:
silhouette_tilesheet_grid_pos = v2i(4,6);
break;
// bottom-right top empty
case TB_L | TB_R | TB_B | TB_BL:
case TB_L | TB_R | TB_B | TB_BL | TB_TL:
case TB_L | TB_R | TB_B | TB_BL | TB_TR:
case TB_L | TB_R | TB_B | TB_BL | TB_TL | TB_TR:
silhouette_tilesheet_grid_pos = v2i(6,4);
break;
// bottom-left top empty
case TB_L | TB_R | TB_B | TB_BR:
case TB_L | TB_R | TB_B | TB_BR | TB_TL:
case TB_L | TB_R | TB_B | TB_BR | TB_TR:
case TB_L | TB_R | TB_B | TB_BR | TB_TL | TB_TR:
silhouette_tilesheet_grid_pos = v2i(5,4);
break;
// top-left bottom empty
case TB_L | TB_R | TB_T | TB_TR:
case TB_L | TB_R | TB_T | TB_TR | TB_BL:
case TB_L | TB_R | TB_T | TB_TR | TB_BR:
case TB_L | TB_R | TB_T | TB_TR | TB_BL | TB_BR:
silhouette_tilesheet_grid_pos = v2i(6,6);
break;
// top-right bottom empty
case TB_L | TB_R | TB_T | TB_TL:
case TB_L | TB_R | TB_T | TB_TL | TB_BL:
case TB_L | TB_R | TB_T | TB_TL | TB_BR:
case TB_L | TB_R | TB_T | TB_TL | TB_BL | TB_BR:
silhouette_tilesheet_grid_pos = v2i(5,6);
break;
// top-right left empty
case TB_T | TB_B | TB_R | TB_BR:
case TB_T | TB_B | TB_R | TB_BR | TB_TL:
case TB_T | TB_B | TB_R | TB_BR | TB_BL:
case TB_T | TB_B | TB_R | TB_BR | TB_TL | TB_BL:
silhouette_tilesheet_grid_pos = v2i(6,5);
break;
// bottom-right left empty
case TB_T | TB_B | TB_R | TB_TR:
case TB_T | TB_B | TB_R | TB_TR | TB_TL:
case TB_T | TB_B | TB_R | TB_TR | TB_BL:
case TB_T | TB_B | TB_R | TB_TR | TB_TL | TB_BL:
silhouette_tilesheet_grid_pos = v2i(5,5);
break;
// bottom-left right empty
case TB_T | TB_B | TB_L | TB_TL:
case TB_T | TB_B | TB_L | TB_TL | TB_TR:
case TB_T | TB_B | TB_L | TB_TL | TB_BR:
case TB_T | TB_B | TB_L | TB_TL | TB_TR | TB_BR:
silhouette_tilesheet_grid_pos = v2i(6,7);
break;
// top-left right empty
case TB_T | TB_B | TB_L | TB_BL:
case TB_T | TB_B | TB_L | TB_BL | TB_TR:
case TB_T | TB_B | TB_L | TB_BL | TB_BR:
case TB_T | TB_B | TB_L | TB_BL | TB_TR | TB_BR:
silhouette_tilesheet_grid_pos = v2i(5,7);
break;
// all alone
case TB_EMPTY:
case TB_BL:
case TB_BR:
case TB_TL:
case TB_TR:
case TB_TL | TB_TR:
case TB_TL | TB_BR:
case TB_TL | TB_BL:
case TB_TR | TB_BL:
case TB_TR | TB_BR:
case TB_BR | TB_BL:
case TB_TL | TB_TR | TB_BL:
case TB_TL | TB_TR | TB_BR:
case TB_BL | TB_TR | TB_BR:
case TB_TL | TB_BL | TB_BR:
case TB_TL | TB_TR | TB_BL | TB_BR:
{
// randomly choose between 4
v2i single_tiles[4] = { v2i(7,7), v2i(7,6), v2i(7,5), v2i(7,4) };
uint32_t index = ( a_grid_pos.x % 2 ) | ( ( a_grid_pos.y % 2 ) << 1 );
silhouette_tilesheet_grid_pos = single_tiles[index];
break;
}
// cross
case TB_L | TB_R | TB_T | TB_B:
silhouette_tilesheet_grid_pos = v2i(0,3);
break;
// bottom-left L
case TB_L | TB_B:
case TB_L | TB_B | TB_TL:
case TB_L | TB_B | TB_TR:
case TB_L | TB_B | TB_BR:
case TB_L | TB_B | TB_TL | TB_TR:
case TB_L | TB_B | TB_TL | TB_BR:
case TB_L | TB_B | TB_TR | TB_BR:
case TB_L | TB_B | TB_TL | TB_TR | TB_BR:
silhouette_tilesheet_grid_pos = v2i(1,3);
break;
// bottom-right L
case TB_R | TB_B:
case TB_R | TB_B | TB_TL:
case TB_R | TB_B | TB_TR:
case TB_R | TB_B | TB_BL:
case TB_R | TB_B | TB_TL | TB_TR:
case TB_R | TB_B | TB_TL | TB_BL:
case TB_R | TB_B | TB_TR | TB_BL:
case TB_R | TB_B | TB_TL | TB_TR | TB_BL:
silhouette_tilesheet_grid_pos = v2i(1,0);
break;
// top-left L
case TB_L | TB_T:
case TB_L | TB_T | TB_BL:
case TB_L | TB_T | TB_TR:
case TB_L | TB_T | TB_BR:
case TB_L | TB_T | TB_BL | TB_TR:
case TB_L | TB_T | TB_BL | TB_BR:
case TB_L | TB_T | TB_TR | TB_BR:
case TB_L | TB_T | TB_BL | TB_TR | TB_BR:
silhouette_tilesheet_grid_pos = v2i(1,2);
break;
// top-right L
case TB_R | TB_T:
case TB_R | TB_T | TB_TL:
case TB_R | TB_T | TB_BR:
case TB_R | TB_T | TB_BL:
case TB_R | TB_T | TB_TL | TB_BR:
case TB_R | TB_T | TB_TL | TB_BL:
case TB_R | TB_T | TB_BR | TB_BL:
case TB_R | TB_T | TB_TL | TB_BR | TB_BL:
silhouette_tilesheet_grid_pos = v2i(1,1);
break;
// left T
case TB_L | TB_T | TB_B:
case TB_L | TB_T | TB_B | TB_TR:
case TB_L | TB_T | TB_B | TB_BR:
case TB_L | TB_T | TB_B | TB_TR | TB_BR:
silhouette_tilesheet_grid_pos = v2i(2,3);
break;
// right T
case TB_R | TB_T | TB_B:
case TB_R | TB_T | TB_B | TB_TL:
case TB_R | TB_T | TB_B | TB_BL:
case TB_R | TB_T | TB_B | TB_TL | TB_BL:
silhouette_tilesheet_grid_pos = v2i(2,1);
break;
// top T
case TB_T | TB_L | TB_R:
case TB_T | TB_L | TB_R | TB_BL:
case TB_T | TB_L | TB_R | TB_BR:
case TB_T | TB_L | TB_R | TB_BL | TB_BR:
silhouette_tilesheet_grid_pos = v2i(2,2);
break;
// bottom T
case TB_B | TB_L | TB_R:
case TB_B | TB_L | TB_R | TB_TL:
case TB_B | TB_L | TB_R | TB_TR:
case TB_B | TB_L | TB_R | TB_TL | TB_TR:
silhouette_tilesheet_grid_pos = v2i(2,0);
break;
// left full-T
case TB_R | TB_T | TB_B | TB_L | TB_TR | TB_BR:
silhouette_tilesheet_grid_pos = v2i(4,2);
break;
// right full-T
case TB_R | TB_T | TB_B | TB_L | TB_TL | TB_BL:
silhouette_tilesheet_grid_pos = v2i(4,0);
break;
// top full-T
case TB_R | TB_T | TB_B | TB_L | TB_BL | TB_BR:
silhouette_tilesheet_grid_pos = v2i(4,1);
break;
// bottom full-T
case TB_R | TB_T | TB_B | TB_L | TB_TL | TB_TR:
silhouette_tilesheet_grid_pos = v2i(4,3);
break;
// weird TR
case TB_R | TB_T | TB_B | TB_L | TB_BL:
silhouette_tilesheet_grid_pos = v2i(5,3);
break;
// weird TL
case TB_R | TB_T | TB_B | TB_L | TB_BR:
silhouette_tilesheet_grid_pos = v2i(5,0);
break;
// weird BR
case TB_R | TB_T | TB_B | TB_L | TB_TL:
silhouette_tilesheet_grid_pos = v2i(5,2);
break;
// weird BL
case TB_R | TB_T | TB_B | TB_L | TB_TR:
silhouette_tilesheet_grid_pos = v2i(5,1);
break;
// diagonal BL-TR
case TB_L | TB_BL | TB_B | TB_T | TB_TR | TB_R:
silhouette_tilesheet_grid_pos = v2i(3,3);
break;
// diagonal TL-BR
case TB_L | TB_TL | TB_T | TB_R | TB_BR | TB_B:
silhouette_tilesheet_grid_pos = v2i(3,2);
break;
// full
case TB_L | TB_R | TB_T | TB_B | TB_TL | TB_TR | TB_BL | TB_BR:
silhouette_tilesheet_grid_pos = v2i(6,3);
break;
// TODO: if 2x2, matchwith right
// corner - top-left
case TB_B | TB_R | TB_BR:
case TB_B | TB_R | TB_BR | TB_TL:
case TB_B | TB_R | TB_BR | TB_TR:
case TB_B | TB_R | TB_BR | TB_BL:
case TB_B | TB_R | TB_BR | TB_TL | TB_TR:
case TB_B | TB_R | TB_BR | TB_TL | TB_BL:
case TB_B | TB_R | TB_BR | TB_TR | TB_BL:
case TB_B | TB_R | TB_BR | TB_TL | TB_TR | TB_BL:
silhouette_tilesheet_grid_pos = v2i(1,4);
break;
// corner - top-right
case TB_B | TB_L | TB_BL:
case TB_B | TB_L | TB_BL | TB_TR:
case TB_B | TB_L | TB_BL | TB_TL:
case TB_B | TB_L | TB_BL | TB_BR:
case TB_B | TB_L | TB_BL | TB_TR | TB_TL:
case TB_B | TB_L | TB_BL | TB_TR | TB_BR:
case TB_B | TB_L | TB_BL | TB_TL | TB_BR:
case TB_B | TB_L | TB_BL | TB_TR | TB_TL | TB_BR:
silhouette_tilesheet_grid_pos = v2i(1,7);
break;
// corner - bottom-left
case TB_T | TB_R | TB_TR:
case TB_T | TB_R | TB_TR | TB_BL:
case TB_T | TB_R | TB_TR | TB_TL:
case TB_T | TB_R | TB_TR | TB_BR:
case TB_T | TB_R | TB_TR | TB_TL | TB_BR:
case TB_T | TB_R | TB_TR | TB_TL | TB_BL:
case TB_T | TB_R | TB_TR | TB_BR | TB_BL:
case TB_T | TB_R | TB_TR | TB_TL | TB_BR | TB_BL:
silhouette_tilesheet_grid_pos = v2i(1,5);
break;
// corner - bottom-right
case TB_T | TB_L | TB_TL:
case TB_T | TB_L | TB_TL | TB_BR:
case TB_T | TB_L | TB_TL | TB_BL:
case TB_T | TB_L | TB_TL | TB_TR:
case TB_T | TB_L | TB_TL | TB_TR | TB_BL:
case TB_T | TB_L | TB_TL | TB_TR | TB_BR:
case TB_T | TB_L | TB_TL | TB_BL | TB_BR:
case TB_T | TB_L | TB_TL | TB_TR | TB_BL | TB_BR:
silhouette_tilesheet_grid_pos = v2i(1,6);
break;
// top
case TB_L | TB_R | TB_B | TB_BL | TB_BR:
case TB_L | TB_R | TB_B | TB_BL | TB_BR | TB_TL:
case TB_L | TB_R | TB_B | TB_BL | TB_BR | TB_TR:
case TB_L | TB_R | TB_B | TB_BL | TB_BR | TB_TL | TB_TR:
silhouette_tilesheet_grid_pos = v2i(0,7);
break;
// bottom
case TB_L | TB_R | TB_T | TB_TL | TB_TR:
case TB_L | TB_R | TB_T | TB_TL | TB_TR | TB_BL:
case TB_L | TB_R | TB_T | TB_TL | TB_TR | TB_BR:
case TB_L | TB_R | TB_T | TB_TL | TB_TR | TB_BL | TB_BR:
silhouette_tilesheet_grid_pos = v2i(0,5);
break;
// left
case TB_L | TB_T | TB_B | TB_TL | TB_BL:
case TB_L | TB_T | TB_B | TB_TL | TB_BL | TB_TR:
case TB_L | TB_T | TB_B | TB_TL | TB_BL | TB_BR:
case TB_L | TB_T | TB_B | TB_TL | TB_BL | TB_TR | TB_BR:
silhouette_tilesheet_grid_pos = v2i(0,6);
break;
// right
case TB_R | TB_T | TB_B | TB_TR | TB_BR:
case TB_R | TB_T | TB_B | TB_TR | TB_BR | TB_TL:
case TB_R | TB_T | TB_B | TB_TR | TB_BR | TB_BL:
case TB_R | TB_T | TB_B | TB_TR | TB_BR | TB_TL | TB_BL:
silhouette_tilesheet_grid_pos = v2i(0,4);
break;
default:
silhouette_tilesheet_grid_pos = v2i(6,3);
break;
}
// TODO: check to see surrounding if can be merged
TileBlockData * tile_block = GetTileBlockAt( a_grid_pos );
tile_block->silhouette_tilesheet_grid_pos = silhouette_tilesheet_grid_pos;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment