mirror of https://github.com/OpenTTD/OpenTTD
Codechange: Use enums as keys for the spritegroups in FixedGRFFileProps.
parent
05504ec463
commit
e1859df1c0
|
@ -394,7 +394,7 @@ static void ObjectMapSpriteGroup(ByteReader &buf, uint8_t idcount)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
spec->grf_prop.SetSpriteGroup(OBJECT_SPRITE_GROUP_PURCHASE, _cur_gps.spritegroups[groupid]);
|
spec->grf_prop.SetSpriteGroup(StandardSpriteGroup::Purchase, _cur_gps.spritegroups[groupid]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -414,7 +414,7 @@ static void ObjectMapSpriteGroup(ByteReader &buf, uint8_t idcount)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
spec->grf_prop.SetSpriteGroup(OBJECT_SPRITE_GROUP_DEFAULT, _cur_gps.spritegroups[groupid]);
|
spec->grf_prop.SetSpriteGroup(StandardSpriteGroup::Default, _cur_gps.spritegroups[groupid]);
|
||||||
spec->grf_prop.SetGRFFile(_cur_gps.grffile);
|
spec->grf_prop.SetGRFFile(_cur_gps.grffile);
|
||||||
spec->grf_prop.local_id = object;
|
spec->grf_prop.local_id = object;
|
||||||
}
|
}
|
||||||
|
|
|
@ -306,9 +306,10 @@ struct GRFFilePropsBase {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fixed-length list of sprite groups for an entity.
|
* Fixed-length list of sprite groups for an entity.
|
||||||
|
* @tparam Tkey Key for indexing spritegroups
|
||||||
* @tparam Tcount Number of spritegroups
|
* @tparam Tcount Number of spritegroups
|
||||||
*/
|
*/
|
||||||
template <size_t Tcount>
|
template <class Tkey, size_t Tcount>
|
||||||
struct FixedGRFFileProps : GRFFilePropsBase {
|
struct FixedGRFFileProps : GRFFilePropsBase {
|
||||||
std::array<const struct SpriteGroup *, Tcount> spritegroups{}; ///< pointers to the different sprite groups of the entity
|
std::array<const struct SpriteGroup *, Tcount> spritegroups{}; ///< pointers to the different sprite groups of the entity
|
||||||
|
|
||||||
|
@ -317,14 +318,14 @@ struct FixedGRFFileProps : GRFFilePropsBase {
|
||||||
* @param index Index to get.
|
* @param index Index to get.
|
||||||
* @returns SpriteGroup at index, or nullptr if not present.
|
* @returns SpriteGroup at index, or nullptr if not present.
|
||||||
*/
|
*/
|
||||||
const struct SpriteGroup *GetSpriteGroup(size_t index = 0) const { return this->spritegroups[index]; }
|
const struct SpriteGroup *GetSpriteGroup(Tkey index) const { return this->spritegroups[static_cast<size_t>(index)]; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the SpriteGroup at the specified index.
|
* Set the SpriteGroup at the specified index.
|
||||||
* @param index Index to set.
|
* @param index Index to set.
|
||||||
* @param spritegroup SpriteGroup to set.
|
* @param spritegroup SpriteGroup to set.
|
||||||
*/
|
*/
|
||||||
void SetSpriteGroup(size_t index, const struct SpriteGroup *spritegroup) { this->spritegroups[index] = spritegroup; }
|
void SetSpriteGroup(Tkey index, const struct SpriteGroup *spritegroup) { this->spritegroups[static_cast<size_t>(index)] = spritegroup; }
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -337,6 +338,16 @@ struct SingleGRFFileProps : GRFFilePropsBase {
|
||||||
void SetSpriteGroup(const struct SpriteGroup *spritegroup) { this->spritegroup = spritegroup; }
|
void SetSpriteGroup(const struct SpriteGroup *spritegroup) { this->spritegroup = spritegroup; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Standard sprite groups.
|
||||||
|
*/
|
||||||
|
enum class StandardSpriteGroup {
|
||||||
|
Default, ///< Default type used when no more-specific group matches.
|
||||||
|
Purchase, ///< Used before an entity exists.
|
||||||
|
End
|
||||||
|
};
|
||||||
|
using StandardGRFFileProps = FixedGRFFileProps<StandardSpriteGroup, static_cast<size_t>(StandardSpriteGroup::End)>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Variable-length list of sprite groups for an entity.
|
* Variable-length list of sprite groups for an entity.
|
||||||
* @tparam Tkey Key for indexing spritegroups
|
* @tparam Tkey Key for indexing spritegroups
|
||||||
|
|
|
@ -386,8 +386,8 @@ ObjectResolverObject::ObjectResolverObject(const ObjectSpec *spec, Object *obj,
|
||||||
CallbackID callback, uint32_t param1, uint32_t param2)
|
CallbackID callback, uint32_t param1, uint32_t param2)
|
||||||
: ResolverObject(spec->grf_prop.grffile, callback, param1, param2), object_scope(*this, obj, spec, tile, view)
|
: ResolverObject(spec->grf_prop.grffile, callback, param1, param2), object_scope(*this, obj, spec, tile, view)
|
||||||
{
|
{
|
||||||
this->root_spritegroup = (obj == nullptr) ? spec->grf_prop.GetSpriteGroup(OBJECT_SPRITE_GROUP_PURCHASE) : nullptr;
|
this->root_spritegroup = (obj == nullptr) ? spec->grf_prop.GetSpriteGroup(StandardSpriteGroup::Purchase) : nullptr;
|
||||||
if (this->root_spritegroup == nullptr) this->root_spritegroup = spec->grf_prop.GetSpriteGroup(OBJECT_SPRITE_GROUP_DEFAULT);
|
if (this->root_spritegroup == nullptr) this->root_spritegroup = spec->grf_prop.GetSpriteGroup(StandardSpriteGroup::Default);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -58,8 +58,7 @@ DECLARE_INCREMENT_DECREMENT_OPERATORS(ObjectClassID)
|
||||||
* default objects in table/object_land.h
|
* default objects in table/object_land.h
|
||||||
*/
|
*/
|
||||||
struct ObjectSpec : NewGRFSpecBase<ObjectClassID> {
|
struct ObjectSpec : NewGRFSpecBase<ObjectClassID> {
|
||||||
/* 2 because of the "normal" and "buy" sprite stacks. */
|
StandardGRFFileProps grf_prop; ///< Properties related the the grf file
|
||||||
FixedGRFFileProps<2> grf_prop; ///< Properties related the the grf file
|
|
||||||
/* Animation speed default differs from other features */
|
/* Animation speed default differs from other features */
|
||||||
AnimationInfo<ObjectAnimationTriggers> animation{0, AnimationStatus::NoAnimation, 0, {}}; ///< Information about the animation.
|
AnimationInfo<ObjectAnimationTriggers> animation{0, AnimationStatus::NoAnimation, 0, {}}; ///< Information about the animation.
|
||||||
StringID name; ///< The name for this object.
|
StringID name; ///< The name for this object.
|
||||||
|
@ -166,9 +165,6 @@ private:
|
||||||
/** Class containing information relating to object classes. */
|
/** Class containing information relating to object classes. */
|
||||||
using ObjectClass = NewGRFClass<ObjectSpec, ObjectClassID, OBJECT_CLASS_MAX>;
|
using ObjectClass = NewGRFClass<ObjectSpec, ObjectClassID, OBJECT_CLASS_MAX>;
|
||||||
|
|
||||||
static const size_t OBJECT_SPRITE_GROUP_DEFAULT = 0;
|
|
||||||
static const size_t OBJECT_SPRITE_GROUP_PURCHASE = 1;
|
|
||||||
|
|
||||||
uint16_t GetObjectCallback(CallbackID callback, uint32_t param1, uint32_t param2, const ObjectSpec *spec, Object *o, TileIndex tile, uint8_t view = 0);
|
uint16_t GetObjectCallback(CallbackID callback, uint32_t param1, uint32_t param2, const ObjectSpec *spec, Object *o, TileIndex tile, uint8_t view = 0);
|
||||||
|
|
||||||
void DrawNewObjectTile(TileInfo *ti, const ObjectSpec *spec);
|
void DrawNewObjectTile(TileInfo *ti, const ObjectSpec *spec);
|
||||||
|
|
|
@ -106,7 +106,7 @@ static const DrawTileSpriteSpan _object_hq[] = {
|
||||||
#undef TILE_SPRITE_LINE
|
#undef TILE_SPRITE_LINE
|
||||||
#undef TILE_SPRITE_LINE_NOTHING
|
#undef TILE_SPRITE_LINE_NOTHING
|
||||||
|
|
||||||
#define M(name, size, build_cost_multiplier, clear_cost_multiplier, height, climate, gen_amount, flags) {{INVALID_OBJECT_CLASS, 0}, FixedGRFFileProps<2>{}, AnimationInfo<ObjectAnimationTriggers>{}, name, climate, size, build_cost_multiplier, clear_cost_multiplier, TimerGameCalendar::Date{}, CalendarTime::MAX_DATE + 1, flags, ObjectCallbackMasks{}, height, 1, gen_amount, {}}
|
#define M(name, size, build_cost_multiplier, clear_cost_multiplier, height, climate, gen_amount, flags) {{INVALID_OBJECT_CLASS, 0}, StandardGRFFileProps{}, AnimationInfo<ObjectAnimationTriggers>{}, name, climate, size, build_cost_multiplier, clear_cost_multiplier, TimerGameCalendar::Date{}, CalendarTime::MAX_DATE + 1, flags, ObjectCallbackMasks{}, height, 1, gen_amount, {}}
|
||||||
|
|
||||||
/* Climates
|
/* Climates
|
||||||
* T = Temperate
|
* T = Temperate
|
||||||
|
|
Loading…
Reference in New Issue