VarAction2: Re-use allocated callback result sprite groups
This commit is contained in:
@@ -369,19 +369,25 @@ protected:
|
||||
struct CallbackResultSpriteGroup : SpriteGroup {
|
||||
/**
|
||||
* Creates a spritegroup representing a callback result
|
||||
* @param result The result as returned from TransformResultValue
|
||||
*/
|
||||
CallbackResultSpriteGroup(uint16 result) :
|
||||
SpriteGroup(SGT_CALLBACK),
|
||||
result(result) {}
|
||||
|
||||
/**
|
||||
* Transforms a callback result value
|
||||
* @param value The value that was used to represent this callback result
|
||||
* @param grf_version8 True, if we are dealing with a new NewGRF which uses GRF version >= 8.
|
||||
*/
|
||||
CallbackResultSpriteGroup(uint16 value, bool grf_version8) :
|
||||
SpriteGroup(SGT_CALLBACK),
|
||||
result(value)
|
||||
static uint16 TransformResultValue(uint16 value, bool grf_version8)
|
||||
{
|
||||
/* Old style callback results (only valid for version < 8) have the highest byte 0xFF so signify it is a callback result.
|
||||
* New style ones only have the highest bit set (allows 15-bit results, instead of just 8) */
|
||||
if (!grf_version8 && (this->result >> 8) == 0xFF) {
|
||||
this->result &= ~0xFF00;
|
||||
if (!grf_version8 && (value >> 8) == 0xFF) {
|
||||
return value & ~0xFF00;
|
||||
} else {
|
||||
this->result &= ~0x8000;
|
||||
return value & ~0x8000;
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user