From 082a44f505c3ee7317d8924c96a7552f17c9b9b1 Mon Sep 17 00:00:00 2001 From: verate Date: Thu, 7 May 2020 20:50:05 -0600 Subject: [PATCH 1/5] Animate tiles marked animated in tile_config.json --- src/cata_tiles.cpp | 18 ++++++++++++++++++ src/cata_tiles.h | 1 + 2 files changed, 19 insertions(+) diff --git a/src/cata_tiles.cpp b/src/cata_tiles.cpp index db94aa5718f16..21808bc81ca94 100644 --- a/src/cata_tiles.cpp +++ b/src/cata_tiles.cpp @@ -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 << @@ -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(now); + 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(); + // 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! diff --git a/src/cata_tiles.h b/src/cata_tiles.h index 2049e20b4fa91..d4c35be85583b 100644 --- a/src/cata_tiles.h +++ b/src/cata_tiles.h @@ -39,6 +39,7 @@ struct tile_type { weighted_int_list> fg, bg; bool multitile = false; bool rotates = false; + bool animated = false; int height_3d = 0; point offset = point_zero; From c87e446fd7acf15bda818484d3a94b3bbba77160 Mon Sep 17 00:00:00 2001 From: verate <64706893+verate@users.noreply.github.com> Date: Fri, 8 May 2020 07:26:46 -0600 Subject: [PATCH 2/5] Style --- src/cata_tiles.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cata_tiles.cpp b/src/cata_tiles.cpp index 21808bc81ca94..ac69aacd46506 100644 --- a/src/cata_tiles.cpp +++ b/src/cata_tiles.cpp @@ -1906,7 +1906,7 @@ bool cata_tiles::draw_from_id_string( std::string id, TILE_CATEGORY category, // 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(now); + auto now_ms = std::chrono::time_point_cast( now ); auto value = now_ms.time_since_epoch(); // aiming roughly at the standard 60 frames per second: long animation_frame = value.count() / 17; From a1e285b7e897bddbc250b6da0c3b230d3483e9e7 Mon Sep 17 00:00:00 2001 From: verate <64706893+verate@users.noreply.github.com> Date: Fri, 8 May 2020 07:27:15 -0600 Subject: [PATCH 3/5] Style --- src/cata_tiles.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cata_tiles.cpp b/src/cata_tiles.cpp index ac69aacd46506..e23817ad0895a 100644 --- a/src/cata_tiles.cpp +++ b/src/cata_tiles.cpp @@ -1902,7 +1902,7 @@ bool cata_tiles::draw_from_id_string( std::string id, TILE_CATEGORY category, loc_rand = c; // idle tile animations: - if ( display_tile.animated ) { + 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(); From 66fc640963704bf83ab6fc556faeb05c705cba50 Mon Sep 17 00:00:00 2001 From: verate <64706893+verate@users.noreply.github.com> Date: Fri, 8 May 2020 12:06:03 -0600 Subject: [PATCH 4/5] Replace tabs Co-authored-by: Alexey Mostovoy <1931904+AMurkin@users.noreply.github.com> --- src/cata_tiles.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cata_tiles.cpp b/src/cata_tiles.cpp index e23817ad0895a..49e76005a1b4c 100644 --- a/src/cata_tiles.cpp +++ b/src/cata_tiles.cpp @@ -1903,8 +1903,8 @@ bool cata_tiles::draw_from_id_string( std::string id, TILE_CATEGORY category, // 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: + // 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( now ); auto value = now_ms.time_since_epoch(); From 67501b79c63a55b7b866fa148fa72a50030ccd1e Mon Sep 17 00:00:00 2001 From: verate <64706893+verate@users.noreply.github.com> Date: Sat, 9 May 2020 07:44:27 -0600 Subject: [PATCH 5/5] use int instead of long --- src/cata_tiles.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cata_tiles.cpp b/src/cata_tiles.cpp index 49e76005a1b4c..2693634bcc025 100644 --- a/src/cata_tiles.cpp +++ b/src/cata_tiles.cpp @@ -1909,10 +1909,10 @@ bool cata_tiles::draw_from_id_string( std::string id, TILE_CATEGORY category, auto now_ms = std::chrono::time_point_cast( now ); auto value = now_ms.time_since_epoch(); // aiming roughly at the standard 60 frames per second: - long animation_frame = value.count() / 17; + int 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(); + 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;