# HG changeset patch # User frosch # Date 1315753753 0 # Node ID 7338f18ce5e4706d86162c99120ef907cd25bf86 # Parent 3a5a17348a42723d4490783d69caf1dd2b8d0535 (svn r22923) -Codechange: Move application of the construction stage into TileLayoutSpriteGroup::ProcessRegisters(). diff --git a/src/newgrf_commons.h b/src/newgrf_commons.h --- a/src/newgrf_commons.h +++ b/src/newgrf_commons.h @@ -70,6 +70,25 @@ DECLARE_ENUM_AS_BIT_SET(TileLayoutFlags) /** + * Determines which sprite to use from a spriteset for a specific construction stage. + * @param construction_stage Construction stage 0 - 3. + * @param num_sprites Number of available sprites to select stage from. + * @return Sprite to use + */ +static inline uint GetConstructionStageOffset(uint construction_stage, uint num_sprites) +{ + assert(num_sprites > 0); + if (num_sprites > 4) num_sprites = 4; + switch (construction_stage) { + case 0: return 0; + case 1: return num_sprites > 2 ? 1 : 0; + case 2: return num_sprites > 2 ? num_sprites - 2 : 0; + case 3: return num_sprites - 1; + default: NOT_REACHED(); + } +} + +/** * Additional modifiers for items in sprite layouts. */ struct TileLayoutRegisters { diff --git a/src/newgrf_house.cpp b/src/newgrf_house.cpp --- a/src/newgrf_house.cpp +++ b/src/newgrf_house.cpp @@ -476,7 +476,6 @@ /* Limit the building stage to the number of stages supplied. */ const TileLayoutSpriteGroup *tlgroup = (const TileLayoutSpriteGroup *)group; byte stage = GetHouseBuildingStage(ti->tile); - stage = tlgroup->GetConstructionStageOffset(stage); DrawTileLayout(ti, tlgroup, stage, house_id); } } diff --git a/src/newgrf_industrytiles.cpp b/src/newgrf_industrytiles.cpp --- a/src/newgrf_industrytiles.cpp +++ b/src/newgrf_industrytiles.cpp @@ -263,7 +263,6 @@ /* Limit the building stage to the number of stages supplied. */ const TileLayoutSpriteGroup *tlgroup = (const TileLayoutSpriteGroup *)group; byte stage = GetIndustryConstructionStage(ti->tile); - stage = tlgroup->GetConstructionStageOffset(stage); IndustryDrawTileLayout(ti, tlgroup, i->random_colour, stage, gfx); return true; } diff --git a/src/newgrf_spritegroup.cpp b/src/newgrf_spritegroup.cpp --- a/src/newgrf_spritegroup.cpp +++ b/src/newgrf_spritegroup.cpp @@ -236,6 +236,7 @@ */ const DrawTileSprites *TileLayoutSpriteGroup::ProcessRegisters(uint8 *stage) const { + if (stage != NULL) *stage = GetConstructionStageOffset(*stage, this->num_building_stages); if (!this->dts.NeedsPreprocessing()) return &this->dts; static DrawTileSprites result; diff --git a/src/newgrf_spritegroup.h b/src/newgrf_spritegroup.h --- a/src/newgrf_spritegroup.h +++ b/src/newgrf_spritegroup.h @@ -292,25 +292,6 @@ NewGRFSpriteLayout dts; const DrawTileSprites *ProcessRegisters(uint8 *stage) const; - - /** - * Determines which sprite to use from a spriteset for a specific construction stage. - * @param construction_stage Construction stage 0 - 3. - * @return Sprite to use - */ - uint GetConstructionStageOffset(uint construction_stage) const - { - uint num_sprites = this->num_building_stages; - assert(num_sprites > 0); - if (num_sprites > 4) num_sprites = 4; - switch (construction_stage) { - case 0: return 0; - case 1: return num_sprites > 2 ? 1 : 0; - case 2: return num_sprites > 2 ? num_sprites - 2 : 0; - case 3: return num_sprites - 1; - default: NOT_REACHED(); - } - } }; struct IndustryProductionSpriteGroup : SpriteGroup {