fix fatal error of eLink/pLink generate algo

This commit is contained in:
yyc12345 2020-04-16 19:22:38 +08:00
parent 849e62886a
commit 6eee3e8f6d
5 changed files with 84 additions and 45 deletions

View File

@ -15,6 +15,7 @@ void dbDataStructHelper::init(CKParameterManager* paramManager) {
_db_pLink = new db_pLink();
_db_pLocalData = new db_pLocalData();
_db_pOper = new db_pOper();
_db_eLink = new db_eLink();
_parameterManager = paramManager;
}
@ -31,6 +32,7 @@ void dbDataStructHelper::dispose() {
delete _db_pLink;
delete _db_pLocal;
delete _db_pOper;
delete _db_eLink;
_parameterManager = NULL;
}
@ -101,6 +103,10 @@ void database::open(const char* file) {
"CREATE TABLE pOper([thisobj] INTEGER, [op] TEXT, [op_guid] TEXT, [belong_to] INTEGER);",
NULL, NULL, &errmsg);
if (result != SQLITE_OK) goto fail;
result = sqlite3_exec(db,
"CREATE TABLE eLink([export_obj] INTEGER, [internal_obj] INTEGER, [is_in] INTEGER, [index] INTEGER, [belong_to] INTEGER);",
NULL, NULL, &errmsg);
if (result != SQLITE_OK) goto fail;
//start job
@ -317,5 +323,17 @@ void database::write_pOper(db_pOper* data) {
sqlite3_exec(db, commandStr, NULL, NULL, &errmsg);
}
void database::write_eLink(db_eLink* data) {
if (db == NULL) return;
sprintf(commandStr, "INSERT INTO eLink VALUES (%d, %d, %d, %d, %d);",
data->export_obj,
data->internal_obj,
data->is_in,
data->index,
data->belong_to);
sqlite3_exec(db, commandStr, NULL, NULL, &errmsg);
}
#pragma endregion

View File

@ -131,6 +131,14 @@ typedef struct {
EXPAND_CK_ID belong_to;
}db_pOper;
typedef struct {
EXPAND_CK_ID export_obj;
EXPAND_CK_ID internal_obj;
BOOL is_in;
int index;
EXPAND_CK_ID belong_to;
}db_eLink;
#pragma endregion
class dbDataStructHelper {
@ -151,6 +159,7 @@ class dbDataStructHelper {
db_pLink* _db_pLink;
db_pLocalData* _db_pLocalData;
db_pOper* _db_pOper;
db_eLink* _db_eLink;
};
class database {
@ -170,6 +179,7 @@ class database {
void write_pLink(db_pLink* data);
void write_pLocalData(db_pLocalData* data);
void write_pOper(db_pOper* data);
void write_eLink(db_eLink* data);
private:
sqlite3* db;

View File

@ -6,7 +6,7 @@
#pragma region inline func
inline void generate_pLink_in_pIn(CKParameterIn* cache, database* db, dbDataStructHelper* helper, EXPAND_CK_ID parents, EXPAND_CK_ID grandparents, int index, BOOL executedFromBB, BOOL isTarget) {
inline void generate_pLink_in_pIn(CKContext* ctx, CKParameterIn* cache, database* db, dbDataStructHelper* 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;
@ -71,7 +71,7 @@ inline void generate_pLink_in_pIn(CKParameterIn* cache, database* db, dbDataStru
}
}
inline void proc_pTarget(CKParameterIn* cache, database* db, dbDataStructHelper* helper, EXPAND_CK_ID parents, EXPAND_CK_ID grandparents) {
inline void proc_pTarget(CKContext* ctx, CKParameterIn* cache, database* db, dbDataStructHelper* helper, EXPAND_CK_ID parents, EXPAND_CK_ID grandparents) {
helper->_db_pTarget->thisobj = cache->GetID();
strcpy(helper->_db_pTarget->name, cache->GetName());
strcpy(helper->_db_pTarget->type, helper->_parameterManager->ParameterTypeToName(cache->GetType()));
@ -84,10 +84,10 @@ inline void proc_pTarget(CKParameterIn* cache, database* db, dbDataStructHelper*
db->write_pTarget(helper->_db_pTarget);
//=========try generate pLink
generate_pLink_in_pIn(cache, db, helper, parents, grandparents, -1, TRUE, TRUE);
generate_pLink_in_pIn(ctx, cache, db, helper, parents, grandparents, -1, TRUE, TRUE);
}
inline void proc_pIn(CKParameterIn* cache, database* db, dbDataStructHelper* helper, EXPAND_CK_ID parents, EXPAND_CK_ID grandparents, int index, BOOL executedFromBB) {
inline void proc_pIn(CKContext* ctx, CKParameterIn* cache, database* db, dbDataStructHelper* helper, EXPAND_CK_ID parents, EXPAND_CK_ID grandparents, int index, BOOL executedFromBB) {
helper->_db_pIn->thisobj = cache->GetID();
helper->_db_pIn->index = index;
strcpy(helper->_db_pIn->name, cache->GetName());
@ -102,12 +102,24 @@ inline void proc_pIn(CKParameterIn* cache, database* db, dbDataStructHelper* hel
db->write_pIn(helper->_db_pIn);
//judge whether expoer parameter and write database
if (((CKBehavior*)ctx->GetObjectA(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;
db->write_eLink(helper->_db_eLink);
return;
}
//=========try generate pLink
generate_pLink_in_pIn(cache, db, helper, parents, grandparents, index, executedFromBB, FALSE);
generate_pLink_in_pIn(ctx, cache, db, helper, parents, grandparents, index, executedFromBB, FALSE);
}
inline void proc_pOut(CKParameterOut* cache, database* db, dbDataStructHelper* helper, EXPAND_CK_ID parents, EXPAND_CK_ID grandparents, int index, BOOL executedFromBB) {
inline void proc_pOut(CKContext* ctx, CKParameterOut* cache, database* db, dbDataStructHelper* helper, EXPAND_CK_ID parents, EXPAND_CK_ID grandparents, int index, BOOL executedFromBB) {
helper->_db_pOut->thisobj = cache->GetID();
helper->_db_pOut->index = index;
strcpy(helper->_db_pOut->name, cache->GetName());
@ -120,6 +132,18 @@ inline void proc_pOut(CKParameterOut* cache, database* db, dbDataStructHelper* h
db->write_pOut(helper->_db_pOut);
//judge whether expoer parameter and write database
if (((CKBehavior*)ctx->GetObjectA(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;
db->write_eLink(helper->_db_eLink);
return;
}
//=========try generate pLink
CKParameter* cache_Dest = NULL;
CKObject* cache_DestOwner = NULL;
@ -212,7 +236,7 @@ inline void proc_pLocal(CKParameterLocal* cache, database* db, dbDataStructHelpe
IteratepLocalData(cache, db, helper, cache->GetID());
}
inline void proc_pOper(CKParameterOperation* cache, database* db, dbDataStructHelper* helper, EXPAND_CK_ID parents) {
inline void proc_pOper(CKContext* ctx, CKParameterOperation* cache, database* db, dbDataStructHelper* helper, EXPAND_CK_ID parents) {
helper->_db_pOper->thisobj = cache->GetID();
strcpy(helper->_db_pOper->op, helper->_parameterManager->OperationGuidToName(cache->GetOperationGuid()));
helper->_db_pOper->op_guid[0] = cache->GetOperationGuid().d1;
@ -222,9 +246,9 @@ inline void proc_pOper(CKParameterOperation* cache, database* db, dbDataStructHe
db->write_pOper(helper->_db_pOper);
//export 2 input param and 1 output param
proc_pIn(cache->GetInParameter1(), db, helper, cache->GetID(), parents, 0, FALSE);
proc_pIn(cache->GetInParameter2(), db, helper, cache->GetID(), parents, 1, FALSE);
proc_pOut(cache->GetOutParameter(), db, helper, cache->GetID(), parents, 0, FALSE);
proc_pIn(ctx, cache->GetInParameter1(), db, helper, cache->GetID(), parents, 0, FALSE);
proc_pIn(ctx, cache->GetInParameter2(), db, helper, cache->GetID(), parents, 1, FALSE);
proc_pOut(ctx, cache->GetOutParameter(), db, helper, cache->GetID(), parents, 0, FALSE);
}
@ -273,12 +297,12 @@ void IterateScript(CKContext* ctx, database* db, dbDataStructHelper* helper) {
db->write_CKScript(helper->_dbCKScript);
//iterate script
IterateBehavior(beh, db, helper, -1);
IterateBehavior(ctx, beh, db, helper, -1);
}
}
}
void IterateBehavior(CKBehavior* bhv, database* db, dbDataStructHelper* helper, EXPAND_CK_ID parents) {
void IterateBehavior(CKContext* ctx, CKBehavior* bhv, database* db, dbDataStructHelper* helper, EXPAND_CK_ID parents) {
//write self data
helper->_dbCKBehavior->thisobj = bhv->GetID();
strcpy(helper->_dbCKBehavior->name, bhv->GetName());
@ -300,15 +324,15 @@ void IterateBehavior(CKBehavior* bhv, database* db, dbDataStructHelper* helper,
//write target
if (bhv->IsUsingTarget())
proc_pTarget(bhv->GetTargetParameter(), db, helper, bhv->GetID(), parents);
proc_pTarget(ctx, bhv->GetTargetParameter(), db, helper, bhv->GetID(), parents);
int count = 0, i = 0;
//pIn
for (i = 0, count = bhv->GetInputParameterCount(); i < count; i++)
proc_pIn(bhv->GetInputParameter(i), db, helper, bhv->GetID(), parents, i, TRUE);
proc_pIn(ctx, bhv->GetInputParameter(i), db, helper, bhv->GetID(), parents, i, TRUE);
//pOut
for (i = 0, count = bhv->GetOutputParameterCount(); i < count; i++)
proc_pOut(bhv->GetOutputParameter(i), db, helper, bhv->GetID(), parents, i, TRUE);
proc_pOut(ctx, bhv->GetOutputParameter(i), db, helper, bhv->GetID(), parents, i, TRUE);
//bIn
for (i = 0, count = bhv->GetInputCount(); i < count; i++)
proc_bIn(bhv->GetInput(i), db, helper, bhv->GetID(), i);
@ -322,13 +346,13 @@ void IterateBehavior(CKBehavior* bhv, database* db, dbDataStructHelper* helper,
for (i = 0, count = bhv->GetLocalParameterCount(); i < count; i++)
proc_pLocal(bhv->GetLocalParameter(i), db, helper, bhv->GetID(),
bhv->IsLocalParameterSetting(i));
//bOper
//pOper
for (i = 0, count = bhv->GetParameterOperationCount(); i < count; i++)
proc_pOper(bhv->GetParameterOperation(i), db, helper, bhv->GetID());
proc_pOper(ctx, bhv->GetParameterOperation(i), db, helper, bhv->GetID());
//iterate sub bb
for (i = 0, count = bhv->GetSubBehaviorCount(); i < count; i++)
IterateBehavior(bhv->GetSubBehavior(i), db, helper, bhv->GetID());
IterateBehavior(ctx, bhv->GetSubBehavior(i), db, helper, bhv->GetID());
}
void IteratepLocalData(CKParameterLocal* p, database* db, dbDataStructHelper* helper, EXPAND_CK_ID parents) {

View File

@ -4,21 +4,21 @@
#include "stdafx.h"
#include "database.h"
inline void generate_pLink_in_pIn(CKParameterIn* cache, database* db, dbDataStructHelper* helper, EXPAND_CK_ID parents, EXPAND_CK_ID grandparents, int index, BOOL executedFromBB, BOOL isTarget);
inline void proc_pTarget(CKParameterIn* cache, database* db, dbDataStructHelper* helper, EXPAND_CK_ID parents, EXPAND_CK_ID grandparents);
inline void proc_pIn(CKParameterIn* cache, database* db, dbDataStructHelper* helper, EXPAND_CK_ID parents, EXPAND_CK_ID grandparents, int index, BOOL executedFromBB);
inline void proc_pOut(CKParameterOut* cache, database* db, dbDataStructHelper* helper, EXPAND_CK_ID parents, EXPAND_CK_ID grandparents, int index, BOOL executedFromBB);
inline void generate_pLink_in_pIn(CKContext* ctx, CKParameterIn* cache, database* db, dbDataStructHelper* helper, EXPAND_CK_ID parents, EXPAND_CK_ID grandparents, int index, BOOL executedFromBB, BOOL isTarget);
inline void proc_pTarget(CKContext* ctx, CKParameterIn* cache, database* db, dbDataStructHelper* helper, EXPAND_CK_ID parents, EXPAND_CK_ID grandparents);
inline void proc_pIn(CKContext* ctx, CKParameterIn* cache, database* db, dbDataStructHelper* helper, EXPAND_CK_ID parents, EXPAND_CK_ID grandparents, int index, BOOL executedFromBB);
inline void proc_pOut(CKContext* ctx, CKParameterOut* cache, database* db, dbDataStructHelper* helper, EXPAND_CK_ID parents, EXPAND_CK_ID grandparents, int index, BOOL executedFromBB);
inline void proc_bIn(CKBehaviorIO* cache, database* db, dbDataStructHelper* helper, EXPAND_CK_ID parents, int index);
inline void proc_bOut(CKBehaviorIO* cache, database* db, dbDataStructHelper* helper, EXPAND_CK_ID parents, int index);
inline void proc_bLink(CKBehaviorLink* cache, database* db, dbDataStructHelper* helper, EXPAND_CK_ID parents);
inline void proc_pLocal(CKParameterLocal* cache, database* db, dbDataStructHelper* helper, EXPAND_CK_ID parents, BOOL is_setting);
inline void proc_pOper(CKParameterOperation* cache, database* db, dbDataStructHelper* helper, EXPAND_CK_ID parents);
inline void proc_pOper(CKContext* ctx, CKParameterOperation* cache, database* db, dbDataStructHelper* helper, EXPAND_CK_ID parents);
inline void helper_pLocalDataExport(const char* field, long data, database* db, dbDataStructHelper* helper, EXPAND_CK_ID parents);
inline void helper_pLocalDataExport(const char* field, float data, database* db, dbDataStructHelper* helper, EXPAND_CK_ID parents);
inline void helper_pLocalDataExport(const char* field, const char* data, database* db, dbDataStructHelper* helper, EXPAND_CK_ID parents);
void IterateBehavior(CKBehavior* bhv, database* db, dbDataStructHelper* helper, EXPAND_CK_ID parents);
void IterateBehavior(CKContext* ctx, CKBehavior* bhv, database* db, dbDataStructHelper* helper, EXPAND_CK_ID parents);
void IterateScript(CKContext* ctx, database* db, dbDataStructHelper* helper);
void IteratepLocalData(CKParameterLocal* pl, database* db, dbDataStructHelper* helper, EXPAND_CK_ID parents);

View File

@ -399,9 +399,6 @@ def buildCell(exDb, deDb, target, currentGraphBlockCell):
createdShortcut = set()
exCur.execute("SELECT * FROM pLink WHERE [belong_to] == ?", (target,))
for i in exCur.fetchall():
# check export pIO.
if (((i[2] != target) and (i[0] in graphPIO)) or ((i[6] != target) and (i[1] in graphPIO))):
continue
# analyse 5 chancee one by one
if (i[7] == dcv.dbPLinkInputOutputType.PTARGET or i[7] == dcv.dbPLinkInputOutputType.PIN):
@ -570,23 +567,6 @@ def buildLink(exDb, deDb, target, currentGraphBlockCell, graphPIO):
# !! the same if framework in cell generator function !! SHARED
exCur.execute("SELECT * FROM pLink WHERE [belong_to] == ?", (target,))
for i in exCur.fetchall():
# check export pIO.
if (i[2] != target) and (i[0] in graphPIO):
# fuck export param, create a export link. in this if, i[0] is a pOut and was plugged into graph. it is start point
(x1, y1) = computLinkPTerminal(i[0], 0, -1, currentGraphBlockCell)
(x2, y2) = computLinkPTerminal(i[2], 1, i[5], currentGraphBlockCell)
deCur.execute("INSERT INTO link VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);",
(target, -2, i[0], i[0], target, i[2], 0, 1, -1, i[5], x1, y1, x2, y2))
continue
if (i[6] != target) and (i[1] in graphPIO):
# fuck export param, create a export link. in this if, i[1] is a pIn/pTarget and was plugged into graph. it is end point
(x1, y1) = computLinkPTerminal(i[1], 0, -1, currentGraphBlockCell)
(x2, y2) = computLinkPTerminal(i[6], 0, i[9], currentGraphBlockCell)
deCur.execute("INSERT INTO link VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);",
(target, -2, i[1], i[1], target, i[6], 0, 0, -1, i[9], x1, y1, x2, y2))
continue
# analyse 5 chancee one by one
if (i[7] == dcv.dbPLinkInputOutputType.PTARGET or i[7] == dcv.dbPLinkInputOutputType.PIN):
if (i[3] == dcv.dbPLinkInputOutputType.PLOCAL):
@ -629,6 +609,13 @@ def buildLink(exDb, deDb, target, currentGraphBlockCell, graphPIO):
deCur.execute("INSERT INTO link VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);",
(target, -1, i[0], i[1], i[2], i[6], 1, 1, i[5], i[9], x1, y1, x2, y2))
# eLink
exCur.execute("SELECT * FROM eLink WHERE [belong_to] == ?", (target,))
for i in exCur.fetchall():
(x1, y1) = computLinkPTerminal(i[0], 0, -1, currentGraphBlockCell)
(x2, y2) = computLinkPTerminal(i[1], 0 if i[2] == 1 else 1, i[3], currentGraphBlockCell)
deCur.execute("INSERT INTO link VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);",
(target, -2, i[0], i[0], target, i[1], 0, 0 if i[2] == 1 else 1, -1, i[3], x1, y1, x2, y2))
def computLinkBTerminal(obj, xtype, index, currentGraphBlockCell):
# index = -1 mean no offset, it will connect to graph io