newgrf_spritegroup.h

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

Generated on Wed Jul 15 20:36:00 2009 for OpenTTD by  doxygen 1.5.6