metaforce/Runtime/Character/TSegIdMap.hpp

71 lines
2.0 KiB
C++
Raw Normal View History

2018-10-07 03:42:33 +00:00
#pragma once
2016-04-13 23:07:18 +00:00
#include <map>
#include "CSegId.hpp"
namespace urde
{
template <class T>
class TSegIdMap
{
2016-04-16 03:24:25 +00:00
CSegId x0_boneCount = 0;
2016-09-04 02:27:35 +00:00
CSegId x1_capacity = 0;
u32 x4_maxCapacity = 100;
std::pair<CSegId, CSegId> x8_indirectionMap[100];
std::unique_ptr<T[]> xd0_bones;
CSegId xd4_curPrevBone = 0;
2016-04-13 23:07:18 +00:00
public:
2016-09-04 02:27:35 +00:00
TSegIdMap(const CSegId& capacity) : x1_capacity(capacity), xd0_bones(new T[capacity]) {}
2016-04-16 03:24:25 +00:00
T& operator[](const CSegId& id) {return SetElement(id);}
2016-09-04 18:59:52 +00:00
const T& operator[](const CSegId& id) const {return xd0_bones[x8_indirectionMap[id].second];}
2016-04-16 03:24:25 +00:00
T& SetElement(const CSegId& id, T&& obj)
{
2016-09-04 18:59:52 +00:00
size_t idx;
2016-09-04 02:27:35 +00:00
if (x8_indirectionMap[id].first == 0xff)
2016-04-16 03:24:25 +00:00
{
2016-09-04 02:27:35 +00:00
x8_indirectionMap[id].first = xd4_curPrevBone;
x8_indirectionMap[id].second = x0_boneCount;
xd4_curPrevBone = id;
2016-09-04 18:59:52 +00:00
idx = x0_boneCount;
2016-04-16 03:24:25 +00:00
++x0_boneCount;
}
2016-09-04 18:59:52 +00:00
else
idx = x8_indirectionMap[id].second;
xd0_bones[idx] = std::move(obj);
return xd0_bones[idx];
2016-04-16 03:24:25 +00:00
}
T& SetElement(const CSegId& id)
{
2016-09-04 18:59:52 +00:00
size_t idx;
2016-09-04 02:27:35 +00:00
if (x8_indirectionMap[id].first == 0xff)
2016-04-16 03:24:25 +00:00
{
2016-09-04 02:27:35 +00:00
x8_indirectionMap[id].first = xd4_curPrevBone;
x8_indirectionMap[id].second = x0_boneCount;
xd4_curPrevBone = id;
2016-09-04 18:59:52 +00:00
idx = x0_boneCount;
2016-04-16 03:24:25 +00:00
++x0_boneCount;
}
2016-09-04 18:59:52 +00:00
else
idx = x8_indirectionMap[id].second;
return xd0_bones[idx];
2016-04-16 03:24:25 +00:00
}
void DelElement(const CSegId& id)
{
2016-09-04 02:27:35 +00:00
if (x8_indirectionMap[id].first != 0xff)
2016-04-16 03:24:25 +00:00
{
2016-09-04 02:27:35 +00:00
if (id == xd4_curPrevBone)
xd4_curPrevBone = x8_indirectionMap[id].first;
x8_indirectionMap[id].first = 0xff;
x8_indirectionMap[id].second = 0xff;
2016-04-16 03:24:25 +00:00
--x0_boneCount;
}
}
2016-09-04 02:27:35 +00:00
bool HasElement(const CSegId& id) const {return x8_indirectionMap[id].first != 0xff;}
u32 GetCapacity() const { return x1_capacity; }
2016-04-13 23:07:18 +00:00
};
}