refactor: update environment database struct

This commit is contained in:
2024-08-05 14:23:26 +08:00
parent d4a5e83a87
commit 78d5e74c6f
4 changed files with 119 additions and 17 deletions

View File

@@ -235,21 +235,35 @@ namespace VSW::Materializer::DataTypes {
}; };
struct Table_plugin { struct Table_plugin {
int dll_index; // Category
std::string dll_name;
int plugin_index;
std::string category; std::string category;
CKBOOL active; // Dll infos
std::string dll_name;
int position_in_dll;
// Plugin infos
int64_t guid; int64_t guid;
std::string desc; std::string desc;
std::string author; std::string author;
std::string summary; std::string summary;
DWORD version; DWORD version;
CK_PLUGIN_TYPE type;
std::string func_init; std::string func_init;
std::string func_exit; std::string func_exit;
// Reader specific
std::string reader_fct;
int reader_opt_count;
CK_DATAREADER_FLAGS reader_flags;
int64_t reader_setting_param_guid;
std::string reader_file_ext;
// Manager and Render Engine specific
CKBOOL manager_active;
// Behavior specific
std::string behavior_guids;
}; };
#if defined(VIRTOOLS_21) #if defined(VIRTOOLS_21)
// Virtools 2.1 doesn't have Variable Manager
// We use a normal type as a placeholder.
using GenericVarType_t = int; using GenericVarType_t = int;
#else #else
using GenericVarType_t = CKVariableManager::Variable::Type; using GenericVarType_t = CKVariableManager::Variable::Type;

View File

@@ -102,6 +102,9 @@ namespace VSW::Materializer::ExportEnvironment {
} }
static void IteratePlugin(ExportContext& expctx, CKPluginManager* plugin_mgr) { static void IteratePlugin(ExportContext& expctx, CKPluginManager* plugin_mgr) {
// prepare variables
CK_PLUGIN_TYPE plugin_type;
// get category count and iterate them // get category count and iterate them
int category_count = plugin_mgr->GetCategoryCount(); int category_count = plugin_mgr->GetCategoryCount();
for (int i = 0; i < category_count; ++i) { for (int i = 0; i < category_count; ++i) {
@@ -115,21 +118,65 @@ namespace VSW::Materializer::ExportEnvironment {
CKPluginInfo* plugin_info = &(plugin_entry->m_PluginInfo); CKPluginInfo* plugin_info = &(plugin_entry->m_PluginInfo);
CKPluginDll* plugin_dll = plugin_mgr->GetPluginDllInfo(plugin_entry->m_PluginDllIndex); CKPluginDll* plugin_dll = plugin_mgr->GetPluginDllInfo(plugin_entry->m_PluginDllIndex);
expctx.cache.plugin.dll_index = plugin_entry->m_PluginDllIndex; // dll infomation (name + position in dll)
expctx.cache.plugin.dll_name = plugin_dll->m_DllFileName.CStr(); expctx.cache.plugin.dll_name = plugin_dll->m_DllFileName.CStr();
expctx.cache.plugin.position_in_dll = plugin_entry->m_PositionInDll;
expctx.cache.plugin.plugin_index = plugin_entry->m_PositionInDll; // plugin info
expctx.cache.plugin.active = plugin_entry->m_Active;
Utilities::CopyGuid(expctx.cache.plugin.guid, plugin_info->m_GUID); Utilities::CopyGuid(expctx.cache.plugin.guid, plugin_info->m_GUID);
expctx.cache.plugin.desc = plugin_info->m_Description.CStr(); expctx.cache.plugin.desc = plugin_info->m_Description.CStr();
expctx.cache.plugin.author = plugin_info->m_Author.CStr(); expctx.cache.plugin.author = plugin_info->m_Author.CStr();
expctx.cache.plugin.summary = plugin_info->m_Summary.CStr(); expctx.cache.plugin.summary = plugin_info->m_Summary.CStr();
expctx.cache.plugin.version = plugin_info->m_Version; expctx.cache.plugin.version = plugin_info->m_Version;
plugin_type = plugin_info->m_Type;
expctx.cache.plugin.type = plugin_type;
expctx.cache.plugin.func_init = Utilities::RelativeAddress(plugin_info->m_InitInstanceFct); expctx.cache.plugin.func_init = Utilities::RelativeAddress(plugin_info->m_InitInstanceFct);
expctx.cache.plugin.func_exit = Utilities::RelativeAddress(plugin_info->m_ExitInstanceFct); expctx.cache.plugin.func_exit = Utilities::RelativeAddress(plugin_info->m_ExitInstanceFct);
// extra fields according to plugin type
// first reset these specific fields
expctx.cache.plugin.reader_fct.clear();
// then try to fetch these specific fields
switch (plugin_type) {
case CKPLUGIN_BITMAP_READER:
case CKPLUGIN_SOUND_READER:
case CKPLUGIN_MODEL_READER:
case CKPLUGIN_MOVIE_READER:
{
// Reader specific
expctx.cache.plugin.reader_fct = Utilities::RelativeAddress(plugin_entry->m_ReadersInfo->m_GetReaderFct);
expctx.cache.plugin.reader_opt_count = plugin_entry->m_ReadersInfo->m_OptionCount;
expctx.cache.plugin.reader_flags = plugin_entry->m_ReadersInfo->m_ReaderFlags;
Utilities::CopyGuid(expctx.cache.plugin.reader_setting_param_guid, plugin_entry->m_ReadersInfo->m_SettingsParameterGuid);
expctx.cache.plugin.reader_file_ext = static_cast<const char*>(plugin_info->m_Extension);
break;
}
case CKPLUGIN_BEHAVIOR_DLL:
{
// Behavior specific
std::vector<YYCC::yycc_u8string> guids;
for (int i = 0; i < plugin_entry->m_BehaviorsInfo->m_BehaviorsGUID.Size(); ++i) {
int64_t guid_cache;
Utilities::CopyGuid(guid_cache, plugin_entry->m_BehaviorsInfo->m_BehaviorsGUID[i]);
guids.emplace_back(YYCC::ParserHelper::ToString(guid_cache));
}
expctx.cache.plugin.behavior_guids = YYCC::EncodingHelper::ToOrdinaryView(
YYCC::StringHelper::Join(guids, YYCC_U8(", "))
);
break;
}
case CKPLUGIN_MANAGER_DLL:
case CKPLUGIN_RENDERENGINE_DLL:
{
// Render engine and manager specific
// active info
expctx.cache.plugin.manager_active = plugin_entry->m_Active;
break;
}
}
expctx.db.Write(expctx.cache.plugin); expctx.db.Write(expctx.cache.plugin);
} }
} }
@@ -139,17 +186,50 @@ namespace VSW::Materializer::ExportEnvironment {
static void IterateVariable(ExportContext& expctx, CKVariableManager* var_mgr) { static void IterateVariable(ExportContext& expctx, CKVariableManager* var_mgr) {
// prepare variables // prepare variables
CKVariableManager::Variable* varobj = nullptr; CKVariableManager::Variable* varobj = nullptr;
const char* var_name;
CKVariableManager::Variable::Type var_type;
const char* var_representation;
int int_cache;
float float_cache;
XString xstring_cache; XString xstring_cache;
for (CKVariableManager::Iterator it = var_mgr->GetVariableIterator(); !it.End(); it++) { for (CKVariableManager::Iterator it = var_mgr->GetVariableIterator(); !it.End(); it++) {
// get variable
varobj = it.GetVariable(); varobj = it.GetVariable();
expctx.cache.variable.name = it.GetName(); // variable name
var_name = it.GetName();
expctx.cache.variable.name = var_name;
// variable description
Utilities::CopyCKString(expctx.cache.variable.desciption, varobj->GetDescription()); Utilities::CopyCKString(expctx.cache.variable.desciption, varobj->GetDescription());
// variable flags
expctx.cache.variable.flags = varobj->GetFlags(); expctx.cache.variable.flags = varobj->GetFlags();
expctx.cache.variable.type = varobj->GetType(); // variable type
Utilities::CopyCKString(expctx.cache.variable.representation, varobj->GetRepresentation()); var_type = varobj->GetType();
varobj->GetStringValue(xstring_cache); expctx.cache.variable.type = var_type;
// variable representation
// Representation need a special treatment.
// Because it is not a name.
// So we should record it as empty string if it is nullptr, instead of default <unamed>
var_representation = varobj->GetRepresentation();
Utilities::CopyCKString(expctx.cache.variable.representation, var_representation, "");
// We output variable stored value in different way
// according to its type.
switch (var_type) {
case CKVariableManager::Variable::Type::INT:
var_mgr->GetValue(var_name, &int_cache);
expctx.cache.variable.data = YYCC::EncodingHelper::ToOrdinaryView(YYCC::ParserHelper::ToString(int_cache));
break;
case CKVariableManager::Variable::Type::FLOAT:
var_mgr->GetValue(var_name, &float_cache);
expctx.cache.variable.data = YYCC::EncodingHelper::ToOrdinaryView(YYCC::ParserHelper::ToString(float_cache));
break;
case CKVariableManager::Variable::Type::STRING:
var_mgr->GetValue(var_name, xstring_cache);
expctx.cache.variable.data = xstring_cache.CStr(); expctx.cache.variable.data = xstring_cache.CStr();
break;
default:
throw std::runtime_error("invalid variable type!");
}
expctx.db.Write(expctx.cache.variable); expctx.db.Write(expctx.cache.variable);
} }

View File

@@ -41,6 +41,11 @@ namespace VSW::Materializer::Utilities {
return ret; return ret;
} }
//void CopyStrGuid(std::string& dst, const CKGUID& src) {
// auto ret = YYCC::StringHelper::Printf(YYCC_U8("<0x%08" PRIX32 ", 0x%08" PRIX32 ">"), src.d1, src.d2);
// dst = YYCC::EncodingHelper::ToOrdinaryView(ret);
//}
void CopyGuid(int64_t& dst, const CKGUID& src) { void CopyGuid(int64_t& dst, const CKGUID& src) {
// todo: use template argument to implement this to improve performance // todo: use template argument to implement this to improve performance
if (sizeof(dst) != sizeof(src)) if (sizeof(dst) != sizeof(src))
@@ -48,8 +53,10 @@ namespace VSW::Materializer::Utilities {
std::memcpy(&dst, &src, sizeof(int64_t)); std::memcpy(&dst, &src, sizeof(int64_t));
} }
void CopyCKString(std::string& storage, const char* str) { void CopyCKString(std::string& storage, const char* str, const char* fallback) {
if (str == nullptr) storage = "<unamed>"; if (fallback == nullptr)
throw std::invalid_argument("fallback string should not be nullptr!");
if (str == nullptr) storage = fallback;
else storage = str; else storage = str;
} }

View File

@@ -26,7 +26,8 @@ namespace VSW::Materializer::Utilities {
* @return Module based relative address like \c xxx.dll+0x00000000. * @return Module based relative address like \c xxx.dll+0x00000000.
*/ */
std::string RelativeAddress(const void* absolute_addr); std::string RelativeAddress(const void* absolute_addr);
//void CopyStrGuid(std::string& dst, const CKGUID& src);
void CopyGuid(int64_t& dst, const CKGUID& src); void CopyGuid(int64_t& dst, const CKGUID& src);
void CopyCKString(std::string& storage, const char* str); void CopyCKString(std::string& storage, const char* str, const char* fallback = "<unamed>");
} }