finish PreDelete and CheckPreDeletion. now there is no problem when deleting object

This commit is contained in:
yyc12345 2023-09-20 15:25:43 +08:00
parent a06f6a58c9
commit 81872053f0
16 changed files with 100 additions and 28 deletions

View File

@ -211,11 +211,11 @@ typedef enum VXCMPFUNC
Summary: Material special effects
Remarks:
o Effects provide additionnal functionnalities to take advantage of graphic features such as bump mapping,cube maps etc...
o When an effect is enabled on a material (CKMaterial::SetEffect) it may override the default settings of mesh channels or material blend options
o New effects can be created by providing a callback function (see CKRenderManager::AddEffect)
o This enumeration provides the list of hardcoded existing effects.
o Most of this effect are heavily hardware and device (DX8,DX7,etc..) dependant
+ Effects provide additionnal functionnalities to take advantage of graphic features such as bump mapping,cube maps etc...
+ When an effect is enabled on a material (CKMaterial::SetEffect) it may override the default settings of mesh channels or material blend options
+ New effects can be created by providing a callback function (see CKRenderManager::AddEffect)
+ This enumeration provides the list of hardcoded existing effects.
+ Most of this effect are heavily hardware and device (DX8,DX7,etc..) dependant
See also: CKMaterial::SetEffect,CKMaterial::GetEffect,CKRenderManager::AddEffect
******************************************************************/
typedef enum VX_EFFECT

View File

@ -97,7 +97,7 @@ namespace LibCmo::CK2::MgrImpls {
// add into list
validObjIds.emplace_back(ids[i]);
}
// then remove deleted object from m_ObjectListByClass
// because we have set to be deleted flag.
for (size_t i = 0; i < m_ObjectsListByClass.size(); ++i) {
@ -117,6 +117,11 @@ namespace LibCmo::CK2::MgrImpls {
}
}
// calling PreDelete function for deleted objects
for (const auto& objid : validObjIds) {
m_ObjectsList[Id2Offset(objid)]->PreDelete();
}
// then free all valid object
for (const auto& objid : validObjIds) {
CKDWORD off = Id2Offset(objid);

View File

@ -19,6 +19,18 @@ namespace LibCmo::CK2::ObjImpls {
CK3dEntity::~CK3dEntity() {}
void CK3dEntity::CheckPreDeletion() {
CKRenderObject::CheckPreDeletion();
// check active mesh
if (m_CurrentMesh->IsToBeDeleted()) {
m_CurrentMesh = nullptr;
}
// check potential meshes
XContainer::NSXObjectPointerArray::PreDeletedCheck(m_PotentialMeshes, m_Context);
}
bool CK3dEntity::Save(CKStateChunk* chunk, CKFileVisitor* file, CKDWORD flags) {
bool suc = CKRenderObject::Save(chunk, file, flags);
if (!suc) return false;

View File

@ -14,10 +14,12 @@ namespace LibCmo::CK2::ObjImpls {
virtual CK_CLASSID GetClassID(void) override {
return CK_CLASSID::CKCID_3DENTITY;
}
//virtual void PreSave(CKFileVisitor* file, CKDWORD flags) override;
virtual void CheckPreDeletion() override;
// 2 RW functions
virtual bool Save(CKStateChunk* chunk, CKFileVisitor* file, CKDWORD flags) override;
virtual bool Load(CKStateChunk* chunk, CKFileVisitor* file) override;
//virtual void PostLoad() override;
// it have special Show and IsVisible method
virtual void Show(CK_OBJECT_SHOWOPTION show = CK_OBJECT_SHOWOPTION::CKSHOW) override;

View File

@ -10,15 +10,7 @@ namespace LibCmo::CK2::ObjImpls {
CKBeObject::CKBeObject(CKContext* ctx, CK_ID ckid, CKSTRING 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);
// }
//}
}
CKBeObject::~CKBeObject() {}
bool CKBeObject::Save(CKStateChunk* chunk, CKFileVisitor* file, CKDWORD flags) {
bool suc = CKSceneObject::Save(chunk, file, flags);

View File

@ -12,9 +12,27 @@ namespace LibCmo::CK2::ObjImpls {
m_GroupIndex(m_Context->GetObjectManager()->AllocateGroupGlobalIndex()) {}
CKGroup::~CKGroup() {
// free self allocated id
m_Context->GetObjectManager()->FreeGroupGlobalIndex(m_GroupIndex);
}
void CKGroup::PreDelete() {
CKBeObject::PreDelete();
// unlink all grouped object
for (auto& ptr : m_ObjectArray) {
static_cast<CKBeObject*>(ptr)->ExplicitSetGroup(m_GroupIndex, false);
}
m_ObjectArray.clear();
}
void CKGroup::CheckPreDeletion() {
CKBeObject::CheckPreDeletion();
// remove self invalid object ptr
XContainer::NSXObjectPointerArray::PreDeletedCheck(m_ObjectArray, m_Context);
}
bool CKGroup::Save(CKStateChunk* chunk, CKFileVisitor* file, CKDWORD flags) {
bool suc = CKBeObject::Save(chunk, file, flags);
if (!suc) return false;

View File

@ -14,6 +14,10 @@ namespace LibCmo::CK2::ObjImpls {
virtual CK_CLASSID GetClassID(void) override {
return CK_CLASSID::CKCID_GROUP;
}
virtual void PreDelete() override;
virtual void CheckPreDeletion() override;
//virtual void PreSave(CKFileVisitor* file, CKDWORD flags) override;
virtual bool Save(CKStateChunk* chunk, CKFileVisitor* file, CKDWORD flags) override;
virtual bool Load(CKStateChunk* chunk, CKFileVisitor* file) override;

View File

@ -33,6 +33,17 @@ namespace LibCmo::CK2::ObjImpls {
CKMaterial::~CKMaterial() {}
void CKMaterial::CheckPreDeletion() {
CKBeObject::CheckPreDeletion();
// check 4 textures
for (auto& tex : m_Textures) {
if (tex != nullptr && tex->IsToBeDeleted()) {
tex = nullptr;
}
}
}
bool CKMaterial::Save(CKStateChunk* chunk, CKFileVisitor* file, CKDWORD flags) {
bool suc = CKBeObject::Save(chunk, file, flags);
if (!suc) return false;

View File

@ -15,11 +15,12 @@ namespace LibCmo::CK2::ObjImpls {
virtual CK_CLASSID GetClassID(void) override {
return CK_CLASSID::CKCID_MATERIAL;
}
virtual void CheckPreDeletion() override;
//virtual void PreSave(CKFileVisitor* file, CKDWORD flags) override;
// 2 RW functions
virtual bool Save(CKStateChunk* chunk, CKFileVisitor* file, CKDWORD flags) override;
virtual bool Load(CKStateChunk* chunk, CKFileVisitor* file) override;
//virtual void PostLoad() override;
protected:
VxMath::VxColor m_Diffuse;

View File

@ -35,6 +35,24 @@ namespace LibCmo::CK2::ObjImpls {
CKMesh::~CKMesh() {}
void CKMesh::CheckPreDeletion() {
CKBeObject::CheckPreDeletion();
// check material slots
for (auto& slot : m_MaterialSlot) {
if (slot != nullptr && slot->IsToBeDeleted()) {
slot = nullptr;
}
}
// check mtl channels
for (auto& chl : m_MaterialChannels) {
if (chl.m_Material != nullptr && chl.m_Material->IsToBeDeleted()) {
chl.m_Material = nullptr;
}
}
}
bool CKMesh::Save(CKStateChunk* chunk, CKFileVisitor* file, CKDWORD flags) {
bool suc = CKBeObject::Save(chunk, file, flags);
if (!suc) return false;

View File

@ -15,10 +15,11 @@ namespace LibCmo::CK2::ObjImpls {
return CK_CLASSID::CKCID_MESH;
}
//virtual void PreSave(CKFileVisitor* file, CKDWORD flags) override;
virtual void CheckPreDeletion() override;
// 2 RW functions
virtual bool Save(CKStateChunk* chunk, CKFileVisitor* file, CKDWORD flags) override;
virtual bool Load(CKStateChunk* chunk, CKFileVisitor* file) override;
//virtual void PostLoad() override;
// it only have special Show method
virtual void Show(CK_OBJECT_SHOWOPTION show = CK_OBJECT_SHOWOPTION::CKSHOW) override;

View File

@ -28,6 +28,9 @@ namespace LibCmo::CK2::ObjImpls {
void CKObject::SetObjectFlags(CK_OBJECT_FLAGS flags) {
m_ObjectFlags = flags;
}
bool CKObject::IsToBeDeleted() const {
return EnumsHelper::Has(m_ObjectFlags, CK_OBJECT_FLAGS::CK_OBJECT_TOBEDELETED);
}
CKContext* CKObject::GetCKContext() const {
return m_Context;
}
@ -35,6 +38,8 @@ namespace LibCmo::CK2::ObjImpls {
#pragma endregion
void CKObject::PreDelete() {}
void CKObject::CheckPreDeletion() {}
void CKObject::CheckPostDeletion() {}

View File

@ -16,6 +16,7 @@ Implement as original meaning:
- Show()
- IsVisible()
- PreDelete()
- CheckPreDeletion()
- CheckPostDeletion()
@ -30,7 +31,6 @@ No implement because don't care:
Implement moved into other location:
- Copy(): Use CKObject::CKObject(CK_ID newid, const CKObject* obj) ctor and CKClassDesc to implement.
- PreDelete(): Write in dtor.
*/
@ -47,12 +47,14 @@ namespace LibCmo::CK2::ObjImpls {
void SetName(CKSTRING u8_name);
CK_OBJECT_FLAGS GetObjectFlags(void) const;
void SetObjectFlags(CK_OBJECT_FLAGS flags);
bool IsToBeDeleted() const;
CKContext* GetCKContext() const;
virtual CK_CLASSID GetClassID(void) {
return CK_CLASSID::CKCID_OBJECT;
}
virtual void PreDelete();
virtual void CheckPreDeletion();
virtual void CheckPostDeletion();

View File

@ -183,11 +183,11 @@ namespace LibCmo::VxMath {
/**
Summary: Material special effects
Remarks:
o Effects provide additionnal functionnalities to take advantage of graphic features such as bump mapping,cube maps etc...
o When an effect is enabled on a material (CKMaterial::SetEffect) it may override the default settings of mesh channels or material blend options
o New effects can be created by providing a callback function (see CKRenderManager::AddEffect)
o This enumeration provides the list of hardcoded existing effects.
o Most of this effect are heavily hardware and device (DX8,DX7,etc..) dependant
+ Effects provide additionnal functionnalities to take advantage of graphic features such as bump mapping,cube maps etc...
+ When an effect is enabled on a material (CKMaterial::SetEffect) it may override the default settings of mesh channels or material blend options
+ New effects can be created by providing a callback function (see CKRenderManager::AddEffect)
+ This enumeration provides the list of hardcoded existing effects.
+ Most of this effect are heavily hardware and device (DX8,DX7,etc..) dependant
See also: CKMaterial::SetEffect,CKMaterial::GetEffect,CKRenderManager::AddEffect
*/
enum class VX_EFFECT : CKDWORD {

View File

@ -98,7 +98,7 @@ namespace LibCmo::XContainer {
} else {
obj = item;
}
if (EnumsHelper::Has(obj->GetObjectFlags(), CK2::CK_OBJECT_FLAGS::CK_OBJECT_TOBEDELETED)) return false;
if (obj->IsToBeDeleted()) return false;
} else {
CK2::MgrImpls::CKObjectManager* objmgr = ctx->GetObjectManager();
if constexpr (std::is_same_v<_Ty, CK2::CK_ID>) {

View File

@ -204,6 +204,7 @@ namespace Unvirt::Context {
// split cmd and parse it
auto cmds = m_Splitter.Convert(u8cmd);
if (cmds.empty()) continue;
// get sub command
if (!m_Root.RootConsume(cmds)) {