diff --git a/src/graphics.cpp b/src/graphics.cpp index e41619445c..cead9aa3ae 100644 --- a/src/graphics.cpp +++ b/src/graphics.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include "graphics.h" #include "bitmap.h" @@ -33,6 +34,11 @@ #include "message_overlay.h" #include "scene.h" +namespace { + constexpr uint32_t size_random_blocks = 4; + constexpr uint32_t size_array_random_blocks = 4800; +} + namespace Graphics { void UpdateTitle(); void DrawFrame(); @@ -60,6 +66,8 @@ namespace Graphics { std::unique_ptr message_overlay; std::unique_ptr fps_overlay; + + std::array random_blocks; } unsigned SecondToFrame(float const second) { @@ -80,6 +88,10 @@ void Graphics::Init() { fps_overlay.reset(new FpsOverlay()); next_fps_time = 0; + + for (uint32_t i = 0; i < size_array_random_blocks; i++) { + random_blocks[i] = i; + } } void Graphics::Quit() { @@ -250,6 +262,10 @@ void Graphics::Transition(TransitionType type, int duration, bool erase) { else screen1 = screen2; } + + if (type == TransitionRandomBlocks) { + std::shuffle(random_blocks.begin(), random_blocks.end(), Utils::GetRNG()); + } } screen_erased = erase; @@ -274,7 +290,6 @@ void Graphics::UpdateTransition() { // Fallback to FadeIn/Out for not implemented transition types: // (Remove from here when implemented below) switch (transition_type) { - case TransitionRandomBlocks: case TransitionRandomBlocksUp: case TransitionRandomBlocksDown: case TransitionZoomIn: @@ -296,6 +311,18 @@ void Graphics::UpdateTransition() { dst->Blit(0, 0, *screen2, screen2->GetRect(), 255 * percentage / 100); break; case TransitionRandomBlocks: + dst->Blit(0, 0, *screen1, screen1->GetRect(), 255); + for (uint32_t i = 0; i < size_array_random_blocks * percentage / 100; i++) { + dst->Blit(random_blocks[i] % (w / size_random_blocks) * size_random_blocks, + random_blocks[i] / (w / size_random_blocks) * size_random_blocks, + *screen2, + Rect( + random_blocks[i] % (w / size_random_blocks) * size_random_blocks, + random_blocks[i] / (w / size_random_blocks) * size_random_blocks, + size_random_blocks, + size_random_blocks), + 255); + } break; case TransitionRandomBlocksUp: break; diff --git a/src/utils.cpp b/src/utils.cpp index d156e9094d..445607338a 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -383,6 +383,10 @@ int32_t Utils::GetRandomNumber(int32_t from, int32_t to) { return int32_t(ures); } +std::mt19937 &Utils::GetRNG() { + return rng; +} + bool Utils::ChanceOf(int32_t n, int32_t m) { assert(n >= 0 && m > 0); return GetRandomNumber(1, m) <= n; diff --git a/src/utils.h b/src/utils.h index 48bb78c99e..4e7bc2bf3c 100644 --- a/src/utils.h +++ b/src/utils.h @@ -22,6 +22,7 @@ #include #include #include +#include #include "system.h" namespace Utils { @@ -172,6 +173,13 @@ namespace Utils { */ int32_t GetRandomNumber(int32_t from, int32_t to); + /** + * Gets the seeded Random Number Generator (RNG). + * + * @return the random number generator + */ + std::mt19937 &GetRNG(); + /** * Has an n/m chance of returning true. If n>m, always returns true. *