Use a std::vector for Object::counts
This commit is contained in:
@@ -43,6 +43,7 @@ struct Object : ObjectPool::PoolItem<&_object_pool> {
|
|||||||
static inline void IncTypeCount(ObjectType type)
|
static inline void IncTypeCount(ObjectType type)
|
||||||
{
|
{
|
||||||
dbg_assert(type < NUM_OBJECTS);
|
dbg_assert(type < NUM_OBJECTS);
|
||||||
|
if (type >= counts.size()) counts.resize(type + 1);
|
||||||
counts[type]++;
|
counts[type]++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,6 +55,7 @@ struct Object : ObjectPool::PoolItem<&_object_pool> {
|
|||||||
static inline void DecTypeCount(ObjectType type)
|
static inline void DecTypeCount(ObjectType type)
|
||||||
{
|
{
|
||||||
dbg_assert(type < NUM_OBJECTS);
|
dbg_assert(type < NUM_OBJECTS);
|
||||||
|
dbg_assert(type < counts.size());
|
||||||
counts[type]--;
|
counts[type]--;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,17 +67,18 @@ struct Object : ObjectPool::PoolItem<&_object_pool> {
|
|||||||
static inline uint16 GetTypeCount(ObjectType type)
|
static inline uint16 GetTypeCount(ObjectType type)
|
||||||
{
|
{
|
||||||
dbg_assert(type < NUM_OBJECTS);
|
dbg_assert(type < NUM_OBJECTS);
|
||||||
|
if (type >= counts.size()) return 0;
|
||||||
return counts[type];
|
return counts[type];
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Resets object counts. */
|
/** Resets object counts. */
|
||||||
static inline void ResetTypeCounts()
|
static inline void ResetTypeCounts()
|
||||||
{
|
{
|
||||||
memset(&counts, 0, sizeof(counts));
|
counts.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
static uint16 counts[NUM_OBJECTS]; ///< Number of objects per type ingame
|
static std::vector<uint16> counts; ///< Number of objects per type ingame
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -41,7 +41,7 @@
|
|||||||
|
|
||||||
ObjectPool _object_pool("Object");
|
ObjectPool _object_pool("Object");
|
||||||
INSTANTIATE_POOL_METHODS(Object)
|
INSTANTIATE_POOL_METHODS(Object)
|
||||||
uint16 Object::counts[NUM_OBJECTS];
|
std::vector<uint16> Object::counts;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the object associated with a tile.
|
* Get the object associated with a tile.
|
||||||
|
Reference in New Issue
Block a user