| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
#pragma once |
| 22 |
|
| 23 |
#include <cstdint> |
| 24 |
#include <functional> |
| 25 |
#include <vector> |
| 26 |
|
| 27 |
#include "timing.h" |
| 28 |
|
| 29 |
namespace fheroes2 |
| 30 |
{ |
| 31 |
class RenderProcessor |
| 32 |
{ |
| 33 |
public: |
| 34 |
RenderProcessor( const RenderProcessor & ) = delete; |
| 35 |
|
| 36 |
~RenderProcessor() = default; |
| 37 |
|
| 38 |
RenderProcessor & operator=( const RenderProcessor & ) = delete; |
| 39 |
|
| 40 |
static RenderProcessor & instance(); |
| 41 |
|
| 42 |
void registerRenderers( const std::function<void()> & preRenderer, const std::function<void()> & postRenderer ) |
| 43 |
{ |
| 44 |
_preRenderer = preRenderer; |
| 45 |
_postRenderer = postRenderer; |
| 46 |
} |
| 47 |
|
| 48 |
void unregisterRenderers() |
| 49 |
{ |
| 50 |
_preRenderer = {}; |
| 51 |
_postRenderer = {}; |
| 52 |
} |
| 53 |
|
| 54 |
void enableRenderers() |
| 55 |
{ |
| 56 |
_enableRenderers = true; |
| 57 |
} |
| 58 |
|
| 59 |
void disableRenderers() |
| 60 |
{ |
| 61 |
_enableRenderers = false; |
| 62 |
} |
| 63 |
|
| 64 |
bool preRenderAction( std::vector<uint8_t> & palette ); |
| 65 |
|
| 66 |
void postRenderAction() const; |
| 67 |
|
| 68 |
void startColorCycling() |
| 69 |
{ |
| 70 |
if ( _enableCycling ) { |
| 71 |
return; |
| 72 |
} |
| 73 |
|
| 74 |
_enableCycling = true; |
| 75 |
|
| 76 |
|
| 77 |
_cyclingTimer.reset(); |
| 78 |
} |
| 79 |
|
| 80 |
void stopColorCycling() |
| 81 |
{ |
| 82 |
_enableCycling = false; |
| 83 |
} |
| 84 |
|
| 85 |
bool isCyclingUpdateRequired() const |
| 86 |
{ |
| 87 |
return _enableCycling && _cyclingTimer.getMs() + _previousCyclingInterval >= 2 * _cyclingInterval && _lastRenderCall.getMs() > _frameHalfInterval; |
| 88 |
} |
| 89 |
|
| 90 |
private: |
| 91 |
RenderProcessor() = default; |
| 92 |
|
| 93 |
std::function<void()> _preRenderer; |
| 94 |
std::function<void()> _postRenderer; |
| 95 |
|
| 96 |
fheroes2::Time _cyclingTimer; |
| 97 |
fheroes2::Time _lastRenderCall; |
| 98 |
|
| 99 |
|
| 100 |
uint64_t _previousCyclingInterval{ _cyclingInterval }; |
| 101 |
|
| 102 |
uint32_t _cyclingCounter{ 0 }; |
| 103 |
|
| 104 |
bool _enableRenderers{ false }; |
| 105 |
bool _enableCycling{ false }; |
| 106 |
|
| 107 |
static const uint64_t _cyclingInterval{ 220 }; |
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
static constexpr uint64_t _frameHalfInterval{ 8 }; |
| 112 |
}; |
| 113 |
} |