# newgrf_spritegroup.h

Go to the documentation of this file.

    00001 /* $Id: newgrf_spritegroup.h 12352 2008-03-10 15:31:07Z frosch $ */
    00002
    00005 #ifndef NEWGRF_SPRITEGROUP_H
    00006 #define NEWGRF_SPRITEGROUP_H
    00007
    00008 #include "town_type.h"
    00009 #include "industry_type.h"
    00010 #include "newgrf_storage.h"
    00011 #include "core/bitmath_func.hpp"
    00012 #include "gfx_type.h"
    00013 #include "newgrf_generic.h"
    00014
    00021 static inline uint32 GetRegister(uint i)
    00022 {
    00023   extern TemporaryStorageArray<uint32, 0x110> _temp_store;
    00024   return _temp_store.Get(i);
    00025 }
    00026
    00027 struct SpriteGroup;
    00028
    00029
    00030 /* 'Real' sprite groups contain a list of other result or callback sprite
    00031  * groups. */
    00032 struct RealSpriteGroup {
    00033   /* Loaded = in motion, loading = not moving
    00034    * Each group contains several spritesets, for various loading stages */
    00035
    00036   /* XXX: For stations the meaning is different - loaded is for stations
    00037    * with small amount of cargo whilst loading is for stations with a lot
    00038    * of da stuff. */
    00039
    00040   byte num_loaded;
    00041   byte num_loading;
    00042   const SpriteGroup **loaded;
    00043   const SpriteGroup **loading;
    00044 };
    00045
    00046 /* Shared by deterministic and random groups. */
    00047 enum VarSpriteGroupScope {
    00048   VSG_SCOPE_SELF,
    00049   /* Engine of consists for vehicles, city for stations. */
    00050   VSG_SCOPE_PARENT,
    00051 };
    00052
    00053 enum DeterministicSpriteGroupSize {
    00054   DSG_SIZE_BYTE,
    00055   DSG_SIZE_WORD,
    00056   DSG_SIZE_DWORD,
    00057 };
    00058
    00059 enum DeterministicSpriteGroupAdjustType {
    00060   DSGA_TYPE_NONE,
    00061   DSGA_TYPE_DIV,
    00062   DSGA_TYPE_MOD,
    00063 };
    00064
    00065 enum DeterministicSpriteGroupAdjustOperation {
    00066   DSGA_OP_ADD,
    00067   DSGA_OP_SUB,
    00068   DSGA_OP_SMIN,
    00069   DSGA_OP_SMAX,
    00070   DSGA_OP_UMIN,
    00071   DSGA_OP_UMAX,
    00072   DSGA_OP_SDIV,
    00073   DSGA_OP_SMOD,
    00074   DSGA_OP_UDIV,
    00075   DSGA_OP_UMOD,
    00076   DSGA_OP_MUL,
    00077   DSGA_OP_AND,
    00078   DSGA_OP_OR,
    00079   DSGA_OP_XOR,
    00080   DSGA_OP_STO,
    00081   DSGA_OP_RST,
    00082   DSGA_OP_STOP,
    00083   DSGA_OP_ROR,
    00084   DSGA_OP_SCMP,
    00085   DSGA_OP_UCMP,
    00086 };
    00087
    00088
    00089 struct DeterministicSpriteGroupAdjust {
    00090   DeterministicSpriteGroupAdjustOperation operation;
    00091   DeterministicSpriteGroupAdjustType type;
    00092   byte variable;
    00093   byte parameter;
    00094   byte shift_num;
    00095   uint32 and_mask;
    00096   uint32 add_val;
    00097   uint32 divmod_val;
    00098   const SpriteGroup *subroutine;
    00099 };
    00100
    00101
    00102 struct DeterministicSpriteGroupRange {
    00103   const SpriteGroup *group;
    00104   uint32 low;
    00105   uint32 high;
    00106 };
    00107
    00108
    00109 struct DeterministicSpriteGroup {
    00110   VarSpriteGroupScope var_scope;
    00111   DeterministicSpriteGroupSize size;
    00112   byte num_adjusts;
    00113   byte num_ranges;
    00114   DeterministicSpriteGroupAdjust *adjusts;
    00115   DeterministicSpriteGroupRange *ranges; // Dynamically allocated
    00116
    00117   /* Dynamically allocated, this is the sole owner */
    00118   const SpriteGroup *default_group;
    00119 };
    00120
    00121 enum RandomizedSpriteGroupCompareMode {
    00122   RSG_CMP_ANY,
    00123   RSG_CMP_ALL,
    00124 };
    00125
    00126 struct RandomizedSpriteGroup {
    00127   VarSpriteGroupScope var_scope;
    00128
    00129   RandomizedSpriteGroupCompareMode cmp_mode;
    00130   byte triggers;
    00131
    00132   byte lowest_randbit;
    00133   byte num_groups;
    00134
    00135   const SpriteGroup **groups;
    00136 };
    00137
    00138
    00139 /* This contains a callback result. A failed callback has a value of
    00140  * CALLBACK_FAILED */
    00141 struct CallbackResultSpriteGroup {
    00142   uint16 result;
    00143 };
    00144
    00145
    00146 /* A result sprite group returns the first SpriteID and the number of
    00147  * sprites in the set */
    00148 struct ResultSpriteGroup {
    00149   SpriteID sprite;
    00150   byte num_sprites;
    00151 };
    00152
    00153 struct TileLayoutSpriteGroup {
    00154   byte num_sprites;
    00155   struct DrawTileSprites *dts;
    00156 };
    00157
    00158 struct IndustryProductionSpriteGroup {
    00159   uint8 version;
    00160   uint16 substract_input[3];
    00161   uint16 add_output[2];
    00162   uint8 again;
    00163 };
    00164
    00165 /* List of different sprite group types */
    00166 enum SpriteGroupType {
    00167   SGT_INVALID,
    00168   SGT_REAL,
    00169   SGT_DETERMINISTIC,
    00170   SGT_RANDOMIZED,
    00171   SGT_CALLBACK,
    00172   SGT_RESULT,
    00173   SGT_TILELAYOUT,
    00174   SGT_INDUSTRY_PRODUCTION,
    00175 };
    00176
    00177 /* Common wrapper for all the different sprite group types */
    00178 struct SpriteGroup {
    00179   SpriteGroupType type;
    00180
    00181   union {
    00182     RealSpriteGroup real;
    00183     DeterministicSpriteGroup determ;
    00184     RandomizedSpriteGroup random;
    00185     CallbackResultSpriteGroup callback;
    00186     ResultSpriteGroup result;
    00187     TileLayoutSpriteGroup layout;
    00188     IndustryProductionSpriteGroup indprod;
    00189   } g;
    00190 };
    00191
    00192
    00193 SpriteGroup *AllocateSpriteGroup();
    00194 void InitializeSpriteGroupPool();
    00195
    00196
    00197 struct ResolverObject {
    00198   CallbackID callback;
    00199   uint32 callback_param1;
    00200   uint32 callback_param2;
    00201   bool procedure_call;
    00202
    00203   byte trigger;
    00204   uint32 last_value;
    00205   uint32 reseed;
    00206   VarSpriteGroupScope scope;
    00207
    00208   bool info_view;
    00209
    00210   BaseStorageArray *psa;
    00211
    00212   union {
    00213     struct {
    00214       const struct Vehicle *self;
    00215       const struct Vehicle *parent;
    00216       EngineID self_type;
    00217     } vehicle;
    00218     struct {
    00219       TileIndex tile;
    00220     } canal;
    00221     struct {
    00222       TileIndex tile;
    00223       const struct Station *st;
    00224       const struct StationSpec *statspec;
    00225       CargoID cargo_type;
    00226     } station;
    00227     struct {
    00228       TileIndex tile;
    00229       Town *town;
    00230       HouseID house_id;
    00231     } house;
    00232     struct {
    00233       TileIndex tile;
    00234       Industry *ind;
    00235       IndustryGfx gfx;
    00236       IndustryType type;
    00237     } industry;
    00238     struct {
    00239       const struct CargoSpec *cs;
    00240     } cargo;
    00241     struct {
    00242       CargoID cargo_type;
    00243       uint8 default_selection;
    00244       IndustryType src_industry;
    00245       IndustryType dst_industry;
    00246       uint8 distance;
    00247       AIConstructionEvent event;
    00248       uint8 count;
    00249       uint8 station_size;
    00250     } generic;
    00251   } u;
    00252
    00253   uint32 (*GetRandomBits)(const struct ResolverObject*);
    00254   uint32 (*GetTriggers)(const struct ResolverObject*);
    00255   void (*SetTriggers)(const struct ResolverObject*, int);
    00256   uint32 (*GetVariable)(const struct ResolverObject*, byte, byte, bool*);
    00257   const SpriteGroup *(*ResolveReal)(const struct ResolverObject*, const SpriteGroup*);
    00258
    00259   ResolverObject() : procedure_call(false) { }
    00260 };
    00261
    00262
    00263 /* Base sprite group resolver */
    00264 const SpriteGroup *Resolve(const SpriteGroup *group, ResolverObject *object);
    00265
    00266
    00267 #endif /* NEWGRF_SPRITEGROUP_H */