finish PreDelete and CheckPreDeletion. now there is no problem when deleting object
This commit is contained in:
parent
a06f6a58c9
commit
81872053f0
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -16,10 +16,11 @@ namespace LibCmo::CK2::ObjImpls {
|
|||
return CK_CLASSID::CKCID_MATERIAL;
|
||||
}
|
||||
|
||||
//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;
|
||||
|
||||
protected:
|
||||
VxMath::VxColor m_Diffuse;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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() {}
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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>) {
|
||||
|
|
|
@ -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)) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user