(svn r22924) -Codechange: Enhance NewGRFSpriteLayout for drawing construction stages in spritelayouts with inconsistent number of sprites per spriteset.

This commit is contained in:
frosch
2011-09-11 15:10:09 +00:00
parent de27360549
commit 7f228d6909
7 changed files with 86 additions and 20 deletions

View File

@@ -571,10 +571,11 @@ void NewGRFSpriteLayout::AllocateRegisters()
* @param orig_offset Offset to apply to non-action-1 sprites.
* @param newgrf_ground_offset Offset to apply to action-1 ground sprites.
* @param newgrf_offset Offset to apply to action-1 non-ground sprites.
* @param constr_stage Construction stage (0-3) to apply to all action-1 sprites.
* @param separate_ground Whether the ground sprite shall be resolved by a separate action-1-2-3 chain by default.
* @return Bitmask of values for variable 10 to resolve action-1-2-3 chains for.
*/
uint32 NewGRFSpriteLayout::PrepareLayout(uint32 orig_offset, uint32 newgrf_ground_offset, uint32 newgrf_offset, bool separate_ground) const
uint32 NewGRFSpriteLayout::PrepareLayout(uint32 orig_offset, uint32 newgrf_ground_offset, uint32 newgrf_offset, uint constr_stage, bool separate_ground) const
{
result_seq.Clear();
uint32 var10_values = 0;
@@ -611,6 +612,7 @@ uint32 NewGRFSpriteLayout::PrepareLayout(uint32 orig_offset, uint32 newgrf_groun
if (!(flags & TLF_SPRITE)) {
if (HasBit(result->image.sprite, SPRITE_MODIFIER_CUSTOM_SPRITE)) {
result->image.sprite += ground ? newgrf_ground_offset : newgrf_offset;
if (constr_stage > 0 && regs != NULL) result->image.sprite += GetConstructionStageOffset(constr_stage, regs->max_sprite_offset);
} else {
result->image.sprite += orig_offset;
}
@@ -626,6 +628,7 @@ uint32 NewGRFSpriteLayout::PrepareLayout(uint32 orig_offset, uint32 newgrf_groun
if (!(flags & TLF_PALETTE)) {
if (HasBit(result->image.pal, SPRITE_MODIFIER_CUSTOM_SPRITE)) {
result->image.sprite += ground ? newgrf_ground_offset : newgrf_offset;
if (constr_stage > 0 && regs != NULL) result->image.sprite += GetConstructionStageOffset(constr_stage, regs->max_palette_offset);
}
}
@@ -663,7 +666,14 @@ void NewGRFSpriteLayout::ProcessRegisters(uint8 resolved_var10, uint32 resolved_
result->image.sprite = 0;
} else {
if (HasBit(result->image.sprite, SPRITE_MODIFIER_CUSTOM_SPRITE)) result->image.sprite += resolved_sprite;
if (flags & TLF_SPRITE) result->image.sprite += (int16)GetRegister(regs->sprite); // mask to 16 bits to avoid trouble
if (flags & TLF_SPRITE) {
int16 offset = (int16)GetRegister(regs->sprite); // mask to 16 bits to avoid trouble
if (!HasBit(result->image.sprite, SPRITE_MODIFIER_CUSTOM_SPRITE) || (offset >= 0 && offset < regs->max_sprite_offset)) {
result->image.sprite += offset;
} else {
result->image.sprite = SPR_IMG_QUERY;
}
}
if (result->IsParentSprite()) {
if (flags & TLF_BB_XY_OFFSET) {
@@ -686,7 +696,15 @@ void NewGRFSpriteLayout::ProcessRegisters(uint8 resolved_var10, uint32 resolved_
if (var10 == resolved_var10) {
/* Apply registers */
if (HasBit(result->image.pal, SPRITE_MODIFIER_CUSTOM_SPRITE)) result->image.pal += resolved_sprite;
if (flags & TLF_PALETTE) result->image.pal += (int16)GetRegister(regs->palette); // mask to 16 bits to avoid trouble
if (flags & TLF_PALETTE) {
int16 offset = (int16)GetRegister(regs->palette); // mask to 16 bits to avoid trouble
if (!HasBit(result->image.pal, SPRITE_MODIFIER_CUSTOM_SPRITE) || (offset >= 0 && offset < regs->max_palette_offset)) {
result->image.pal += offset;
} else {
result->image.sprite = SPR_IMG_QUERY;
result->image.pal = PAL_NONE;
}
}
}
}