File: ImageCache.h

package info (click to toggle)
lordsawar 0.3.2%2Bfrogknows-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 41,716 kB
  • sloc: cpp: 103,193; sh: 4,965; xml: 2,220; makefile: 1,371
file content (1107 lines) | stat: -rw-r--r-- 41,243 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
// Copyright (C) 2003, 2004, 2005, 2006, 2007 Ulf Lorenz
// Copyright (C) 2004, 2006 Andrea Paternesi
// Copyright (C) 2006-2011, 2014, 2015, 2017, 2020 Ben Asselstine
//
//  This program is free software; you can redistribute it and/or modify
//  it under the terms of the GNU General Public License as published by
//  the Free Software Foundation; either version 3 of the License, or
//  (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU Library General Public License for more details.
//
//  You should have received a copy of the GNU General Public License
//  along with this program; if not, write to the Free Software
//  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 
//  02110-1301, USA.

#pragma once
#ifndef IMAGE_CACHE_H
#define IMAGE_CACHE_H

#include <list>
#include <map>
#include <vector>
#include <string.h>
#include <cairomm/context.h>
#include "PixMaskCache.h"

#include "player.h"
#include "PixMask.h"
#include "maptile.h"
#include "hero.h"

class Road;
class City;
class Temple;
class Ruin;
class Bridge;
class Stack;
class Shieldset;
class SelectorPixMaskCacheItem;
class ArmyPixMaskCacheItem;
class FlagPixMaskCacheItem;
class CircledArmyPixMaskCacheItem;
class TilePixMaskCacheItem;
class CityPixMaskCacheItem;
class TowerPixMaskCacheItem;
class TemplePixMaskCacheItem;
class RuinPixMaskCacheItem;
class DiplomacyPixMaskCacheItem;
class RoadPixMaskCacheItem;
class FogPixMaskCacheItem;
class BridgePixMaskCacheItem;
class CursorPixMaskCacheItem;
class ShieldPixMaskCacheItem;
class ProdShieldPixMaskCacheItem;
class MoveBonusPixMaskCacheItem;
class ShipPixMaskCacheItem;
class PlantedStandardPixMaskCacheItem;
class PortPixMaskCacheItem;
class SignpostPixMaskCacheItem;
class BagPixMaskCacheItem;
class ExplosionPixMaskCacheItem;
class NewLevelPixMaskCacheItem;
class DefaultTileStylePixMaskCacheItem;
class TartanPixMaskCacheItem;
class EmptyTartanPixMaskCacheItem;
class StatusPixMaskCacheItem;
class GameButtonPixMaskCacheItem;
class DialogPixMaskCacheItem;
class MedalPixMaskCacheItem;

//! Cache for generated army and map images.
/** Soliton class for caching army and map images
  * 
  * With the introduction of player-specific colors, the problem of caching
  * images has popped up. The player colors are implemented by taking an army
  * picture and a mask, with the mask being a 16 color image, substituting
  * the colors in the mask and blitting the mask over the army (or e.g. city)
  * image. This takes several blits (>3, there are also things like medals 
  * to be considered) and is therefore costly.
  *
  * This class approaches this problem by caching formatted images. You get
  * e.g. an army image by querying the cache, which either gives you the cached
  * image or creates a new one. If the size is exceeded, the class will free
  * the oldest (not used for the longest time) images until it gets below the
  * treshold. It maintains some kind of balance between cached city pictures
  * and cached army pictures, but the kind of balance may change, so I'll
  * better not describe it here. :)
  *
  * Recently, it has been improved to cache flag pictures (showing how many
  * armies a stack contains) as well.
  *
  * The maximum cache size can be changed on the fly by modifying the value in 
  * the Configuration class. However, if set too small (around 1 megabyte), this
  * value will silently be ignored.
  *
  * @note For efficiency reasons, the class will not copy the surfaces it has,
  * so DON'T MODIFY THEM unless you know what you do!
  */
class ImageCache
{
    public:
  enum CursorType
    {
      POINTER = 0,
      MAGNIFYING_GLASS,
      SHIP,
      ROOK,
      HAND,
      TARGET,
      FEET,
      RUIN,
      SWORD,
      QUESTION,
      HEART,
      GOTO_ARROW,
      CLOSED_HAND,
    };
  enum GameButtonType
    {
      DIPLOMACY_NO_PROPOSALS = 0,
      STACK_PARK,
      NEXT_MOVABLE_STACK,
      STACK_MOVE,
      MOVE_ALL_STACKS,
      CENTER_ON_STACK,
      STACK_DEFEND,
      STACK_DESELECT,
      DIPLOMACY_NEW_PROPOSALS,
      STACK_SEARCH,
      END_TURN,
      GARRISON
    };
  enum StatusBoxImageType
    {
      STATUS_CITY = 0,
      STATUS_TREASURY,
      STATUS_INCOME,
      STATUS_UPKEEP,
      STATUS_DEFENSE, //doesn't belong but we put it here anyway
    };

  enum DialogImageType
    {
      DIALOG_NEXT_TURN = 0,
      DIALOG_NEW_HERO_MALE,
      DIALOG_NEW_HERO_FEMALE,
      DIALOG_CONQUERED_CITY,
      DIALOG_WINNING,
      DIALOG_RUIN_SUCCESS,
      DIALOG_RUIN_DEFEAT,
      DIALOG_PARLEY_OFFERED,
      DIALOG_PARLEY_REFUSED,
      DIALOG_COMMENTATOR,
    };

        //! Method for getting/creating the soliton instance.
        static ImageCache* getInstance();

        //! Explicitly deletes the soliton instance
        static void deleteInstance();

        //! Get the current cache size, the maximum is in Configuration::s_cacheSize
        guint32 getCacheSize() const {return d_cachesize;}

        /** Method for getting the army picture from the cache
          * 
          * This method returns either the cached image of the given type or
          * creates a new one and caches it. Use this method to access
          * army images! And: Don't touch the returned surface!! For performance
          * reasons you get the original surface which is also in the cache.
          *
          * The returned surface contains the correct player colors and some
          * icons displaying the level of the unit.
          *
          * @param armyset      the armyset to be used
          * @param army         the index of the army to be used
          * @param player       the player owning the army
          * @param medals       an array of medal types
          * @param map          whether or not this army appears on a map
          * @param font_size    the height of the default font, if not on map
	  * @param greyed       the image is greyed out; deselected/inactive.
          * @return the image of the unit
          */
        PixMask* getArmyPic(guint32 armyset, guint32 army, const Player* p,
                                const bool* medals, bool map, guint32 font_size,
                                bool greyed = false);
	PixMask* getArmyPic(Army *a, bool greyed = false);
        PixMask* getDialogArmyPic(Army *a, guint32 font_size, bool greyed = false);
        PixMask* getCircledArmyPic(guint32 armyset, guint32 army, 
                                   const Player* p, const bool* medals, 
                                   bool greyed, guint32 circle_colour_id,
                                   bool show_army, guint32 font_size);
        PixMask *getCircledArmyPic(Army *a, bool greyed,
                                   guint32 circle_colour_id, bool show_army,
                                   guint32 font_size);

        /** Method for getting the shield picture from the cache
          * 
          * This method returns either the cached image of the given type or
          * creates a new one and caches it. Use this method to access
          * army images! And: Don't touch the returned surface!! For performance
          * reasons you get the original surface which is also in the cache.
          *
          * The returned surface contains the correct player colors and some
          * icons displaying the level of the unit.
          *
          * @param shieldset    the id of the shieldset to be used
	  * @param type         the size of the shield: 0=sm, 1=med, 2=lg
          * @param colour       which player the shield is for
          * @param map          whether or not this shield appears on a map
          * @param font_size    for map=false, to calculate relative size
          * @return the image of the shield
          */
        PixMask* getShieldPic(guint32 shieldset, guint32 type, guint32 colour,
                              bool map, guint32 font_size);
        PixMask* getShieldPic(guint32 type, Player *p, bool map,
                              guint32 font_size);

        /** Method for getting a ruin picture
          *
          * @param type         the type of the ruin
          * @return image of the ruin 
          */
        PixMask* getRuinPic(Ruin *r);
        PixMask* getRuinPic(int type);
        PixMask* getRuinPic(int type, guint32 cityset);

        /** Method for getting a diplomacy icon
          *
          * @param type         0 = small, or 1 = large.
          * @param state        the diplomatic state.  e.g. peace, war, etc
          * @font_size is the height of the default font in pixels.
          * @return image of the icon
          */
        PixMask* getDiplomacyPic(int type, Player::DiplomaticState state,
                                 guint32 font_size);

        /** Method for getting a temple picture
          *
          * @param type         the type of the temple
          * @return image of the temple
          */
        PixMask* getTemplePic(Temple *t);
        PixMask* getTemplePic(int type);
        PixMask* getTemplePic(int type, guint32 cityset);

        /** Method for getting a road picture
          *
          * @param type         the type of the road
          * @return image of the road
          */
        PixMask* getRoadPic(Road *r);
        PixMask* getRoadPic(int type, guint32 tileset);
        PixMask* getRoadPic(int type);

        /** Method for getting a fog picture
          *
          * @param type         the type of the fog
          * @return image of the fog
          */
        PixMask* getFogPic(int type, guint32 tileset);
        PixMask* getFogPic(int type);

        /** Method for getting a bridge picture
          *
          * @param type         the type of the bridge 0=e/w 1=n/s
          * @return image of the bridge
          */
        PixMask* getBridgePic(Bridge *b);
        PixMask* getBridgePic(int type, guint32 tileset);
        PixMask* getBridgePic(int type);

        /** Method for getting a cursor picture
          *
          * @param type         the type of the cursor 
          * @font_size          the height of the default font in pixels.
          * @return image of the cursor
          */
        PixMask* getCursorPic(int type, guint32 font_size);

        /** Method for getting a ship picture.  This is the picture
	  * that appears when the stack goes into the water.
          *
          * @param p            the player to colour the ship as
          * @return image of the ship
          */
        PixMask* getShipPic(const Player* p);

        /** Method for getting a standard picture.  This is the picture
	  * that appears when the hero plants a flag..
          *
          * @param p            the player to colour the flag as
          * @return image of the standard
          */
        PixMask* getPlantedStandardPic(const Player* p);

        /** Method for getting a port picture.  This is the picture
	  * that appears often as an anchor on coastal regions.
          *
          * @return image of the port
          */
        PixMask* getPortPic();
        PixMask* getPortPic(guint32 cityset);

        /** Method for getting a signpost picture.  This is the picture
	  * that appears as a little tiny sign on grassy tiles.
          *
          * @return image of the signpost
          */
        PixMask* getSignpostPic();
        PixMask* getSignpostPic(guint32 cityset);

        /** Method for getting a bag-of-items picture.  This is the picture
	  * that shows when a hero drops one or more items on the ground.
          *
          * @return image of the sack of items
          */
        PixMask* getBagPic();
        PixMask* getBagPic(guint32 armyset);

        /** Method for getting an explosion picture.  This is the picture
	  * that shows when stacks are fighting.
          *
          * @return image of the explosion.
          */
        PixMask* getExplosionPic();
        PixMask* getExplosionPic(guint32 tileset);

	/** Method for getting a new-level picture.  This is the picture
	 * that appears when a hero gains a new level, and subsequently gets
	 * to increase a stat.
	 *
	 * @param p the player to colour the image as.
         * @param gender male=1, female=2.
         * @font_size is the height of the default font in pixels.
	 * @return new-level image.
	 */
        PixMask* getNewLevelPic(const Player* p, guint32 gender,
                                guint32 font_size);

        /** Method for getting a picture that represents a type of tile style.
         *  The parameter is related to tilestyle.h:TileStyle::Type.
         */
        PixMask* getDefaultTileStylePic(guint32 tilestyle_type, 
                                        guint32 tilesize);

        /** Method for getting a picture of the tartan progess bar.
         * The image will not be any wider than width, but can be less wide.
         */
        PixMask* getTartanPic (const Player *p, guint32 width,
                               Shieldset *s, guint32 font_size);

        /** Method for getting a picture of the empty tartan progess bar.
         * The image will not be any wider than width, but can be less wide.
         */
        PixMask* getEmptyTartanPic (const Player *p, guint32 width,
                                    Shieldset *s, guint32 font_size);

        /** Method for getting a city picture
          * 
          * For simplicity we have extended the basic_image/mask style to
          * cities as well, since it greatly reduces the number of images.
          * Use this method solely to get city images, and don't touch the
          * images!
          *
          * @param type         the level of the city; -1 returns the pic for
          *                     the razed city
          * @param player       the player owning the city
	  * @param cityset      the cityset that has the city image
          * @return image of the described city
          */
        PixMask* getCityPic(int type, const Player* p, guint32 cityset);
        /** Another method for getting a city picture
          *
          * Most often, we don't need such a sophisticated method. So just
          * supply the city instance and be happy. :)
          *
          * @param city     the city whose picture we want to get
          * @return image of the city
          */
        PixMask* getCityPic(const City* city);
        PixMask* getCityPic(const City* city, guint32 cityset);

        /** Method for getting tower pictures.
          *
          * As with the other methods, use solely this method to get the tower 
          * images. And DON'T modify the images!
          *
          * @param p the player for which we want to get the tower
          * @return image for the tower
          */
        PixMask* getTowerPic(const Player *p);
	PixMask* getTowerPic(const Player* p, guint32 cityset);
        /** Method for getting flag pictures.
          *
          * As with the other methods, use solely this method to get the flag
          * images. And DON'T modify the images!
          *
          * @param stack    the stack for which we want to get the flag
          * @return image for the flag
          */
        PixMask* getFlagPic(const Stack* s);
        PixMask* getFlagPic(const Stack* s, guint32 tileset);
	PixMask* getFlagPic(guint32 stack_size, const Player *p);
        PixMask* getFlagPic(guint32 stack_size, const Player *p, guint32 tileset);

        /** Method for getting selector pictures.
          *
          * As with the other methods, use solely this method to get the 
          * selector images. And DON'T modify the images!
          *
          * @param type the frame of the selector
          * @param p the player to draw it for
          * @return image for the flag
          */
        PixMask* getSelectorPic(guint32 type, guint32 frame, const Player* p, guint32 tileset);

	PixMask* getSelectorPic(guint32 type, guint32 frame, const Player *p);

	PixMask* getTilePic(int tile_style_id, int fog_type_id, bool has_bag, bool has_standard, int standard_player_id, int stack_size, int stack_player_id, int army_type_id, bool has_tower, bool has_ship, Maptile::Building building_type, int building_subtype, Vector<int> building_tile, int building_player_id, guint32 tilesize, bool has_grid, guint32 tileset, guint32 cityset, guint32 shieldset, int stone_type);
	PixMask* getTilePic(int tile_style_id, int fog_type_id, bool has_bag, bool has_standard, int standard_player_id, int stack_size, int stack_player_id, int army_type_id, bool has_tower, bool has_ship, Maptile::Building building_type, int building_subtype, Vector<int> building_tile, int building_player_id, guint32 tilesize, bool has_grid, int stone_type);


        PixMask* getMoveBonusPic(guint32 bonus, bool has_ship, guint32 font_size);
        /** Method for getting production shield pictures.
          *
          * As with the other methods, use solely this method to get the 
          * shield images. And DON'T modify the images!
          *
          * @param type home/away/destination/source/invalid.  
	  * one sees home/away
	  * normally, but when "see all" is turned on, one sees source/dest.
          * @param prod city production is going on, true or false
          * @return image for the shield
	  * note that type=source, production=false is impossible
	  * note that type=invalid,production=true is used to show the symbol
	  * that means no more units can be vectored to this city.
          */
        PixMask* getProdShieldPic(guint32 type, bool prod);

        PixMask* getMedalPic(bool large, guint32 type, guint32 font_size);

        //! Erase cached graphics.
        void reset();

        //these routines get a base image, not a cached image.
        PixMask* getDiplomacyImage(int type, Player::DiplomaticState state);
        PixMask* getCursorImage(int type);
        PixMask *getProdShieldImage(guint32 type);
        PixMask* getMoveBonusImage(guint32 type);
        PixMask* getDefaultTileStyleImage(guint32 type);
        PixMask* getMedalImage(bool large, int type);
        PixMask *getNewLevelImage(bool female, bool mask);
        PixMask* getSmallRuinedCityImage();
	//! Return a small hero picture, either white (active==true) or black.
        PixMask* getSmallHeroImage(bool active);
        PixMask* getSmallBagImage();
        PixMask*getSmallTempleImage();
        PixMask*getSmallRuinExploredImage();
        PixMask* getSmallRuinUnexploredImage();
        PixMask* getSmallStrongholdUnexploredImage();
        //! get an image for one of the buttons on the main game window.
        PixMask* getStatusPic(guint32 type, guint32 font_size);
        /** Method for getting main screen game button pictures.
         *
         * @param type is one of the enums.
         * @font_size is the height of the default font in pixels.
         */
        PixMask* getGameButtonPic(guint32 type, guint32 font_size);
        PixMask* getDialogPic(guint32 type, guint32 font_size);
        PixMask* getWaypointImage(guint32 type);

        PixMask* getNextTurnPic ();
        PixMask* getCityDefeatedPic ();
        PixMask* getWinningPic();
        PixMask* getHeroPic (Hero::Gender gender);
        PixMask* getRuinSuccessPic();
        PixMask* getRuinDefeatPic();
        PixMask *getParleyOfferedPic();
        PixMask *getParleyRefusedPic();
        PixMask *getCommentatorPic ();

        PixMask* getGameButtonImage(guint32 type);

	static PixMask* applyMask(PixMask* image, PixMask* mask, const Player* p);
	static PixMask* applyMask(PixMask* image, PixMask* mask, Gdk::RGBA colour);

	static PixMask* greyOut(PixMask* image);

        static PixMask* circled(PixMask* image, Gdk::RGBA colour, bool coloured = true, double width_percent = 75.0);
        static void draw_circle(Cairo::RefPtr<Cairo::Context> cr, double width_percent, int width, int height, Gdk::RGBA colour, bool coloured = true, bool mask = false);
        static PixMask* loadMiscImage(Glib::ustring pngfile);

        static int calculate_width_from_adjusted_height (PixMask *p, double new_height);
        static void add_underline (PixMask **p, Gdk::RGBA color, guint32 font_size);
    private:
        ImageCache();
        ~ImageCache();

        //! Checks if the cache has exceeded the maximum size and reduce it.
        void checkPictures();
        
        bool loadDiplomacyImages();
        bool loadCursorImages();
        bool loadProdShieldImages();
        bool loadMoveBonusImages();
        bool loadNewLevelImages();
        bool loadMedalImages(Glib::ustring sm, Glib::ustring lg);
        bool loadDefaultTileStyleImages();
        bool loadWaypointImages();
        bool loadGameButtonImages();

        //the data
        static ImageCache* s_instance;

        guint32 d_cachesize;
  
        PixMaskCache<SelectorPixMaskCacheItem> selectorcache;
        PixMaskCache<ArmyPixMaskCacheItem> armycache;
        PixMaskCache<FlagPixMaskCacheItem> flagcache;
        PixMaskCache<CircledArmyPixMaskCacheItem> circledarmycache;
        PixMaskCache<TilePixMaskCacheItem> tilecache;
        PixMaskCache<CityPixMaskCacheItem> citycache;
        PixMaskCache<TowerPixMaskCacheItem> towercache;
        PixMaskCache<TemplePixMaskCacheItem> templecache;
        PixMaskCache<RuinPixMaskCacheItem> ruincache;
        PixMaskCache<DiplomacyPixMaskCacheItem> diplomacycache;
        PixMaskCache<RoadPixMaskCacheItem> roadcache;
        PixMaskCache<FogPixMaskCacheItem> fogcache;
        PixMaskCache<BridgePixMaskCacheItem> bridgecache;
        PixMaskCache<CursorPixMaskCacheItem> cursorcache;
        PixMaskCache<ShieldPixMaskCacheItem> shieldcache;
        PixMaskCache<ProdShieldPixMaskCacheItem> prodshieldcache;
        PixMaskCache<MoveBonusPixMaskCacheItem> movebonuscache;
        PixMaskCache<ShipPixMaskCacheItem> shipcache;
        PixMaskCache<PlantedStandardPixMaskCacheItem> plantedstandardcache;
        PixMaskCache<PortPixMaskCacheItem> portcache;
        PixMaskCache<SignpostPixMaskCacheItem> signpostcache;
        PixMaskCache<BagPixMaskCacheItem> bagcache;
        PixMaskCache<ExplosionPixMaskCacheItem> explosioncache;
        PixMaskCache<NewLevelPixMaskCacheItem> newlevelcache;
        PixMaskCache<DefaultTileStylePixMaskCacheItem> defaulttilestylecache;
        PixMaskCache<TartanPixMaskCacheItem> tartancache;
        PixMaskCache<EmptyTartanPixMaskCacheItem> emptytartancache;
        PixMaskCache<StatusPixMaskCacheItem> statuscache;
        PixMaskCache<GameButtonPixMaskCacheItem> gamebuttoncache;
        PixMaskCache<DialogPixMaskCacheItem> dialogcache;
        PixMaskCache<MedalPixMaskCacheItem> medalcache;

        PixMask* d_diplomacy[2][DIPLOMACY_TYPES];
        PixMask* d_cursor[CURSOR_TYPES];
        PixMask* d_prodshield[PRODUCTION_SHIELD_TYPES];
        PixMask* d_movebonus[MOVE_BONUS_TYPES];
	PixMask *d_newlevel_male;
	PixMask *d_newlevelmask_male;
	PixMask *d_newlevel_female;
	PixMask *d_newlevelmask_female;
        PixMask *d_default_tilestyles[DEFAULT_TILESTYLE_TYPES];
        PixMask* d_medal[2][MEDAL_TYPES];
	PixMask* d_smallruinedcity;
	PixMask* d_smallhero;
	PixMask* d_smallbag;
	PixMask* d_smallinactivehero;
	PixMask* d_small_ruin_unexplored;
	PixMask* d_small_stronghold_unexplored;
	PixMask* d_small_ruin_explored;
	PixMask* d_small_temple;
        PixMask *d_waypoint[NUM_WAYPOINTS];
        PixMask *d_gamebuttons[NUM_GAME_BUTTON_IMAGES];
        PixMask *d_nextturn;
        PixMask *d_citydefeated;
        PixMask *d_winning;
        PixMask *d_malehero;
        PixMask *d_femalehero;
        PixMask *d_ruinsuccess;
        PixMask *d_ruindefeat;
        PixMask *d_parleyoffered;
        PixMask *d_parleyrefused;
        PixMask *d_commentator;
};

//! Helper class for selector box items in the ImageCache.
/**
 * These selector box images appear around the active stack.
 * It's a set of frames for an animation.
 */
class SelectorPixMaskCacheItem
{
public:
    static PixMask *generate(SelectorPixMaskCacheItem item);
    static bool loadSelectorImages(Glib::ustring filename, guint32 size, std::vector<PixMask* > &images, std::vector<PixMask* > &masks, bool scale);
    static bool loadSelectors(PixMask *p, guint32 size, std::vector<PixMask* > &images, std::vector<PixMask* > &masks, bool scale);
    int comp(const SelectorPixMaskCacheItem item) const;
    bool operator == (const SelectorPixMaskCacheItem &c) {return !comp(c);};
    bool operator < (const SelectorPixMaskCacheItem &c) const {return comp(c)<0;};
    guint32 tileset;
    guint32 type;
    guint32 frame;
    guint32 player_id;
};

//! Helper class for army items in the ImageCache.
/**
 * These army images appear on the big map as the leader of a stack.
 */
class ArmyPixMaskCacheItem
{
public:
    static PixMask *generate(ArmyPixMaskCacheItem item);
    int comp(const ArmyPixMaskCacheItem item) const;
    bool operator == (const ArmyPixMaskCacheItem &c) {return !comp(c);};
    bool operator < (const ArmyPixMaskCacheItem &c) const {return comp(c)<0;};
    guint32 armyset;
    guint32 army_id;
    guint32 player_id;
    bool medals[3];
    bool map;
    guint32 font_size;
    bool greyed;
};

//! Helper class for stack flag items in the ImageCache.
/**
 * These stack flag images have 8 different sizes, and appear on the big map.
 */
class FlagPixMaskCacheItem
{
public:
    static PixMask *generate(FlagPixMaskCacheItem item);
    static bool loadFlagImages(Glib::ustring filename, guint32 size, std::vector<PixMask* > &images, std::vector<PixMask* > &masks, bool scale);
    static bool loadFlagImages(PixMask *p, guint32 size, std::vector<PixMask* > &images, std::vector<PixMask* > &masks, bool scale);
    int comp(const FlagPixMaskCacheItem item) const;
    bool operator == (const FlagPixMaskCacheItem &c) {return !comp(c);};
    bool operator < (const FlagPixMaskCacheItem &c) const {return comp(c)<0;};
    guint32 tileset;
    guint32 size;
    guint32 player_id;
};

//! Helper class for circled army items in the ImageCache.
/**
 * These circled army images appear in various places in the gui.
 * It's just an army unit with a coloured circle behind it.
 */
class CircledArmyPixMaskCacheItem
{
public:
    static PixMask *generate(CircledArmyPixMaskCacheItem item);
    int comp(const CircledArmyPixMaskCacheItem item) const;
    bool operator == (const CircledArmyPixMaskCacheItem &c) {return !comp(c);};
    bool operator < (const CircledArmyPixMaskCacheItem &c) const {return comp(c)<0;};
    guint32 armyset;
    guint32 army_id;
    guint32 player_id;
    bool medals[3];
    bool greyed;
    guint32 circle_colour_id;
    bool show_army;
    guint32 font_size;
};

//! Helper class for big map tile items in the ImageCache.
/**
 * These tile images are the almalgmation of all the things on a given tile of
 * the big map.
 */
class TilePixMaskCacheItem
{
public:
    static PixMask *generate(TilePixMaskCacheItem item);
    int comp(const TilePixMaskCacheItem item) const;
    bool operator == (const TilePixMaskCacheItem &c) {return !comp(c);};
    bool operator < (const TilePixMaskCacheItem &c) const {return comp(c)<0;};
  int tile_style_id;
  int fog_type_id;
  bool has_bag;
  bool has_standard;
  int standard_player_id;
  int stack_size; //flag size
  int stack_player_id;
  int army_type_id;
  bool has_tower;
  bool has_ship;
  Maptile::Building building_type;
  int building_subtype;
  Vector<int> building_tile;
  int building_player_id;
  guint32 tilesize;
  bool has_grid;
  guint32 tileset;
  guint32 cityset;
  guint32 shieldset;
  int stone_type;
};

//! Helper class for city items in the ImageCache.
/**
 * These city images appear on the big map.
 */
class CityPixMaskCacheItem
{
public:
    static PixMask *generate(CityPixMaskCacheItem item);
    int comp(const CityPixMaskCacheItem item) const;
    bool operator == (const CityPixMaskCacheItem &c) {return !comp(c);};
    bool operator < (const CityPixMaskCacheItem &c) const {return comp(c)<0;};
    guint32 cityset;
    int type;
    guint32 player_id;
};

//! Helper class for tower items in the ImageCache.
/**
 * These tower images appear on the big map when a stack goes into defend mode.
 */
class TowerPixMaskCacheItem
{
public:
    static PixMask *generate(TowerPixMaskCacheItem item);
    int comp(const TowerPixMaskCacheItem item) const;
    bool operator == (const TowerPixMaskCacheItem &c) {return !comp(c);};
    bool operator < (const TowerPixMaskCacheItem &c) const {return comp(c)<0;};
    guint32 cityset;
    guint32 player_id;
};

//! Helper class for temple items in the ImageCache.
/**
 * These temple images appear on the big map.
 */
class TemplePixMaskCacheItem
{
public:
    static PixMask *generate(TemplePixMaskCacheItem item);
    int comp(const TemplePixMaskCacheItem item) const;
    bool operator == (const TemplePixMaskCacheItem &c) {return !comp(c);};
    bool operator < (const TemplePixMaskCacheItem &c) const {return comp(c)<0;};
    guint32 cityset;
    int type;
};

//! Helper class for ruin items in the ImageCache.
/**
 * These ruin images appear on the big map.
 */
class RuinPixMaskCacheItem
{
public:
    static PixMask *generate(RuinPixMaskCacheItem item);
    int comp(const RuinPixMaskCacheItem item) const;
    bool operator == (const RuinPixMaskCacheItem &c) {return !comp(c);};
    bool operator < (const RuinPixMaskCacheItem &c) const {return comp(c)<0;};
    guint32 cityset;
    int type;
};

//! Helper class for diplomacy icon items in the ImageCache.
/**
 * These diplomacy icons appear in the diplomacy dialog.
 */
class DiplomacyPixMaskCacheItem
{
public:
    static PixMask *generate(DiplomacyPixMaskCacheItem item);
    int comp(const DiplomacyPixMaskCacheItem item) const;
    bool operator == (const DiplomacyPixMaskCacheItem &c) {return !comp(c);};
    bool operator < (const DiplomacyPixMaskCacheItem &c) const {return comp(c)<0;};
    int type;
    Player::DiplomaticState state;
    guint32 font_size;
};

//! Helper class for road items in the ImageCache.
/**
 * These are the road images that appear on the big map.
 */
class RoadPixMaskCacheItem
{
public:
    static PixMask *generate(RoadPixMaskCacheItem item);
    int comp(const RoadPixMaskCacheItem item) const;
    bool operator == (const RoadPixMaskCacheItem &c) {return !comp(c);};
    bool operator < (const RoadPixMaskCacheItem &c) const {return comp(c)<0;};
    guint32 tileset;
    int type;
};

//! Helper class for fog items in the ImageCache.
/**
 * These are the black fog images that appear on top of the big map.
 * E.g. more of the map gets exposed when army units move around.
 */
class FogPixMaskCacheItem
{
public:
    static PixMask *generate(FogPixMaskCacheItem item);
    int comp(const FogPixMaskCacheItem item) const;
    bool operator == (const FogPixMaskCacheItem &c) {return !comp(c);};
    bool operator < (const FogPixMaskCacheItem &c) const {return comp(c)<0;};
    guint32 tileset;
    int type;
};

//! Helper class for bridge items in the ImageCache.
/**
 * These are the bridge images that appear on the big map.
 */
class BridgePixMaskCacheItem
{
public:
    static PixMask *generate(BridgePixMaskCacheItem item);
    int comp(const BridgePixMaskCacheItem item) const;
    bool operator == (const BridgePixMaskCacheItem &c) {return !comp(c);};
    bool operator < (const BridgePixMaskCacheItem &c) const {return comp(c)<0;};
    guint32 tileset;
    int type;
};

//! Helper class for cursor items in the ImageCache.
/**
 * These are the black and white mouse cursor images.
 */
class CursorPixMaskCacheItem
{
public:
    static PixMask *generate(CursorPixMaskCacheItem item);
    int comp(const CursorPixMaskCacheItem item) const;
    bool operator == (const CursorPixMaskCacheItem &c) {return !comp(c);};
    bool operator < (const CursorPixMaskCacheItem &c) const {return comp(c)<0;};
    int type;
    guint32 font_size;
};

//! Helper class for shield items in the ImageCache.
/**
 * These shield images include the small, medium and large shield images.
 */
class ShieldPixMaskCacheItem
{
public:
    static PixMask *generate(ShieldPixMaskCacheItem item);
    int comp(const ShieldPixMaskCacheItem item) const;
    bool operator == (const ShieldPixMaskCacheItem &c) {return !comp(c);};
    bool operator < (const ShieldPixMaskCacheItem &c) const {return comp(c)<0;};
    guint32 shieldset;
    guint32 type;
    guint32 colour;
    bool map;
    guint32 font_size;
};

//! Helper class for production icon items in the ImageCache.
/**
 * these icons appear on the smallmap.
 */
class ProdShieldPixMaskCacheItem
{
public:
    static PixMask *generate(ProdShieldPixMaskCacheItem item);
    int comp(const ProdShieldPixMaskCacheItem item) const;
    bool operator == (const ProdShieldPixMaskCacheItem &c) {return !comp(c);};
    bool operator < (const ProdShieldPixMaskCacheItem &c) const {return comp(c)<0;};
    guint32 type;
    bool prod;
};

//! Helper class for movement bonus icon items in the ImageCache.
/**
 * These icons appear in the gui, on stack tip infos, or in the stack box.
 */
class MoveBonusPixMaskCacheItem
{
public:
    static PixMask *generate(MoveBonusPixMaskCacheItem item);
    int comp(const MoveBonusPixMaskCacheItem item) const;
    bool operator == (const MoveBonusPixMaskCacheItem &c) {return !comp(c);};
    bool operator < (const MoveBonusPixMaskCacheItem &c) const {return comp(c)<0;};
    guint32 type; // 0=empty, 1=trees, 2=foothills, 3=hills+trees, 4=fly, 5=boat
    guint32 font_size;
};

//! Helper class for boat items in the ImageCache.
/**
 * ship images are for when a stack is in a boat.
 * one ship image per army set, and drawn in the player's colour.
 */
class ShipPixMaskCacheItem
{
public:
    static PixMask *generate(ShipPixMaskCacheItem item);
    int comp(const ShipPixMaskCacheItem item) const;
    bool operator == (const ShipPixMaskCacheItem &c) {return !comp(c);};
    bool operator < (const ShipPixMaskCacheItem &c) const {return comp(c)<0;};
    guint32 player_id;
    guint32 armyset;
};

//! Helper class for planted standard items in the ImageCache.
/**
 * planted standard images are for when the hero plants a flag on the big map.
 */
class PlantedStandardPixMaskCacheItem
{
public:
    static PixMask *generate(PlantedStandardPixMaskCacheItem item);
    int comp(const PlantedStandardPixMaskCacheItem item) const;
    bool operator == (const PlantedStandardPixMaskCacheItem &c) {return !comp(c);};
    bool operator < (const PlantedStandardPixMaskCacheItem &c) const {return comp(c)<0;};
    guint32 player_id;
    guint32 armyset;
};

//! Helper class for port items in the ImageCache.
/**
 * port images are for the ship loading/unloading points on the big map.
 */
class PortPixMaskCacheItem
{
public:
    static PixMask *generate(PortPixMaskCacheItem item);
    int comp(const PortPixMaskCacheItem item) const;
    bool operator == (const PortPixMaskCacheItem &c) {return !comp(c);};
    bool operator < (const PortPixMaskCacheItem &c) const {return comp(c)<0;};
  guint32 cityset;
};

//! Helper class for signpost items in the ImageCache.
/**
 * signpost images are for the signs on the big map.
 */
class SignpostPixMaskCacheItem
{
public:
    static PixMask *generate(SignpostPixMaskCacheItem item);
    int comp(const SignpostPixMaskCacheItem item) const;
    bool operator == (const SignpostPixMaskCacheItem &c) {return !comp(c);};
    bool operator < (const SignpostPixMaskCacheItem &c) const {return comp(c)<0;};
  guint32 cityset;
};

//! Helper class for bag items in the ImageCache.
/**
 * Bags are the things that hold item objects on the big map.
 * There is one bag image per army set.
 */
class BagPixMaskCacheItem
{
public:
    static PixMask *generate(BagPixMaskCacheItem item);
    int comp(const BagPixMaskCacheItem item) const;
    bool operator == (const BagPixMaskCacheItem &c) {return !comp(c);};
    bool operator < (const BagPixMaskCacheItem &c) const {return comp(c)<0;};
    guint32 armyset;
};

//! Helper class for explosion items in the ImageCache.
/**
 * Explosion images appear on the big map and in the fight window.
 * Sometimes they appear in a 2x2 tile size, and sometimes in a 1x1 tile size.
 */
class ExplosionPixMaskCacheItem
{
public:
    static PixMask *generate(ExplosionPixMaskCacheItem item);
    int comp(const ExplosionPixMaskCacheItem item) const;
    bool operator == (const ExplosionPixMaskCacheItem &c) {return !comp(c);};
    bool operator < (const ExplosionPixMaskCacheItem &c) const {return comp(c)<0;};
    guint32 tileset;
};

//! Helper class for "new level" items in the ImageCache.
/**
 * New Level images are full-body images of the hero who is levelling up.  There
 * is a male image and a female image.
 */
class NewLevelPixMaskCacheItem
{
public:
    static PixMask *generate(NewLevelPixMaskCacheItem item);
    int comp(const NewLevelPixMaskCacheItem item) const;
    bool operator == (const NewLevelPixMaskCacheItem &c) {return !comp(c);};
    bool operator < (const NewLevelPixMaskCacheItem &c) const {return comp(c)<0;};
    guint32 player_id;
    guint32 gender;
    guint32 font_size;
};

//! Helper class for default tile style items in the ImageCache.
/**
 * "default tile style" images are the black and white representations of TileStyle::Type.
 */
class DefaultTileStylePixMaskCacheItem
{
public:
    static PixMask *generate(DefaultTileStylePixMaskCacheItem item);
    int comp(const DefaultTileStylePixMaskCacheItem item) const;
    bool operator == (const DefaultTileStylePixMaskCacheItem &c) {return !comp(c);};
    bool operator < (const DefaultTileStylePixMaskCacheItem &c) const {return comp(c)<0;};
public:
    guint32 tilestyle_type;
    guint32 tilesize;
};

//! Helper class for tartan progress bar images in the ImageCache.
/**
 * These images appear on the screen when the computer player is moving
 * to show how much more they have yet to move.
 */
class TartanPixMaskCacheItem
{
public:
    static PixMask *generate(TartanPixMaskCacheItem item);
    static void calculateWidth(guint32 iwidth, PixMask *left, PixMask *center, PixMask *right, guint32 &width, guint32 &centers, bool &include_right);
    int comp(const TartanPixMaskCacheItem item) const;
    bool operator == (const TartanPixMaskCacheItem &c) {return !comp(c);};
    bool operator < (const TartanPixMaskCacheItem &c) const {return comp(c)<0;};
    guint32 width;
    guint32 player_id;
    guint32 shieldset;
    guint32 font_size;
};

//! Helper class for empty tartan progress bar images in the ImageCache.
/**
 * These images appear on the screen when the computer player is moving
 * to show how much more they have yet to move.
 */
class EmptyTartanPixMaskCacheItem
{
public:
    static PixMask *generate(EmptyTartanPixMaskCacheItem item);
    int comp(const EmptyTartanPixMaskCacheItem item) const;
    bool operator == (const EmptyTartanPixMaskCacheItem &c) {return !comp(c);};
    bool operator < (const EmptyTartanPixMaskCacheItem &c) const {return comp(c)<0;};
    guint32 width;
    guint32 player_id;
    guint32 shieldset;
    guint32 font_size;
};

//! Helper class for status images in the ImageCache.
/**
 * These status images include city, treasury, upkeep and income.
 */
class StatusPixMaskCacheItem
{
public:
    static PixMask *generate(StatusPixMaskCacheItem item);
    int comp(const StatusPixMaskCacheItem item) const;
    bool operator == (const StatusPixMaskCacheItem &c) {return !comp(c);};
    bool operator < (const StatusPixMaskCacheItem &c) const {return comp(c)<0;};
    guint32 type;
    guint32 font_size;
};

//! Helper class for the main screen button images in the ImageCache.
/**
 * These images include end turn, move all stacks, park, search and so on.
 */
class GameButtonPixMaskCacheItem
{
public:
    static PixMask *generate(GameButtonPixMaskCacheItem item);
    int comp(const GameButtonPixMaskCacheItem item) const;
    bool operator == (const GameButtonPixMaskCacheItem &c) {return !comp(c);};
    bool operator < (const GameButtonPixMaskCacheItem &c) const {return comp(c)<0;};
    guint32 type;
    guint32 font_size;
};

//! Helper class for the various images that appear on dialogs.
/**
 * These images include next turn, new hero, conquered city and so on.
 */
class DialogPixMaskCacheItem
{
public:
    static PixMask *generate(DialogPixMaskCacheItem item);
    int comp(const DialogPixMaskCacheItem item) const;
    bool operator == (const DialogPixMaskCacheItem &c) {return !comp(c);};
    bool operator < (const DialogPixMaskCacheItem &c) const {return comp(c)<0;};
    guint32 type;
    guint32 font_size;
};

//! Helper class for the medal images in the ImageCache.
/**
 * These images include the tiny medals that get awarded to armies,
 * and then the large ones that appear on dialogs..
 */
class MedalPixMaskCacheItem
{
public:
    static PixMask *generate(MedalPixMaskCacheItem item);
    int comp(const MedalPixMaskCacheItem item) const;
    bool operator == (const MedalPixMaskCacheItem &c) {return !comp(c);};
    bool operator < (const MedalPixMaskCacheItem &c) const {return comp(c)<0;};
    bool large;
    guint32 type;
    guint32 font_size;
};

#endif