fix qualified name error in CKFileOthers. add some stupid wrapper for BMap

This commit is contained in:
yyc12345 2023-10-02 20:54:31 +08:00
parent b477c468cd
commit 4c8500e444
4 changed files with 150 additions and 1 deletions

View File

@ -2,13 +2,17 @@
#include <IronPad.hpp> #include <IronPad.hpp>
#include <set> #include <set>
static bool g_IsInited = false;
static std::set<BMap::BMFile*> g_AllBMFiles = std::set<BMap::BMFile*>(); static std::set<BMap::BMFile*> g_AllBMFiles = std::set<BMap::BMFile*>();
static std::set<BMap::BMMeshTransition*> g_AllBMMeshTrans = std::set<BMap::BMMeshTransition*>();
void BMInit() { void BMInit() {
// register IronPad // register IronPad
IronPad::IronPadRegister(); IronPad::IronPadRegister();
// and startup CK environment // and startup CK environment
LibCmo::CK2::CKStartUp(); LibCmo::CK2::CKStartUp();
// set init
g_IsInited = true;
} }
void BMDispose() { void BMDispose() {
@ -17,13 +21,24 @@ void BMDispose() {
delete ptr; delete ptr;
} }
g_AllBMFiles.clear(); g_AllBMFiles.clear();
// free all mesh transition
for (auto ptr : g_AllBMMeshTrans) {
delete ptr;
}
g_AllBMMeshTrans.clear();
// disable init
g_IsInited = false;
// shutdown CK environment // shutdown CK environment
LibCmo::CK2::CKShutdown(); LibCmo::CK2::CKShutdown();
// unregister iron pad // unregister iron pad
IronPad::IronPadUnregister(); IronPad::IronPadUnregister();
} }
#pragma region BMFile
BMap::BMFile* BMFile_Load(LibCmo::CKSTRING file_name, LibCmo::CKSTRING temp_folder, LibCmo::CKSTRING texture_folder, LibCmo::CKDWORD encoding_count, LibCmo::CKSTRING encodings[]) { BMap::BMFile* BMFile_Load(LibCmo::CKSTRING file_name, LibCmo::CKSTRING temp_folder, LibCmo::CKSTRING texture_folder, LibCmo::CKDWORD encoding_count, LibCmo::CKSTRING encodings[]) {
if (!g_IsInited) return nullptr;
auto file = new BMap::BMFile(temp_folder, texture_folder, encoding_count, encodings, false); auto file = new BMap::BMFile(temp_folder, texture_folder, encoding_count, encodings, false);
if (file->IsFailed()) { if (file->IsFailed()) {
delete file; delete file;
@ -39,6 +54,7 @@ BMap::BMFile* BMFile_Load(LibCmo::CKSTRING file_name, LibCmo::CKSTRING temp_fold
} }
BMap::BMFile* BMFile_Create(LibCmo::CKSTRING temp_folder, LibCmo::CKSTRING texture_folder, LibCmo::CKDWORD encoding_count, LibCmo::CKSTRING encodings[]) { BMap::BMFile* BMFile_Create(LibCmo::CKSTRING temp_folder, LibCmo::CKSTRING texture_folder, LibCmo::CKDWORD encoding_count, LibCmo::CKSTRING encodings[]) {
if (!g_IsInited) return nullptr;
auto file = new BMap::BMFile(temp_folder, texture_folder, encoding_count, encodings, false); auto file = new BMap::BMFile(temp_folder, texture_folder, encoding_count, encodings, false);
if (file->IsFailed()) { if (file->IsFailed()) {
delete file; delete file;
@ -61,3 +77,104 @@ void BMFile_Free(BMap::BMFile* map_file) {
delete map_file; delete map_file;
} }
} }
#define VISITOR_IMPL(namepart, cidpart) \
LibCmo::CKDWORD BMFile_Get ## namepart ## Count(BMap::BMFile* map_file) { \
if (!g_AllBMFiles.contains(map_file)) return 0; \
return map_file->Get ## namepart ## Count(); \
} \
LibCmo::CK2::ObjImpls::CK ## namepart * BMFile_Get ## namepart (BMap::BMFile* map_file, LibCmo::CKDWORD idx) { \
if (!g_AllBMFiles.contains(map_file)) return nullptr; \
return map_file->Get ## namepart (idx); \
} \
LibCmo::CK2::ObjImpls::CK ## namepart * BMFile_Create ## namepart (BMap::BMFile* map_file, LibCmo::CKSTRING name) { \
if (!g_AllBMFiles.contains(map_file)) return nullptr; \
return map_file->Create ## namepart (name); \
}
VISITOR_IMPL(Group, GROUP)
VISITOR_IMPL(3dObject, 3DOBJECT)
VISITOR_IMPL(Mesh, MESH)
VISITOR_IMPL(Material, MATERIAL)
VISITOR_IMPL(Texture, TEXTURE)
#undef VISITOR_IMPL
#pragma endregion
#pragma region BMMeshTransition
BMap::BMMeshTransition* BMMeshTrans_New() {
if (!g_IsInited) return nullptr;
auto meshtrans = new BMap::BMMeshTransition();
g_AllBMMeshTrans.emplace(meshtrans);
return meshtrans;
}
void BMMeshTrans_Delete(BMap::BMMeshTransition* trans) {
// only free correct pointer
if (trans == nullptr) return;
if (g_AllBMMeshTrans.erase(trans) != 0) {
delete trans;
}
}
void BMMeshTrans_PrepareVertexCount(BMap::BMMeshTransition* trans, LibCmo::CKDWORD count) {
if (!g_AllBMMeshTrans.contains(trans)) return;
trans->PrepareVertexCount(count);
}
LibCmo::VxMath::VxVector3* BMMeshTrans_PrepareVertex(BMap::BMMeshTransition* trans) {
if (!g_AllBMMeshTrans.contains(trans)) return nullptr;
return trans->PrepareVertex();
}
void BMMeshTrans_PrepareNormalCount(BMap::BMMeshTransition* trans, LibCmo::CKDWORD count) {
if (!g_AllBMMeshTrans.contains(trans)) return;
trans->PrepareNormalCount(count);
}
LibCmo::VxMath::VxVector3* BMMeshTrans_PrepareNormal(BMap::BMMeshTransition* trans) {
if (!g_AllBMMeshTrans.contains(trans)) return nullptr;
return trans->PrepareNormal();
}
void BMMeshTrans_PrepareUVCount(BMap::BMMeshTransition* trans, LibCmo::CKDWORD count) {
if (!g_AllBMMeshTrans.contains(trans)) return;
trans->PrepareUVCount(count);
}
LibCmo::VxMath::VxVector2* BMMeshTrans_PrepareUV(BMap::BMMeshTransition* trans) {
if (!g_AllBMMeshTrans.contains(trans)) return nullptr;
return trans->PrepareUV();
}
void BMMeshTrans_PrepareMtlSlotCount(BMap::BMMeshTransition* trans, LibCmo::CKDWORD count) {
if (!g_AllBMMeshTrans.contains(trans)) return;
trans->PrepareMtlSlotCount(count);
}
LibCmo::CK2::ObjImpls::CKMaterial** BMMeshTrans_PrepareMtlSlot(BMap::BMMeshTransition* trans) {
if (!g_AllBMMeshTrans.contains(trans)) return nullptr;
return trans->PrepareMtlSlot();
}
void BMMeshTrans_PrepareFaceCount(BMap::BMMeshTransition* trans, LibCmo::CKDWORD count) {
if (!g_AllBMMeshTrans.contains(trans)) return;
trans->PrepareFaceCount(count);
}
LibCmo::CKDWORD* BMMeshTrans_PrepareFaceVertexIndices(BMap::BMMeshTransition* trans) {
if (!g_AllBMMeshTrans.contains(trans)) return nullptr;
return trans->PrepareFaceVertexIndices();
}
LibCmo::CKDWORD* BMMeshTrans_PrepareFaceNormalIndices(BMap::BMMeshTransition* trans) {
if (!g_AllBMMeshTrans.contains(trans)) return nullptr;
return trans->PrepareFaceNormalIndices();
}
LibCmo::CKDWORD* BMMeshTrans_PrepareFaceUVIndices(BMap::BMMeshTransition* trans) {
if (!g_AllBMMeshTrans.contains(trans)) return nullptr;
return trans->PrepareFaceUVIndices();
}
LibCmo::CKDWORD* BMMeshTrans_PrepareFaceMtlSlot(BMap::BMMeshTransition* trans) {
if (!g_AllBMMeshTrans.contains(trans)) return nullptr;
return trans->PrepareFaceMtlSlot();
}
bool BMMeshTrans_Parse(BMap::BMMeshTransition* trans, LibCmo::CK2::ObjImpls::CKMesh* write_into_mesh) {
if (!g_AllBMMeshTrans.contains(trans)) return false;
return trans->Parse(write_into_mesh);
}
#pragma endregion

View File

@ -16,10 +16,40 @@ LIBCMO_EXPORT BMap::BMFile* BMFile_Create(LibCmo::CKSTRING temp_folder, LibCmo::
LIBCMO_EXPORT bool BMFile_Save(BMap::BMFile* map_file, LibCmo::CKSTRING file_name, LibCmo::CKINT compreess_level); LIBCMO_EXPORT bool BMFile_Save(BMap::BMFile* map_file, LibCmo::CKSTRING file_name, LibCmo::CKINT compreess_level);
LIBCMO_EXPORT void BMFile_Free(BMap::BMFile* map_file); LIBCMO_EXPORT void BMFile_Free(BMap::BMFile* map_file);
#define VISITOR_DECL(namepart) \
LIBCMO_EXPORT LibCmo::CKDWORD BMFile_Get ## namepart ## Count(BMap::BMFile* map_file); \
LIBCMO_EXPORT LibCmo::CK2::ObjImpls::CK ## namepart * BMFile_Get ## namepart (BMap::BMFile* map_file, LibCmo::CKDWORD idx); \
LIBCMO_EXPORT LibCmo::CK2::ObjImpls::CK ## namepart * BMFile_Create ## namepart (BMap::BMFile* map_file, LibCmo::CKSTRING name);
VISITOR_DECL(Group)
VISITOR_DECL(3dObject)
VISITOR_DECL(Mesh)
VISITOR_DECL(Material)
VISITOR_DECL(Texture)
#undef VISITOR_DECL
#pragma endregion #pragma endregion
#pragma region BMMeshTransition #pragma region BMMeshTransition
LIBCMO_EXPORT BMap::BMMeshTransition* BMMeshTrans_New();
LIBCMO_EXPORT void BMMeshTrans_Delete(BMap::BMMeshTransition* trans);
LIBCMO_EXPORT void BMMeshTrans_PrepareVertexCount(BMap::BMMeshTransition* trans, LibCmo::CKDWORD count);
LIBCMO_EXPORT LibCmo::VxMath::VxVector3* BMMeshTrans_PrepareVertex(BMap::BMMeshTransition* trans);
LIBCMO_EXPORT void BMMeshTrans_PrepareNormalCount(BMap::BMMeshTransition* trans, LibCmo::CKDWORD count);
LIBCMO_EXPORT LibCmo::VxMath::VxVector3* BMMeshTrans_PrepareNormal(BMap::BMMeshTransition* trans);
LIBCMO_EXPORT void BMMeshTrans_PrepareUVCount(BMap::BMMeshTransition* trans, LibCmo::CKDWORD count);
LIBCMO_EXPORT LibCmo::VxMath::VxVector2* BMMeshTrans_PrepareUV(BMap::BMMeshTransition* trans);
LIBCMO_EXPORT void BMMeshTrans_PrepareMtlSlotCount(BMap::BMMeshTransition* trans, LibCmo::CKDWORD count);
LIBCMO_EXPORT LibCmo::CK2::ObjImpls::CKMaterial** BMMeshTrans_PrepareMtlSlot(BMap::BMMeshTransition* trans);
LIBCMO_EXPORT void BMMeshTrans_PrepareFaceCount(BMap::BMMeshTransition* trans, LibCmo::CKDWORD count);
LIBCMO_EXPORT LibCmo::CKDWORD* BMMeshTrans_PrepareFaceVertexIndices(BMap::BMMeshTransition* trans);
LIBCMO_EXPORT LibCmo::CKDWORD* BMMeshTrans_PrepareFaceNormalIndices(BMap::BMMeshTransition* trans);
LIBCMO_EXPORT LibCmo::CKDWORD* BMMeshTrans_PrepareFaceUVIndices(BMap::BMMeshTransition* trans);
LIBCMO_EXPORT LibCmo::CKDWORD* BMMeshTrans_PrepareFaceMtlSlot(BMap::BMMeshTransition* trans);
LIBCMO_EXPORT bool BMMeshTrans_Parse(BMap::BMMeshTransition* trans, LibCmo::CK2::ObjImpls::CKMesh* write_into_mesh);
#pragma endregion #pragma endregion

View File

@ -230,6 +230,8 @@ namespace BMap {
cache.emplace_back(encodings[i]); cache.emplace_back(encodings[i]);
} }
m_Context->SetEncoding(cache); m_Context->SetEncoding(cache);
// set default texture save mode is external
m_Context->SetGlobalImagesSaveOptions(LibCmo::CK2::CK_TEXTURE_SAVEOPTIONS::CKTEXTURE_EXTERNAL);
} }
BMFile::~BMFile() { BMFile::~BMFile() {

View File

@ -262,7 +262,7 @@ namespace LibCmo::CK2 {
CKFileWriter::~CKFileWriter() {} CKFileWriter::~CKFileWriter() {}
bool LibCmo::CK2::CKFileWriter::InternalObjectAdder(ObjImpls::CKObject * obj, CKDWORD flags) { bool CKFileWriter::InternalObjectAdder(ObjImpls::CKObject * obj, CKDWORD flags) {
if (obj == nullptr) return false; if (obj == nullptr) return false;
// check whether is saved. // check whether is saved.