Skip to content

Commit

Permalink
Animate tiles marked as animated in tile_config.json (#40342)
Browse files Browse the repository at this point in the history
* Animate tiles marked animated in tile_config.json

* Style

* Style

* Replace tabs

Co-authored-by: Alexey Mostovoy <[email protected]>

* use int instead of long

Co-authored-by: verate <[email protected]>
Co-authored-by: Alexey Mostovoy <[email protected]>
  • Loading branch information
3 people authored May 11, 2020
1 parent f6d85ac commit 2abca8f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/cata_tiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -877,6 +877,7 @@ void tileset_loader::load_tilejson_from_file( const JsonObject &config )
curr_tile.multitile = t_multi;
curr_tile.rotates = t_rota;
curr_tile.height_3d = t_h3d;
curr_tile.animated = entry.get_bool( "animated", false );
}
}
dbg( D_INFO ) << "Tile Width: " << ts.tile_width << " Tile Height: " << ts.tile_height <<
Expand Down Expand Up @@ -1899,6 +1900,23 @@ bool cata_tiles::draw_from_id_string( std::string id, TILE_CATEGORY category,
c ^= b;
c -= rot32( b, 24 );
loc_rand = c;

// idle tile animations:
if( display_tile.animated ) {
// idle animations run during the user's turn, and the animation speed
// needs to be defined by the tileset to look good, so we use system clock:
auto now = std::chrono::system_clock::now();
auto now_ms = std::chrono::time_point_cast<std::chrono::milliseconds>( now );
auto value = now_ms.time_since_epoch();
// aiming roughly at the standard 60 frames per second:
int animation_frame = value.count() / 17;
// offset by log_rand so that everything does not blink at the same time:
animation_frame += loc_rand;
int frames_in_loop = display_tile.fg.get_weight();
// loc_rand is actually the weighed index of the selected tile, and
// for animations the "weight" is the number of frames to show the tile for:
loc_rand = animation_frame % frames_in_loop;
}
}

//draw it!
Expand Down
1 change: 1 addition & 0 deletions src/cata_tiles.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ struct tile_type {
weighted_int_list<std::vector<int>> fg, bg;
bool multitile = false;
bool rotates = false;
bool animated = false;
int height_3d = 0;
point offset = point_zero;

Expand Down

0 comments on commit 2abca8f

Please sign in to comment.