00001
00002
00003
00004
00005
00006
00007
00008
00009
00012 #ifndef NEWGRF_SPRITEGROUP_H
00013 #define NEWGRF_SPRITEGROUP_H
00014
00015 #include "town_type.h"
00016 #include "gfx_type.h"
00017 #include "engine_type.h"
00018 #include "core/pool_type.hpp"
00019 #include "house_type.h"
00020
00021 #include "newgrf_callbacks.h"
00022 #include "newgrf_generic.h"
00023 #include "newgrf_storage.h"
00024 #include "newgrf_commons.h"
00025
00032 static inline uint32 GetRegister(uint i)
00033 {
00034 extern TemporaryStorageArray<int32, 0x110> _temp_store;
00035 return _temp_store.Get(i);
00036 }
00037
00043 static inline void ClearRegister(uint i)
00044 {
00045 extern TemporaryStorageArray<int32, 0x110> _temp_store;
00046 _temp_store.Store(i, 0);
00047 }
00048
00049
00050 enum SpriteGroupType {
00051 SGT_REAL,
00052 SGT_DETERMINISTIC,
00053 SGT_RANDOMIZED,
00054 SGT_CALLBACK,
00055 SGT_RESULT,
00056 SGT_TILELAYOUT,
00057 SGT_INDUSTRY_PRODUCTION,
00058 };
00059
00060 struct SpriteGroup;
00061 typedef uint32 SpriteGroupID;
00062
00063
00064
00065
00066 typedef Pool<SpriteGroup, SpriteGroupID, 1024, 1 << 30, PT_DATA> SpriteGroupPool;
00067 extern SpriteGroupPool _spritegroup_pool;
00068
00069
00070 struct SpriteGroup : SpriteGroupPool::PoolItem<&_spritegroup_pool> {
00071 protected:
00072 SpriteGroup(SpriteGroupType type) : type(type) {}
00074 virtual const SpriteGroup *Resolve(struct ResolverObject *object) const { return this; };
00075
00076 public:
00077 virtual ~SpriteGroup() {}
00078
00079 SpriteGroupType type;
00080
00081 virtual SpriteID GetResult() const { return 0; }
00082 virtual byte GetNumResults() const { return 0; }
00083 virtual uint16 GetCallbackResult() const { return CALLBACK_FAILED; }
00084
00094 static const SpriteGroup *Resolve(const SpriteGroup *group, ResolverObject *object)
00095 {
00096 return group == NULL ? NULL : group->Resolve(object);
00097 }
00098 };
00099
00100
00101
00102
00103 struct RealSpriteGroup : SpriteGroup {
00104 RealSpriteGroup() : SpriteGroup(SGT_REAL) {}
00105 ~RealSpriteGroup();
00106
00107
00108
00109
00110
00111
00112
00113
00114 byte num_loaded;
00115 byte num_loading;
00116 const SpriteGroup **loaded;
00117 const SpriteGroup **loading;
00118
00119 protected:
00120 const SpriteGroup *Resolve(ResolverObject *object) const;
00121 };
00122
00123
00124 enum VarSpriteGroupScope {
00125 VSG_SCOPE_SELF,
00126
00127 VSG_SCOPE_PARENT,
00128
00129 VSG_SCOPE_RELATIVE,
00130 };
00131
00132 enum DeterministicSpriteGroupSize {
00133 DSG_SIZE_BYTE,
00134 DSG_SIZE_WORD,
00135 DSG_SIZE_DWORD,
00136 };
00137
00138 enum DeterministicSpriteGroupAdjustType {
00139 DSGA_TYPE_NONE,
00140 DSGA_TYPE_DIV,
00141 DSGA_TYPE_MOD,
00142 };
00143
00144 enum DeterministicSpriteGroupAdjustOperation {
00145 DSGA_OP_ADD,
00146 DSGA_OP_SUB,
00147 DSGA_OP_SMIN,
00148 DSGA_OP_SMAX,
00149 DSGA_OP_UMIN,
00150 DSGA_OP_UMAX,
00151 DSGA_OP_SDIV,
00152 DSGA_OP_SMOD,
00153 DSGA_OP_UDIV,
00154 DSGA_OP_UMOD,
00155 DSGA_OP_MUL,
00156 DSGA_OP_AND,
00157 DSGA_OP_OR,
00158 DSGA_OP_XOR,
00159 DSGA_OP_STO,
00160 DSGA_OP_RST,
00161 DSGA_OP_STOP,
00162 DSGA_OP_ROR,
00163 DSGA_OP_SCMP,
00164 DSGA_OP_UCMP,
00165 DSGA_OP_SHL,
00166 DSGA_OP_SHR,
00167 DSGA_OP_SAR,
00168 };
00169
00170
00171 struct DeterministicSpriteGroupAdjust {
00172 DeterministicSpriteGroupAdjustOperation operation;
00173 DeterministicSpriteGroupAdjustType type;
00174 byte variable;
00175 byte parameter;
00176 byte shift_num;
00177 uint32 and_mask;
00178 uint32 add_val;
00179 uint32 divmod_val;
00180 const SpriteGroup *subroutine;
00181 };
00182
00183
00184 struct DeterministicSpriteGroupRange {
00185 const SpriteGroup *group;
00186 uint32 low;
00187 uint32 high;
00188 };
00189
00190
00191 struct DeterministicSpriteGroup : SpriteGroup {
00192 DeterministicSpriteGroup() : SpriteGroup(SGT_DETERMINISTIC) {}
00193 ~DeterministicSpriteGroup();
00194
00195 VarSpriteGroupScope var_scope;
00196 DeterministicSpriteGroupSize size;
00197 byte num_adjusts;
00198 byte num_ranges;
00199 DeterministicSpriteGroupAdjust *adjusts;
00200 DeterministicSpriteGroupRange *ranges;
00201
00202
00203 const SpriteGroup *default_group;
00204
00205 protected:
00206 const SpriteGroup *Resolve(ResolverObject *object) const;
00207 };
00208
00209 enum RandomizedSpriteGroupCompareMode {
00210 RSG_CMP_ANY,
00211 RSG_CMP_ALL,
00212 };
00213
00214 struct RandomizedSpriteGroup : SpriteGroup {
00215 RandomizedSpriteGroup() : SpriteGroup(SGT_RANDOMIZED) {}
00216 ~RandomizedSpriteGroup();
00217
00218 VarSpriteGroupScope var_scope;
00219
00220 RandomizedSpriteGroupCompareMode cmp_mode;
00221 byte triggers;
00222 byte count;
00223
00224 byte lowest_randbit;
00225 byte num_groups;
00226
00227 const SpriteGroup **groups;
00228
00229 protected:
00230 const SpriteGroup *Resolve(ResolverObject *object) const;
00231 };
00232
00233
00234
00235
00236 struct CallbackResultSpriteGroup : SpriteGroup {
00241 CallbackResultSpriteGroup(uint16 value) :
00242 SpriteGroup(SGT_CALLBACK),
00243 result(value)
00244 {
00245
00246
00247 if ((this->result >> 8) == 0xFF) {
00248 this->result &= ~0xFF00;
00249 } else {
00250 this->result &= ~0x8000;
00251 }
00252 }
00253
00254 uint16 result;
00255 uint16 GetCallbackResult() const { return this->result; }
00256 };
00257
00258
00259
00260
00261 struct ResultSpriteGroup : SpriteGroup {
00268 ResultSpriteGroup(SpriteID sprite, byte num_sprites) :
00269 SpriteGroup(SGT_RESULT),
00270 sprite(sprite),
00271 num_sprites(num_sprites)
00272 {
00273 }
00274
00275 SpriteID sprite;
00276 byte num_sprites;
00277 SpriteID GetResult() const { return this->sprite; }
00278 byte GetNumResults() const { return this->num_sprites; }
00279 };
00280
00284 struct TileLayoutSpriteGroup : SpriteGroup {
00285 TileLayoutSpriteGroup() : SpriteGroup(SGT_TILELAYOUT) {}
00286 ~TileLayoutSpriteGroup() {}
00287
00288 byte num_building_stages;
00289 NewGRFSpriteLayout dts;
00290
00291 const DrawTileSprites *ProcessRegisters(uint8 *stage) const;
00292 };
00293
00294 struct IndustryProductionSpriteGroup : SpriteGroup {
00295 IndustryProductionSpriteGroup() : SpriteGroup(SGT_INDUSTRY_PRODUCTION) {}
00296
00297 uint8 version;
00298 int16 subtract_input[3];
00299 uint16 add_output[2];
00300 uint8 again;
00301 };
00302
00303
00304 struct ResolverObject {
00305 CallbackID callback;
00306 uint32 callback_param1;
00307 uint32 callback_param2;
00308
00309 byte trigger;
00310
00311 uint32 last_value;
00312 uint32 reseed;
00313
00314 VarSpriteGroupScope scope;
00315 byte count;
00316
00317 BaseStorageArray *psa;
00318
00319 const GRFFile *grffile;
00320
00321 union {
00322 struct {
00323 const struct Vehicle *self;
00324 const struct Vehicle *parent;
00325 EngineID self_type;
00326 bool info_view;
00327 } vehicle;
00328 struct {
00329 TileIndex tile;
00330 } canal;
00331 struct {
00332 TileIndex tile;
00333 const struct BaseStation *st;
00334 const struct StationSpec *statspec;
00335 CargoID cargo_type;
00336 } station;
00337 struct {
00338 TileIndex tile;
00339 const Town *town;
00340 HouseID house_id;
00341 uint16 initial_random_bits;
00342 bool not_yet_constructed;
00343 } house;
00344 struct {
00345 TileIndex tile;
00346 Industry *ind;
00347 IndustryGfx gfx;
00348 IndustryType type;
00349 } industry;
00350 struct {
00351 const struct CargoSpec *cs;
00352 } cargo;
00353 struct {
00354 CargoID cargo_type;
00355 uint8 default_selection;
00356 uint8 src_industry;
00357 uint8 dst_industry;
00358 uint8 distance;
00359 AIConstructionEvent event;
00360 uint8 count;
00361 uint8 station_size;
00362 } generic;
00363 struct {
00364 TileIndex tile;
00365 TileContext context;
00366 } routes;
00367 struct {
00368 const struct Station *st;
00369 byte airport_id;
00370 byte layout;
00371 TileIndex tile;
00372 } airport;
00373 struct {
00374 const struct Object *o;
00375 TileIndex tile;
00376 uint8 view;
00377 } object;
00378 } u;
00379
00380 uint32 (*GetRandomBits)(const struct ResolverObject*);
00381 uint32 (*GetTriggers)(const struct ResolverObject*);
00382 void (*SetTriggers)(const struct ResolverObject*, int);
00383 uint32 (*GetVariable)(const struct ResolverObject*, byte, byte, bool*);
00384 const SpriteGroup *(*ResolveReal)(const struct ResolverObject*, const RealSpriteGroup*);
00385 };
00386
00387 #endif