Skip to content

Commit

Permalink
Merge pull request CleverRaven#60283 from irwiss/isometric-fixes
Browse files Browse the repository at this point in the history
Isometric fixes
  • Loading branch information
dseguin authored Aug 29, 2022
2 parents fd28f48 + ced7298 commit 36ef515
Show file tree
Hide file tree
Showing 17 changed files with 66 additions and 50 deletions.
4 changes: 2 additions & 2 deletions src/action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ action_id get_movement_action_from_delta( const tripoint &d, const iso_rotate ro
return ACTION_MOVE_UP;
}

const bool iso_mode = rot == iso_rotate::yes && use_tiles && tile_iso;
const bool iso_mode = rot == iso_rotate::yes && g->is_tileset_isometric();
if( d.xy() == point_north ) {
return iso_mode ? ACTION_MOVE_FORTH_LEFT : ACTION_MOVE_FORTH;
} else if( d.xy() == point_north_east ) {
Expand All @@ -574,7 +574,7 @@ action_id get_movement_action_from_delta( const tripoint &d, const iso_rotate ro

point get_delta_from_movement_action( const action_id act, const iso_rotate rot )
{
const bool iso_mode = rot == iso_rotate::yes && use_tiles && tile_iso;
const bool iso_mode = rot == iso_rotate::yes && g->is_tileset_isometric();
switch( act ) {
case ACTION_MOVE_FORTH:
return iso_mode ? point_north_east : point_north;
Expand Down
2 changes: 1 addition & 1 deletion src/advanced_inv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ bool advanced_inventory::get_square( const std::string &action, aim_location &re

aim_location advanced_inventory::screen_relative_location( aim_location area )
{
if( use_tiles && tile_iso ) {
if( g->is_tileset_isometric() ) {
return squares[area].relative_location;
} else {
return area;
Expand Down
2 changes: 1 addition & 1 deletion src/avatar_action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ bool avatar_action::move( avatar &you, map &m, const tripoint &d )
// If the player is *attempting to* move on the X axis, update facing direction of their sprite to match.
point new_d( dest_loc.xy() + point( -you.posx(), -you.posy() ) );

if( !tile_iso ) {
if( !g->is_tileset_isometric() ) {
if( new_d.x > 0 ) {
you.facing = FacingDirection::RIGHT;
if( is_riding ) {
Expand Down
1 change: 0 additions & 1 deletion src/cached_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ bool log_from_top;
int message_ttl;
int message_cooldown;
bool test_mode;
bool tile_iso;
bool use_tiles;
bool use_far_tiles;
bool use_tiles_overmap;
Expand Down
1 change: 0 additions & 1 deletion src/cached_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ extern bool keycode_mode;
extern bool log_from_top;
extern int message_ttl;
extern int message_cooldown;
extern bool tile_iso;
extern bool use_tiles;
extern bool use_far_tiles;
extern bool use_tiles_overmap;
Expand Down
45 changes: 20 additions & 25 deletions src/cata_tiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,8 +331,6 @@ void cata_tiles::load_tileset( const std::string &tileset_id, const bool prechec
tileset_ptr = cache.load_tileset( tileset_id, renderer, precheck, force, pump_events );

set_draw_scale( 16 );

minimap->set_type( tile_iso ? pixel_minimap_type::iso : pixel_minimap_type::ortho );
}

void cata_tiles::reinit()
Expand Down Expand Up @@ -660,7 +658,7 @@ void tileset_cache::loader::load( const std::string &tileset_id, const bool prec
for( const JsonObject curr_info : config.get_array( "tile_info" ) ) {
ts.tile_height = curr_info.get_int( "height" );
ts.tile_width = curr_info.get_int( "width" );
tile_iso = curr_info.get_bool( "iso", false );
ts.tile_isometric = curr_info.get_bool( "iso", false );
ts.tile_pixelscale = curr_info.get_float( "pixelscale", 1.0f );
}

Expand Down Expand Up @@ -1258,9 +1256,7 @@ void cata_tiles::draw( const point &dest, const tripoint &center, int width, int
map &here = get_map();
const visibility_variables &cache = here.get_visibility_variables_cache();

const bool iso_mode = tile_iso;

o = iso_mode ? center.xy() : center.xy() - point( POSX, POSY );
o = is_isometric() ? center.xy() : center.xy() - point( POSX, POSY );

op = dest;
// Rounding up to include incomplete tiles at the bottom/right edges
Expand Down Expand Up @@ -1354,7 +1350,7 @@ void cata_tiles::draw( const point &dest, const tripoint &center, int width, int
draw_points.reserve( max_col );
for( int col = min_col; col < max_col; col ++ ) {
point temp;
if( iso_mode ) {
if( is_isometric() ) {
// in isometric, rows and columns represent a checkerboard screen space,
// and we place the appropriate tile in valid squares by getting position
// relative to the screen center.
Expand Down Expand Up @@ -1624,7 +1620,7 @@ void cata_tiles::draw( const point &dest, const tripoint &center, int width, int
for( int mem_x = min_visible.x; mem_x <= max_visible.x; mem_x++ ) {
half_open_rectangle<point> already_drawn(
point( min_col, min_row ), point( max_col, max_row ) );
if( iso_mode ) {
if( is_isometric() ) {
// calculate the screen position according to the drawing code above
// (division rounded down):

Expand Down Expand Up @@ -1741,13 +1737,14 @@ void cata_tiles::draw( const point &dest, const tripoint &center, int width, int

void cata_tiles::draw_minimap( const point &dest, const tripoint &center, int width, int height )
{
minimap->set_type( is_isometric() ? pixel_minimap_type::iso : pixel_minimap_type::ortho );
minimap->draw( SDL_Rect{ dest.x, dest.y, width, height }, center );
}

void cata_tiles::get_window_tile_counts( const int width, const int height, int &columns,
int &rows ) const
{
if( tile_iso ) {
if( is_isometric() ) {
columns = std::ceil( static_cast<double>( width ) / tile_width ) * 2 + 4;
rows = std::ceil( static_cast<double>( height ) / ( tile_width / 2.0 - 1 ) ) * 2 + 4;
} else {
Expand Down Expand Up @@ -2020,8 +2017,7 @@ bool cata_tiles::draw_from_id_string( const std::string &id, TILE_CATEGORY categ
// [0->width|height / tile_width|height]

half_open_rectangle<point> screen_bounds( o, o + point( screentile_width, screentile_height ) );
if( !tile_iso &&
!screen_bounds.contains( pos.xy() ) ) {
if( !is_isometric() && !screen_bounds.contains( pos.xy() ) ) {
return false;
}

Expand Down Expand Up @@ -2509,7 +2505,7 @@ bool cata_tiles::draw_sprite_at(
destination.y -= 1;
}
#endif
if( !tile_iso ) {
if( !is_isometric() ) {
// never rotate isometric tiles
ret = sprite_tex->render_copy_ex( renderer, &destination, -90, nullptr,
SDL_FLIP_NONE );
Expand All @@ -2520,7 +2516,7 @@ bool cata_tiles::draw_sprite_at(
break;
case 2:
// 180 degrees, implemented with flips instead of rotation
if( !tile_iso ) {
if( !is_isometric() ) {
// never flip isometric tiles vertically
ret = sprite_tex->render_copy_ex(
renderer, &destination, 0, nullptr,
Expand All @@ -2539,7 +2535,7 @@ bool cata_tiles::draw_sprite_at(
destination.x -= 1;
}
#endif
if( !tile_iso ) {
if( !is_isometric() ) {
// never rotate isometric tiles
ret = sprite_tex->render_copy_ex( renderer, &destination, 90, nullptr,
SDL_FLIP_NONE );
Expand Down Expand Up @@ -2655,15 +2651,14 @@ bool cata_tiles::draw_terrain_below( const tripoint &p, const lit_level, int &,
}

SDL_Rect belowRect;
point screen;
belowRect.h = tile_width / sizefactor;
belowRect.w = tile_height / sizefactor;
if( tile_iso ) {
if( is_isometric() ) {
belowRect.h = ( belowRect.h * 2 ) / 3;
belowRect.w = ( belowRect.w * 3 ) / 4;
}
// translate from player-relative to screen relative tile position
point screen;
if( tile_iso ) {

// translate from player-relative to screen relative tile position
screen.x = ( ( pbelow.x - o.x ) - ( o.y - pbelow.y ) + screentile_width - 2 ) *
tile_width / 2 + op.x;
// y uses tile_width because width is definitive for iso tiles
Expand All @@ -2677,7 +2672,7 @@ bool cata_tiles::draw_terrain_below( const tripoint &p, const lit_level, int &,
}
belowRect.x = screen.x + ( tile_width - belowRect.w ) / 2;
belowRect.y = screen.y + ( tile_height - belowRect.h ) / 2;
if( tile_iso ) {
if( is_isometric() ) {
belowRect.y += tile_height / 8;
}
geometry->rect( renderer, belowRect, tercol );
Expand Down Expand Up @@ -3465,15 +3460,15 @@ bool cata_tiles::draw_critter_at_below( const tripoint &p, const lit_level, int
belowRect.h = tile_width / sizefactor;
belowRect.w = tile_height / sizefactor;

if( tile_iso ) {
if( is_isometric() ) {
belowRect.h = ( belowRect.h * 2 ) / 3;
belowRect.w = ( belowRect.w * 3 ) / 4;
}

belowRect.x = screen_point.x + ( tile_width - belowRect.w ) / 2;
belowRect.y = screen_point.y + ( tile_height - belowRect.h ) / 2;

if( tile_iso ) {
if( is_isometric() ) {
belowRect.y += tile_height / 8;
}

Expand Down Expand Up @@ -4113,7 +4108,7 @@ void cata_tiles::draw_weather_frame()
for( auto &vdrop : anim_weather.vdrops ) {
// TODO: Z-level awareness if weather ever happens on anything but z-level 0.
tripoint p( vdrop.first, vdrop.second, 0 );
if( !tile_iso ) {
if( !is_isometric() ) {
// currently in ASCII screen coordinates
p += o;
}
Expand Down Expand Up @@ -4158,7 +4153,7 @@ void cata_tiles::draw_sct_frame( std::multimap<point, formatted_text> &overlay_s
0, 0, lit_level::LIT, false );
}

if( tile_iso ) {
if( is_isometric() ) {
iOffset.y++;
}
iOffset.x++;
Expand Down Expand Up @@ -4506,7 +4501,7 @@ void cata_tiles::do_tile_loading_report()
point cata_tiles::player_to_screen( const point &p ) const
{
point screen;
if( tile_iso ) {
if( is_isometric() ) {
screen.x = ( ( p.x - o.x ) - ( o.y - p.y ) + screentile_width - 2 ) * tile_width / 2 +
op.x;
// y uses tile_width because width is definitive for iso tiles
Expand Down
7 changes: 7 additions & 0 deletions src/cata_tiles.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ class tileset

std::string tileset_id;

bool tile_isometric = false;
int tile_width = 0;
int tile_height = 0;

Expand Down Expand Up @@ -161,6 +162,9 @@ class tileset

void clear();

bool is_isometric() const {
return tile_isometric;
}
int get_tile_width() const {
return tile_width;
}
Expand Down Expand Up @@ -583,6 +587,9 @@ class cata_tiles
*/
void reinit();

bool is_isometric() const {
return tileset_ptr->is_isometric();
}
int get_tile_height() const {
return tile_height;
}
Expand Down
11 changes: 10 additions & 1 deletion src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,15 @@ void game::toggle_pixel_minimap() const
#endif // TILES
}

bool game::is_tileset_isometric() const
{
#if defined(TILES)
return use_tiles && tilecontext && tilecontext->is_isometric();
#else
return false;
#endif
}

void game::reload_tileset()
{
#if defined(TILES)
Expand Down Expand Up @@ -2305,7 +2314,7 @@ std::pair<tripoint, tripoint> game::mouse_edge_scrolling( input_context &ctxt, c
tripoint game::mouse_edge_scrolling_terrain( input_context &ctxt )
{
auto ret = mouse_edge_scrolling( ctxt, std::max( DEFAULT_TILESET_ZOOM / tileset_zoom, 1 ),
last_mouse_edge_scroll_vector_terrain, tile_iso );
last_mouse_edge_scroll_vector_terrain, g->is_tileset_isometric() );
last_mouse_edge_scroll_vector_terrain = ret.second;
last_mouse_edge_scroll_vector_overmap = tripoint_zero;
return ret.first;
Expand Down
1 change: 1 addition & 0 deletions src/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,7 @@ class game

void toggle_fullscreen();
void toggle_pixel_minimap() const;
bool is_tileset_isometric() const;
void reload_tileset();
void temp_exit_fullscreen();
void reenter_fullscreen();
Expand Down
7 changes: 4 additions & 3 deletions src/handle_action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ input_context game::get_player_input( std::string &action )
-getmaxy( w_terrain ) / 2 + u.posy() ) );

#if defined(TILES)
if( tile_iso && use_tiles ) {
if( g->is_tileset_isometric() ) {
iStart.x = 0;
iStart.y = 0;
iEnd.x = MAPSIZE_X;
Expand Down Expand Up @@ -1866,8 +1866,9 @@ static void do_deathcam_action( const action_id &act, avatar &player_character )
{ ACTION_SHIFT_NW, { point_north_west, point_north } },
};
int soffset = get_option<int>( "MOVE_VIEW_OFFSET" );
player_character.view_offset += use_tiles && tile_iso ?
shift_delta.at( act ).second * soffset : shift_delta.at( act ).first * soffset;
player_character.view_offset += g->is_tileset_isometric()
? shift_delta.at( act ).second * soffset
: shift_delta.at( act ).first * soffset;
}
break;

Expand Down
2 changes: 1 addition & 1 deletion src/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1291,7 +1291,7 @@ cata::optional<tripoint> input_context::get_direction( const std::string &action
rotate_direction_cw( p.x, p.y );
return p;
} );
const auto transform = iso_mode && tile_iso && use_tiles ? rotate : noop;
const auto transform = iso_mode && g->is_tileset_isometric() ? rotate : noop;

if( action == "UP" ) {
return transform( tripoint_north );
Expand Down
2 changes: 1 addition & 1 deletion src/monmove.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -950,7 +950,7 @@ void monster::move()
point new_d( destination.xy() - pos().xy() );

// toggle facing direction for sdl flip
if( !tile_iso ) {
if( !g->is_tileset_isometric() ) {
if( new_d.x < 0 ) {
facing = FacingDirection::LEFT;
} else if( new_d.x > 0 ) {
Expand Down
8 changes: 7 additions & 1 deletion src/options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2085,9 +2085,15 @@ void options_manager::add_options_graphics()

get_option( "USE_TILES_OVERMAP" ).setPrerequisite( "USE_TILES" );

std::vector<options_manager::id_and_option> om_tilesets = build_tilesets_list();
// filter out SmashButton_iso from overmap tilesets
om_tilesets.erase( std::remove_if( om_tilesets.begin(), om_tilesets.end(), []( const auto & it ) {
return it.first == "SmashButton_iso";
} ), om_tilesets.end() );

add( "OVERMAP_TILES", "graphics", to_translation( "Choose overmap tileset" ),
to_translation( "Choose the overmap tileset you want to use." ),
build_tilesets_list(), "retrodays", COPT_CURSES_HIDE
om_tilesets, "retrodays", COPT_CURSES_HIDE
); // populate the options dynamically

get_option( "OVERMAP_TILES" ).setPrerequisite( "USE_TILES_OVERMAP" );
Expand Down
12 changes: 5 additions & 7 deletions src/output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "item.h"
#include "line.h"
#include "name.h"
#include "game.h"
#include "options.h"
#include "point.h"
#include "popup.h"
Expand Down Expand Up @@ -2402,12 +2403,9 @@ scrollingcombattext::cSCT::cSCT( const point &p_pos, const direction p_oDir,
sType = p_sType;
oDir = p_oDir;

iso_mode = g->is_tileset_isometric();

// translate from player relative to screen relative direction
#if defined(TILES)
iso_mode = tile_iso && use_tiles;
#else
iso_mode = false;
#endif
oUp = iso_mode ? direction::NORTHEAST : direction::NORTH;
oUpRight = iso_mode ? direction::EAST : direction::NORTHEAST;
oRight = iso_mode ? direction::SOUTHEAST : direction::EAST;
Expand Down Expand Up @@ -2452,10 +2450,10 @@ void scrollingcombattext::add( const point &pos, direction p_oDir,
int iCurStep = 0;

bool tiled = false;
bool iso_mode = false;
bool iso_mode = g->is_tileset_isometric();

#if defined(TILES)
tiled = use_tiles;
iso_mode = tile_iso && use_tiles;
#endif

if( p_sType == "hp" ) {
Expand Down
6 changes: 4 additions & 2 deletions src/pixel_minimap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,10 @@ pixel_minimap::~pixel_minimap() = default;

void pixel_minimap::set_type( pixel_minimap_type type )
{
this->type = type;
reset();
if( this->type != type ) {
this->type = type;
reset();
}
}

void pixel_minimap::set_settings( const pixel_minimap_settings &settings )
Expand Down
Loading

0 comments on commit 36ef515

Please sign in to comment.