mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 18:07:34 +00:00
LibCards: Centralise card bitmap creation
Instead of each card being responsible for painting its own bitmaps, we now have a CardPainter which is responsible for this. It paints a given card the first time it is requested, and then re-uses that bitmap when requested in the future. This saves memory for duplicate cards (such as in Spider where several sets of the same suit are used) or unused ones (for example, the inverted cards which are only used by Hearts). It also means we don't throw away bitmaps and then re-create identical ones when starting a new game. We get some nice memory savings from this: | | Before | After | Before (Virtual) | After (Virtual) | |:----------|---------:|---------:|-----------------:|----------------:| | Hearts | 12.2 MiB | 9.3 MiB | 25.1 MiB | 22.2 MiB | | Spider | 12.1 MiB | 10.1 MiB | 29.2 MiB | 22.9 MiB | | Solitaire | 16.4 MiB | 9.0 MiB | 25.0 MiB | 21.9 MiB | All these measurements taken from x86_64 build, from a fresh launch of each game after the animation has finished, but without making any moves. The Hearts value will go up once inverted cards start being requested.
This commit is contained in:
parent
aac2488d5c
commit
7f46d31849
5 changed files with 249 additions and 141 deletions
|
@ -113,11 +113,7 @@ public:
|
|||
private:
|
||||
Card(Suit, Rank);
|
||||
|
||||
static NonnullRefPtr<Gfx::Bitmap> invert_bitmap(Gfx::Bitmap&);
|
||||
|
||||
Gfx::IntRect m_rect;
|
||||
NonnullRefPtr<Gfx::Bitmap> m_front;
|
||||
RefPtr<Gfx::Bitmap> m_front_inverted;
|
||||
Gfx::IntPoint m_old_position;
|
||||
Suit m_suit;
|
||||
Rank m_rank;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue