Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix automatic sprite rotation for non-linear overmap tiles #1762

Merged
merged 1 commit into from
Jul 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/om_direction.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const size_t size = all.size();
const std::array<std::string, 4> all_suffixes = {{ "_north", "_east", "_south", "_west" }};
const std::string invalid_dir_suffix;
const std::array<int, 4> all_cw_rotations = {{ 0, 1, 2, 3 }};
const std::array<int, 4> all_ccw_rotations = { { 0, 3, 2, 1 } };
const int invalid_dir_rotations = 0;

/** Returns directional suffix associated with the value, e.g. _north or _west. */
Expand All @@ -51,6 +52,16 @@ constexpr int get_num_cw_rotations( type dir )
}
}

/** Returns number of counterclockwise rotations needed to reach this direction from 'north'. */
constexpr int get_num_ccw_rotations( type dir )
{
if( dir == type::invalid ) {
return invalid_dir_rotations;
} else {
return all_ccw_rotations[static_cast<size_t>( dir )];
}
}

/** Number of bits needed to store directions. */
const size_t bits = static_cast<size_t>( -1 ) >> ( CHAR_BIT *sizeof( size_t ) - size );

Expand Down
2 changes: 1 addition & 1 deletion src/overmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,7 @@ void oter_t::get_rotation_and_subtile( int &rotation, int &subtile ) const
rotation = t.rotation;
subtile = t.subtile;
} else if( is_rotatable() ) {
rotation = static_cast<int>( get_dir() );
rotation = om_direction::get_num_ccw_rotations( get_dir() );
subtile = -1;
} else {
rotation = 0;
Expand Down