mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-09-01 02:49:10 +00:00
(svn r22925) -Feature: [NewGRF] Allow referencing spritesets from different Action1 in a single Action2.
This commit is contained in:
@@ -83,11 +83,14 @@ static const uint MAX_SPRITEGROUP = UINT8_MAX; ///< Maximum GRF-local ID for a s
|
|||||||
/** Temporary data during loading of GRFs */
|
/** Temporary data during loading of GRFs */
|
||||||
struct GrfProcessingState {
|
struct GrfProcessingState {
|
||||||
private:
|
private:
|
||||||
/* Currently referenceable spritesets */
|
/** Definition of a single Action1 spriteset */
|
||||||
SpriteID spriteset_start; ///< SpriteID of the first sprite of the first set.
|
struct SpriteSet {
|
||||||
uint spriteset_numsets; ///< Number of spritesets.
|
SpriteID sprite; ///< SpriteID of the first sprite of the set.
|
||||||
uint spriteset_numents; ///< Number of sprites per set.
|
uint num_sprites; ///< Number of sprites in the set.
|
||||||
byte spriteset_feature; ///< GrfSpecFeature of the spriteset.
|
};
|
||||||
|
|
||||||
|
/** Currently referenceable spritesets */
|
||||||
|
std::map<uint, SpriteSet> spritesets[GSF_END];
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/* Global state */
|
/* Global state */
|
||||||
@@ -115,10 +118,9 @@ public:
|
|||||||
this->skip_sprites = 0;
|
this->skip_sprites = 0;
|
||||||
this->data_blocks = 0;
|
this->data_blocks = 0;
|
||||||
|
|
||||||
this->spriteset_start = 0;
|
for (uint i = 0; i < GSF_END; i++) {
|
||||||
this->spriteset_numsets = 0;
|
this->spritesets[i].clear();
|
||||||
this->spriteset_numents = 0;
|
}
|
||||||
this->spriteset_feature = GSF_INVALID;
|
|
||||||
|
|
||||||
memset(this->spritegroups, 0, sizeof(this->spritegroups));
|
memset(this->spritegroups, 0, sizeof(this->spritegroups));
|
||||||
}
|
}
|
||||||
@@ -132,10 +134,12 @@ public:
|
|||||||
*/
|
*/
|
||||||
void AddSpriteSets(byte feature, SpriteID first_sprite, uint numsets, uint numents)
|
void AddSpriteSets(byte feature, SpriteID first_sprite, uint numsets, uint numents)
|
||||||
{
|
{
|
||||||
this->spriteset_feature = feature;
|
assert(feature < GSF_END);
|
||||||
this->spriteset_start = first_sprite;
|
for (uint i = 0; i < numsets; i++) {
|
||||||
this->spriteset_numsets = numsets;
|
SpriteSet &set = this->spritesets[feature][i];
|
||||||
this->spriteset_numents = numents;
|
set.sprite = first_sprite + i * numents;
|
||||||
|
set.num_sprites = numents;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -146,7 +150,8 @@ public:
|
|||||||
*/
|
*/
|
||||||
bool HasValidSpriteSets(byte feature) const
|
bool HasValidSpriteSets(byte feature) const
|
||||||
{
|
{
|
||||||
return feature == this->spriteset_feature && this->spriteset_numsets > 0;
|
assert(feature < GSF_END);
|
||||||
|
return !this->spritesets[feature].empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -158,7 +163,8 @@ public:
|
|||||||
*/
|
*/
|
||||||
bool IsValidSpriteSet(byte feature, uint set) const
|
bool IsValidSpriteSet(byte feature, uint set) const
|
||||||
{
|
{
|
||||||
return feature == this->spriteset_feature && set < this->spriteset_numsets;
|
assert(feature < GSF_END);
|
||||||
|
return this->spritesets[feature].find(set) != this->spritesets[feature].end();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -170,7 +176,7 @@ public:
|
|||||||
SpriteID GetSprite(byte feature, uint set) const
|
SpriteID GetSprite(byte feature, uint set) const
|
||||||
{
|
{
|
||||||
assert(IsValidSpriteSet(feature, set));
|
assert(IsValidSpriteSet(feature, set));
|
||||||
return this->spriteset_start + set * this->spriteset_numents;
|
return this->spritesets[feature].find(set)->second.sprite;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -182,7 +188,7 @@ public:
|
|||||||
uint GetNumEnts(byte feature, uint set) const
|
uint GetNumEnts(byte feature, uint set) const
|
||||||
{
|
{
|
||||||
assert(IsValidSpriteSet(feature, set));
|
assert(IsValidSpriteSet(feature, set));
|
||||||
return this->spriteset_numents;
|
return this->spritesets[feature].find(set)->second.num_sprites;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user