2018-10-07 03:42:33 +00:00
|
|
|
#pragma once
|
2016-04-13 23:07:18 +00:00
|
|
|
|
|
|
|
#include <map>
|
2019-09-28 02:53:03 +00:00
|
|
|
#include <memory>
|
|
|
|
#include <utility>
|
|
|
|
|
|
|
|
#include "Runtime/Character/CSegId.hpp"
|
2016-04-13 23:07:18 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
namespace urde {
|
2016-04-13 23:07:18 +00:00
|
|
|
|
|
|
|
template <class T>
|
2018-12-08 05:30:43 +00:00
|
|
|
class TSegIdMap {
|
|
|
|
CSegId x0_boneCount = 0;
|
|
|
|
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:
|
2020-03-31 03:52:22 +00:00
|
|
|
explicit TSegIdMap(const CSegId& capacity) : x1_capacity(capacity), xd0_bones(new T[capacity]) {}
|
2019-10-27 01:53:11 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
T& operator[](const CSegId& id) { return SetElement(id); }
|
|
|
|
const T& operator[](const CSegId& id) const { return xd0_bones[x8_indirectionMap[id].second]; }
|
2019-10-27 01:53:11 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
T& SetElement(const CSegId& id, T&& obj) {
|
|
|
|
size_t idx;
|
2019-10-27 01:53:11 +00:00
|
|
|
|
|
|
|
if (HasElement(id)) {
|
|
|
|
idx = x8_indirectionMap[id].second;
|
|
|
|
} else {
|
|
|
|
x8_indirectionMap[id] = std::make_pair(xd4_curPrevBone, x0_boneCount);
|
2018-12-08 05:30:43 +00:00
|
|
|
xd4_curPrevBone = id;
|
|
|
|
idx = x0_boneCount;
|
|
|
|
++x0_boneCount;
|
2019-10-27 01:53:11 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
xd0_bones[idx] = std::move(obj);
|
|
|
|
return xd0_bones[idx];
|
|
|
|
}
|
2019-10-27 01:53:11 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
T& SetElement(const CSegId& id) {
|
|
|
|
size_t idx;
|
2019-10-27 01:53:11 +00:00
|
|
|
|
|
|
|
if (HasElement(id)) {
|
|
|
|
idx = x8_indirectionMap[id].second;
|
|
|
|
} else {
|
|
|
|
x8_indirectionMap[id] = std::make_pair(xd4_curPrevBone, x0_boneCount);
|
2018-12-08 05:30:43 +00:00
|
|
|
xd4_curPrevBone = id;
|
|
|
|
idx = x0_boneCount;
|
|
|
|
++x0_boneCount;
|
2019-10-27 01:53:11 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
return xd0_bones[idx];
|
|
|
|
}
|
2019-10-27 01:53:11 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void DelElement(const CSegId& id) {
|
2019-10-27 01:53:11 +00:00
|
|
|
if (!HasElement(id)) {
|
|
|
|
return;
|
2016-04-16 03:24:25 +00:00
|
|
|
}
|
2019-10-27 01:53:11 +00:00
|
|
|
|
|
|
|
if (id == xd4_curPrevBone) {
|
|
|
|
xd4_curPrevBone = x8_indirectionMap[id].first;
|
|
|
|
}
|
|
|
|
|
|
|
|
x8_indirectionMap[id] = {};
|
|
|
|
--x0_boneCount;
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2019-10-27 01:53:11 +00:00
|
|
|
|
|
|
|
bool HasElement(const CSegId& id) const { return x8_indirectionMap[id].first.IsValid(); }
|
2016-09-04 02:27:35 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
u32 GetCapacity() const { return x1_capacity; }
|
2016-04-13 23:07:18 +00:00
|
|
|
};
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
} // namespace urde
|