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

Animate tiles marked as animated in tile_config.json #40342

Merged
merged 5 commits into from
May 11, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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 ) {
verate marked this conversation as resolved.
Show resolved Hide resolved
verate marked this conversation as resolved.
Show resolved Hide resolved
// 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:
verate marked this conversation as resolved.
Show resolved Hide resolved
auto now = std::chrono::system_clock::now();
auto now_ms = std::chrono::time_point_cast<std::chrono::milliseconds>(now);
verate marked this conversation as resolved.
Show resolved Hide resolved
auto value = now_ms.time_since_epoch();
// aiming roughly at the standard 60 frames per second:
long animation_frame = value.count() / 17;
// offset by log_rand so that everything does not blink at the same time:
animation_frame += loc_rand;
long frames_in_loop = display_tile.fg.get_weight();
verate marked this conversation as resolved.
Show resolved Hide resolved
// 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