refactor doc_export.cpp (1/3)

This commit is contained in:
yyc12345 2022-08-02 21:19:11 +08:00
parent 1a4b5ed55f
commit 59c16b2763
11 changed files with 1483 additions and 1403 deletions

View File

@ -108,11 +108,11 @@
</Link> </Link>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="database.h" /> <ClInclude Include="database.hpp" />
<ClInclude Include="data_export.h" /> <ClInclude Include="data_export.h" />
<ClInclude Include="env_export.h" /> <ClInclude Include="env_export.h" />
<ClInclude Include="resource.h" /> <ClInclude Include="resource.h" />
<ClInclude Include="script_export.h" /> <ClInclude Include="doc_export.hpp" />
<ClInclude Include="shared_export.h" /> <ClInclude Include="shared_export.h" />
<ClInclude Include="string_helper.hpp" /> <ClInclude Include="string_helper.hpp" />
<ClInclude Include="virtools_compatible.h" /> <ClInclude Include="virtools_compatible.h" />
@ -124,7 +124,7 @@
<ClCompile Include="data_export.cpp" /> <ClCompile Include="data_export.cpp" />
<ClCompile Include="env_export.cpp" /> <ClCompile Include="env_export.cpp" />
<ClCompile Include="main.cpp" /> <ClCompile Include="main.cpp" />
<ClCompile Include="script_export.cpp" /> <ClCompile Include="doc_export.cpp" />
<ClCompile Include="shared_export.cpp" /> <ClCompile Include="shared_export.cpp" />
<ClCompile Include="string_helper.cpp" /> <ClCompile Include="string_helper.cpp" />
<ClCompile Include="virtools_compatible.cpp" /> <ClCompile Include="virtools_compatible.cpp" />

View File

@ -15,7 +15,7 @@
</Filter> </Filter>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="database.h"> <ClInclude Include="database.hpp">
<Filter>头文件</Filter> <Filter>头文件</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="env_export.h"> <ClInclude Include="env_export.h">
@ -24,7 +24,7 @@
<ClInclude Include="resource.h"> <ClInclude Include="resource.h">
<Filter>头文件</Filter> <Filter>头文件</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="script_export.h"> <ClInclude Include="doc_export.hpp">
<Filter>头文件</Filter> <Filter>头文件</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="stdafx.h"> <ClInclude Include="stdafx.h">
@ -56,7 +56,7 @@
<ClCompile Include="main.cpp"> <ClCompile Include="main.cpp">
<Filter>源文件</Filter> <Filter>源文件</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="script_export.cpp"> <ClCompile Include="doc_export.cpp">
<Filter>源文件</Filter> <Filter>源文件</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="vt_menu.cpp"> <ClCompile Include="vt_menu.cpp">

View File

@ -1,8 +1,11 @@
#include "database.h" #include "database.hpp"
#pragma region data struct helper namespace SSMaterializer {
DbDataStructHelper_Doc::DbDataStructHelper_Doc(CKParameterManager* paramManager) : namespace DataStruct {
namespace Helper {
DocumentHelper::DocumentHelper(CKParameterManager* paramManager) :
script(), script_behavior(), script_pOper(), script(), script_behavior(), script_pOper(),
script_bIn(), script_bOut(), script_bLink(), script_bIn(), script_bOut(), script_bLink(),
script_pIn(), script_pOut(), script_pLink(), script_eLink(), script_pIn(), script_pOut(), script_pLink(), script_eLink(),
@ -11,26 +14,29 @@ DbDataStructHelper_Doc::DbDataStructHelper_Doc(CKParameterManager* paramManager)
_array(), array_header(), array_cell(), _array(), array_header(), array_cell(),
data() { data() {
param_manager = paramManager; param_manager = paramManager;
} }
DbDataStructHelper_Doc::~DbDataStructHelper_Doc() { DocumentHelper::~DocumentHelper() {
; ;
} }
DbDataStructHelper_Env::DbDataStructHelper_Env() : EnvironmentHelper::EnvironmentHelper() :
op(), param(), attr(), plugin(), variable() { op(), param(), attr(), plugin(), variable() {
; ;
} }
DbDataStructHelper_Env::~DbDataStructHelper_Env() { EnvironmentHelper::~EnvironmentHelper() {
; ;
} }
#pragma endregion }
}
namespace Database {
#pragma region universal sqlite database init and free #pragma region universal sqlite database init and free
SSMaterializerDatabase::SSMaterializerDatabase(const char* file) : SSMaterializerDatabase::SSMaterializerDatabase(const char* file) :
mStmtCache(), mDb(NULL) { mStmtCache(), mDb(NULL) {
// open mDb // open mDb
int result; int result;
@ -48,11 +54,11 @@ SSMaterializerDatabase::SSMaterializerDatabase(const char* file) :
sqlite3_exec(mDb, "begin;", NULL, NULL, NULL); sqlite3_exec(mDb, "begin;", NULL, NULL, NULL);
return; return;
fail: fail:
mDb = NULL; mDb = NULL;
} }
SSMaterializerDatabase::~SSMaterializerDatabase() { SSMaterializerDatabase::~SSMaterializerDatabase() {
if (mDb == NULL) return; if (mDb == NULL) return;
//free all cached stmts and commit job //free all cached stmts and commit job
@ -68,9 +74,9 @@ SSMaterializerDatabase::~SSMaterializerDatabase() {
//release res //release res
sqlite3_close(mDb); sqlite3_close(mDb);
mDb = NULL; mDb = NULL;
} }
sqlite3_stmt* SSMaterializerDatabase::CreateStmt(const char* str_stmt) { sqlite3_stmt* SSMaterializerDatabase::CreateStmt(const char* str_stmt) {
int result; int result;
sqlite3_stmt* stmt = NULL; sqlite3_stmt* stmt = NULL;
result = sqlite3_prepare_v2(mDb, str_stmt, -1, &stmt, NULL); result = sqlite3_prepare_v2(mDb, str_stmt, -1, &stmt, NULL);
@ -78,29 +84,29 @@ sqlite3_stmt* SSMaterializerDatabase::CreateStmt(const char* str_stmt) {
// append new one // append new one
mStmtCache.push_back(stmt); mStmtCache.push_back(stmt);
} }
#pragma endregion #pragma endregion
#pragma region sub-database constructor and deconstructor #pragma region sub-database constructor and deconstructor
DocumentDatabase::DocumentDatabase(const char* file) : DocumentDatabase::DocumentDatabase(const char* file, CKParameterManager* paramManager) :
SSMaterializerDatabase(file), m_pAttrUniqueEnsurance() { SSMaterializerDatabase(file), m_pAttrUniqueEnsurance(), mDbHelper(paramManager) {
; ;
} }
DocumentDatabase::~DocumentDatabase() { DocumentDatabase::~DocumentDatabase() {
; ;
} }
EnvironmentDatabase::EnvironmentDatabase(const char* file) : EnvironmentDatabase::EnvironmentDatabase(const char* file) :
SSMaterializerDatabase(file) { SSMaterializerDatabase(file), mDbHelper() {
; ;
} }
EnvironmentDatabase::~EnvironmentDatabase() { EnvironmentDatabase::~EnvironmentDatabase() {
; ;
} }
#pragma endregion #pragma endregion
@ -109,7 +115,7 @@ EnvironmentDatabase::~EnvironmentDatabase() {
#define SafeSqlExec(sql) result = sqlite3_exec(mDb, sql, NULL, NULL, NULL); \ #define SafeSqlExec(sql) result = sqlite3_exec(mDb, sql, NULL, NULL, NULL); \
if (result != SQLITE_OK) { return FALSE; } if (result != SQLITE_OK) { return FALSE; }
BOOL DocumentDatabase::Init() { BOOL DocumentDatabase::Init() {
int result; int result;
//Init table //Init table
@ -140,9 +146,9 @@ BOOL DocumentDatabase::Init() {
SafeSqlExec("commit;"); SafeSqlExec("commit;");
return TRUE; return TRUE;
} }
BOOL DocumentDatabase::Finalize() { BOOL DocumentDatabase::Finalize() {
//create index for quick select in SuperScriptDecorator //create index for quick select in SuperScriptDecorator
int result; int result;
@ -164,9 +170,9 @@ BOOL DocumentDatabase::Finalize() {
SafeSqlExec("commit;"); SafeSqlExec("commit;");
return TRUE; return TRUE;
} }
BOOL EnvironmentDatabase::Init() { BOOL EnvironmentDatabase::Init() {
int result; int result;
//init table //init table
@ -181,11 +187,11 @@ BOOL EnvironmentDatabase::Init() {
SafeSqlExec("commit;"); SafeSqlExec("commit;");
return TRUE; return TRUE;
} }
BOOL EnvironmentDatabase::Finalize() { BOOL EnvironmentDatabase::Finalize() {
return TRUE; return TRUE;
} }
#undef SafeSqlExec #undef SafeSqlExec
@ -199,7 +205,7 @@ if (stmt == NULL) { \
#pragma region document database #pragma region document database
void DocumentDatabase::write_script(dbdoc_script& data) { void DocumentDatabase::write_script(DataStruct::dbdoc_script& data) {
if (mDb == NULL) return; if (mDb == NULL) return;
TryGetStmtCache("INSERT INTO [script] VALUES (?, ?, ?, ?)"); TryGetStmtCache("INSERT INTO [script] VALUES (?, ?, ?, ?)");
@ -210,9 +216,9 @@ void DocumentDatabase::write_script(dbdoc_script& data) {
sqlite3_bind_int(stmt, 3, data.index); sqlite3_bind_int(stmt, 3, data.index);
sqlite3_bind_int(stmt, 4, data.behavior); sqlite3_bind_int(stmt, 4, data.behavior);
sqlite3_step(stmt); sqlite3_step(stmt);
} }
void DocumentDatabase::write_script_behavior(dbdoc_script_behavior& data) { void DocumentDatabase::write_script_behavior(DataStruct::dbdoc_script_behavior& data) {
if (mDb == NULL) return; if (mDb == NULL) return;
TryGetStmtCache("INSERT INTO [script_behavior] VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); TryGetStmtCache("INSERT INTO [script_behavior] VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
@ -229,10 +235,10 @@ void DocumentDatabase::write_script_behavior(dbdoc_script_behavior& data) {
sqlite3_bind_text(stmt, 9, data.pin_count.c_str(), -1, SQLITE_TRANSIENT); sqlite3_bind_text(stmt, 9, data.pin_count.c_str(), -1, SQLITE_TRANSIENT);
sqlite3_bind_int(stmt, 10, data.parent); sqlite3_bind_int(stmt, 10, data.parent);
sqlite3_step(stmt); sqlite3_step(stmt);
} }
void DocumentDatabase::write_script_pTarget(dbdoc_script_pTarget& data) { void DocumentDatabase::write_script_pTarget(DataStruct::dbdoc_script_pTarget& data) {
if (mDb == NULL) return; if (mDb == NULL) return;
TryGetStmtCache("INSERT INTO [script_pTarget] VALUES (?, ?, ?, ?, ?, ?, ?)"); TryGetStmtCache("INSERT INTO [script_pTarget] VALUES (?, ?, ?, ?, ?, ?, ?)");
@ -246,9 +252,9 @@ void DocumentDatabase::write_script_pTarget(dbdoc_script_pTarget& data) {
sqlite3_bind_int(stmt, 6, data.direct_source); sqlite3_bind_int(stmt, 6, data.direct_source);
sqlite3_bind_int(stmt, 7, data.shared_source); sqlite3_bind_int(stmt, 7, data.shared_source);
sqlite3_step(stmt); sqlite3_step(stmt);
} }
void DocumentDatabase::write_script_pIn(dbdoc_script_pIn& data) { void DocumentDatabase::write_script_pIn(DataStruct::dbdoc_script_pIn& data) {
if (mDb == NULL) return; if (mDb == NULL) return;
TryGetStmtCache("INSERT INTO [script_pIn] VALUES (?, ?, ?, ?, ?, ?, ?, ?)"); TryGetStmtCache("INSERT INTO [script_pIn] VALUES (?, ?, ?, ?, ?, ?, ?, ?)");
@ -263,9 +269,9 @@ void DocumentDatabase::write_script_pIn(dbdoc_script_pIn& data) {
sqlite3_bind_int(stmt, 7, data.direct_source); sqlite3_bind_int(stmt, 7, data.direct_source);
sqlite3_bind_int(stmt, 8, data.shared_source); sqlite3_bind_int(stmt, 8, data.shared_source);
sqlite3_step(stmt); sqlite3_step(stmt);
} }
void DocumentDatabase::write_script_pOut(dbdoc_script_pOut& data) { void DocumentDatabase::write_script_pOut(DataStruct::dbdoc_script_pOut& data) {
if (mDb == NULL) return; if (mDb == NULL) return;
TryGetStmtCache("INSERT INTO [script_pOut] VALUES (?, ?, ?, ?, ?, ?)"); TryGetStmtCache("INSERT INTO [script_pOut] VALUES (?, ?, ?, ?, ?, ?)");
@ -278,9 +284,9 @@ void DocumentDatabase::write_script_pOut(dbdoc_script_pOut& data) {
sqlite3_bind_text(stmt, 5, data.type_guid.c_str(), -1, SQLITE_TRANSIENT); sqlite3_bind_text(stmt, 5, data.type_guid.c_str(), -1, SQLITE_TRANSIENT);
sqlite3_bind_int(stmt, 6, data.parent); sqlite3_bind_int(stmt, 6, data.parent);
sqlite3_step(stmt); sqlite3_step(stmt);
} }
void DocumentDatabase::write_script_bIn(dbdoc_script_bIn& data) { void DocumentDatabase::write_script_bIn(DataStruct::dbdoc_script_bIn& data) {
if (mDb == NULL) return; if (mDb == NULL) return;
TryGetStmtCache("INSERT INTO [script_bIn] VALUES (?, ?, ?, ?)"); TryGetStmtCache("INSERT INTO [script_bIn] VALUES (?, ?, ?, ?)");
@ -291,9 +297,9 @@ void DocumentDatabase::write_script_bIn(dbdoc_script_bIn& data) {
sqlite3_bind_text(stmt, 3, data.name.c_str(), -1, SQLITE_TRANSIENT); sqlite3_bind_text(stmt, 3, data.name.c_str(), -1, SQLITE_TRANSIENT);
sqlite3_bind_int(stmt, 4, data.parent); sqlite3_bind_int(stmt, 4, data.parent);
sqlite3_step(stmt); sqlite3_step(stmt);
} }
void DocumentDatabase::write_script_bOut(dbdoc_script_bOut& data) { void DocumentDatabase::write_script_bOut(DataStruct::dbdoc_script_bOut& data) {
if (mDb == NULL) return; if (mDb == NULL) return;
TryGetStmtCache("INSERT INTO [script_bOut] VALUES (?, ?, ?, ?)"); TryGetStmtCache("INSERT INTO [script_bOut] VALUES (?, ?, ?, ?)");
@ -304,9 +310,9 @@ void DocumentDatabase::write_script_bOut(dbdoc_script_bOut& data) {
sqlite3_bind_text(stmt, 3, data.name.c_str(), -1, SQLITE_TRANSIENT); sqlite3_bind_text(stmt, 3, data.name.c_str(), -1, SQLITE_TRANSIENT);
sqlite3_bind_int(stmt, 4, data.parent); sqlite3_bind_int(stmt, 4, data.parent);
sqlite3_step(stmt); sqlite3_step(stmt);
} }
void DocumentDatabase::write_script_bLink(dbdoc_script_bLink& data) { void DocumentDatabase::write_script_bLink(DataStruct::dbdoc_script_bLink& data) {
if (mDb == NULL) return; if (mDb == NULL) return;
TryGetStmtCache("INSERT INTO [script_bLink] VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); TryGetStmtCache("INSERT INTO [script_bLink] VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
@ -323,9 +329,9 @@ void DocumentDatabase::write_script_bLink(dbdoc_script_bLink& data) {
sqlite3_bind_int(stmt, 9, data.output_index); sqlite3_bind_int(stmt, 9, data.output_index);
sqlite3_bind_int(stmt, 10, data.parent); sqlite3_bind_int(stmt, 10, data.parent);
sqlite3_step(stmt); sqlite3_step(stmt);
} }
void DocumentDatabase::write_script_pLocal(dbdoc_script_pLocal& data) { void DocumentDatabase::write_script_pLocal(DataStruct::dbdoc_script_pLocal& data) {
if (mDb == NULL) return; if (mDb == NULL) return;
TryGetStmtCache("INSERT INTO [script_pLocal] VALUES (?, ?, ?, ?, ?, ?)"); TryGetStmtCache("INSERT INTO [script_pLocal] VALUES (?, ?, ?, ?, ?, ?)");
@ -338,9 +344,9 @@ void DocumentDatabase::write_script_pLocal(dbdoc_script_pLocal& data) {
sqlite3_bind_int(stmt, 5, data.is_setting); sqlite3_bind_int(stmt, 5, data.is_setting);
sqlite3_bind_int(stmt, 6, data.parent); sqlite3_bind_int(stmt, 6, data.parent);
sqlite3_step(stmt); sqlite3_step(stmt);
} }
void DocumentDatabase::write_script_pLink(dbdoc_script_pLink& data) { void DocumentDatabase::write_script_pLink(DataStruct::dbdoc_script_pLink& data) {
if (mDb == NULL) return; if (mDb == NULL) return;
TryGetStmtCache("INSERT INTO [script_pLink] VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); TryGetStmtCache("INSERT INTO [script_pLink] VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
@ -358,9 +364,9 @@ void DocumentDatabase::write_script_pLink(dbdoc_script_pLink& data) {
sqlite3_bind_int(stmt, 10, data.output_index); sqlite3_bind_int(stmt, 10, data.output_index);
sqlite3_bind_int(stmt, 11, data.parent); sqlite3_bind_int(stmt, 11, data.parent);
sqlite3_step(stmt); sqlite3_step(stmt);
} }
void DocumentDatabase::write_script_pOper(dbdoc_script_pOper& data) { void DocumentDatabase::write_script_pOper(DataStruct::dbdoc_script_pOper& data) {
if (mDb == NULL) return; if (mDb == NULL) return;
TryGetStmtCache("INSERT INTO [script_pOper] VALUES (?, ?, ?, ?)"); TryGetStmtCache("INSERT INTO [script_pOper] VALUES (?, ?, ?, ?)");
@ -371,9 +377,9 @@ void DocumentDatabase::write_script_pOper(dbdoc_script_pOper& data) {
sqlite3_bind_text(stmt, 3, data.op_guid.c_str(), -1, SQLITE_TRANSIENT); sqlite3_bind_text(stmt, 3, data.op_guid.c_str(), -1, SQLITE_TRANSIENT);
sqlite3_bind_int(stmt, 4, data.parent); sqlite3_bind_int(stmt, 4, data.parent);
sqlite3_step(stmt); sqlite3_step(stmt);
} }
void DocumentDatabase::write_script_eLink(dbdoc_script_eLink& data) { void DocumentDatabase::write_script_eLink(DataStruct::dbdoc_script_eLink& data) {
if (mDb == NULL) return; if (mDb == NULL) return;
TryGetStmtCache("INSERT INTO [script_eLink] VALUES (?, ?, ?, ?, ?)"); TryGetStmtCache("INSERT INTO [script_eLink] VALUES (?, ?, ?, ?, ?)");
@ -385,9 +391,9 @@ void DocumentDatabase::write_script_eLink(dbdoc_script_eLink& data) {
sqlite3_bind_int(stmt, 4, data.index); sqlite3_bind_int(stmt, 4, data.index);
sqlite3_bind_int(stmt, 5, data.parent); sqlite3_bind_int(stmt, 5, data.parent);
sqlite3_step(stmt); sqlite3_step(stmt);
} }
void DocumentDatabase::write_script_pAttr(dbdoc_script_pAttr& data, BOOL* already_exist) { void DocumentDatabase::write_script_pAttr(DataStruct::dbdoc_script_pAttr& data, BOOL* already_exist) {
// check duplication first // check duplication first
if (m_pAttrUniqueEnsurance.find(data.thisobj) != m_pAttrUniqueEnsurance.end()) { if (m_pAttrUniqueEnsurance.find(data.thisobj) != m_pAttrUniqueEnsurance.end()) {
//existing item. skip it to make sure unique //existing item. skip it to make sure unique
@ -412,9 +418,9 @@ void DocumentDatabase::write_script_pAttr(dbdoc_script_pAttr& data, BOOL* alread
sqlite3_step(stmt); sqlite3_step(stmt);
return; return;
} }
void DocumentDatabase::write_msg(dbdoc_msg& data) { void DocumentDatabase::write_msg(DataStruct::dbdoc_msg& data) {
if (mDb == NULL) return; if (mDb == NULL) return;
TryGetStmtCache("INSERT INTO [msg] VALUES (?, ?)"); TryGetStmtCache("INSERT INTO [msg] VALUES (?, ?)");
@ -423,9 +429,9 @@ void DocumentDatabase::write_msg(dbdoc_msg& data) {
sqlite3_bind_int(stmt, 1, data.index); sqlite3_bind_int(stmt, 1, data.index);
sqlite3_bind_text(stmt, 2, data.name.c_str(), -1, SQLITE_TRANSIENT); sqlite3_bind_text(stmt, 2, data.name.c_str(), -1, SQLITE_TRANSIENT);
sqlite3_step(stmt); sqlite3_step(stmt);
} }
void DocumentDatabase::write_array(dbdoc_array& data) { void DocumentDatabase::write_array(DataStruct::dbdoc_array& data) {
if (mDb == NULL) return; if (mDb == NULL) return;
TryGetStmtCache("INSERT INTO [array] VALUES (?, ?, ?, ?)"); TryGetStmtCache("INSERT INTO [array] VALUES (?, ?, ?, ?)");
@ -436,9 +442,9 @@ void DocumentDatabase::write_array(dbdoc_array& data) {
sqlite3_bind_int(stmt, 3, data.rows); sqlite3_bind_int(stmt, 3, data.rows);
sqlite3_bind_int(stmt, 4, data.columns); sqlite3_bind_int(stmt, 4, data.columns);
sqlite3_step(stmt); sqlite3_step(stmt);
} }
void DocumentDatabase::write_array_header(dbdoc_array_header& data) { void DocumentDatabase::write_array_header(DataStruct::dbdoc_array_header& data) {
if (mDb == NULL) return; if (mDb == NULL) return;
TryGetStmtCache("INSERT INTO [array_header] VALUES (?, ?, ?, ?, ?, ?)"); TryGetStmtCache("INSERT INTO [array_header] VALUES (?, ?, ?, ?, ?, ?)");
@ -451,9 +457,9 @@ void DocumentDatabase::write_array_header(dbdoc_array_header& data) {
sqlite3_bind_text(stmt, 5, data.param_type_guid.c_str(), -1, SQLITE_TRANSIENT); sqlite3_bind_text(stmt, 5, data.param_type_guid.c_str(), -1, SQLITE_TRANSIENT);
sqlite3_bind_int(stmt, 6, data.parent); sqlite3_bind_int(stmt, 6, data.parent);
sqlite3_step(stmt); sqlite3_step(stmt);
} }
void DocumentDatabase::write_array_cell(dbdoc_array_cell& data) { void DocumentDatabase::write_array_cell(DataStruct::dbdoc_array_cell& data) {
if (mDb == NULL) return; if (mDb == NULL) return;
TryGetStmtCache("INSERT INTO [array_cell] VALUES (?, ?, ?, ?, ?)"); TryGetStmtCache("INSERT INTO [array_cell] VALUES (?, ?, ?, ?, ?)");
@ -465,9 +471,9 @@ void DocumentDatabase::write_array_cell(dbdoc_array_cell& data) {
sqlite3_bind_int(stmt, 4, data.inner_param); sqlite3_bind_int(stmt, 4, data.inner_param);
sqlite3_bind_int(stmt, 5, data.parent); sqlite3_bind_int(stmt, 5, data.parent);
sqlite3_step(stmt); sqlite3_step(stmt);
} }
void DocumentDatabase::write_data(dbdoc_data& data) { void DocumentDatabase::write_data(DataStruct::dbdoc_data& data) {
if (mDb == NULL) return; if (mDb == NULL) return;
TryGetStmtCache("INSERT INTO [data] VALUES (?, ?, ?)"); TryGetStmtCache("INSERT INTO [data] VALUES (?, ?, ?)");
@ -477,13 +483,13 @@ void DocumentDatabase::write_data(dbdoc_data& data) {
sqlite3_bind_text(stmt, 2, data.data.c_str(), -1, SQLITE_TRANSIENT); sqlite3_bind_text(stmt, 2, data.data.c_str(), -1, SQLITE_TRANSIENT);
sqlite3_bind_int(stmt, 3, data.parent); sqlite3_bind_int(stmt, 3, data.parent);
sqlite3_step(stmt); sqlite3_step(stmt);
} }
#pragma endregion #pragma endregion
#pragma region environment database #pragma region environment database
void EnvironmentDatabase::write_op(dbenv_op& data) { void EnvironmentDatabase::write_op(DataStruct::dbenv_op& data) {
if (mDb == NULL) return; if (mDb == NULL) return;
TryGetStmtCache("INSERT INTO [op] VALUES (?, ?, ?, ?, ?, ?, ?)"); TryGetStmtCache("INSERT INTO [op] VALUES (?, ?, ?, ?, ?, ?, ?)");
@ -497,9 +503,9 @@ void EnvironmentDatabase::write_op(dbenv_op& data) {
sqlite3_bind_text(stmt, 6, data.op_name.c_str(), -1, SQLITE_TRANSIENT); sqlite3_bind_text(stmt, 6, data.op_name.c_str(), -1, SQLITE_TRANSIENT);
sqlite3_bind_int(stmt, 7, data.op_code); sqlite3_bind_int(stmt, 7, data.op_code);
sqlite3_step(stmt); sqlite3_step(stmt);
} }
void EnvironmentDatabase::write_param(dbenv_param& data) { void EnvironmentDatabase::write_param(DataStruct::dbenv_param& data) {
if (mDb == NULL) return; if (mDb == NULL) return;
TryGetStmtCache("INSERT INTO [param] VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); TryGetStmtCache("INSERT INTO [param] VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
@ -524,9 +530,9 @@ void EnvironmentDatabase::write_param(dbenv_param& data) {
sqlite3_bind_int(stmt, 17, data.cid); sqlite3_bind_int(stmt, 17, data.cid);
sqlite3_bind_text(stmt, 18, data.saver_manager.c_str(), -1, SQLITE_TRANSIENT); sqlite3_bind_text(stmt, 18, data.saver_manager.c_str(), -1, SQLITE_TRANSIENT);
sqlite3_step(stmt); sqlite3_step(stmt);
} }
void EnvironmentDatabase::write_attr(dbenv_attr& data) { void EnvironmentDatabase::write_attr(DataStruct::dbenv_attr& data) {
if (mDb == NULL) return; if (mDb == NULL) return;
TryGetStmtCache("INSERT INTO [attr] VALUES (?, ?, ?, ?, ?, ?, ?, ?)"); TryGetStmtCache("INSERT INTO [attr] VALUES (?, ?, ?, ?, ?, ?, ?, ?)");
@ -541,9 +547,9 @@ void EnvironmentDatabase::write_attr(dbenv_attr& data) {
sqlite3_bind_int(stmt, 7, data.compatible_classid); sqlite3_bind_int(stmt, 7, data.compatible_classid);
sqlite3_bind_text(stmt, 8, data.default_value.c_str(), -1, SQLITE_TRANSIENT); sqlite3_bind_text(stmt, 8, data.default_value.c_str(), -1, SQLITE_TRANSIENT);
sqlite3_step(stmt); sqlite3_step(stmt);
} }
void EnvironmentDatabase::write_plugin(dbenv_plugin& data) { void EnvironmentDatabase::write_plugin(DataStruct::dbenv_plugin& data) {
if (mDb == NULL) return; if (mDb == NULL) return;
TryGetStmtCache("INSERT INTO [plugin] VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); TryGetStmtCache("INSERT INTO [plugin] VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
@ -562,9 +568,9 @@ void EnvironmentDatabase::write_plugin(dbenv_plugin& data) {
sqlite3_bind_int(stmt, 11, (int)data.func_init); sqlite3_bind_int(stmt, 11, (int)data.func_init);
sqlite3_bind_int(stmt, 12, (int)data.func_exit); sqlite3_bind_int(stmt, 12, (int)data.func_exit);
sqlite3_step(stmt); sqlite3_step(stmt);
} }
void EnvironmentDatabase::write_variable(dbenv_variable& data) { void EnvironmentDatabase::write_variable(DataStruct::dbenv_variable& data) {
if (mDb == NULL) return; if (mDb == NULL) return;
#if !defined(VIRTOOLS_21) #if !defined(VIRTOOLS_21)
@ -579,9 +585,11 @@ void EnvironmentDatabase::write_variable(dbenv_variable& data) {
sqlite3_bind_text(stmt, 6, data.data.c_str(), -1, SQLITE_TRANSIENT); sqlite3_bind_text(stmt, 6, data.data.c_str(), -1, SQLITE_TRANSIENT);
sqlite3_step(stmt); sqlite3_step(stmt);
#endif #endif
} }
#pragma endregion #pragma endregion
#undef TryGetStmtCache #undef TryGetStmtCache
}
}

View File

@ -1,362 +0,0 @@
#if !defined(_YYCDLL_DATABASE_H__IMPORTED_)
#define _YYCDLL_DATABASE_H__IMPORTED_
#include <sqlite3.h>
#include "stdafx.h"
#include <string>
#include <vector>
#include <set>
#include "virtools_compatible.h"
typedef long EXPAND_CK_ID;
enum bLinkInputOutputType {
bLinkInputOutputType_INPUT,
bLinkInputOutputType_OUTPUT
};
enum pLinkInputOutputType {
pLinkInputOutputType_PIN,
pLinkInputOutputType_POUT,
pLinkInputOutputType_PLOCAL, //when using pLocal, omit [index] and [input_is_bb], [input_index] set -1
pLinkInputOutputType_PTARGET, //when using pTarget, omit [index] and [input_is_bb], [input_index] set -1
pLinkInputOutputType_PATTR //when using pAttr, omit [index] and [input_is_bb], [input_index] set -1
};
#pragma region data struct define
// =================== doc mDb
struct dbdoc_script {
EXPAND_CK_ID thisobj;
std::string host_name;
int index;
EXPAND_CK_ID behavior;
};
struct dbdoc_script_behavior {
EXPAND_CK_ID thisobj;
std::string name;
CK_BEHAVIOR_TYPE type;
std::string proto_name;
std::string proto_guid;
CK_BEHAVIOR_FLAGS flags;
int priority;
CKDWORD version;
//pTarget, pIn, pOut, bIn, bOut
std::string pin_count;
EXPAND_CK_ID parent;
};
struct dbdoc_script_bIO {
EXPAND_CK_ID thisobj;
int index;
std::string name;
EXPAND_CK_ID parent;
};
typedef dbdoc_script_bIO dbdoc_script_bIn;
typedef dbdoc_script_bIO dbdoc_script_bOut;
struct dbdoc_script_pTarget {
EXPAND_CK_ID thisobj;
std::string name;
std::string type;
std::string type_guid;
EXPAND_CK_ID parent;
EXPAND_CK_ID direct_source;
EXPAND_CK_ID shared_source;
};
struct dbdoc_script_pIn {
EXPAND_CK_ID thisobj;
int index;
std::string name;
std::string type;
std::string type_guid;
EXPAND_CK_ID parent;
EXPAND_CK_ID direct_source;
EXPAND_CK_ID shared_source;
};
struct dbdoc_script_pOut {
EXPAND_CK_ID thisobj;
int index;
std::string name;
std::string type;
std::string type_guid;
EXPAND_CK_ID parent;
};
struct dbdoc_script_bLink {
EXPAND_CK_ID input;
EXPAND_CK_ID output;
int delay;
EXPAND_CK_ID parent;
//additional field
EXPAND_CK_ID input_obj;
bLinkInputOutputType input_type;
int input_index;
EXPAND_CK_ID output_obj;
bLinkInputOutputType output_type;
int output_index;
};
struct dbdoc_script_pLocal {
EXPAND_CK_ID thisobj;
std::string name;
std::string type;
std::string type_guid;
BOOL is_setting;
EXPAND_CK_ID parent;
};
struct dbdoc_script_pAttr {
EXPAND_CK_ID thisobj;
std::string name;
std::string type;
std::string type_guid;
};
struct dbdoc_script_pLink {
EXPAND_CK_ID input;
EXPAND_CK_ID output;
EXPAND_CK_ID parent;
//additional field
EXPAND_CK_ID input_obj;
pLinkInputOutputType input_type;
BOOL input_is_bb;
int input_index;
EXPAND_CK_ID output_obj;
pLinkInputOutputType output_type;
BOOL output_is_bb;
int output_index;
};
struct dbdoc_script_pOper {
EXPAND_CK_ID thisobj;
std::string op;
std::string op_guid;
EXPAND_CK_ID parent;
};
struct dbdoc_script_eLink {
EXPAND_CK_ID export_obj;
EXPAND_CK_ID internal_obj;
BOOL is_in;
int index;
EXPAND_CK_ID parent;
};
struct dbdoc_msg {
CKMessageType index;
std::string name;
};
struct dbdoc_array {
EXPAND_CK_ID thisobj;
std::string name;
int rows;
int columns;
};
struct dbdoc_array_header {
int index;
std::string name;
CK_ARRAYTYPE type;
std::string param_type;
std::string param_type_guid;
EXPAND_CK_ID parent;
};
struct dbdoc_array_cell {
int row;
int column;
std::string showcase;
EXPAND_CK_ID inner_param;
EXPAND_CK_ID parent;
};
struct dbdoc_data {
std::string field;
std::string data;
EXPAND_CK_ID parent;
};
// =================== env mDb
struct dbenv_op {
CK_PARAMETEROPERATION funcPtr;
std::string in1_guid;
std::string in2_guid;
std::string out_guid;
std::string op_guid;
std::string op_name;
CKOperationType op_code;
};
struct dbenv_param {
CKParameterType index;
std::string guid;
std::string derived_from;
std::string type_name;
int default_size;
CK_PARAMETERCREATEDEFAULTFUNCTION func_CreateDefault;
CK_PARAMETERDELETEFUNCTION func_Delete;
CK_PARAMETERSAVELOADFUNCTION func_SaveLoad;
CK_PARAMETERCHECKFUNCTION func_Check;
CK_PARAMETERCOPYFUNCTION func_Copy;
CK_PARAMETERSTRINGFUNCTION func_String;
CK_PARAMETERUICREATORFUNCTION func_UICreator;
int creator_dll_index;
int creator_plugin_index;
CKDWORD dw_param;
CKDWORD dw_flags;
CKDWORD cid;
std::string saver_manager;
};
struct dbenv_attr {
CKAttributeType index;
std::string name;
CKAttributeCategory category_index;
std::string category_name;
CK_ATTRIBUT_FLAGS flags;
CKParameterType param_index;
CK_CLASSID compatible_classid;
std::string default_value;
};
struct dbenv_plugin {
int dll_index;
std::string dll_name;
int plugin_index;
std::string category;
CKBOOL active;
std::string guid;
std::string desc;
std::string author;
std::string summary;
DWORD version;
CK_INITINSTANCEFCT func_init;
CK_EXITINSTANCEFCT func_exit;
};
struct dbenv_variable {
std::string name;
std::string desciption;
XWORD flags;
UNIVERSAL_VAR_TYPE type;
std::string representation;
std::string data;
};
#pragma endregion
class DbDataStructHelper_Doc {
public:
DbDataStructHelper_Doc(CKParameterManager* paramManager);
~DbDataStructHelper_Doc();
CKParameterManager* param_manager;
dbdoc_script script;
dbdoc_script_behavior script_behavior;
dbdoc_script_bIn script_bIn;
dbdoc_script_bOut script_bOut;
dbdoc_script_pIn script_pIn;
dbdoc_script_pOut script_pOut;
dbdoc_script_bLink script_bLink;
dbdoc_script_pLocal script_pLocal;
dbdoc_script_pAttr script_pAttr;
dbdoc_script_pLink script_pLink;
dbdoc_script_pOper script_pOper;
dbdoc_script_eLink script_eLink;
dbdoc_script_pTarget script_pTarget;
dbdoc_msg msg;
dbdoc_array _array;
dbdoc_array_header array_header;
dbdoc_array_cell array_cell;
dbdoc_data data;
};
class DbDataStructHelper_Env {
public:
DbDataStructHelper_Env();
~DbDataStructHelper_Env();
dbenv_op op;
dbenv_param param;
dbenv_attr attr;
dbenv_plugin plugin;
dbenv_variable variable;
};
class SSMaterializerDatabase {
public:
SSMaterializerDatabase(const char* file);
virtual ~SSMaterializerDatabase();
protected:
sqlite3_stmt* CreateStmt(const char* stmt);
virtual BOOL Init() = 0;
virtual BOOL Finalize() = 0;
sqlite3* mDb;
std::vector<sqlite3_stmt*> mStmtCache;
};
class DocumentDatabase : public SSMaterializerDatabase {
public:
DocumentDatabase(const char* file);
virtual ~DocumentDatabase();
void write_script(dbdoc_script& data);
void write_script_behavior(dbdoc_script_behavior& data);
void write_script_pTarget(dbdoc_script_pTarget& data);
void write_script_pIn(dbdoc_script_pIn& data);
void write_script_pOut(dbdoc_script_pOut& data);
void write_script_bIn(dbdoc_script_bIn& data);
void write_script_bOut(dbdoc_script_bOut& data);
void write_script_bLink(dbdoc_script_bLink& data);
void write_script_pLocal(dbdoc_script_pLocal& data);
void write_script_pLink(dbdoc_script_pLink& data);
void write_script_pOper(dbdoc_script_pOper& data);
void write_script_eLink(dbdoc_script_eLink& data);
void write_script_pAttr(dbdoc_script_pAttr& data, BOOL* already_exist);
void write_msg(dbdoc_msg& data);
void write_array(dbdoc_array& data);
void write_array_header(dbdoc_array_header& data);
void write_array_cell(dbdoc_array_cell& data);
void write_data(dbdoc_data& data);
protected:
BOOL Init() override;
BOOL Finalize() override;
std::set<EXPAND_CK_ID> m_pAttrUniqueEnsurance;
};
class EnvironmentDatabase : public SSMaterializerDatabase {
public:
EnvironmentDatabase(const char* file);
virtual ~EnvironmentDatabase();
void write_op(dbenv_op& data);
void write_param(dbenv_param& data);
void write_attr(dbenv_attr& data);
void write_plugin(dbenv_plugin& data);
void write_variable(dbenv_variable& data);
protected:
BOOL Init() override;
BOOL Finalize() override;
};
#endif

View File

@ -0,0 +1,374 @@
#pragma once
#include <sqlite3.h>
#include "stdafx.h"
#include "virtools_compatible.h"
#include <string>
#include <vector>
#include <set>
namespace SSMaterializer {
namespace DataStruct {
#pragma region data struct
typedef long EXPAND_CK_ID;
enum bLinkInputOutputType {
bLinkInputOutputType_INPUT,
bLinkInputOutputType_OUTPUT
};
enum pLinkInputOutputType {
pLinkInputOutputType_PIN,
pLinkInputOutputType_POUT,
pLinkInputOutputType_PLOCAL, //when using pLocal, omit [index] and [input_is_bb], [input_index] set -1
pLinkInputOutputType_PTARGET, //when using pTarget, omit [index] and [input_is_bb], [input_index] set -1
pLinkInputOutputType_PATTR //when using pAttr, omit [index] and [input_is_bb], [input_index] set -1
};
// =================== doc mDb
struct dbdoc_script {
EXPAND_CK_ID thisobj;
std::string host_name;
int index;
EXPAND_CK_ID behavior;
};
struct dbdoc_script_behavior {
EXPAND_CK_ID thisobj;
std::string name;
CK_BEHAVIOR_TYPE type;
std::string proto_name;
std::string proto_guid;
CK_BEHAVIOR_FLAGS flags;
int priority;
CKDWORD version;
//pTarget, pIn, pOut, bIn, bOut
std::string pin_count;
EXPAND_CK_ID parent;
};
struct dbdoc_script_bIO {
EXPAND_CK_ID thisobj;
int index;
std::string name;
EXPAND_CK_ID parent;
};
typedef dbdoc_script_bIO dbdoc_script_bIn;
typedef dbdoc_script_bIO dbdoc_script_bOut;
struct dbdoc_script_pTarget {
EXPAND_CK_ID thisobj;
std::string name;
std::string type;
std::string type_guid;
EXPAND_CK_ID parent;
EXPAND_CK_ID direct_source;
EXPAND_CK_ID shared_source;
};
struct dbdoc_script_pIn {
EXPAND_CK_ID thisobj;
int index;
std::string name;
std::string type;
std::string type_guid;
EXPAND_CK_ID parent;
EXPAND_CK_ID direct_source;
EXPAND_CK_ID shared_source;
};
struct dbdoc_script_pOut {
EXPAND_CK_ID thisobj;
int index;
std::string name;
std::string type;
std::string type_guid;
EXPAND_CK_ID parent;
};
struct dbdoc_script_bLink {
EXPAND_CK_ID input;
EXPAND_CK_ID output;
int delay;
EXPAND_CK_ID parent;
//additional field
EXPAND_CK_ID input_obj;
bLinkInputOutputType input_type;
int input_index;
EXPAND_CK_ID output_obj;
bLinkInputOutputType output_type;
int output_index;
};
struct dbdoc_script_pLocal {
EXPAND_CK_ID thisobj;
std::string name;
std::string type;
std::string type_guid;
BOOL is_setting;
EXPAND_CK_ID parent;
};
struct dbdoc_script_pAttr {
EXPAND_CK_ID thisobj;
std::string name;
std::string type;
std::string type_guid;
};
struct dbdoc_script_pLink {
EXPAND_CK_ID input;
EXPAND_CK_ID output;
EXPAND_CK_ID parent;
//additional field
EXPAND_CK_ID input_obj;
pLinkInputOutputType input_type;
BOOL input_is_bb;
int input_index;
EXPAND_CK_ID output_obj;
pLinkInputOutputType output_type;
BOOL output_is_bb;
int output_index;
};
struct dbdoc_script_pOper {
EXPAND_CK_ID thisobj;
std::string op;
std::string op_guid;
EXPAND_CK_ID parent;
};
struct dbdoc_script_eLink {
EXPAND_CK_ID export_obj;
EXPAND_CK_ID internal_obj;
BOOL is_in;
int index;
EXPAND_CK_ID parent;
};
struct dbdoc_msg {
CKMessageType index;
std::string name;
};
struct dbdoc_array {
EXPAND_CK_ID thisobj;
std::string name;
int rows;
int columns;
};
struct dbdoc_array_header {
int index;
std::string name;
CK_ARRAYTYPE type;
std::string param_type;
std::string param_type_guid;
EXPAND_CK_ID parent;
};
struct dbdoc_array_cell {
int row;
int column;
std::string showcase;
EXPAND_CK_ID inner_param;
EXPAND_CK_ID parent;
};
struct dbdoc_data {
std::string field;
std::string data;
EXPAND_CK_ID parent;
};
// =================== env mDb
struct dbenv_op {
CK_PARAMETEROPERATION funcPtr;
std::string in1_guid;
std::string in2_guid;
std::string out_guid;
std::string op_guid;
std::string op_name;
CKOperationType op_code;
};
struct dbenv_param {
CKParameterType index;
std::string guid;
std::string derived_from;
std::string type_name;
int default_size;
CK_PARAMETERCREATEDEFAULTFUNCTION func_CreateDefault;
CK_PARAMETERDELETEFUNCTION func_Delete;
CK_PARAMETERSAVELOADFUNCTION func_SaveLoad;
CK_PARAMETERCHECKFUNCTION func_Check;
CK_PARAMETERCOPYFUNCTION func_Copy;
CK_PARAMETERSTRINGFUNCTION func_String;
CK_PARAMETERUICREATORFUNCTION func_UICreator;
int creator_dll_index;
int creator_plugin_index;
CKDWORD dw_param;
CKDWORD dw_flags;
CKDWORD cid;
std::string saver_manager;
};
struct dbenv_attr {
CKAttributeType index;
std::string name;
CKAttributeCategory category_index;
std::string category_name;
CK_ATTRIBUT_FLAGS flags;
CKParameterType param_index;
CK_CLASSID compatible_classid;
std::string default_value;
};
struct dbenv_plugin {
int dll_index;
std::string dll_name;
int plugin_index;
std::string category;
CKBOOL active;
std::string guid;
std::string desc;
std::string author;
std::string summary;
DWORD version;
CK_INITINSTANCEFCT func_init;
CK_EXITINSTANCEFCT func_exit;
};
struct dbenv_variable {
std::string name;
std::string desciption;
XWORD flags;
UNIVERSAL_VAR_TYPE type;
std::string representation;
std::string data;
};
#pragma endregion
namespace Helper {
class DocumentHelper {
public:
DocumentHelper(CKParameterManager* paramManager);
~DocumentHelper();
CKParameterManager* param_manager;
dbdoc_script script;
dbdoc_script_behavior script_behavior;
dbdoc_script_bIn script_bIn;
dbdoc_script_bOut script_bOut;
dbdoc_script_pIn script_pIn;
dbdoc_script_pOut script_pOut;
dbdoc_script_bLink script_bLink;
dbdoc_script_pLocal script_pLocal;
dbdoc_script_pAttr script_pAttr;
dbdoc_script_pLink script_pLink;
dbdoc_script_pOper script_pOper;
dbdoc_script_eLink script_eLink;
dbdoc_script_pTarget script_pTarget;
dbdoc_msg msg;
dbdoc_array _array;
dbdoc_array_header array_header;
dbdoc_array_cell array_cell;
dbdoc_data data;
};
class EnvironmentHelper {
public:
EnvironmentHelper();
~EnvironmentHelper();
dbenv_op op;
dbenv_param param;
dbenv_attr attr;
dbenv_plugin plugin;
dbenv_variable variable;
};
}
}
namespace Database {
class SSMaterializerDatabase {
public:
SSMaterializerDatabase(const char* file);
virtual ~SSMaterializerDatabase();
protected:
sqlite3_stmt* CreateStmt(const char* stmt);
virtual BOOL Init() = 0;
virtual BOOL Finalize() = 0;
sqlite3* mDb;
std::vector<sqlite3_stmt*> mStmtCache;
};
class DocumentDatabase : public SSMaterializerDatabase {
public:
DocumentDatabase(const char* file, CKParameterManager* paramManager);
virtual ~DocumentDatabase();
DataStruct::Helper::DocumentHelper mDbHelper;
void write_script(DataStruct::dbdoc_script& data);
void write_script_behavior(DataStruct::dbdoc_script_behavior& data);
void write_script_pTarget(DataStruct::dbdoc_script_pTarget& data);
void write_script_pIn(DataStruct::dbdoc_script_pIn& data);
void write_script_pOut(DataStruct::dbdoc_script_pOut& data);
void write_script_bIn(DataStruct::dbdoc_script_bIn& data);
void write_script_bOut(DataStruct::dbdoc_script_bOut& data);
void write_script_bLink(DataStruct::dbdoc_script_bLink& data);
void write_script_pLocal(DataStruct::dbdoc_script_pLocal& data);
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_msg(DataStruct::dbdoc_msg& data);
void write_array(DataStruct::dbdoc_array& data);
void write_array_header(DataStruct::dbdoc_array_header& data);
void write_array_cell(DataStruct::dbdoc_array_cell& data);
void write_data(DataStruct::dbdoc_data& data);
protected:
BOOL Init() override;
BOOL Finalize() override;
std::set<DataStruct::EXPAND_CK_ID> m_pAttrUniqueEnsurance;
};
class EnvironmentDatabase : public SSMaterializerDatabase {
public:
EnvironmentDatabase(const char* file);
virtual ~EnvironmentDatabase();
DataStruct::Helper::EnvironmentHelper mDbHelper;
void write_op(DataStruct::dbenv_op& data);
void write_param(DataStruct::dbenv_param& data);
void write_attr(DataStruct::dbenv_attr& data);
void write_plugin(DataStruct::dbenv_plugin& data);
void write_variable(DataStruct::dbenv_variable& data);
protected:
BOOL Init() override;
BOOL Finalize() override;
};
}
}

View File

@ -0,0 +1,578 @@
#include "doc_export.hpp"
#include "string_helper.hpp"
// some shitty features process
//disable shit tip
#pragma warning(disable:26812)
// disable microsoft shitty macro to avoid build error
#undef GetClassName
#define changeSuffix(a) prefix[endIndex]='\0';strcat(prefix,a)
#define copyGuid(guid,str) sprintf(helper->_stringCache,"%d,%d",guid.d1,guid.d2);str=helper->_stringCache;
#define safeStringCopy(storage,str) storage=(str)?(str):"";
namespace SSMaterializer {
namespace DocumentExporter {
#pragma region script
void generate_pLink_in_pIn(CKContext* ctx, CKParameterIn* cache, Database::DocumentDatabase* mDb, DataStruct::EXPAND_CK_ID parents, DataStruct::EXPAND_CK_ID grandparents, int index, BOOL executedFromBB, BOOL isTarget) {
//WARNING: i only choose one between [DirectSource] and [SharedSource] bucause i don't find any pIn both have these two field
CKParameter* directSource = NULL;
CKObject* ds_Owner = NULL;
CKParameterIn* sharedSource = NULL;
CKBehavior* ss_Owner = NULL;
if (directSource = cache->GetDirectSource()) {
helper->_db_pLink->input = directSource->GetID();
if (directSource->GetClassID() == CKCID_PARAMETERLOCAL || directSource->GetClassID() == CKCID_PARAMETERVARIABLE) {
//pLocal
helper->_db_pLink->input_obj = directSource->GetID();
helper->_db_pLink->input_type = pLinkInputOutputType_PLOCAL;
helper->_db_pLink->input_is_bb = FALSE;
helper->_db_pLink->input_index = -1;
} else {
//WARNING: when GetClassID() return CKDataArray there are untested code
//pParam from bb pOut / pOper pOut / object Attribute / CKDataArray
ds_Owner = directSource->GetOwner();
switch (ds_Owner->GetClassID()) {
case CKCID_BEHAVIOR:
helper->_db_pLink->input_obj = ds_Owner->GetID();
helper->_db_pLink->input_type = pLinkInputOutputType_POUT;
helper->_db_pLink->input_is_bb = TRUE;
helper->_db_pLink->input_index = ((CKBehavior*)ds_Owner)->GetOutputParameterPosition((CKParameterOut*)directSource);
break;
case CKCID_PARAMETEROPERATION:
helper->_db_pLink->input_obj = ds_Owner->GetID();
helper->_db_pLink->input_type = pLinkInputOutputType_POUT;
helper->_db_pLink->input_is_bb = FALSE;
helper->_db_pLink->input_index = 0;
break;
case CKCID_DATAARRAY:
// dataarray, see as virtual bb pLocal shortcut
helper->_db_pLink->input_obj = directSource->GetID();
helper->_db_pLink->input_type = pLinkInputOutputType_PATTR;
helper->_db_pLink->input_is_bb = FALSE;
helper->_db_pLink->input_index = -1;
proc_pAttr(ctx, mDb, helper, directSource);
break;
default:
//normal object, see as virtual bb pLocal shortcut
helper->_db_pLink->input_obj = directSource->GetID();
helper->_db_pLink->input_type = pLinkInputOutputType_PATTR;
helper->_db_pLink->input_is_bb = FALSE;
helper->_db_pLink->input_index = -1;
proc_pAttr(ctx, mDb, helper, directSource);
break;
}
}
}
if (sharedSource = cache->GetSharedSource()) {
//pIn from BB
helper->_db_pLink->input = sharedSource->GetID();
ss_Owner = (CKBehavior*)sharedSource->GetOwner();
helper->_db_pLink->input_obj = ss_Owner->GetID();
if (ss_Owner->IsUsingTarget() && (ss_Owner->GetTargetParameter() == sharedSource)) {
//pTarget
helper->_db_pLink->input_type = pLinkInputOutputType_PTARGET;
helper->_db_pLink->input_is_bb = TRUE;
helper->_db_pLink->input_index = -1;
} else {
//pIn
helper->_db_pLink->input_type = pLinkInputOutputType_PIN;
helper->_db_pLink->input_is_bb = TRUE;
helper->_db_pLink->input_index = ss_Owner->GetInputParameterPosition(sharedSource);
}
}
if (sharedSource != NULL || directSource != NULL) {
helper->_db_pLink->output = cache->GetID();
helper->_db_pLink->output_obj = parents;
helper->_db_pLink->output_type = isTarget ? pLinkInputOutputType_PTARGET : pLinkInputOutputType_PIN;
helper->_db_pLink->output_is_bb = executedFromBB;
helper->_db_pLink->output_index = index;
helper->_db_pLink->belong_to = grandparents;
mDb->write_script_pLink(helper->_db_pLink);
}
}
void proc_pTarget(CKContext* ctx, CKParameterIn* cache, Database::DocumentDatabase* mDb, DataStruct::EXPAND_CK_ID parents, DataStruct::EXPAND_CK_ID grandparents) {
helper->_db_pTarget->thisobj = cache->GetID();
helper->_db_pTarget->name = cache->GetName();
helper->_db_pTarget->type = helper->_parameterManager->ParameterTypeToName(cache->GetType());
copyGuid(cache->GetGUID(), helper->_db_pTarget->type_guid);
helper->_db_pTarget->belong_to = parents;
helper->_db_pTarget->direct_source = cache->GetDirectSource() ? cache->GetDirectSource()->GetID() : -1;
helper->_db_pTarget->shared_source = cache->GetSharedSource() ? cache->GetSharedSource()->GetID() : -1;
mDb->write_script_pTarget(helper->_db_pTarget);
//judge whether expoer parameter and write SSMaterializerDatabase
if (((CKBehavior*)ctx->GetObject(grandparents))->GetInputParameterPosition(cache) != -1) {
helper->_db_eLink->export_obj = cache->GetID();
helper->_db_eLink->internal_obj = parents;
helper->_db_eLink->is_in = TRUE;
helper->_db_eLink->index = -1;
helper->_db_eLink->belong_to = grandparents;
mDb->write_script_eLink(helper->_db_eLink);
return;
}
//=========try generate pLink
generate_pLink_in_pIn(ctx, cache, mDb, helper, parents, grandparents, -1, TRUE, TRUE);
}
void proc_pIn(CKContext* ctx, CKParameterIn* cache, Database::DocumentDatabase* mDb, DataStruct::EXPAND_CK_ID parents, DataStruct::EXPAND_CK_ID grandparents, int index, BOOL executedFromBB) {
helper->_db_pIn->thisobj = cache->GetID();
helper->_db_pIn->index = index;
helper->_db_pIn->name = cache->GetName();
CKParameterType vaildTypeChecker = cache->GetType();
if (vaildTypeChecker != -1) helper->_db_pIn->type = helper->_parameterManager->ParameterTypeToName(cache->GetType()); //known types
else helper->_db_pIn->type = "!!UNKNOW TYPE!!"; //unknow type
copyGuid(cache->GetGUID(), helper->_db_pIn->type_guid);
helper->_db_pIn->belong_to = parents;
helper->_db_pIn->direct_source = cache->GetDirectSource() ? cache->GetDirectSource()->GetID() : -1;
helper->_db_pIn->shared_source = cache->GetSharedSource() ? cache->GetSharedSource()->GetID() : -1;
mDb->write_script_pIn(helper->_db_pIn);
//judge whether expoer parameter and write SSMaterializerDatabase
if (((CKBehavior*)ctx->GetObject(grandparents))->GetInputParameterPosition(cache) != -1) {
helper->_db_eLink->export_obj = cache->GetID();
helper->_db_eLink->internal_obj = parents;
helper->_db_eLink->is_in = TRUE;
helper->_db_eLink->index = index;
helper->_db_eLink->belong_to = grandparents;
mDb->write_script_eLink(helper->_db_eLink);
return;
}
//=========try generate pLink
generate_pLink_in_pIn(ctx, cache, mDb, helper, parents, grandparents, index, executedFromBB, FALSE);
}
void proc_pOut(CKContext* ctx, CKParameterOut* cache, Database::DocumentDatabase* mDb, DataStruct::EXPAND_CK_ID parents, DataStruct::EXPAND_CK_ID grandparents, int index, BOOL executedFromBB) {
helper->_db_pOut->thisobj = cache->GetID();
helper->_db_pOut->index = index;
helper->_db_pOut->name = cache->GetName();
CKParameterType vaildTypeChecker = cache->GetType();
if (vaildTypeChecker != -1) helper->_db_pOut->type = helper->_parameterManager->ParameterTypeToName(cache->GetType()); //known types
else helper->_db_pOut->type = "!!UNKNOW TYPE!!"; //unknow type
copyGuid(cache->GetGUID(), helper->_db_pOut->type_guid);
helper->_db_pOut->belong_to = parents;
mDb->write_script_pOut(helper->_db_pOut);
//judge whether expoer parameter and write SSMaterializerDatabase
if (((CKBehavior*)ctx->GetObject(grandparents))->GetOutputParameterPosition(cache) != -1) {
helper->_db_eLink->export_obj = cache->GetID();
helper->_db_eLink->internal_obj = parents;
helper->_db_eLink->is_in = FALSE;
helper->_db_eLink->index = index;
helper->_db_eLink->belong_to = grandparents;
mDb->write_script_eLink(helper->_db_eLink);
return;
}
//=========try generate pLink
CKParameter* cache_Dest = NULL;
CKObject* cache_DestOwner = NULL;
for (int j = 0, jCount = cache->GetDestinationCount(); j < jCount; j++) {
cache_Dest = cache->GetDestination(j);
helper->_db_pLink->input = cache->GetID();
helper->_db_pLink->input_obj = parents;
helper->_db_pLink->input_type = pLinkInputOutputType_POUT;
helper->_db_pLink->input_is_bb = executedFromBB;
helper->_db_pLink->input_index = index;
helper->_db_pLink->output = cache_Dest->GetID();
if (cache_Dest->GetClassID() == CKCID_PARAMETERLOCAL) {
//pLocal
helper->_db_pLink->output_obj = cache_Dest->GetID();
helper->_db_pLink->output_type = pLinkInputOutputType_PLOCAL;
helper->_db_pLink->output_is_bb = FALSE;
helper->_db_pLink->output_index = -1;
} else {
//pOut, it must belong to a BB
cache_DestOwner = cache_Dest->GetOwner();
helper->_db_pLink->output_obj = cache_DestOwner->GetID();
helper->_db_pLink->output_type = pLinkInputOutputType_POUT;
helper->_db_pLink->output_is_bb = TRUE;
helper->_db_pLink->output_index = ((CKBehavior*)cache_DestOwner)->GetOutputParameterPosition((CKParameterOut*)cache_Dest);
}
helper->_db_pLink->belong_to = grandparents;
mDb->write_script_pLink(helper->_db_pLink);
}
}
void proc_bIn(CKBehaviorIO* cache, Database::DocumentDatabase* mDb, DataStruct::EXPAND_CK_ID parents, int index) {
helper->_db_bIn->thisobj = cache->GetID();
helper->_db_bIn->index = index;
helper->_db_bIn->name = cache->GetName();
helper->_db_bIn->belong_to = parents;
mDb->write_script_bIn(helper->_db_bIn);
}
void proc_bOut(CKBehaviorIO* cache, Database::DocumentDatabase* mDb, DataStruct::EXPAND_CK_ID parents, int index) {
helper->_db_bOut->thisobj = cache->GetID();
helper->_db_bOut->index = index;
helper->_db_bOut->name = cache->GetName();
helper->_db_bOut->belong_to = parents;
mDb->write_script_bOut(helper->_db_bOut);
}
void proc_bLink(CKBehaviorLink* cache, Database::DocumentDatabase* mDb, DataStruct::EXPAND_CK_ID parents) {
CKBehaviorIO* io = cache->GetInBehaviorIO();
CKBehavior* beh = io->GetOwner();
helper->_db_bLink->input = io->GetID();
helper->_db_bLink->input_obj = beh->GetID();
helper->_db_bLink->input_type = (io->GetType() == CK_BEHAVIORIO_IN ? bLinkInputOutputType_INPUT : bLinkInputOutputType_OUTPUT);
helper->_db_bLink->input_index = (io->GetType() == CK_BEHAVIORIO_IN ? io->GetOwner()->GetInputPosition(io) : io->GetOwner()->GetOutputPosition(io));
io = cache->GetOutBehaviorIO();
beh = io->GetOwner();
helper->_db_bLink->output = io->GetID();
helper->_db_bLink->output_obj = beh->GetID();
helper->_db_bLink->output_type = (io->GetType() == CK_BEHAVIORIO_IN ? bLinkInputOutputType_INPUT : bLinkInputOutputType_OUTPUT);
helper->_db_bLink->output_index = (io->GetType() == CK_BEHAVIORIO_IN ? io->GetOwner()->GetInputPosition(io) : io->GetOwner()->GetOutputPosition(io));
helper->_db_bLink->delay = cache->GetActivationDelay();
helper->_db_bLink->belong_to = parents;
mDb->write_script_bLink(helper->_db_bLink);
}
void proc_pLocal(CKParameterLocal* cache, Database::DocumentDatabase* mDb, DataStruct::EXPAND_CK_ID parents, BOOL is_setting) {
helper->_db_pLocal->thisobj = cache->GetID();
helper->_db_pLocal->name = cache->GetName() ? cache->GetName() : "";
CKParameterType vaildTypeChecker = cache->GetType();
if (vaildTypeChecker != -1) helper->_db_pLocal->type = helper->_parameterManager->ParameterTypeToName(cache->GetType()); //known types
else helper->_db_pLocal->type = "!!UNKNOW TYPE!!"; //unknow type
copyGuid(cache->GetGUID(), helper->_db_pLocal->type_guid);
helper->_db_pLocal->is_setting = is_setting;
helper->_db_pLocal->belong_to = parents;
mDb->write_script_pLocal(helper->_db_pLocal);
//export plocal metadata
DigParameterData(cache, mDb, helper, cache->GetID());
}
void proc_pOper(CKContext* ctx, CKParameterOperation* cache, Database::DocumentDatabase* mDb, DataStruct::EXPAND_CK_ID parents) {
helper->_db_pOper->thisobj = cache->GetID();
helper->_db_pOper->op = helper->_parameterManager->OperationGuidToName(cache->GetOperationGuid());
copyGuid(cache->GetOperationGuid(), helper->_db_pOper->op_guid);
helper->_db_pOper->belong_to = parents;
mDb->write_script_pOper(helper->_db_pOper);
//export 2 input param and 1 output param
proc_pIn(ctx, cache->GetInParameter1(), mDb, helper, cache->GetID(), parents, 0, FALSE);
proc_pIn(ctx, cache->GetInParameter2(), mDb, helper, cache->GetID(), parents, 1, FALSE);
proc_pOut(ctx, cache->GetOutParameter(), mDb, helper, cache->GetID(), parents, 0, FALSE);
}
void proc_pAttr(CKContext* ctx, Database::DocumentDatabase* mDb, CKParameter* cache) {
//write self first to detect conflict
helper->_db_pAttr->thisobj = cache->GetID();
safeStringCopy(helper->_db_pAttr->name, cache->GetName());
CKParameterType vaildTypeChecker = cache->GetType();
if (vaildTypeChecker != -1) helper->_db_pAttr->type = helper->_parameterManager->ParameterTypeToName(cache->GetType()); //known types
else helper->_db_pAttr->type = "!!UNKNOW TYPE!!"; //unknow type
copyGuid(cache->GetGUID(), helper->_db_pAttr->type_guid);
BOOL already_exist = FALSE;
mDb->write_script_pAttr(helper->_db_pAttr, &already_exist);
if (!already_exist) {
//not duplicated, continue write property
CKObject* host = cache->GetOwner();
DataDictWritter("attr.host_id", (long)host->GetID(), mDb, helper, cache->GetID());
DataDictWritter("attr.host_name", host->GetName(), mDb, helper, cache->GetID());
}
}
void IterateScript(CKContext* ctx, Database::DocumentDatabase* mDb) {
CKBeObject* beobj = NULL;
CKBehavior* beh = NULL;
XObjectPointerArray objArray = ctx->GetObjectListByType(CKCID_BEOBJECT, TRUE);
int len = objArray.Size();
int scriptLen = 0;
for (int i = 0; i < len; i++) {
beobj = (CKBeObject*)objArray.GetObjectA(i);
if ((scriptLen = beobj->GetScriptCount()) == 0) continue;
for (int j = 0; j < scriptLen; j++) {
//write script table
beh = beobj->GetScript(j);
helper->_db_script->thisobj = beobj->GetID();
helper->_db_script->host_name = beobj->GetName();
helper->_db_script->index = j;
helper->_db_script->behavior = beh->GetID();
mDb->write_script(helper->_db_script);
//iterate script
IterateBehavior(ctx, beh, mDb, helper, -1);
}
}
}
void IterateBehavior(CKContext* ctx, CKBehavior* bhv, Database::DocumentDatabase* mDb, DataStruct::EXPAND_CK_ID parents) {
//write self data
helper->_db_behavior->thisobj = bhv->GetID();
helper->_db_behavior->name = bhv->GetName();
helper->_db_behavior->type = bhv->GetType();
helper->_db_behavior->proto_name = bhv->GetPrototypeName() ? bhv->GetPrototypeName() : "";
copyGuid(bhv->GetPrototypeGuid(), helper->_db_behavior->proto_guid);
helper->_db_behavior->flags = bhv->GetFlags();
helper->_db_behavior->priority = bhv->GetPriority();
helper->_db_behavior->version = bhv->GetVersion();
helper->_db_behavior->parent = parents;
sprintf(helper->_stringCache, "%d,%d,%d,%d,%d",
(bhv->IsUsingTarget() ? 1 : 0),
bhv->GetInputParameterCount(),
bhv->GetOutputParameterCount(),
bhv->GetInputCount(),
bhv->GetOutputCount());
helper->_db_behavior->pin_count = helper->_stringCache;
mDb->write_script_behavior(helper->_db_behavior);
//write target
if (bhv->IsUsingTarget())
proc_pTarget(ctx, bhv->GetTargetParameter(), mDb, helper, bhv->GetID(), parents);
int count = 0, i = 0;
//pIn
for (i = 0, count = bhv->GetInputParameterCount(); i < count; i++)
proc_pIn(ctx, bhv->GetInputParameter(i), mDb, helper, bhv->GetID(), parents, i, TRUE);
//pOut
for (i = 0, count = bhv->GetOutputParameterCount(); i < count; i++)
proc_pOut(ctx, bhv->GetOutputParameter(i), mDb, helper, bhv->GetID(), parents, i, TRUE);
//bIn
for (i = 0, count = bhv->GetInputCount(); i < count; i++)
proc_bIn(bhv->GetInput(i), mDb, helper, bhv->GetID(), i);
//bOut
for (i = 0, count = bhv->GetOutputCount(); i < count; i++)
proc_bOut(bhv->GetOutput(i), mDb, helper, bhv->GetID(), i);
//bLink
for (i = 0, count = bhv->GetSubBehaviorLinkCount(); i < count; i++)
proc_bLink(bhv->GetSubBehaviorLink(i), mDb, helper, bhv->GetID());
//pLocal
for (i = 0, count = bhv->GetLocalParameterCount(); i < count; i++)
proc_pLocal(bhv->GetLocalParameter(i), mDb, helper, bhv->GetID(),
bhv->IsLocalParameterSetting(i));
//pOper
for (i = 0, count = bhv->GetParameterOperationCount(); i < count; i++)
proc_pOper(ctx, bhv->GetParameterOperation(i), mDb, helper, bhv->GetID());
//iterate sub bb
for (i = 0, count = bhv->GetSubBehaviorCount(); i < count; i++)
IterateBehavior(ctx, bhv->GetSubBehavior(i), mDb, helper, bhv->GetID());
}
#pragma endregion
#pragma region array
#pragma endregion
#pragma region data process
void DigParameterData(CKParameterLocal* p, Database::DocumentDatabase* mDb, DataStruct::EXPAND_CK_ID parents) {
CKGUID t = p->GetGUID();
BOOL unknowType = FALSE;
if (t.d1 & t.d2) unknowType = TRUE;
//nothing
if (t == CKPGUID_NONE) return;
if (p->GetParameterClassID() && p->GetValueObject(false)) {
DataDictWritter("id", (long)p->GetValueObject(false)->GetID(), mDb, helper, parents);
DataDictWritter("name", p->GetValueObject(false)->GetName(), mDb, helper, parents);
CK_CLASSID none_classid = p->GetValueObject(false)->GetClassID();
CKParameterType none_type = helper->_parameterManager->ClassIDToType(none_classid);
DataDictWritter("type", helper->_parameterManager->ParameterTypeToName(none_type), mDb, helper, parents);
return;
}
//float
if (t == CKPGUID_FLOAT || t == CKPGUID_ANGLE || t == CKPGUID_PERCENTAGE || t == CKPGUID_TIME
#if defined(VIRTOOLS_50) || defined(VIRTOOLS_40) || defined(VIRTOOLS_35)
|| t == CKPGUID_FLOATSLIDER
#endif
) {
DataDictWritter("float-data", *(float*)(p->GetReadDataPtr(false)), mDb, helper, parents);
return;
}
//int
if (t == CKPGUID_INT || t == CKPGUID_KEY || t == CKPGUID_BOOL || t == CKPGUID_ID || t == CKPGUID_POINTER
|| t == CKPGUID_MESSAGE || t == CKPGUID_ATTRIBUTE || t == CKPGUID_BLENDMODE || t == CKPGUID_FILTERMODE
|| t == CKPGUID_BLENDFACTOR || t == CKPGUID_FILLMODE || t == CKPGUID_LITMODE || t == CKPGUID_SHADEMODE
|| t == CKPGUID_ADDRESSMODE || t == CKPGUID_WRAPMODE || t == CKPGUID_3DSPRITEMODE || t == CKPGUID_FOGMODE
|| t == CKPGUID_LIGHTTYPE || t == CKPGUID_SPRITEALIGN || t == CKPGUID_DIRECTION || t == CKPGUID_LAYERTYPE
|| t == CKPGUID_COMPOPERATOR || t == CKPGUID_BINARYOPERATOR || t == CKPGUID_SETOPERATOR
|| t == CKPGUID_OBSTACLEPRECISION || t == CKPGUID_OBSTACLEPRECISIONBEH) {
DataDictWritter("int-data", (long)(*(int*)(p->GetReadDataPtr(false))), mDb, helper, parents);
return;
}
if (t == CKPGUID_VECTOR) {
VxVector vec;
memcpy(&vec, p->GetReadDataPtr(false), sizeof(vec));
DataDictWritter("vector.x", vec.x, mDb, helper, parents);
DataDictWritter("vector.y", vec.y, mDb, helper, parents);
DataDictWritter("vector.z", vec.z, mDb, helper, parents);
return;
}
if (t == CKPGUID_2DVECTOR) {
Vx2DVector vec;
memcpy(&vec, p->GetReadDataPtr(false), sizeof(vec));
DataDictWritter("2dvector.x", vec.x, mDb, helper, parents);
DataDictWritter("2dvector.y", vec.y, mDb, helper, parents);
return;
}
if (t == CKPGUID_MATRIX) {
VxMatrix mat;
char position[128];
memcpy(&mat, p->GetReadDataPtr(false), sizeof(mat));
for (int i = 0; i < 4; ++i) {
for (int j = 0; j < 4; ++j) {
sprintf(position, "matrix[%d][%d]", i, j);
DataDictWritter(position, mat[i][j], mDb, helper, parents);
}
}
return;
}
if (t == CKPGUID_COLOR) {
VxColor col;
memcpy(&col, p->GetReadDataPtr(false), sizeof(col));
DataDictWritter("color.r", col.r, mDb, helper, parents);
DataDictWritter("color.g", col.g, mDb, helper, parents);
DataDictWritter("color.b", col.b, mDb, helper, parents);
DataDictWritter("color.a", col.a, mDb, helper, parents);
return;
}
if (t == CKPGUID_2DCURVE) {
//CK2dCurve* c;
CK2dCurve* c = (CK2dCurve*)p->GetReadDataPtr(false);
char prefix[128];
int endIndex = 0;
//memcpy(&c, p->GetReadDataPtr(false), sizeof(c));
for (int i = 0, cc = c->GetControlPointCount(); i < cc; ++i) {
sprintf(prefix, "2dcurve.control_point[%d]", i);
endIndex = strlen(prefix);
changeSuffix(".pos.x");
DataDictWritter(prefix, c->GetControlPoint(i)->GetPosition().x, mDb, helper, parents);
changeSuffix(".pos.y");
DataDictWritter(prefix, c->GetControlPoint(i)->GetPosition().y, mDb, helper, parents);
changeSuffix(".islinear");
DataDictWritter(prefix, (long)c->GetControlPoint(i)->IsLinear(), mDb, helper, parents);
if (c->GetControlPoint(i)->IsTCB()) {
changeSuffix(".bias");
DataDictWritter(prefix, c->GetControlPoint(i)->GetBias(), mDb, helper, parents);
changeSuffix(".continuity");
DataDictWritter(prefix, c->GetControlPoint(i)->GetContinuity(), mDb, helper, parents);
changeSuffix(".tension");
DataDictWritter(prefix, c->GetControlPoint(i)->GetTension(), mDb, helper, parents);
} else {
changeSuffix(".intangent.x");
DataDictWritter(prefix, c->GetControlPoint(i)->GetInTangent().x, mDb, helper, parents);
changeSuffix(".intangent.y");
DataDictWritter(prefix, c->GetControlPoint(i)->GetInTangent().y, mDb, helper, parents);
changeSuffix(".outtangent.x");
DataDictWritter(prefix, c->GetControlPoint(i)->GetOutTangent().x, mDb, helper, parents);
changeSuffix(".outtangent.y");
DataDictWritter(prefix, c->GetControlPoint(i)->GetOutTangent().y, mDb, helper, parents);
}
}
return;
}
if (t == CKPGUID_STRING) {
char* cptr = (char*)p->GetReadDataPtr(false);
int cc = p->GetDataSize();
helper->_db_pData->data.clear();
helper->_db_pData->data.insert(0, cptr, 0, cc);
helper->_db_pData->field = "str";
helper->_db_pData->belong_to = p->GetID();
mDb->write_pData(helper->_db_pData);
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 defined(VIRTOOLS_50) || defined(VIRTOOLS_40) || defined(VIRTOOLS_35)
|| t == CKPGUID_SHADER || t == CKPGUID_TECHNIQUE || t == CKPGUID_PASS
#endif
) {
//dump data
unsigned char* cptr = (unsigned char*)p->GetReadDataPtr(false);
char temp[8];
int cc = 0, rcc = 0, pos = 0;
rcc = cc = p->GetDataSize();
if (rcc > 1024) rcc = 1024;
helper->_db_pData->data.clear();
for (int i = 0; i < rcc; i++) {
sprintf(temp, "0x%02X", cptr[i]);
helper->_db_pData->data += temp;
if (i != rcc - 1)
helper->_db_pData->data += ", ";
}
if (rcc == cc)
helper->_db_pData->field = "dump.data";
else
helper->_db_pData->field = "dump.partial_data";
helper->_db_pData->belong_to = p->GetID();
mDb->write_pData(helper->_db_pData);
//dump data length
DataDictWritter("dump.length", (long)cc, mDb, helper, parents);
return;
}
}
void DataDictWritter(const char* field, const char* data, Database::DocumentDatabase* mDb, DataStruct::EXPAND_CK_ID parents) {
mDb->mDbHelper.data.field = field;
mDb->mDbHelper.data.data = data;
mDb->mDbHelper.data.parent = parents;
mDb->write_data(mDb->mDbHelper.data);
}
void DataDictWritter(const char* field, float data, Database::DocumentDatabase* mDb, DataStruct::EXPAND_CK_ID parents) {
static std::string float_conv;
Utils::StdstringPrintf(float_conv, "%f", data);
DataDictWritter(field, float_conv.c_str(), mDb, parents);
}
void DataDictWritter(const char* field, long data, Database::DocumentDatabase* mDb, DataStruct::EXPAND_CK_ID parents) {
static std::string int_conv;
Utils::StdstringPrintf(int_conv, "%d", data);
DataDictWritter(field, int_conv.c_str(), mDb, parents);
}
#pragma endregion
}
}

View File

@ -0,0 +1,32 @@
#pragma once
#include "stdafx.h"
#include "database.hpp"
namespace SSMaterializer {
namespace DocumentExporter {
void generate_pLink_in_pIn(CKContext* ctx, CKParameterIn* cache, Database::DocumentDatabase* mDb, DataStruct::EXPAND_CK_ID parents, DataStruct::EXPAND_CK_ID grandparents, int index, BOOL executedFromBB, BOOL isTarget);
void proc_pTarget(CKContext* ctx, CKParameterIn* cache, Database::DocumentDatabase* mDb, DataStruct::EXPAND_CK_ID parents, DataStruct::EXPAND_CK_ID grandparents);
void proc_pIn(CKContext* ctx, CKParameterIn* cache, Database::DocumentDatabase* mDb, DataStruct::EXPAND_CK_ID parents, DataStruct::EXPAND_CK_ID grandparents, int index, BOOL executedFromBB);
void proc_pOut(CKContext* ctx, CKParameterOut* cache, Database::DocumentDatabase* mDb, DataStruct::EXPAND_CK_ID parents, DataStruct::EXPAND_CK_ID grandparents, int index, BOOL executedFromBB);
void proc_bIn(CKBehaviorIO* cache, Database::DocumentDatabase* mDb, DataStruct::EXPAND_CK_ID parents, int index);
void proc_bOut(CKBehaviorIO* cache, Database::DocumentDatabase* mDb, DataStruct::EXPAND_CK_ID parents, int index);
void proc_bLink(CKBehaviorLink* cache, Database::DocumentDatabase* mDb, DataStruct::EXPAND_CK_ID parents);
void proc_pLocal(CKParameterLocal* cache, Database::DocumentDatabase* mDb, DataStruct::EXPAND_CK_ID parents, BOOL is_setting);
void proc_pOper(CKContext* ctx, CKParameterOperation* cache, Database::DocumentDatabase* mDb, DataStruct::EXPAND_CK_ID parents);
void proc_pAttr(CKContext* ctx, Database::DocumentDatabase* mDb, CKParameter* cache);
void IterateBehavior(CKContext* ctx, CKBehavior* bhv, Database::DocumentDatabase* mDb, DataStruct::EXPAND_CK_ID parents);
void IterateScript(CKContext* ctx, Database::DocumentDatabase* mDb);
void IterateArray(CKContext* ctx, Database::DocumentDatabase* mDb);
void DigParameterData(CKParameterLocal* pl, Database::DocumentDatabase* mDb, DataStruct::EXPAND_CK_ID parents);
void DataDictWritter(const char* field, long data, Database::DocumentDatabase* mDb, DataStruct::EXPAND_CK_ID parents);
void DataDictWritter(const char* field, float data, Database::DocumentDatabase* mDb, DataStruct::EXPAND_CK_ID parents);
void DataDictWritter(const char* field, const char* data, Database::DocumentDatabase* mDb, DataStruct::EXPAND_CK_ID parents);
}
}

View File

@ -1,568 +0,0 @@
#include "script_export.h"
//disable shit tip
#pragma warning(disable:26812)
// disable microsoft shitty macro to avoid build error
#undef GetClassName
#define changeSuffix(a) prefix[endIndex]='\0';strcat(prefix,a)
#define copyGuid(guid,str) sprintf(helper->_stringCache,"%d,%d",guid.d1,guid.d2);str=helper->_stringCache;
#define safeStringCopy(storage,str) storage=(str)?(str):"";
#pragma region inline func
void generate_pLink_in_pIn(CKContext* ctx, CKParameterIn* cache, DocumentDatabase* mDb, dbDocDataStructHelper* helper, EXPAND_CK_ID parents, EXPAND_CK_ID grandparents, int index, BOOL executedFromBB, BOOL isTarget) {
//WARNING: i only choose one between [DirectSource] and [SharedSource] bucause i don't find any pIn both have these two field
CKParameter* directSource = NULL;
CKObject* ds_Owner = NULL;
CKParameterIn* sharedSource = NULL;
CKBehavior* ss_Owner = NULL;
if (directSource = cache->GetDirectSource()) {
helper->_db_pLink->input = directSource->GetID();
if (directSource->GetClassID() == CKCID_PARAMETERLOCAL || directSource->GetClassID() == CKCID_PARAMETERVARIABLE) {
//pLocal
helper->_db_pLink->input_obj = directSource->GetID();
helper->_db_pLink->input_type = pLinkInputOutputType_PLOCAL;
helper->_db_pLink->input_is_bb = FALSE;
helper->_db_pLink->input_index = -1;
} else {
//WARNING: when GetClassID() return CKDataArray there are untested code
//pParam from bb pOut / pOper pOut / object Attribute / CKDataArray
ds_Owner = directSource->GetOwner();
switch (ds_Owner->GetClassID()) {
case CKCID_BEHAVIOR:
helper->_db_pLink->input_obj = ds_Owner->GetID();
helper->_db_pLink->input_type = pLinkInputOutputType_POUT;
helper->_db_pLink->input_is_bb = TRUE;
helper->_db_pLink->input_index = ((CKBehavior*)ds_Owner)->GetOutputParameterPosition((CKParameterOut*)directSource);
break;
case CKCID_PARAMETEROPERATION:
helper->_db_pLink->input_obj = ds_Owner->GetID();
helper->_db_pLink->input_type = pLinkInputOutputType_POUT;
helper->_db_pLink->input_is_bb = FALSE;
helper->_db_pLink->input_index = 0;
break;
case CKCID_DATAARRAY:
// dataarray, see as virtual bb pLocal shortcut
helper->_db_pLink->input_obj = directSource->GetID();
helper->_db_pLink->input_type = pLinkInputOutputType_PATTR;
helper->_db_pLink->input_is_bb = FALSE;
helper->_db_pLink->input_index = -1;
proc_pAttr(ctx, mDb, helper, directSource);
break;
default:
//normal object, see as virtual bb pLocal shortcut
helper->_db_pLink->input_obj = directSource->GetID();
helper->_db_pLink->input_type = pLinkInputOutputType_PATTR;
helper->_db_pLink->input_is_bb = FALSE;
helper->_db_pLink->input_index = -1;
proc_pAttr(ctx, mDb, helper, directSource);
break;
}
}
}
if (sharedSource = cache->GetSharedSource()) {
//pIn from BB
helper->_db_pLink->input = sharedSource->GetID();
ss_Owner = (CKBehavior*)sharedSource->GetOwner();
helper->_db_pLink->input_obj = ss_Owner->GetID();
if (ss_Owner->IsUsingTarget() && (ss_Owner->GetTargetParameter() == sharedSource)) {
//pTarget
helper->_db_pLink->input_type = pLinkInputOutputType_PTARGET;
helper->_db_pLink->input_is_bb = TRUE;
helper->_db_pLink->input_index = -1;
} else {
//pIn
helper->_db_pLink->input_type = pLinkInputOutputType_PIN;
helper->_db_pLink->input_is_bb = TRUE;
helper->_db_pLink->input_index = ss_Owner->GetInputParameterPosition(sharedSource);
}
}
if (sharedSource != NULL || directSource != NULL) {
helper->_db_pLink->output = cache->GetID();
helper->_db_pLink->output_obj = parents;
helper->_db_pLink->output_type = isTarget ? pLinkInputOutputType_PTARGET : pLinkInputOutputType_PIN;
helper->_db_pLink->output_is_bb = executedFromBB;
helper->_db_pLink->output_index = index;
helper->_db_pLink->belong_to = grandparents;
mDb->write_script_pLink(helper->_db_pLink);
}
}
void proc_pTarget(CKContext* ctx, CKParameterIn* cache, DocumentDatabase* mDb, dbDocDataStructHelper* helper, EXPAND_CK_ID parents, EXPAND_CK_ID grandparents) {
helper->_db_pTarget->thisobj = cache->GetID();
helper->_db_pTarget->name = cache->GetName();
helper->_db_pTarget->type = helper->_parameterManager->ParameterTypeToName(cache->GetType());
copyGuid(cache->GetGUID(), helper->_db_pTarget->type_guid);
helper->_db_pTarget->belong_to = parents;
helper->_db_pTarget->direct_source = cache->GetDirectSource() ? cache->GetDirectSource()->GetID() : -1;
helper->_db_pTarget->shared_source = cache->GetSharedSource() ? cache->GetSharedSource()->GetID() : -1;
mDb->write_script_pTarget(helper->_db_pTarget);
//judge whether expoer parameter and write SSMaterializerDatabase
if (((CKBehavior*)ctx->GetObject(grandparents))->GetInputParameterPosition(cache) != -1) {
helper->_db_eLink->export_obj = cache->GetID();
helper->_db_eLink->internal_obj = parents;
helper->_db_eLink->is_in = TRUE;
helper->_db_eLink->index = -1;
helper->_db_eLink->belong_to = grandparents;
mDb->write_script_eLink(helper->_db_eLink);
return;
}
//=========try generate pLink
generate_pLink_in_pIn(ctx, cache, mDb, helper, parents, grandparents, -1, TRUE, TRUE);
}
void proc_pIn(CKContext* ctx, CKParameterIn* cache, DocumentDatabase* mDb, dbDocDataStructHelper* helper, EXPAND_CK_ID parents, EXPAND_CK_ID grandparents, int index, BOOL executedFromBB) {
helper->_db_pIn->thisobj = cache->GetID();
helper->_db_pIn->index = index;
helper->_db_pIn->name = cache->GetName();
CKParameterType vaildTypeChecker = cache->GetType();
if (vaildTypeChecker != -1) helper->_db_pIn->type = helper->_parameterManager->ParameterTypeToName(cache->GetType()); //known types
else helper->_db_pIn->type = "!!UNKNOW TYPE!!"; //unknow type
copyGuid(cache->GetGUID(), helper->_db_pIn->type_guid);
helper->_db_pIn->belong_to = parents;
helper->_db_pIn->direct_source = cache->GetDirectSource() ? cache->GetDirectSource()->GetID() : -1;
helper->_db_pIn->shared_source = cache->GetSharedSource() ? cache->GetSharedSource()->GetID() : -1;
mDb->write_script_pIn(helper->_db_pIn);
//judge whether expoer parameter and write SSMaterializerDatabase
if (((CKBehavior*)ctx->GetObject(grandparents))->GetInputParameterPosition(cache) != -1) {
helper->_db_eLink->export_obj = cache->GetID();
helper->_db_eLink->internal_obj = parents;
helper->_db_eLink->is_in = TRUE;
helper->_db_eLink->index = index;
helper->_db_eLink->belong_to = grandparents;
mDb->write_script_eLink(helper->_db_eLink);
return;
}
//=========try generate pLink
generate_pLink_in_pIn(ctx, cache, mDb, helper, parents, grandparents, index, executedFromBB, FALSE);
}
void proc_pOut(CKContext* ctx, CKParameterOut* cache, DocumentDatabase* mDb, dbDocDataStructHelper* helper, EXPAND_CK_ID parents, EXPAND_CK_ID grandparents, int index, BOOL executedFromBB) {
helper->_db_pOut->thisobj = cache->GetID();
helper->_db_pOut->index = index;
helper->_db_pOut->name = cache->GetName();
CKParameterType vaildTypeChecker = cache->GetType();
if (vaildTypeChecker != -1) helper->_db_pOut->type = helper->_parameterManager->ParameterTypeToName(cache->GetType()); //known types
else helper->_db_pOut->type = "!!UNKNOW TYPE!!"; //unknow type
copyGuid(cache->GetGUID(), helper->_db_pOut->type_guid);
helper->_db_pOut->belong_to = parents;
mDb->write_script_pOut(helper->_db_pOut);
//judge whether expoer parameter and write SSMaterializerDatabase
if (((CKBehavior*)ctx->GetObject(grandparents))->GetOutputParameterPosition(cache) != -1) {
helper->_db_eLink->export_obj = cache->GetID();
helper->_db_eLink->internal_obj = parents;
helper->_db_eLink->is_in = FALSE;
helper->_db_eLink->index = index;
helper->_db_eLink->belong_to = grandparents;
mDb->write_script_eLink(helper->_db_eLink);
return;
}
//=========try generate pLink
CKParameter* cache_Dest = NULL;
CKObject* cache_DestOwner = NULL;
for (int j = 0, jCount = cache->GetDestinationCount(); j < jCount; j++) {
cache_Dest = cache->GetDestination(j);
helper->_db_pLink->input = cache->GetID();
helper->_db_pLink->input_obj = parents;
helper->_db_pLink->input_type = pLinkInputOutputType_POUT;
helper->_db_pLink->input_is_bb = executedFromBB;
helper->_db_pLink->input_index = index;
helper->_db_pLink->output = cache_Dest->GetID();
if (cache_Dest->GetClassID() == CKCID_PARAMETERLOCAL) {
//pLocal
helper->_db_pLink->output_obj = cache_Dest->GetID();
helper->_db_pLink->output_type = pLinkInputOutputType_PLOCAL;
helper->_db_pLink->output_is_bb = FALSE;
helper->_db_pLink->output_index = -1;
} else {
//pOut, it must belong to a BB
cache_DestOwner = cache_Dest->GetOwner();
helper->_db_pLink->output_obj = cache_DestOwner->GetID();
helper->_db_pLink->output_type = pLinkInputOutputType_POUT;
helper->_db_pLink->output_is_bb = TRUE;
helper->_db_pLink->output_index = ((CKBehavior*)cache_DestOwner)->GetOutputParameterPosition((CKParameterOut*)cache_Dest);
}
helper->_db_pLink->belong_to = grandparents;
mDb->write_script_pLink(helper->_db_pLink);
}
}
void proc_bIn(CKBehaviorIO* cache, DocumentDatabase* mDb, dbDocDataStructHelper* helper, EXPAND_CK_ID parents, int index) {
helper->_db_bIn->thisobj = cache->GetID();
helper->_db_bIn->index = index;
helper->_db_bIn->name = cache->GetName();
helper->_db_bIn->belong_to = parents;
mDb->write_script_bIn(helper->_db_bIn);
}
void proc_bOut(CKBehaviorIO* cache, DocumentDatabase* mDb, dbDocDataStructHelper* helper, EXPAND_CK_ID parents, int index) {
helper->_db_bOut->thisobj = cache->GetID();
helper->_db_bOut->index = index;
helper->_db_bOut->name = cache->GetName();
helper->_db_bOut->belong_to = parents;
mDb->write_script_bOut(helper->_db_bOut);
}
void proc_bLink(CKBehaviorLink* cache, DocumentDatabase* mDb, dbDocDataStructHelper* helper, EXPAND_CK_ID parents) {
CKBehaviorIO* io = cache->GetInBehaviorIO();
CKBehavior* beh = io->GetOwner();
helper->_db_bLink->input = io->GetID();
helper->_db_bLink->input_obj = beh->GetID();
helper->_db_bLink->input_type = (io->GetType() == CK_BEHAVIORIO_IN ? bLinkInputOutputType_INPUT : bLinkInputOutputType_OUTPUT);
helper->_db_bLink->input_index = (io->GetType() == CK_BEHAVIORIO_IN ? io->GetOwner()->GetInputPosition(io) : io->GetOwner()->GetOutputPosition(io));
io = cache->GetOutBehaviorIO();
beh = io->GetOwner();
helper->_db_bLink->output = io->GetID();
helper->_db_bLink->output_obj = beh->GetID();
helper->_db_bLink->output_type = (io->GetType() == CK_BEHAVIORIO_IN ? bLinkInputOutputType_INPUT : bLinkInputOutputType_OUTPUT);
helper->_db_bLink->output_index = (io->GetType() == CK_BEHAVIORIO_IN ? io->GetOwner()->GetInputPosition(io) : io->GetOwner()->GetOutputPosition(io));
helper->_db_bLink->delay = cache->GetActivationDelay();
helper->_db_bLink->belong_to = parents;
mDb->write_script_bLink(helper->_db_bLink);
}
void proc_pLocal(CKParameterLocal* cache, DocumentDatabase* mDb, dbDocDataStructHelper* helper, EXPAND_CK_ID parents, BOOL is_setting) {
helper->_db_pLocal->thisobj = cache->GetID();
helper->_db_pLocal->name = cache->GetName() ? cache->GetName() : "";
CKParameterType vaildTypeChecker = cache->GetType();
if (vaildTypeChecker != -1) helper->_db_pLocal->type = helper->_parameterManager->ParameterTypeToName(cache->GetType()); //known types
else helper->_db_pLocal->type = "!!UNKNOW TYPE!!"; //unknow type
copyGuid(cache->GetGUID(), helper->_db_pLocal->type_guid);
helper->_db_pLocal->is_setting = is_setting;
helper->_db_pLocal->belong_to = parents;
mDb->write_script_pLocal(helper->_db_pLocal);
//export plocal metadata
DigParameterData(cache, mDb, helper, cache->GetID());
}
void proc_pOper(CKContext* ctx, CKParameterOperation* cache, DocumentDatabase* mDb, dbDocDataStructHelper* helper, EXPAND_CK_ID parents) {
helper->_db_pOper->thisobj = cache->GetID();
helper->_db_pOper->op = helper->_parameterManager->OperationGuidToName(cache->GetOperationGuid());
copyGuid(cache->GetOperationGuid(), helper->_db_pOper->op_guid);
helper->_db_pOper->belong_to = parents;
mDb->write_script_pOper(helper->_db_pOper);
//export 2 input param and 1 output param
proc_pIn(ctx, cache->GetInParameter1(), mDb, helper, cache->GetID(), parents, 0, FALSE);
proc_pIn(ctx, cache->GetInParameter2(), mDb, helper, cache->GetID(), parents, 1, FALSE);
proc_pOut(ctx, cache->GetOutParameter(), mDb, helper, cache->GetID(), parents, 0, FALSE);
}
void proc_pAttr(CKContext* ctx, DocumentDatabase* mDb, dbDocDataStructHelper* helper, CKParameter* cache) {
//write self first to detect conflict
helper->_db_pAttr->thisobj = cache->GetID();
safeStringCopy(helper->_db_pAttr->name, cache->GetName());
CKParameterType vaildTypeChecker = cache->GetType();
if (vaildTypeChecker != -1) helper->_db_pAttr->type = helper->_parameterManager->ParameterTypeToName(cache->GetType()); //known types
else helper->_db_pAttr->type = "!!UNKNOW TYPE!!"; //unknow type
copyGuid(cache->GetGUID(), helper->_db_pAttr->type_guid);
BOOL already_exist = FALSE;
mDb->write_script_pAttr(helper->_db_pAttr, &already_exist);
if (!already_exist) {
//not duplicated, continue write property
CKObject* host = cache->GetOwner();
helper_pDataExport("attr.host_id", (long)host->GetID(), mDb, helper, cache->GetID());
helper_pDataExport("attr.host_name", host->GetName(), mDb, helper, cache->GetID());
}
}
//============================helper for pLocal data export
void helper_pDataExport(const char* field, const char* data, DocumentDatabase* mDb, dbDocDataStructHelper* helper, EXPAND_CK_ID parents) {
helper->_db_pData->field = field;
helper->_db_pData->data = data;
helper->_db_pData->belong_to = parents;
mDb->write_pData(helper->_db_pData);
}
void helper_pDataExport(const char* field, float data, DocumentDatabase* mDb, dbDocDataStructHelper* helper, EXPAND_CK_ID parents) {
char str[32];
sprintf(str, "%f", data);
helper_pDataExport(field, str, mDb, helper, parents);
}
void helper_pDataExport(const char* field, long data, DocumentDatabase* mDb, dbDocDataStructHelper* helper, EXPAND_CK_ID parents) {
char str[32];
ltoa(data, str, 10);
helper_pDataExport(field, str, mDb, helper, parents);
}
#pragma endregion
#pragma region normal func
void IterateScript(CKContext* ctx, DocumentDatabase* mDb, dbDocDataStructHelper* helper) {
CKBeObject* beobj = NULL;
CKBehavior* beh = NULL;
XObjectPointerArray objArray = ctx->GetObjectListByType(CKCID_BEOBJECT, TRUE);
int len = objArray.Size();
int scriptLen = 0;
for (int i = 0; i < len; i++) {
beobj = (CKBeObject*)objArray.GetObjectA(i);
if ((scriptLen = beobj->GetScriptCount()) == 0) continue;
for (int j = 0; j < scriptLen; j++) {
//write script table
beh = beobj->GetScript(j);
helper->_db_script->thisobj = beobj->GetID();
helper->_db_script->host_name = beobj->GetName();
helper->_db_script->index = j;
helper->_db_script->behavior = beh->GetID();
mDb->write_script(helper->_db_script);
//iterate script
IterateBehavior(ctx, beh, mDb, helper, -1);
}
}
}
void IterateBehavior(CKContext* ctx, CKBehavior* bhv, DocumentDatabase* mDb, dbDocDataStructHelper* helper, EXPAND_CK_ID parents) {
//write self data
helper->_db_behavior->thisobj = bhv->GetID();
helper->_db_behavior->name = bhv->GetName();
helper->_db_behavior->type = bhv->GetType();
helper->_db_behavior->proto_name = bhv->GetPrototypeName() ? bhv->GetPrototypeName() : "";
copyGuid(bhv->GetPrototypeGuid(), helper->_db_behavior->proto_guid);
helper->_db_behavior->flags = bhv->GetFlags();
helper->_db_behavior->priority = bhv->GetPriority();
helper->_db_behavior->version = bhv->GetVersion();
helper->_db_behavior->parent = parents;
sprintf(helper->_stringCache, "%d,%d,%d,%d,%d",
(bhv->IsUsingTarget() ? 1 : 0),
bhv->GetInputParameterCount(),
bhv->GetOutputParameterCount(),
bhv->GetInputCount(),
bhv->GetOutputCount());
helper->_db_behavior->pin_count = helper->_stringCache;
mDb->write_script_behavior(helper->_db_behavior);
//write target
if (bhv->IsUsingTarget())
proc_pTarget(ctx, bhv->GetTargetParameter(), mDb, helper, bhv->GetID(), parents);
int count = 0, i = 0;
//pIn
for (i = 0, count = bhv->GetInputParameterCount(); i < count; i++)
proc_pIn(ctx, bhv->GetInputParameter(i), mDb, helper, bhv->GetID(), parents, i, TRUE);
//pOut
for (i = 0, count = bhv->GetOutputParameterCount(); i < count; i++)
proc_pOut(ctx, bhv->GetOutputParameter(i), mDb, helper, bhv->GetID(), parents, i, TRUE);
//bIn
for (i = 0, count = bhv->GetInputCount(); i < count; i++)
proc_bIn(bhv->GetInput(i), mDb, helper, bhv->GetID(), i);
//bOut
for (i = 0, count = bhv->GetOutputCount(); i < count; i++)
proc_bOut(bhv->GetOutput(i), mDb, helper, bhv->GetID(), i);
//bLink
for (i = 0, count = bhv->GetSubBehaviorLinkCount(); i < count; i++)
proc_bLink(bhv->GetSubBehaviorLink(i), mDb, helper, bhv->GetID());
//pLocal
for (i = 0, count = bhv->GetLocalParameterCount(); i < count; i++)
proc_pLocal(bhv->GetLocalParameter(i), mDb, helper, bhv->GetID(),
bhv->IsLocalParameterSetting(i));
//pOper
for (i = 0, count = bhv->GetParameterOperationCount(); i < count; i++)
proc_pOper(ctx, bhv->GetParameterOperation(i), mDb, helper, bhv->GetID());
//iterate sub bb
for (i = 0, count = bhv->GetSubBehaviorCount(); i < count; i++)
IterateBehavior(ctx, bhv->GetSubBehavior(i), mDb, helper, bhv->GetID());
}
void DigParameterData(CKParameterLocal* p, DocumentDatabase* mDb, dbDocDataStructHelper* helper, EXPAND_CK_ID parents) {
CKGUID t = p->GetGUID();
BOOL unknowType = FALSE;
if (t.d1 & t.d2) unknowType = TRUE;
//nothing
if (t == CKPGUID_NONE) return;
if (p->GetParameterClassID() && p->GetValueObject(false)) {
helper_pDataExport("id", (long)p->GetValueObject(false)->GetID(), mDb, helper, parents);
helper_pDataExport("name", p->GetValueObject(false)->GetName(), mDb, helper, parents);
CK_CLASSID none_classid = p->GetValueObject(false)->GetClassID();
CKParameterType none_type = helper->_parameterManager->ClassIDToType(none_classid);
helper_pDataExport("type", helper->_parameterManager->ParameterTypeToName(none_type), mDb, helper, parents);
return;
}
//float
if (t == CKPGUID_FLOAT || t == CKPGUID_ANGLE || t == CKPGUID_PERCENTAGE || t == CKPGUID_TIME
#if defined(VIRTOOLS_50) || defined(VIRTOOLS_40) || defined(VIRTOOLS_35)
|| t == CKPGUID_FLOATSLIDER
#endif
) {
helper_pDataExport("float-data", *(float*)(p->GetReadDataPtr(false)), mDb, helper, parents);
return;
}
//int
if (t == CKPGUID_INT || t == CKPGUID_KEY || t == CKPGUID_BOOL || t == CKPGUID_ID || t == CKPGUID_POINTER
|| t == CKPGUID_MESSAGE || t == CKPGUID_ATTRIBUTE || t == CKPGUID_BLENDMODE || t == CKPGUID_FILTERMODE
|| t == CKPGUID_BLENDFACTOR || t == CKPGUID_FILLMODE || t == CKPGUID_LITMODE || t == CKPGUID_SHADEMODE
|| t == CKPGUID_ADDRESSMODE || t == CKPGUID_WRAPMODE || t == CKPGUID_3DSPRITEMODE || t == CKPGUID_FOGMODE
|| t == CKPGUID_LIGHTTYPE || t == CKPGUID_SPRITEALIGN || t == CKPGUID_DIRECTION || t == CKPGUID_LAYERTYPE
|| t == CKPGUID_COMPOPERATOR || t == CKPGUID_BINARYOPERATOR || t == CKPGUID_SETOPERATOR
|| t == CKPGUID_OBSTACLEPRECISION || t == CKPGUID_OBSTACLEPRECISIONBEH) {
helper_pDataExport("int-data", (long)(*(int*)(p->GetReadDataPtr(false))), mDb, helper, parents);
return;
}
if (t == CKPGUID_VECTOR) {
VxVector vec;
memcpy(&vec, p->GetReadDataPtr(false), sizeof(vec));
helper_pDataExport("vector.x", vec.x, mDb, helper, parents);
helper_pDataExport("vector.y", vec.y, mDb, helper, parents);
helper_pDataExport("vector.z", vec.z, mDb, helper, parents);
return;
}
if (t == CKPGUID_2DVECTOR) {
Vx2DVector vec;
memcpy(&vec, p->GetReadDataPtr(false), sizeof(vec));
helper_pDataExport("2dvector.x", vec.x, mDb, helper, parents);
helper_pDataExport("2dvector.y", vec.y, mDb, helper, parents);
return;
}
if (t == CKPGUID_MATRIX) {
VxMatrix mat;
char position[128];
memcpy(&mat, p->GetReadDataPtr(false), sizeof(mat));
for (int i = 0; i < 4; ++i) {
for (int j = 0; j < 4; ++j) {
sprintf(position, "matrix[%d][%d]", i, j);
helper_pDataExport(position, mat[i][j], mDb, helper, parents);
}
}
return;
}
if (t == CKPGUID_COLOR) {
VxColor col;
memcpy(&col, p->GetReadDataPtr(false), sizeof(col));
helper_pDataExport("color.r", col.r, mDb, helper, parents);
helper_pDataExport("color.g", col.g, mDb, helper, parents);
helper_pDataExport("color.b", col.b, mDb, helper, parents);
helper_pDataExport("color.a", col.a, mDb, helper, parents);
return;
}
if (t == CKPGUID_2DCURVE) {
//CK2dCurve* c;
CK2dCurve* c = (CK2dCurve*)p->GetReadDataPtr(false);
char prefix[128];
int endIndex = 0;
//memcpy(&c, p->GetReadDataPtr(false), sizeof(c));
for (int i = 0, cc = c->GetControlPointCount(); i < cc; ++i) {
sprintf(prefix, "2dcurve.control_point[%d]", i);
endIndex = strlen(prefix);
changeSuffix(".pos.x");
helper_pDataExport(prefix, c->GetControlPoint(i)->GetPosition().x, mDb, helper, parents);
changeSuffix(".pos.y");
helper_pDataExport(prefix, c->GetControlPoint(i)->GetPosition().y, mDb, helper, parents);
changeSuffix(".islinear");
helper_pDataExport(prefix, (long)c->GetControlPoint(i)->IsLinear(), mDb, helper, parents);
if (c->GetControlPoint(i)->IsTCB()) {
changeSuffix(".bias");
helper_pDataExport(prefix, c->GetControlPoint(i)->GetBias(), mDb, helper, parents);
changeSuffix(".continuity");
helper_pDataExport(prefix, c->GetControlPoint(i)->GetContinuity(), mDb, helper, parents);
changeSuffix(".tension");
helper_pDataExport(prefix, c->GetControlPoint(i)->GetTension(), mDb, helper, parents);
} else {
changeSuffix(".intangent.x");
helper_pDataExport(prefix, c->GetControlPoint(i)->GetInTangent().x, mDb, helper, parents);
changeSuffix(".intangent.y");
helper_pDataExport(prefix, c->GetControlPoint(i)->GetInTangent().y, mDb, helper, parents);
changeSuffix(".outtangent.x");
helper_pDataExport(prefix, c->GetControlPoint(i)->GetOutTangent().x, mDb, helper, parents);
changeSuffix(".outtangent.y");
helper_pDataExport(prefix, c->GetControlPoint(i)->GetOutTangent().y, mDb, helper, parents);
}
}
return;
}
if (t == CKPGUID_STRING) {
char* cptr = (char*)p->GetReadDataPtr(false);
int cc = p->GetDataSize();
helper->_db_pData->data.clear();
helper->_db_pData->data.insert(0, cptr, 0, cc);
helper->_db_pData->field = "str";
helper->_db_pData->belong_to = p->GetID();
mDb->write_pData(helper->_db_pData);
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 defined(VIRTOOLS_50) || defined(VIRTOOLS_40) || defined(VIRTOOLS_35)
|| t == CKPGUID_SHADER || t == CKPGUID_TECHNIQUE || t == CKPGUID_PASS
#endif
) {
//dump data
unsigned char* cptr = (unsigned char*)p->GetReadDataPtr(false);
char temp[8];
int cc = 0, rcc = 0, pos = 0;
rcc = cc = p->GetDataSize();
if (rcc > 1024) rcc = 1024;
helper->_db_pData->data.clear();
for (int i = 0; i < rcc; i++) {
sprintf(temp, "0x%02X", cptr[i]);
helper->_db_pData->data += temp;
if (i != rcc - 1)
helper->_db_pData->data += ", ";
}
if (rcc == cc)
helper->_db_pData->field = "dump.data";
else
helper->_db_pData->field = "dump.partial_data";
helper->_db_pData->belong_to = p->GetID();
mDb->write_pData(helper->_db_pData);
//dump data length
helper_pDataExport("dump.length", (long)cc, mDb, helper, parents);
return;
}
}
#pragma endregion

View File

@ -1,26 +0,0 @@
#if !defined(_YYCDLL_SCRIPT_EXPORT_H__IMPORTED_)
#define _YYCDLL_SCRIPT_EXPORT_H__IMPORTED_
#include "stdafx.h"
#include "database.h"
void generate_pLink_in_pIn(CKContext* ctx, CKParameterIn* cache, DocumentDatabase* mDb, dbDocDataStructHelper* helper, EXPAND_CK_ID parents, EXPAND_CK_ID grandparents, int index, BOOL executedFromBB, BOOL isTarget);
void proc_pTarget(CKContext* ctx, CKParameterIn* cache, DocumentDatabase* mDb, dbDocDataStructHelper* helper, EXPAND_CK_ID parents, EXPAND_CK_ID grandparents);
void proc_pIn(CKContext* ctx, CKParameterIn* cache, DocumentDatabase* mDb, dbDocDataStructHelper* helper, EXPAND_CK_ID parents, EXPAND_CK_ID grandparents, int index, BOOL executedFromBB);
void proc_pOut(CKContext* ctx, CKParameterOut* cache, DocumentDatabase* mDb, dbDocDataStructHelper* helper, EXPAND_CK_ID parents, EXPAND_CK_ID grandparents, int index, BOOL executedFromBB);
void proc_bIn(CKBehaviorIO* cache, DocumentDatabase* mDb, dbDocDataStructHelper* helper, EXPAND_CK_ID parents, int index);
void proc_bOut(CKBehaviorIO* cache, DocumentDatabase* mDb, dbDocDataStructHelper* helper, EXPAND_CK_ID parents, int index);
void proc_bLink(CKBehaviorLink* cache, DocumentDatabase* mDb, dbDocDataStructHelper* helper, EXPAND_CK_ID parents);
void proc_pLocal(CKParameterLocal* cache, DocumentDatabase* mDb, dbDocDataStructHelper* helper, EXPAND_CK_ID parents, BOOL is_setting);
void proc_pOper(CKContext* ctx, CKParameterOperation* cache, DocumentDatabase* mDb, dbDocDataStructHelper* helper, EXPAND_CK_ID parents);
void proc_pAttr(CKContext* ctx, DocumentDatabase* mDb, dbDocDataStructHelper* helper, CKParameter* cache);
void helper_pDataExport(const char* field, long data, DocumentDatabase* mDb, dbDocDataStructHelper* helper, EXPAND_CK_ID parents);
void helper_pDataExport(const char* field, float data, DocumentDatabase* mDb, dbDocDataStructHelper* helper, EXPAND_CK_ID parents);
void helper_pDataExport(const char* field, const char* data, DocumentDatabase* mDb, dbDocDataStructHelper* helper, EXPAND_CK_ID parents);
void IterateBehavior(CKContext* ctx, CKBehavior* bhv, DocumentDatabase* mDb, dbDocDataStructHelper* helper, EXPAND_CK_ID parents);
void IterateScript(CKContext* ctx, DocumentDatabase* mDb, dbDocDataStructHelper* helper);
void DigParameterData(CKParameterLocal* pl, DocumentDatabase* mDb, dbDocDataStructHelper* helper, EXPAND_CK_ID parents);
#endif

View File

@ -0,0 +1,31 @@
#include "string_helper.hpp"
namespace SSMaterializer {
namespace Utils {
void StdstringPrintf(std::string& strl, const char* format, ...) {
va_list argptr;
va_start(argptr, format);
StdstringVPrintf(strl, format, argptr);
va_end(argptr);
}
void StdstringVPrintf(std::string& strl, const char* format, va_list argptr) {
int count = _vsnprintf(NULL, 0, format, argptr);
count++;
strl.resize(count);
strl[count - 1] = '\0';
int write_result = _vsnprintf((char*)strl.data(), count, format, argptr);
if (write_result < 0 || write_result >= count) {
//something goes wrong
strl.clear();
}
}
void CopyGUID(std::string& strl, CKGUID& guid) {
StdstringPrintf(strl, "0x%08x, 0x%08x", guid.d1, guid.d2);
}
}
}

View File

@ -1 +1,14 @@
#pragma once #pragma once
#include "stdafx.h"
#include <string>
namespace SSMaterializer {
namespace Utils {
void StdstringPrintf(std::string& strl, const char* format, ...);
void StdstringVPrintf(std::string& strl, const char* format, va_list argptr);
void CopyGUID(std::string& strl, CKGUID& guid);
}
}