Skip to content

Commit

Permalink
typified animation.cpp (#73609)
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrikLundell authored May 11, 2024
1 parent a5dbbed commit 15c4984
Show file tree
Hide file tree
Showing 12 changed files with 542 additions and 282 deletions.
424 changes: 307 additions & 117 deletions src/animation.cpp

Large diffs are not rendered by default.

181 changes: 99 additions & 82 deletions src/cata_tiles.cpp

Large diffs are not rendered by default.

89 changes: 47 additions & 42 deletions src/cata_tiles.h
Original file line number Diff line number Diff line change
Expand Up @@ -514,16 +514,16 @@ class cata_tiles
void get_tile_values_with_ter( const tripoint &p, int t, const std::array<int, 4> &tn,
int &subtile, int &rotation,
const std::bitset<NUM_TERCONN> &rotate_to_group );
static void get_connect_values( const tripoint &p, int &subtile, int &rotation,
static void get_connect_values( const tripoint_bub_ms &p, int &subtile, int &rotation,
const std::bitset<NUM_TERCONN> &connect_group,
const std::bitset<NUM_TERCONN> &rotate_to_group,
const std::map<tripoint, ter_id> &ter_override );
const std::map<tripoint_bub_ms, ter_id> &ter_override );
static void get_furn_connect_values( const tripoint &p, int &subtile, int &rotation,
const std::bitset<NUM_TERCONN> &connect_group,
const std::bitset<NUM_TERCONN> &rotate_to_group,
const std::map<tripoint, furn_id> &furn_override );
void get_terrain_orientation( const tripoint &p, int &rota, int &subtile,
const std::map<tripoint, ter_id> &ter_override,
void get_terrain_orientation( const tripoint_bub_ms &p, int &rota, int &subtile,
const std::map<tripoint_bub_ms, ter_id> &ter_override,
const std::array<bool, 5> &invisible,
const std::bitset<NUM_TERCONN> &rotate_group );

Expand Down Expand Up @@ -583,35 +583,39 @@ class cata_tiles

public:
// Animation layers
void init_explosion( const tripoint &p, int radius );
void init_explosion( const tripoint_bub_ms &p, int radius );
void draw_explosion_frame();
void void_explosion();

// TODO: Get rid of untyped overload
void init_custom_explosion_layer( const std::map<tripoint, explosion_tile> &layer );
void init_custom_explosion_layer( const std::map<tripoint_bub_ms, explosion_tile> &layer );
void draw_custom_explosion_frame();
void void_custom_explosion();

void init_draw_bullet( const tripoint &p, std::string name );
void init_draw_bullet( const tripoint_bub_ms &p, std::string name );
void draw_bullet_frame();
void void_bullet();

void init_draw_hit( const tripoint &p, std::string name );
void init_draw_hit( const tripoint_bub_ms &p, std::string name );
void draw_hit_frame();
void void_hit();

void draw_footsteps_frame( const tripoint &center );

// pseudo-animated layer, not really though.
void init_draw_line( const tripoint &p, std::vector<tripoint> trajectory,
void init_draw_line( const tripoint_bub_ms &p, std::vector<tripoint_bub_ms> trajectory,
std::string line_end_name, bool target_line );
void draw_line();
void void_line();

void init_draw_cursor( const tripoint &p );
void init_draw_cursor( const tripoint_bub_ms &p );
void draw_cursor();
void void_cursor();

// TODO: Get rid of untyped overload
void init_draw_highlight( const tripoint &p );
void init_draw_highlight( const tripoint_bub_ms &p );
void draw_highlight();
void void_highlight();

Expand All @@ -623,44 +627,45 @@ class cata_tiles
void draw_sct_frame( std::multimap<point, formatted_text> &overlay_strings );
void void_sct();

void init_draw_zones( const tripoint &start, const tripoint &end, const tripoint &offset );
void init_draw_zones( const tripoint_bub_ms &start, const tripoint_bub_ms &end,
const tripoint &offset );
void draw_zones_frame();
void void_zones();

void init_draw_async_anim( const tripoint &p, const std::string &tile_id );
void init_draw_async_anim( const tripoint_bub_ms &p, const std::string &tile_id );
void draw_async_anim();
void void_async_anim();

void init_draw_radiation_override( const tripoint &p, int rad );
void init_draw_radiation_override( const tripoint_bub_ms &p, int rad );
void void_radiation_override();

void init_draw_terrain_override( const tripoint &p, const ter_id &id );
void init_draw_terrain_override( const tripoint_bub_ms &p, const ter_id &id );
void void_terrain_override();

void init_draw_furniture_override( const tripoint &p, const furn_id &id );
void init_draw_furniture_override( const tripoint_bub_ms &p, const furn_id &id );
void void_furniture_override();

void init_draw_graffiti_override( const tripoint &p, bool has );
void init_draw_graffiti_override( const tripoint_bub_ms &p, bool has );
void void_graffiti_override();

void init_draw_trap_override( const tripoint &p, const trap_id &id );
void init_draw_trap_override( const tripoint_bub_ms &p, const trap_id &id );
void void_trap_override();

void init_draw_field_override( const tripoint &p, const field_type_id &id );
void init_draw_field_override( const tripoint_bub_ms &p, const field_type_id &id );
void void_field_override();

void init_draw_item_override( const tripoint &p, const itype_id &id, const mtype_id &mid,
void init_draw_item_override( const tripoint_bub_ms &p, const itype_id &id, const mtype_id &mid,
bool hilite );
void void_item_override();

void init_draw_vpart_override( const tripoint &p, const vpart_id &id, int part_mod,
void init_draw_vpart_override( const tripoint_bub_ms &p, const vpart_id &id, int part_mod,
const units::angle &veh_dir, bool hilite, const point &mount );
void void_vpart_override();

void init_draw_below_override( const tripoint &p, bool draw );
void init_draw_below_override( const tripoint_bub_ms &p, bool draw );
void void_draw_below_override();

void init_draw_monster_override( const tripoint &p, const mtype_id &id, int count,
void init_draw_monster_override( const tripoint_bub_ms &p, const mtype_id &id, int count,
bool more, Creature::Attitude att );
void void_monster_override();

Expand Down Expand Up @@ -779,52 +784,52 @@ class cata_tiles
bool do_draw_zones = false;
bool do_draw_async_anim = false;

tripoint exp_pos;
tripoint_bub_ms exp_pos;
int exp_rad = 0;

std::map<tripoint, explosion_tile> custom_explosion_layer;
std::map<tripoint, std::string> async_anim_layer;
std::map<tripoint_bub_ms, explosion_tile> custom_explosion_layer;
std::map<tripoint_bub_ms, std::string> async_anim_layer;

tripoint bul_pos;
tripoint_bub_ms bul_pos;
std::string bul_id;

tripoint hit_pos;
tripoint_bub_ms hit_pos;
std::string hit_entity_id;

tripoint line_pos;
tripoint_bub_ms line_pos;
bool is_target_line = false;
std::vector<tripoint> line_trajectory;
std::vector<tripoint_bub_ms> line_trajectory;
std::string line_endpoint_id;

std::vector<tripoint> cursors;
std::vector<tripoint> highlights;
std::vector<tripoint_bub_ms> cursors;
std::vector<tripoint_bub_ms> highlights;

weather_printable anim_weather;
std::string weather_name;

tripoint zone_start;
tripoint zone_end;
tripoint_bub_ms zone_start;
tripoint_bub_ms zone_end;
tripoint zone_offset;

// offset values, in tile coordinates, not pixels
point o;
// offset for drawing, in pixels.
point op;

std::map<tripoint, int> radiation_override;
std::map<tripoint, ter_id> terrain_override;
std::map<tripoint, furn_id> furniture_override;
std::map<tripoint, bool> graffiti_override;
std::map<tripoint, trap_id> trap_override;
std::map<tripoint, field_type_id> field_override;
std::map<tripoint_bub_ms, int> radiation_override;
std::map<tripoint_bub_ms, ter_id> terrain_override;
std::map<tripoint_bub_ms, furn_id> furniture_override;
std::map<tripoint_bub_ms, bool> graffiti_override;
std::map<tripoint_bub_ms, trap_id> trap_override;
std::map<tripoint_bub_ms, field_type_id> field_override;
// bool represents item highlight
std::map<tripoint, std::tuple<itype_id, mtype_id, bool>> item_override;
std::map<tripoint_bub_ms, std::tuple<itype_id, mtype_id, bool>> item_override;
// int, angle, bool represents part_mod, veh_dir, and highlight respectively
// point represents the mount direction
std::map<tripoint, std::tuple<vpart_id, int, units::angle, bool, point>> vpart_override;
std::map<tripoint, bool> draw_below_override;
std::map<tripoint_bub_ms, std::tuple<vpart_id, int, units::angle, bool, point>> vpart_override;
std::map<tripoint_bub_ms, bool> draw_below_override;
// int represents spawn count
std::map<tripoint, std::tuple<mtype_id, int, bool, Creature::Attitude>> monster_override;
std::map<tripoint_bub_ms, std::tuple<mtype_id, int, bool, Creature::Attitude>> monster_override;

private:
/**
Expand Down
6 changes: 6 additions & 0 deletions src/creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3004,6 +3004,12 @@ void Creature::draw( const catacurses::window &w, const tripoint &origin, bool i
}
}

void Creature::draw( const catacurses::window &w, const tripoint_bub_ms &origin,
bool inverted ) const
{
Creature::draw( w, origin.raw(), inverted );
}

bool Creature::is_symbol_highlighted() const
{
return false;
Expand Down
2 changes: 2 additions & 0 deletions src/creature.h
Original file line number Diff line number Diff line change
Expand Up @@ -940,7 +940,9 @@ class Creature : public viewer

bool underwater;
void draw( const catacurses::window &w, const point &origin, bool inverted ) const;
// TODO: Get rid of the untyped overload
void draw( const catacurses::window &w, const tripoint &origin, bool inverted ) const;
void draw( const catacurses::window &w, const tripoint_bub_ms &origin, bool inverted ) const;
/**
* Write information about this creature.
* @param w the window to print the text into.
Expand Down
9 changes: 5 additions & 4 deletions src/editmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -626,14 +626,14 @@ void editmap::draw_main_ui_overlay()
for( int y = 0; y < SEEY * 2; y++ ) {
const tripoint tmp_p( x, y, target.z );
const tripoint map_p = origin_p + tmp_p;
g->draw_radiation_override( map_p, tmpmap.get_radiation( tmp_p ) );
g->draw_radiation_override( tripoint_bub_ms( map_p ), tmpmap.get_radiation( tmp_p ) );
// scent is managed in `game` instead of `map`, so there's no override for it
// temperature is managed in `game` instead of `map`, so there's no override for it
// TODO: visibility could be affected by both the actual map and the preview map,
// which complicates calculation, so there's no override for it (yet)
g->draw_terrain_override( map_p, tmpmap.ter( tmp_p ) );
g->draw_furniture_override( map_p, tmpmap.furn( tmp_p ) );
g->draw_graffiti_override( map_p, tmpmap.has_graffiti_at( tmp_p ) );
g->draw_graffiti_override( tripoint_bub_ms( map_p ), tmpmap.has_graffiti_at( tmp_p ) );
g->draw_trap_override( map_p, tmpmap.tr_at( tmp_p ).loadid );
g->draw_field_override( map_p, tmpmap.field_at( tmp_p ).displayed_field_type() );
const maptile &tile = tmpmap.maptile_at( tmp_p );
Expand All @@ -659,7 +659,7 @@ void editmap::draw_main_ui_overlay()
} else {
g->draw_vpart_override( map_p, vpart_id::NULL_ID(), 0, 0_degrees, false, point_zero );
}
g->draw_below_override( map_p,
g->draw_below_override( tripoint_bub_ms( map_p ),
tmpmap.ter( tmp_p ).obj().has_flag( ter_furn_flag::TFLAG_NO_FLOOR ) );
}
}
Expand All @@ -684,7 +684,8 @@ void editmap::draw_main_ui_overlay()
}
}
for( const auto &it : spawns ) {
g->draw_monster_override( it.first, std::get<0>( it.second ), std::get<1>( it.second ),
g->draw_monster_override( tripoint_bub_ms( it.first ), std::get<0>( it.second ),
std::get<1>( it.second ),
std::get<2>( it.second ), std::get<3>( it.second ) );
}
} else {
Expand Down
5 changes: 5 additions & 0 deletions src/explosion.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,14 @@ void nuke( const tripoint_abs_omt &p );
void shockwave( const tripoint &p, int radius, int force, int stun, int dam_mult,
bool ignore_player );

// TODO: Get rid of untyped overload
void draw_explosion( const tripoint &p, int radius, const nc_color &col );
void draw_explosion( const tripoint_bub_ms &p, int radius, const nc_color &col );
// TODO: Get rid of untyped overload
void draw_custom_explosion( const tripoint &p, const std::map<tripoint, nc_color> &area,
const std::optional<std::string> &tile_id = std::nullopt );
void draw_custom_explosion( const std::map<tripoint_bub_ms, nc_color> &area,
const std::optional<std::string> &tile_id = std::nullopt );

int ballistic_damage( float velocity, float mass );
float gurney_spherical( double charge, double mass );
Expand Down
28 changes: 14 additions & 14 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3884,12 +3884,12 @@ static shared_ptr_fast<game::draw_callback_t> create_zone_callback(
}
#endif

const tripoint start( std::min( zone_start->x, zone_end->x ),
std::min( zone_start->y, zone_end->y ),
zone_end->z );
const tripoint end( std::max( zone_start->x, zone_end->x ),
std::max( zone_start->y, zone_end->y ),
zone_end->z );
const tripoint_bub_ms start( std::min( zone_start->x, zone_end->x ),
std::min( zone_start->y, zone_end->y ),
zone_end->z );
const tripoint_bub_ms end( std::max( zone_start->x, zone_end->x ),
std::max( zone_start->y, zone_end->y ),
zone_end->z );
g->draw_zones( start, end, offset );
}
} );
Expand All @@ -3909,7 +3909,7 @@ static shared_ptr_fast<game::draw_callback_t> create_trail_callback(
} );
}

void game::init_draw_async_anim_curses( const tripoint &p, const std::string &ncstr,
void game::init_draw_async_anim_curses( const tripoint_bub_ms &p, const std::string &ncstr,
const nc_color &nccol )
{
std::pair <std::string, nc_color> anim( ncstr, nccol );
Expand All @@ -3921,12 +3921,12 @@ void game::draw_async_anim_curses()
// game::draw_async_anim_curses can be called multiple times, storing each animation to be played in async_anim_layer_curses
// Iterate through every animation in async_anim_layer
for( const auto &anim : async_anim_layer_curses ) {
const tripoint p = anim.first - u.view_offset + tripoint( POSX - u.posx(), POSY - u.posy(),
-u.posz() );
const tripoint_bub_ms p = anim.first - u.view_offset + tripoint( POSX - u.posx(), POSY - u.posy(),
-u.posz() );
const std::string ncstr = anim.second.first;
const nc_color nccol = anim.second.second;

mvwprintz( w_terrain, p.xy(), nccol, ncstr );
mvwprintz( w_terrain, p.xy().raw(), nccol, ncstr );
}
}

Expand Down Expand Up @@ -4119,12 +4119,12 @@ void game::draw_critter( const Creature &critter, const tripoint &center )
}
}

bool game::is_in_viewport( const tripoint &p, int margin ) const
bool game::is_in_viewport( const tripoint_bub_ms &p, int margin ) const
{
const tripoint diff( u.pos() + u.view_offset - p );
const tripoint_rel_ms diff( u.pos_bub() + u.view_offset - p );

return ( std::abs( diff.x ) <= getmaxx( w_terrain ) / 2 - margin ) &&
( std::abs( diff.y ) <= getmaxy( w_terrain ) / 2 - margin );
return ( std::abs( diff.x() ) <= getmaxx( w_terrain ) / 2 - margin ) &&
( std::abs( diff.y() ) <= getmaxy( w_terrain ) / 2 - margin );
}

void game::draw_ter( const bool draw_sounds )
Expand Down
Loading

0 comments on commit 15c4984

Please sign in to comment.