Permalink
Browse files

Simplify cata_tiles::get_rotation_and_subtile

It was working from a bitfield for connections and a number of
connections, but really the bitfield is sufficient.
  • Loading branch information...
jbytheway committed Dec 1, 2018
1 parent bed4743 commit 810b9488ad4b67971c511a8c2305b550da1ba955
Showing with 66 additions and 74 deletions.
  1. +65 −73 src/cata_tiles.cpp
  2. +1 −1 src/cata_tiles.h
@@ -2976,95 +2976,91 @@ void cata_tiles::get_terrain_orientation( const tripoint &p, int &rota, int &sub

bool connects[4];
char val = 0;
int num_connects = 0;

// populate connection information
for( int i = 0; i < 4; ++i ) {
connects[i] = ( neighborhood[i] == tid );

if( connects[i] ) {
++num_connects;
val += 1 << i;
}
}

get_rotation_and_subtile( val, num_connects, rota, subtile );
get_rotation_and_subtile( val, rota, subtile );
}
void cata_tiles::get_rotation_and_subtile( const char val, const int num_connects, int &rotation,
int &subtile )

void cata_tiles::get_rotation_and_subtile( const char val, int &rotation, int &subtile )
{
switch( num_connects ) {
switch( val ) {
// no connections
case 0:
rotation = 0;
subtile = unconnected;
break;
case 4:
rotation = 0;
break;
// all connections
case 15:
subtile = center;
rotation = 0;
break;
case 1: // all end pieces
// end pieces
case 8:
subtile = end_piece;
switch( val ) {
case 8:
rotation = 2;
break;
case 4:
rotation = 3;
break;
case 2:
rotation = 1;
break;
case 1:
rotation = 0;
break;
}
rotation = 2;
break;
case 4:
subtile = end_piece;
rotation = 3;
break;
case 2:
switch( val ) {
// edges
case 9:
subtile = edge;
rotation = 0;
break;
case 6:
subtile = edge;
rotation = 1;
break;
// corners
case 12:
subtile = corner;
rotation = 2;
break;
case 10:
subtile = corner;
rotation = 1;
break;
case 3:
subtile = corner;
rotation = 0;
break;
case 5:
subtile = corner;
rotation = 3;
break;
}
subtile = end_piece;
rotation = 1;
break;
case 3: // all t_connections
case 1:
subtile = end_piece;
rotation = 0;
break;
// edges
case 9:
subtile = edge;
rotation = 0;
break;
case 6:
subtile = edge;
rotation = 1;
break;
// corners
case 12:
subtile = corner;
rotation = 2;
break;
case 10:
subtile = corner;
rotation = 1;
break;
case 3:
subtile = corner;
rotation = 0;
break;
case 5:
subtile = corner;
rotation = 3;
break;
// all t_connections
case 14:
subtile = t_connection;
switch( val ) {
case 14:
rotation = 2;
break;
case 11:
rotation = 1;
break;
case 7:
rotation = 0;
break;
case 13:
rotation = 3;
break;
}
rotation = 2;
break;
case 11:
subtile = t_connection;
rotation = 1;
break;
case 7:
subtile = t_connection;
rotation = 0;
break;
case 13:
subtile = t_connection;
rotation = 3;
break;
}
}
@@ -3080,7 +3076,6 @@ void cata_tiles::get_connect_values( const tripoint &p, int &subtile, int &rotat
bool is_transparent =
ch.transparency_cache[p.x][p.y] > LIGHT_TRANSPARENCY_SOLID;
char val = 0;
int num_connects = 0;

// populate connection information
for( int i = 0; i < 4; ++i ) {
@@ -3098,26 +3093,23 @@ void cata_tiles::get_connect_values( const tripoint &p, int &subtile, int &rotat
}
}
if( neighbour_terrain && neighbour_terrain->connects_to( connect_group ) ) {
++num_connects;
val += 1 << i;
}
}
get_rotation_and_subtile( val, num_connects, rotation, subtile );
get_rotation_and_subtile( val, rotation, subtile );
}

void cata_tiles::get_tile_values( const int t, const int *tn, int &subtile, int &rotation )
{
bool connects[4];
int num_connects = 0;
char val = 0;
for( int i = 0; i < 4; ++i ) {
connects[i] = ( tn[i] == t );
if( connects[i] ) {
++num_connects;
val += 1 << i;
}
}
get_rotation_and_subtile( val, num_connects, rotation, subtile );
get_rotation_and_subtile( val, rotation, subtile );
}

void cata_tiles::do_tile_loading_report()
@@ -432,7 +432,7 @@ class cata_tiles
void get_tile_values( const int t, const int *tn, int &subtile, int &rotation );
void get_connect_values( const tripoint &p, int &subtile, int &rotation, int connect_group );
void get_terrain_orientation( const tripoint &p, int &rota, int &subtype );
void get_rotation_and_subtile( const char val, const int num_connects, int &rota, int &subtype );
void get_rotation_and_subtile( const char val, int &rota, int &subtype );

/** Drawing Layers */
bool apply_vision_effects( const tripoint &pos, const visibility_type visibility );

0 comments on commit 810b948

Please sign in to comment.