fix fatal CKStateChunk error
This commit is contained in:
parent
eea15c2028
commit
5c1af5be24
|
@ -57,7 +57,7 @@ namespace LibCmo::CK2 {
|
||||||
}
|
}
|
||||||
|
|
||||||
// create one
|
// create one
|
||||||
ObjImpls::CKObject* obj = desc->CreationFct(this, decided_id, name);
|
ObjImpls::CKObject* obj = desc->CreationFct(this, decided_id + c_ObjectIdOffset, name);
|
||||||
|
|
||||||
// put into slot
|
// put into slot
|
||||||
m_ObjectsList[decided_id] = obj;
|
m_ObjectsList[decided_id] = obj;
|
||||||
|
@ -67,6 +67,7 @@ namespace LibCmo::CK2 {
|
||||||
}
|
}
|
||||||
|
|
||||||
ObjImpls::CKObject* CKContext::GetObject(CK_ID id) {
|
ObjImpls::CKObject* CKContext::GetObject(CK_ID id) {
|
||||||
|
id -= c_ObjectIdOffset;
|
||||||
if (id >= m_ObjectsList.size()) return nullptr;
|
if (id >= m_ObjectsList.size()) return nullptr;
|
||||||
return m_ObjectsList[id];
|
return m_ObjectsList[id];
|
||||||
}
|
}
|
||||||
|
@ -89,6 +90,7 @@ namespace LibCmo::CK2 {
|
||||||
desc->ReleaseFct(ctx, obj);
|
desc->ReleaseFct(ctx, obj);
|
||||||
}
|
}
|
||||||
void CKContext::DestroyObject(CK_ID id) {
|
void CKContext::DestroyObject(CK_ID id) {
|
||||||
|
id -= c_ObjectIdOffset;
|
||||||
if (id >= m_ObjectsList.size()) return;
|
if (id >= m_ObjectsList.size()) return;
|
||||||
|
|
||||||
// get object and free it
|
// get object and free it
|
||||||
|
|
|
@ -97,6 +97,13 @@ namespace LibCmo::CK2 {
|
||||||
protected:
|
protected:
|
||||||
// ========== Objects Management ==========
|
// ========== Objects Management ==========
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The global offset of created CK_ID.
|
||||||
|
* The value close to zero may cause some issue.
|
||||||
|
* So we add a static offset to every created CK_ID.
|
||||||
|
*/
|
||||||
|
const CK_ID c_ObjectIdOffset = 61u;
|
||||||
|
|
||||||
XContainer::XArray<ObjImpls::CKObject*> m_ObjectsList;
|
XContainer::XArray<ObjImpls::CKObject*> m_ObjectsList;
|
||||||
std::deque<CK_ID> m_ReturnedObjectIds;
|
std::deque<CK_ID> m_ReturnedObjectIds;
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,9 @@
|
||||||
#include "ObjImpls/CKSceneObject.hpp"
|
#include "ObjImpls/CKSceneObject.hpp"
|
||||||
#include "ObjImpls/CKBeObject.hpp"
|
#include "ObjImpls/CKBeObject.hpp"
|
||||||
#include "ObjImpls/CKGroup.hpp"
|
#include "ObjImpls/CKGroup.hpp"
|
||||||
|
#include "ObjImpls/CKRenderObject.hpp"
|
||||||
|
#include "ObjImpls/CK3dEntity.hpp"
|
||||||
|
#include "ObjImpls/CK3dObject.hpp"
|
||||||
|
|
||||||
namespace LibCmo::CK2 {
|
namespace LibCmo::CK2 {
|
||||||
|
|
||||||
|
@ -222,11 +225,9 @@ CKClassRegister(cid, parentCid, \
|
||||||
EasyClassReg(ObjImpls::CKSceneObject, CK_CLASSID::CKCID_SCENEOBJECT, CK_CLASSID::CKCID_OBJECT, "Scene Object");
|
EasyClassReg(ObjImpls::CKSceneObject, CK_CLASSID::CKCID_SCENEOBJECT, CK_CLASSID::CKCID_OBJECT, "Scene Object");
|
||||||
EasyClassReg(ObjImpls::CKBeObject, CK_CLASSID::CKCID_BEOBJECT, CK_CLASSID::CKCID_SCENEOBJECT, "Behavioral Object");
|
EasyClassReg(ObjImpls::CKBeObject, CK_CLASSID::CKCID_BEOBJECT, CK_CLASSID::CKCID_SCENEOBJECT, "Behavioral Object");
|
||||||
EasyClassReg(ObjImpls::CKGroup, CK_CLASSID::CKCID_GROUP, CK_CLASSID::CKCID_BEOBJECT, "Group");
|
EasyClassReg(ObjImpls::CKGroup, CK_CLASSID::CKCID_GROUP, CK_CLASSID::CKCID_BEOBJECT, "Group");
|
||||||
|
EasyClassReg(ObjImpls::CKRenderObject, CK_CLASSID::CKCID_RENDEROBJECT, CK_CLASSID::CKCID_BEOBJECT, "Render Object");
|
||||||
//CKClassRegister(CK_CLASSID::CKCID_OBJECT, CK_CLASSID::CKCID_OBJECT,
|
EasyClassReg(ObjImpls::CK3dEntity, CK_CLASSID::CKCID_3DENTITY, CK_CLASSID::CKCID_RENDEROBJECT, "3D Entity");
|
||||||
// [](CKContext* ctx, CK_ID id, CKSTRING name) -> ObjImpls::CKObject* { return new ObjImpls::CKObject(ctx, id, name); },
|
EasyClassReg(ObjImpls::CK3dObject, CK_CLASSID::CKCID_3DOBJECT, CK_CLASSID::CKCID_3DENTITY, "3D Object");
|
||||||
// [](CKContext* ctx, ObjImpls::CKObject* obj) -> void { delete obj; },
|
|
||||||
// []() -> CKSTRING { return "Basic Object"; });
|
|
||||||
|
|
||||||
#undef EasyClassReg
|
#undef EasyClassReg
|
||||||
|
|
||||||
|
|
|
@ -565,6 +565,7 @@ namespace LibCmo::CK2 {
|
||||||
CKDWORD size_in_dword = this->GetCeilDwordSize(size_in_byte);
|
CKDWORD size_in_dword = this->GetCeilDwordSize(size_in_byte);
|
||||||
if (this->EnsureReadSpace(size_in_dword)) {
|
if (this->EnsureReadSpace(size_in_dword)) {
|
||||||
std::memcpy(data_ptr, this->m_pData + this->m_Parser.m_CurrentPos, size_in_byte);
|
std::memcpy(data_ptr, this->m_pData + this->m_Parser.m_CurrentPos, size_in_byte);
|
||||||
|
this->m_Parser.m_CurrentPos += size_in_dword;
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
// failed, report to context
|
// failed, report to context
|
||||||
|
|
20
LibCmo/CK2/ObjImpls/CK3dEntity.cpp
Normal file
20
LibCmo/CK2/ObjImpls/CK3dEntity.cpp
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
#include "CK3dEntity.hpp"
|
||||||
|
#include "../CKStateChunk.hpp"
|
||||||
|
|
||||||
|
namespace LibCmo::CK2::ObjImpls {
|
||||||
|
|
||||||
|
bool CK3dEntity::Save(CKStateChunk* chunk, CKFileVisitor* file, CKDWORD flags) {
|
||||||
|
bool suc = CKRenderObject::Save(chunk, file, flags);
|
||||||
|
if (!suc) return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CK3dEntity::Load(CKStateChunk* chunk, CKFileVisitor* file) {
|
||||||
|
bool suc = CKRenderObject::Load(chunk, file);
|
||||||
|
if (!suc) return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
32
LibCmo/CK2/ObjImpls/CK3dEntity.hpp
Normal file
32
LibCmo/CK2/ObjImpls/CK3dEntity.hpp
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "../../VTAll.hpp"
|
||||||
|
#include "CKRenderObject.hpp"
|
||||||
|
|
||||||
|
namespace LibCmo::CK2::ObjImpls {
|
||||||
|
|
||||||
|
class CK3dEntity : public CKRenderObject {
|
||||||
|
public:
|
||||||
|
CK3dEntity(CKContext* ctx, CK_ID ckid, CKSTRING name) :
|
||||||
|
CKRenderObject(ctx, ckid, name),
|
||||||
|
m_Meshes(), m_CurrentMesh(nullptr), m_WorldMatrix()
|
||||||
|
{}
|
||||||
|
virtual ~CK3dEntity() {}
|
||||||
|
LIBCMO_DISABLE_COPY_MOVE(CK3dEntity);
|
||||||
|
|
||||||
|
virtual CK_CLASSID GetClassID(void) override {
|
||||||
|
return CK_CLASSID::CKCID_3DENTITY;
|
||||||
|
}
|
||||||
|
//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;
|
||||||
|
//virtual void PostLoad() override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
XContainer::XObjectPointerArray m_Meshes;
|
||||||
|
CKMesh* m_CurrentMesh;
|
||||||
|
VxMath::VxMatrix m_WorldMatrix;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
28
LibCmo/CK2/ObjImpls/CK3dObject.hpp
Normal file
28
LibCmo/CK2/ObjImpls/CK3dObject.hpp
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "../../VTAll.hpp"
|
||||||
|
#include "CK3dEntity.hpp"
|
||||||
|
|
||||||
|
namespace LibCmo::CK2::ObjImpls {
|
||||||
|
|
||||||
|
class CK3dObject : public CK3dEntity {
|
||||||
|
public:
|
||||||
|
CK3dObject(CKContext* ctx, CK_ID ckid, CKSTRING name) :
|
||||||
|
CK3dEntity(ctx, ckid, name)
|
||||||
|
{}
|
||||||
|
virtual ~CK3dObject() {}
|
||||||
|
LIBCMO_DISABLE_COPY_MOVE(CK3dObject);
|
||||||
|
|
||||||
|
virtual CK_CLASSID GetClassID(void) override {
|
||||||
|
return CK_CLASSID::CKCID_3DOBJECT;
|
||||||
|
}
|
||||||
|
// CK3dObject do not implement any load/save functions
|
||||||
|
//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;
|
||||||
|
//virtual void PostLoad() override;
|
||||||
|
protected:
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
8
LibCmo/CK2/ObjImpls/CKRenderObject.cpp
Normal file
8
LibCmo/CK2/ObjImpls/CKRenderObject.cpp
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
#include "CKRenderObject.hpp"
|
||||||
|
#include "../CKStateChunk.hpp"
|
||||||
|
|
||||||
|
namespace LibCmo::CK2::ObjImpls {
|
||||||
|
|
||||||
|
// nothing to compile now
|
||||||
|
|
||||||
|
}
|
28
LibCmo/CK2/ObjImpls/CKRenderObject.hpp
Normal file
28
LibCmo/CK2/ObjImpls/CKRenderObject.hpp
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "../../VTAll.hpp"
|
||||||
|
#include "CKBeObject.hpp"
|
||||||
|
|
||||||
|
namespace LibCmo::CK2::ObjImpls {
|
||||||
|
|
||||||
|
class CKRenderObject : public CKBeObject {
|
||||||
|
public:
|
||||||
|
CKRenderObject(CKContext* ctx, CK_ID ckid, CKSTRING name) :
|
||||||
|
CKBeObject(ctx, ckid, name)
|
||||||
|
{}
|
||||||
|
virtual ~CKRenderObject() {}
|
||||||
|
LIBCMO_DISABLE_COPY_MOVE(CKRenderObject);
|
||||||
|
|
||||||
|
virtual CK_CLASSID GetClassID(void) override {
|
||||||
|
return CK_CLASSID::CKCID_RENDEROBJECT;
|
||||||
|
}
|
||||||
|
// CKRenderObject do not implement any load/save functions
|
||||||
|
//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;
|
||||||
|
//virtual void PostLoad() override;
|
||||||
|
protected:
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
|
@ -180,9 +180,11 @@
|
||||||
<ClCompile Include="CK2\CKGlobals.cpp" />
|
<ClCompile Include="CK2\CKGlobals.cpp" />
|
||||||
<ClCompile Include="CK2\MgrImpls\CKBaseManager.cpp" />
|
<ClCompile Include="CK2\MgrImpls\CKBaseManager.cpp" />
|
||||||
<ClCompile Include="CK2\CKContext.cpp" />
|
<ClCompile Include="CK2\CKContext.cpp" />
|
||||||
|
<ClCompile Include="CK2\ObjImpls\CK3dEntity.cpp" />
|
||||||
<ClCompile Include="CK2\ObjImpls\CKBeObject.cpp" />
|
<ClCompile Include="CK2\ObjImpls\CKBeObject.cpp" />
|
||||||
<ClCompile Include="CK2\ObjImpls\CKGroup.cpp" />
|
<ClCompile Include="CK2\ObjImpls\CKGroup.cpp" />
|
||||||
<ClCompile Include="CK2\ObjImpls\CKObject.cpp" />
|
<ClCompile Include="CK2\ObjImpls\CKObject.cpp" />
|
||||||
|
<ClCompile Include="CK2\ObjImpls\CKRenderObject.cpp" />
|
||||||
<ClCompile Include="CK2\ObjImpls\CKSceneObject.cpp" />
|
<ClCompile Include="CK2\ObjImpls\CKSceneObject.cpp" />
|
||||||
<ClCompile Include="VTEncoding.cpp" />
|
<ClCompile Include="VTEncoding.cpp" />
|
||||||
<ClCompile Include="CK2\CKFileReader.cpp" />
|
<ClCompile Include="CK2\CKFileReader.cpp" />
|
||||||
|
@ -201,8 +203,11 @@
|
||||||
<ClInclude Include="CK2\CKContext.hpp" />
|
<ClInclude Include="CK2\CKContext.hpp" />
|
||||||
<ClInclude Include="CK2\CKStateChunk.hpp" />
|
<ClInclude Include="CK2\CKStateChunk.hpp" />
|
||||||
<ClInclude Include="CK2\CKTypes.hpp" />
|
<ClInclude Include="CK2\CKTypes.hpp" />
|
||||||
|
<ClInclude Include="CK2\ObjImpls\CK3dEntity.hpp" />
|
||||||
|
<ClInclude Include="CK2\ObjImpls\CK3dObject.hpp" />
|
||||||
<ClInclude Include="CK2\ObjImpls\CKBeObject.hpp" />
|
<ClInclude Include="CK2\ObjImpls\CKBeObject.hpp" />
|
||||||
<ClInclude Include="CK2\ObjImpls\CKGroup.hpp" />
|
<ClInclude Include="CK2\ObjImpls\CKGroup.hpp" />
|
||||||
|
<ClInclude Include="CK2\ObjImpls\CKRenderObject.hpp" />
|
||||||
<ClInclude Include="CK2\ObjImpls\CKSceneObject.hpp" />
|
<ClInclude Include="CK2\ObjImpls\CKSceneObject.hpp" />
|
||||||
<ClInclude Include="VTAll.hpp" />
|
<ClInclude Include="VTAll.hpp" />
|
||||||
<ClInclude Include="VTEncoding.hpp" />
|
<ClInclude Include="VTEncoding.hpp" />
|
||||||
|
|
|
@ -90,6 +90,12 @@
|
||||||
<ClCompile Include="XContainer\XBitArray.cpp">
|
<ClCompile Include="XContainer\XBitArray.cpp">
|
||||||
<Filter>Sources\XContainer</Filter>
|
<Filter>Sources\XContainer</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="CK2\ObjImpls\CKRenderObject.cpp">
|
||||||
|
<Filter>Sources\CK2\ObjImpls</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="CK2\ObjImpls\CK3dEntity.cpp">
|
||||||
|
<Filter>Sources\CK2\ObjImpls</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="VTUtils.hpp">
|
<ClInclude Include="VTUtils.hpp">
|
||||||
|
@ -152,5 +158,14 @@
|
||||||
<ClInclude Include="XContainer\XBitArray.hpp">
|
<ClInclude Include="XContainer\XBitArray.hpp">
|
||||||
<Filter>Headers\XContainer</Filter>
|
<Filter>Headers\XContainer</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="CK2\ObjImpls\CKRenderObject.hpp">
|
||||||
|
<Filter>Headers\CK2\ObjImpls</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="CK2\ObjImpls\CK3dEntity.hpp">
|
||||||
|
<Filter>Headers\CK2\ObjImpls</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="CK2\ObjImpls\CK3dObject.hpp">
|
||||||
|
<Filter>Headers\CK2\ObjImpls</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
Loading…
Reference in New Issue
Block a user