continue refactor project
This commit is contained in:
@ -8,16 +8,16 @@
|
||||
namespace LibCmo::CK2::ObjImpls {
|
||||
|
||||
CKBeObject::CKBeObject(CKContext* ctx, CK_ID ckid, CKSTRING name) :
|
||||
CKSceneObject(ctx, ckid, name) {}
|
||||
CKSceneObject(ctx, ckid, name), m_Groups() {}
|
||||
|
||||
CKBeObject::~CKBeObject() {
|
||||
// remove self from all group
|
||||
for (size_t i = 0; i < m_Groups.size(); ++i) {
|
||||
if (m_Groups[i]) {
|
||||
CKGroup* group = static_cast<CKGroup*>(m_Context->GetObjectManager()->GetGroupByGlobalIndex(static_cast<CKDWORD>(i)));
|
||||
group->RemoveObject(this);
|
||||
}
|
||||
}
|
||||
//for (size_t i = 0; i < m_Groups.size(); ++i) {
|
||||
// if (m_Groups[i]) {
|
||||
// CKGroup* group = static_cast<CKGroup*>(m_Context->GetObjectManager()->GetGroupByGlobalIndex(static_cast<CKDWORD>(i)));
|
||||
// group->RemoveObject(this);
|
||||
// }
|
||||
//}
|
||||
}
|
||||
|
||||
bool CKBeObject::Save(CKStateChunk* chunk, CKFileVisitor* file, CKDWORD flags) {
|
||||
@ -36,12 +36,12 @@ namespace LibCmo::CK2::ObjImpls {
|
||||
|
||||
bool CKBeObject::IsInGroup(CKGroup* group) {
|
||||
if (group == nullptr) return false;
|
||||
CKDWORD idx = group->CKBeObject_GetGroupIndex();
|
||||
CKDWORD idx = group->GetGroupIndex();
|
||||
if (idx >= m_Groups.size()) return false;
|
||||
return m_Groups[idx];
|
||||
}
|
||||
|
||||
void CKBeObject::CKGroup_SetGroups(CKDWORD pos, bool val) {
|
||||
void CKBeObject::ExplicitSetGroup(CKDWORD pos, bool val) {
|
||||
if (pos >= m_Groups.size()) m_Groups.resize(pos + 1);
|
||||
m_Groups[pos] = val;
|
||||
}
|
||||
|
@ -20,7 +20,13 @@ namespace LibCmo::CK2::ObjImpls {
|
||||
//virtual void PostLoad() override;
|
||||
|
||||
bool IsInGroup(CKGroup* group);
|
||||
void CKGroup_SetGroups(CKDWORD pos, bool val);
|
||||
/**
|
||||
* @brief Directly set group data.
|
||||
* @param pos
|
||||
* @param val
|
||||
* @warning This function only should be called by CKGroup. Any other classes should not call this.
|
||||
*/
|
||||
void ExplicitSetGroup(CKDWORD pos, bool val);
|
||||
|
||||
protected:
|
||||
XContainer::XBitArray m_Groups;
|
||||
|
@ -9,7 +9,7 @@ namespace LibCmo::CK2::ObjImpls {
|
||||
CKGroup::CKGroup(CKContext* ctx, CK_ID ckid, CKSTRING name) :
|
||||
CKBeObject(ctx, ckid, name),
|
||||
m_ObjectArray(),
|
||||
m_GroupIndex(m_Context->GetObjectManager()->AllocateGroupGlobalIndex(this)) {}
|
||||
m_GroupIndex(m_Context->GetObjectManager()->AllocateGroupGlobalIndex()) {}
|
||||
|
||||
CKGroup::~CKGroup() {
|
||||
m_Context->GetObjectManager()->FreeGroupGlobalIndex(m_GroupIndex);
|
||||
@ -45,7 +45,7 @@ namespace LibCmo::CK2::ObjImpls {
|
||||
if (beobj->IsInGroup(this)) continue;
|
||||
|
||||
// add good one
|
||||
beobj->CKGroup_SetGroups(m_GroupIndex, true);
|
||||
beobj->ExplicitSetGroup(m_GroupIndex, true);
|
||||
m_ObjectArray.emplace_back(beobj);
|
||||
}
|
||||
|
||||
@ -54,7 +54,7 @@ namespace LibCmo::CK2::ObjImpls {
|
||||
return true;
|
||||
}
|
||||
|
||||
CKDWORD CKGroup::CKBeObject_GetGroupIndex() {
|
||||
CKDWORD CKGroup::GetGroupIndex() {
|
||||
return m_GroupIndex;
|
||||
}
|
||||
|
||||
@ -67,7 +67,7 @@ namespace LibCmo::CK2::ObjImpls {
|
||||
}
|
||||
|
||||
// set object
|
||||
o->CKGroup_SetGroups(m_GroupIndex, true);
|
||||
o->ExplicitSetGroup(m_GroupIndex, true);
|
||||
// set self
|
||||
m_ObjectArray.emplace_back(o);
|
||||
return CKERROR::CKERR_OK;
|
||||
@ -80,7 +80,7 @@ namespace LibCmo::CK2::ObjImpls {
|
||||
auto it = m_ObjectArray.begin() + pos;
|
||||
CKBeObject* obj = static_cast<CKBeObject*>(*it);
|
||||
// set object
|
||||
obj->CKGroup_SetGroups(m_GroupIndex, false);
|
||||
obj->ExplicitSetGroup(m_GroupIndex, false);
|
||||
// remove self
|
||||
m_ObjectArray.erase(it);
|
||||
return obj;
|
||||
@ -91,7 +91,7 @@ namespace LibCmo::CK2::ObjImpls {
|
||||
auto finder = std::find(m_ObjectArray.begin(), m_ObjectArray.end(), static_cast<CKObject*>(obj));
|
||||
if (finder != m_ObjectArray.end()) {
|
||||
// set object
|
||||
static_cast<CKBeObject*>(*finder)->CKGroup_SetGroups(m_GroupIndex, false);
|
||||
static_cast<CKBeObject*>(*finder)->ExplicitSetGroup(m_GroupIndex, false);
|
||||
// remove self
|
||||
m_ObjectArray.erase(finder);
|
||||
}
|
||||
@ -100,7 +100,7 @@ namespace LibCmo::CK2::ObjImpls {
|
||||
void CKGroup::Clear() {
|
||||
for (auto& beobj : m_ObjectArray) {
|
||||
// set object
|
||||
static_cast<CKBeObject*>(beobj)->CKGroup_SetGroups(m_GroupIndex, false);
|
||||
static_cast<CKBeObject*>(beobj)->ExplicitSetGroup(m_GroupIndex, false);
|
||||
}
|
||||
|
||||
m_ObjectArray.clear();
|
||||
|
@ -19,7 +19,7 @@ namespace LibCmo::CK2::ObjImpls {
|
||||
virtual bool Load(CKStateChunk* chunk, CKFileVisitor* file) override;
|
||||
//virtual void PostLoad() override;
|
||||
|
||||
CKDWORD CKBeObject_GetGroupIndex();
|
||||
CKDWORD GetGroupIndex();
|
||||
|
||||
// ===== Insert =====
|
||||
CKERROR AddObject(CKBeObject *o);
|
||||
|
Reference in New Issue
Block a user