finish SSMaterializer plugin version refactor.

This commit is contained in:
yyc12345 2022-08-07 10:56:57 +08:00
parent 1de5483432
commit 5f715de4a9
13 changed files with 125 additions and 103 deletions

View File

@ -1,5 +1,4 @@
LIBRARY "SuperScriptMaterializer"
DESCRIPTION 'Fuck Virtools'
EXPORTS
GetVirtoolsPluginInfoCount

View File

@ -114,8 +114,9 @@
<ClInclude Include="doc_export.hpp" />
<ClInclude Include="string_helper.hpp" />
<ClInclude Include="virtools_compatible.hpp" />
<ClInclude Include="vt_menu.h" />
<ClInclude Include="vt_menu.hpp" />
<ClInclude Include="stdafx.h" />
<ClInclude Include="vt_player.hpp" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="database.cpp" />

View File

@ -30,7 +30,7 @@
<ClInclude Include="stdafx.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="vt_menu.h">
<ClInclude Include="vt_menu.hpp">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="virtools_compatible.hpp">
@ -39,6 +39,9 @@
<ClInclude Include="string_helper.hpp">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="vt_player.hpp">
<Filter>头文件</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="database.cpp">

View File

@ -84,14 +84,23 @@ namespace SSMaterializer {
// append new one
mStmtCache.push_back(stmt);
return stmt;
}
BOOL SSMaterializerDatabase::Init() {
return TRUE;
}
BOOL SSMaterializerDatabase::Finalize() {
return TRUE;
}
#pragma endregion
#pragma region sub-database constructor and deconstructor
#pragma region sub-database constructor, deconstructor and help functions
DocumentDatabase::DocumentDatabase(const char* file, CKParameterManager* paramManager) :
SSMaterializerDatabase(file), m_pAttrUniqueEnsurance(), mDbHelper(paramManager) {
SSMaterializerDatabase(file), mUniqueAttr(), mUniqueObj(), mDbHelper(paramManager) {
;
}
@ -108,6 +117,30 @@ namespace SSMaterializer {
;
}
BOOL DocumentDatabase::is_attr_duplicated(DataStruct::EXPAND_CK_ID parents) {
// check duplication
if (mUniqueAttr.find(parents) != mUniqueAttr.end()) {
//existing item. skip it to make sure unique
return TRUE;
} else {
//add this item
mUniqueAttr.insert(parents);
return FALSE;
}
}
BOOL DocumentDatabase::is_obj_duplicated(DataStruct::EXPAND_CK_ID parents) {
// check duplication
if (mUniqueObj.find(parents) != mUniqueObj.end()) {
//existing item. skip it to make sure unique
return TRUE;
} else {
//add this item
mUniqueObj.insert(parents);
return FALSE;
}
}
#pragma endregion
#pragma region table, index creation functions
@ -116,6 +149,9 @@ namespace SSMaterializer {
if (result != SQLITE_OK) { return FALSE; }
BOOL DocumentDatabase::Init() {
// execute parent first
if (!SSMaterializerDatabase::Init()) return FALSE;
int result;
//Init table
@ -149,6 +185,9 @@ if (result != SQLITE_OK) { return FALSE; }
}
BOOL DocumentDatabase::Finalize() {
// execute parent first
if (!SSMaterializerDatabase::Finalize()) return FALSE;
//create index for quick select in SuperScriptDecorator
int result;
@ -165,14 +204,16 @@ if (result != SQLITE_OK) { return FALSE; }
SafeSqlExec("CREATE INDEX [quick_where10] ON [script_bLink] ([parent])");
SafeSqlExec("CREATE INDEX [quick_where11] ON [script_elink] ([parent])");
SafeSqlExec("CREATE INDEX [quick_where12] ON [script_pAttr] ([thisobj])");
SafeSqlExec("CREATE INDEX [quick_where13] ON [array_cell] ([parent])");
SafeSqlExec("CREATE INDEX [quick_where14] ON [data] ([parent])");
SafeSqlExec("CREATE INDEX [quick_where13] ON [data] ([parent])");
SafeSqlExec("commit;");
return TRUE;
}
BOOL EnvironmentDatabase::Init() {
// execute parent first
if (!SSMaterializerDatabase::Init()) return FALSE;
int result;
//init table
@ -190,6 +231,9 @@ if (result != SQLITE_OK) { return FALSE; }
}
BOOL EnvironmentDatabase::Finalize() {
// execute parent first
if (!SSMaterializerDatabase::Finalize()) return FALSE;
return TRUE;
}
@ -393,18 +437,7 @@ if (stmt == NULL) { \
sqlite3_step(stmt);
}
void DocumentDatabase::write_script_pAttr(DataStruct::dbdoc_script_pAttr& data, BOOL* already_exist) {
// check duplication first
if (m_pAttrUniqueEnsurance.find(data.thisobj) != m_pAttrUniqueEnsurance.end()) {
//existing item. skip it to make sure unique
*already_exist = TRUE;
return;
} else {
//add this item
m_pAttrUniqueEnsurance.insert(data.thisobj);
*already_exist = FALSE;
}
void DocumentDatabase::write_script_pAttr(DataStruct::dbdoc_script_pAttr& data) {
// then check database validation
if (mDb == NULL) return;

View File

@ -311,8 +311,8 @@ namespace SSMaterializer {
protected:
sqlite3_stmt* CreateStmt(const char* stmt);
virtual BOOL Init() = 0;
virtual BOOL Finalize() = 0;
virtual BOOL Init();
virtual BOOL Finalize();
sqlite3* mDb;
std::vector<sqlite3_stmt*> mStmtCache;
@ -336,7 +336,7 @@ namespace SSMaterializer {
void write_script_pLink(DataStruct::dbdoc_script_pLink& data);
void write_script_pOper(DataStruct::dbdoc_script_pOper& data);
void write_script_eLink(DataStruct::dbdoc_script_eLink& data);
void write_script_pAttr(DataStruct::dbdoc_script_pAttr& data, BOOL* already_exist);
void write_script_pAttr(DataStruct::dbdoc_script_pAttr& data);
void write_msg(DataStruct::dbdoc_msg& data);
@ -346,11 +346,15 @@ namespace SSMaterializer {
void write_data(DataStruct::dbdoc_data& data);
BOOL is_attr_duplicated(DataStruct::EXPAND_CK_ID parents);
BOOL is_obj_duplicated(DataStruct::EXPAND_CK_ID parents);
protected:
BOOL Init() override;
BOOL Finalize() override;
std::set<DataStruct::EXPAND_CK_ID> m_pAttrUniqueEnsurance;
std::set<DataStruct::EXPAND_CK_ID> mUniqueAttr;
std::set<DataStruct::EXPAND_CK_ID> mUniqueObj;
};
class EnvironmentDatabase : public SSMaterializerDatabase {

View File

@ -337,21 +337,23 @@ namespace SSMaterializer {
* we need check possible duplication here.
*/
void Proc_pAttr(CKContext* ctx, Database::DocumentDatabase* mDb, CKParameter* cache) {
// check duplication
if (mDb->is_attr_duplicated(cache->GetID())) return;
// write self first to detect conflict
mDb->mDbHelper.script_pAttr.thisobj = cache->GetID();
CopyCKString(mDb->mDbHelper.script_pAttr.name, cache->GetName());
CopyCKParamTypeStr(mDb->mDbHelper.script_pAttr.type, cache->GetType(), mDb->mDbHelper.param_manager);
CopyGuid(mDb->mDbHelper.script_pAttr.type_guid, cache->GetGUID());
BOOL already_exist = FALSE;
mDb->write_script_pAttr(mDb->mDbHelper.script_pAttr, &already_exist);
if (!already_exist) {
// not duplicated, continue write some properties to indicate the host of this attribute
CKObject* host = cache->GetOwner();
DataDictWritter("attr.host_id", (long)host->GetID(), mDb, cache->GetID());
DataDictWritter("attr.host_name", host->GetName(), mDb, cache->GetID());
}
mDb->write_script_pAttr(mDb->mDbHelper.script_pAttr);
// continue write some properties to indicate the host of this attribute
CKObject* host = cache->GetOwner();
// write owner id
DataDictWritter("attr.owner", (long)host->GetID(), mDb, cache->GetID());
// write data for owner
DigObjectData(host, mDb, host->GetID());
}
void Proc_Behavior(CKContext* ctx, CKBehavior* bhv, Database::DocumentDatabase* mDb, DataStruct::EXPAND_CK_ID parents) {
@ -507,7 +509,7 @@ namespace SSMaterializer {
mDb->mDbHelper.array_cell.row = row;
mDb->mDbHelper.array_cell.parent = parents;
Utils::StdstringPrintf(mDb->mDbHelper.array_cell.showcase, "%d", &((int*)cache->GetElement(row, col)));
Utils::StdstringPrintf(mDb->mDbHelper.array_cell.showcase, "%d", *((int*)cache->GetElement(row, col)));
mDb->mDbHelper.array_cell.inner_param = -1;
mDb->write_array_cell(mDb->mDbHelper.array_cell);
@ -519,7 +521,7 @@ namespace SSMaterializer {
mDb->mDbHelper.array_cell.row = row;
mDb->mDbHelper.array_cell.parent = parents;
Utils::StdstringPrintf(mDb->mDbHelper.array_cell.showcase, "%f", &((float*)cache->GetElement(row, col)));
Utils::StdstringPrintf(mDb->mDbHelper.array_cell.showcase, "%f", *((float*)cache->GetElement(row, col)));
mDb->mDbHelper.array_cell.inner_param = -1;
mDb->write_array_cell(mDb->mDbHelper.array_cell);
@ -585,13 +587,21 @@ namespace SSMaterializer {
#pragma region data process
void DigObjectData(CKObject* o, Database::DocumentDatabase* mDb, DataStruct::EXPAND_CK_ID parents) {
// check duplication
// we use `parents` not o->GetID() because in some call they are not equal.
if (mDb->is_obj_duplicated(parents)) return;
DataDictWritter("obj.id", (long)o->GetID(), mDb, parents);
DataDictWritter("obj.name", o->GetName() ? o->GetName() : "", mDb, parents);
DataDictWritter("obj.classid", (long)o->GetClassID(), mDb, parents);
DataDictWritter("obj.type", o->GetClassNameA(), mDb, parents);
}
void DigParameterData(CKParameter* p, Database::DocumentDatabase* mDb, DataStruct::EXPAND_CK_ID parents) {
// due to our algorithm, parameter can not be duplicated
// so we don't need to check its duplication.
CKGUID t = p->GetGUID();
CKParameterType pt = p->GetType();
BOOL unknowType = FALSE;
// export guid and type name corresponding with guid
static std::string str_guid;
@ -601,15 +611,13 @@ namespace SSMaterializer {
CopyCKParamTypeStr(str_typename, pt, mDb->mDbHelper.param_manager);
DataDictWritter("typename", str_typename.c_str(), mDb, parents);
if (!(t.d1 & t.d2)) unknowType = TRUE;
// value object
if (p->GetParameterClassID() && p->GetValueObject(false)) {
CKObject* vobj = p->GetValueObject(false);
DataDictWritter("vobj.id", (long)vobj->GetID(), mDb, parents);
DataDictWritter("vobj.name", vobj->GetName() ? vobj->GetName() : "", mDb, parents);
DataDictWritter("vobj.classid", (long)vobj->GetClassID(), mDb, parents);
DataDictWritter("vobj.type", vobj->GetClassNameA(), mDb, parents);
// write its id
DataDictWritter("vobj", (long)vobj->GetID(), mDb, parents);
// write more data for its id
DigObjectData(vobj, mDb, vobj->GetID());
return;
}
@ -656,7 +664,6 @@ namespace SSMaterializer {
}
if (t == CKPGUID_MATRIX) {
VxMatrix mat;
char position[128];
memcpy(&mat, p->GetReadDataPtr(false), sizeof(mat));
static std::string str_matrix;
@ -738,10 +745,9 @@ namespace SSMaterializer {
return;
}
unknowType = TRUE;
//if it gets here, we have no idea what it really is. so simply dump it.
//buffer-like
if (unknowType || t == CKPGUID_VOIDBUF
if (t == CKPGUID_VOIDBUF
#if defined(VIRTOOLS_50) || defined(VIRTOOLS_40) || defined(VIRTOOLS_35)
|| t == CKPGUID_SHADER || t == CKPGUID_TECHNIQUE || t == CKPGUID_PASS
#endif

View File

@ -1,6 +1,6 @@
#include "stdafx.h"
#include "vt_menu.h"
#include "vt_player.h"
#include "vt_menu.hpp"
#include "vt_player.hpp"
#if defined(VIRTOOLS_PLUGIN)
PluginInterface* s_Plugininterface = NULL;
@ -29,7 +29,7 @@ SuperScriptMaterializer theApp;
BOOL SuperScriptMaterializer::InitInstance() {
CWinApp::InitInstance();
strcpy(g_PluginInfo0.m_Name, "Super Script Materializer");
strcpy(g_PluginInfo0.m_Name, "SSMaterializer");
g_PluginInfo0.m_PluginType = PluginInfo::PT_EDITOR;
g_PluginInfo0.m_PluginType = (PluginInfo::PLUGIN_TYPE)(g_PluginInfo0.m_PluginType | PluginInfo::PTF_RECEIVENOTIFICATION);
g_PluginInfo0.m_PluginCallback = PluginCallback;

View File

@ -4,6 +4,8 @@
//
#pragma once
#define _WIN32_WINNT 0x0A00
#define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers
#include <afxwin.h> // MFC core and standard components

View File

@ -1,4 +1,4 @@
#include "virtools_compatible.h"
#include "virtools_compatible.hpp"
#if defined(VIRTOOLS_50) && defined(VIRTOOLS_STANDALONE)

View File

@ -1,7 +1,7 @@
#include "vt_menu.h"
#include "database.h"
#include "script_export.h"
#include "env_export.h"
#include "vt_menu.hpp"
#include "database.hpp"
#include "doc_export.hpp"
#include "env_export.hpp"
#if defined(VIRTOOLS_PLUGIN)
@ -34,7 +34,7 @@ void InitMenu() {
if (!s_Plugininterface)
return;
s_MainMenu = s_Plugininterface->AddPluginMenu("Super Script Materializer", 20, NULL, (VoidFunc1Param)PluginMenuCallback);
s_MainMenu = s_Plugininterface->AddPluginMenu("SSMaterializer", 20, NULL, (VoidFunc1Param)PluginMenuCallback);
}
void RemoveMenu() {
@ -47,23 +47,12 @@ void RemoveMenu() {
void UpdateMenu() {
s_Plugininterface->ClearPluginMenu(s_MainMenu); //clear menu
s_Plugininterface->AddPluginMenuItem(s_MainMenu, 0, "Export all scripts");
s_Plugininterface->AddPluginMenuItem(s_MainMenu, 0, "Export document");
s_Plugininterface->AddPluginMenuItem(s_MainMenu, 1, "Export environment");
s_Plugininterface->AddPluginMenuItem(s_MainMenu, -1, NULL, TRUE);
s_Plugininterface->AddPluginMenuItem(s_MainMenu, 2, "Report bug");
s_Plugininterface->AddPluginMenuItem(s_MainMenu, 3, "Plugin homepage");
//===========================freeze chirs241097 code for future expand
//s_Plugininterface->AddPluginMenuItem(s_MainMenu, -1, NULL, TRUE);
////note : sub menu must have independent command ids that must be >=0
//CMenu* sub0 = s_Plugininterface->AddPluginMenuItem(s_MainMenu, 0, "Fsck /dev/sdb", FALSE, TRUE);//bb manipulation
//s_Plugininterface->AddPluginMenuItem(sub0, 1, "Fsck /dev/sdb1");//modify bb proto
//s_Plugininterface->AddPluginMenuItem(sub0, 2, "Fsck /dev/sdb2");//not implemented
//s_Plugininterface->AddPluginMenuItem(s_MainMenu, -1, NULL, TRUE);
//s_Plugininterface->AddPluginMenuItem(s_MainMenu, 10, "Exit Fsck");
s_Plugininterface->UpdatePluginMenu(s_MainMenu); //update menu,always needed when you finished to update the menu
//unless you want the menu not to have Virtools Dev main menu color scheme.
@ -88,21 +77,18 @@ void PluginMenuCallback(int commandID) {
DeleteFile(file.c_str());
//Init resources
DocumentDatabase* _db = new DocumentDatabase();
dbDocDataStructHelper* _helper = new dbDocDataStructHelper();
_db->Open(file.c_str());
_helper->Init(ctx->GetParameterManager());
SSMaterializer::Database::DocumentDatabase* db =
new SSMaterializer::Database::DocumentDatabase(file.c_str(), ctx->GetParameterManager());
//iterate item
IterateScript(ctx, _db, _helper);
SSMaterializer::DocumentExporter::IterateScript(ctx, db);
SSMaterializer::DocumentExporter::IterateMessage(ctx, db);
SSMaterializer::DocumentExporter::IterateArray(ctx, db);
//Close all resources
_helper->dispose();
_db->Close();
delete _helper;
delete _db;
delete db;
ctx->OutputToConsole("[Super Script Materializer] Done");
ctx->OutputToConsole("[SSMaterializer] Done");
}
break;
case 1:
@ -115,28 +101,22 @@ void PluginMenuCallback(int commandID) {
DeleteFile(file.c_str());
//Init
EnvironmentDatabase* _db = new EnvironmentDatabase();
dbEnvDataStructHelper* _helper = new dbEnvDataStructHelper();
_db->Open(file.c_str());
_helper->Init();
SSMaterializer::Database::EnvironmentDatabase* db =
new SSMaterializer::Database::EnvironmentDatabase(file.c_str());
//iterate parameter operation/param
IterateParameterOperation(ctx->GetParameterManager(), _db, _helper);
IterateParameter(ctx->GetParameterManager(), _db, _helper);
IterateMessage(ctx->GetMessageManager(), _db, _helper);
IterateAttribute(ctx->GetAttributeManager(), _db, _helper);
IteratePlugin(CKGetPluginManager(), _db, _helper);
SSMaterializer::EnvironmentExporter::IterateParameterOperation(ctx->GetParameterManager(), db);
SSMaterializer::EnvironmentExporter::IterateParameter(ctx->GetParameterManager(), db);
SSMaterializer::EnvironmentExporter::IterateAttribute(ctx->GetAttributeManager(), db);
SSMaterializer::EnvironmentExporter::IteratePlugin(CKGetPluginManager(), db);
#if !defined(VIRTOOLS_21)
IterateVariable(ctx->GetVariableManager(), _db, _helper);
SSMaterializer::EnvironmentExporter::IterateVariable(ctx->GetVariableManager(), db);
#endif
//release all
_helper->dispose();
_db->Close();
delete _helper;
delete _db;
delete db;
ctx->OutputToConsole("[Super Script Materializer] Done");
ctx->OutputToConsole("[SSMaterializer] Done");
}
break;
case 2:

View File

@ -1,9 +1,8 @@
#if !defined(_YYCDLL_VT_MENU_H__IMPORTED_)
#define _YYCDLL_VT_MENU_H__IMPORTED_
#pragma once
#if defined(VIRTOOLS_PLUGIN)
#include "stdafx.h"
#include "database.h"
#include "database.hpp"
void PluginCallback(PluginInfo::CALLBACK_REASON reason, PluginInterface* plugininterface);
@ -14,5 +13,3 @@ void PluginMenuCallback(int commandID);
BOOL OpenFileDialog(std::string* returned_file);
#endif
#endif

View File

@ -1,6 +1,6 @@
#include "vt_player.h"
#include "script_export.h"
#include "env_export.h"
#include "vt_player.hpp"
#include "doc_export.hpp"
#include "env_export.hpp"
#if defined(VIRTOOLS_STANDALONE)

View File

@ -1,13 +1,10 @@
#if !defined(_YYCDLL_VT_PLAYER_H__IMPORTED_)
#define _YYCDLL_VT_PLAYER_H__IMPORTED_
#pragma once
#if defined(VIRTOOLS_STANDALONE)
#include "stdafx.h"
#include "database.h"
#include "database.hpp"
void PlayerMain(const char* virtools_composition, const char* script_db_path, const char* env_db_path);
void CommonAssert(BOOL condition, const char* desc);
#endif
#endif