Skip to content

Commit 57e3558

Browse files
committed
组件功能完善, 当组件没有某个部分的任何内容时,不创建该进程上的组件属性
kbengine#610
1 parent 91803be commit 57e3558

File tree

2 files changed

+56
-38
lines changed

2 files changed

+56
-38
lines changed

kbe/src/lib/entitydef/entity_component.cpp

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -697,16 +697,19 @@ bool EntityComponent::isSamePersistentType(PyObject* pyValue)
697697

698698
if (g_componentType == BASEAPP_TYPE)
699699
{
700-
PyObject* cellDataDict = PyObject_GetAttrString(owner(), "cellData");
701-
if (!cellDataDict)
700+
if (pPropertyDescription_->hasCell())
702701
{
703-
PyErr_Clear();
704-
}
705-
else
706-
{
707-
cellComponentPart = PyDict_GetItemString(cellDataDict, pPropertyDescription_->getName());
708-
Py_DECREF(cellDataDict);
709-
Py_INCREF(cellComponentPart);
702+
PyObject* cellDataDict = PyObject_GetAttrString(owner(), "cellData");
703+
if (!cellDataDict)
704+
{
705+
PyErr_Clear();
706+
}
707+
else
708+
{
709+
cellComponentPart = PyDict_GetItemString(cellDataDict, pPropertyDescription_->getName());
710+
Py_DECREF(cellDataDict);
711+
Py_INCREF(cellComponentPart);
712+
}
710713
}
711714

712715
if (componentType_ == BASEAPP_TYPE)
@@ -857,16 +860,19 @@ void EntityComponent::addPersistentToStream(MemoryStream* mstream, PyObject* pyV
857860

858861
if (g_componentType == BASEAPP_TYPE)
859862
{
860-
PyObject* cellDataDict = PyObject_GetAttrString(owner(), "cellData");
861-
if (!cellDataDict)
863+
if (pPropertyDescription_->hasCell())
862864
{
863-
PyErr_Clear();
864-
}
865-
else
866-
{
867-
cellComponentPart = PyDict_GetItemString(cellDataDict, pPropertyDescription_->getName());
868-
Py_DECREF(cellDataDict);
869-
Py_INCREF(cellComponentPart);
865+
PyObject* cellDataDict = PyObject_GetAttrString(owner(), "cellData");
866+
if (!cellDataDict)
867+
{
868+
PyErr_Clear();
869+
}
870+
else
871+
{
872+
cellComponentPart = PyDict_GetItemString(cellDataDict, pPropertyDescription_->getName());
873+
Py_DECREF(cellDataDict);
874+
Py_INCREF(cellComponentPart);
875+
}
870876
}
871877

872878
if (componentType_ == BASEAPP_TYPE)

kbe/src/lib/entitydef/entitydef.cpp

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ bool EntityDef::loadComponents(const std::string& defFilePath,
568568

569569
// 产生一个属性描述实例
570570
ENTITY_PROPERTY_UID futype = 0;
571-
uint32 flags = ENTITY_BASE_DATA_FLAGS | ENTITY_CELL_DATA_FLAGS | ENTITY_CLIENT_DATA_FLAGS;
571+
uint32 flags = ED_FLAG_BASE | ED_FLAG_CELL_PUBLIC | ENTITY_CLIENT_DATA_FLAGS;
572572
bool isPersistent = true;
573573
bool isIdentifier = false; // 是否是一个索引键
574574
uint32 databaseLength = 0; // 这个属性在数据库中的长度
@@ -608,25 +608,28 @@ bool EntityDef::loadComponents(const std::string& defFilePath,
608608
pCompScriptDefModule->isComponentModule(true);
609609

610610
EntityDef::__scriptModules.push_back(pCompScriptDefModule);
611-
612-
pPropertyDescription = addComponentProperty(futype, componentTypeName, componentName, flags, isPersistent, isIdentifier,
613-
indexType, databaseLength, defaultStr, detailLevel, pScriptModule, pCompScriptDefModule);
614611
}
615612
else
616613
{
617-
pPropertyDescription = addComponentProperty(futype, componentTypeName, componentName, flags, isPersistent, isIdentifier,
618-
indexType, databaseLength, defaultStr, detailLevel, pScriptModule, pCompScriptDefModule);
614+
flags = ED_FLAG_UNKOWN;
619615

620-
if (!pCompScriptDefModule->hasBase())
621-
flags &= ~ENTITY_BASE_DATA_FLAGS;
616+
if (pCompScriptDefModule->hasBase())
617+
flags |= ED_FLAG_BASE;
622618

623-
if (!pCompScriptDefModule->hasCell())
624-
flags &= ~ENTITY_CELL_DATA_FLAGS;
619+
if (pCompScriptDefModule->hasCell())
620+
flags |= ED_FLAG_CELL_PUBLIC;
625621

626-
if (!pCompScriptDefModule->hasClient())
627-
flags &= ~ENTITY_CLIENT_DATA_FLAGS;
622+
if (pCompScriptDefModule->hasClient())
623+
{
624+
if (pCompScriptDefModule->hasBase())
625+
flags |= ED_FLAG_BASE_AND_CLIENT;
626+
else
627+
flags |= (ED_FLAG_ALL_CLIENTS | ED_FLAG_CELL_PUBLIC_AND_OWN | ED_FLAG_OTHER_CLIENTS | ED_FLAG_OWN_CLIENT);
628+
}
629+
630+
pPropertyDescription = addComponentProperty(futype, componentTypeName, componentName, flags, isPersistent, isIdentifier,
631+
indexType, databaseLength, defaultStr, detailLevel, pScriptModule, pCompScriptDefModule);
628632

629-
pPropertyDescription->setFlags(flags);
630633
pScriptModule->addComponentDescription(componentName.c_str(), pCompScriptDefModule);
631634
continue;
632635
}
@@ -664,16 +667,25 @@ bool EntityDef::loadComponents(const std::string& defFilePath,
664667
return false;
665668
}
666669

667-
if (!pCompScriptDefModule->hasBase())
668-
flags &= ~ENTITY_BASE_DATA_FLAGS;
670+
flags = ED_FLAG_UNKOWN;
671+
672+
if (pCompScriptDefModule->hasBase())
673+
flags |= ED_FLAG_BASE;
669674

670-
if (!pCompScriptDefModule->hasCell())
671-
flags &= ~ENTITY_CELL_DATA_FLAGS;
675+
if (pCompScriptDefModule->hasCell())
676+
flags |= ED_FLAG_CELL_PUBLIC;
672677

673-
if (!pCompScriptDefModule->hasClient())
674-
flags &= ~ENTITY_CLIENT_DATA_FLAGS;
678+
if (pCompScriptDefModule->hasClient())
679+
{
680+
if (pCompScriptDefModule->hasBase())
681+
flags |= ED_FLAG_BASE_AND_CLIENT;
682+
683+
if (pCompScriptDefModule->hasCell())
684+
flags |= (ED_FLAG_ALL_CLIENTS | ED_FLAG_CELL_PUBLIC_AND_OWN | ED_FLAG_OTHER_CLIENTS | ED_FLAG_OWN_CLIENT);
685+
}
675686

676-
pPropertyDescription->setFlags(flags);
687+
pPropertyDescription = addComponentProperty(futype, componentTypeName, componentName, flags, isPersistent, isIdentifier,
688+
indexType, databaseLength, defaultStr, detailLevel, pScriptModule, pCompScriptDefModule);
677689

678690
pScriptModule->addComponentDescription(componentName.c_str(), pCompScriptDefModule);
679691
}

0 commit comments

Comments
 (0)