Skip to content

Commit a63266f

Browse files
committed
up
1 parent e761f49 commit a63266f

File tree

6 files changed

+94
-26
lines changed

6 files changed

+94
-26
lines changed

kbe/src/lib/entitydef/entity_component.cpp

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1352,28 +1352,37 @@ void EntityComponent::convertDictDataToEntityComponent(ENTITY_ID entityID, Scrip
13521352
for (; comps_iter != componentDescrs.end(); ++comps_iter)
13531353
{
13541354
PyObject* pyObj = PyDict_GetItemString(cellData, comps_iter->first.c_str());
1355-
if (pyObj && PyDict_Check(pyObj))
1355+
if (!pyObj || !PyDict_Check(pyObj))
13561356
{
1357-
KBE_ASSERT(EntityDef::context().currEntityID > 0);
1357+
// 由于存在一种情况, 组件def中没有内容, 但有cell脚本,此时baseapp上无法判断他是否有cell属性,所以写celldata时没有数据写入
1358+
if (g_componentType == BASEAPP_TYPE)
1359+
{
1360+
SCRIPT_ERROR_CHECK();
1361+
continue;
1362+
}
1363+
else
1364+
{
1365+
PyErr_Clear();
1366+
}
1367+
}
13581368

1359-
PyObject* pyobj = comps_iter->second->createObject();
1369+
KBE_ASSERT(EntityDef::context().currEntityID > 0);
13601370

1361-
// 执行Entity的构造函数
1362-
PyObject* pyEntityComponent = new(pyobj) EntityComponent(entityID, comps_iter->second, g_componentType);
1371+
PyObject* pyobj = comps_iter->second->createObject();
13631372

1364-
EntityComponent* pEntityComponent = static_cast<EntityComponent*>(pyEntityComponent);
1373+
// 执行Entity的构造函数
1374+
PyObject* pyEntityComponent = new(pyobj) EntityComponent(entityID, comps_iter->second, g_componentType);
1375+
1376+
EntityComponent* pEntityComponent = static_cast<EntityComponent*>(pyEntityComponent);
1377+
1378+
if(pyObj)
13651379
pEntityComponent->createFromDict(pyObj);
13661380

1367-
PropertyDescription* pPropertyDescription = pEntityScriptDescrs->findCellPropertyDescription(comps_iter->first.c_str());
1368-
KBE_ASSERT(pPropertyDescription);
1369-
pEntityComponent->pPropertyDescription(pPropertyDescription);
1370-
PyDict_SetItemString(cellData, comps_iter->first.c_str(), pEntityComponent);
1371-
Py_DECREF(pEntityComponent);
1372-
}
1373-
else
1374-
{
1375-
SCRIPT_ERROR_CHECK();
1376-
}
1381+
PropertyDescription* pPropertyDescription = pEntityScriptDescrs->findCellPropertyDescription(comps_iter->first.c_str());
1382+
KBE_ASSERT(pPropertyDescription);
1383+
pEntityComponent->pPropertyDescription(pPropertyDescription);
1384+
PyDict_SetItemString(cellData, comps_iter->first.c_str(), pEntityComponent);
1385+
Py_DECREF(pEntityComponent);
13771386
}
13781387
}
13791388

kbe/src/lib/entitydef/entitydef.cpp

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ ENTITY_SCRIPT_UID g_scriptUtype = 1;
5050
// 获得某个entity的函数地址
5151
EntityDef::GetEntityFunc EntityDef::__getEntityFunc;
5252

53+
static std::map<std::string, std::vector<PropertyDescription*> > g_logComponentPropertys;
54+
5355
//-------------------------------------------------------------------------------------
5456
EntityDef::EntityDef()
5557
{
@@ -625,8 +627,8 @@ bool EntityDef::loadComponents(const std::string& defFilePath,
625627
flags |= (ED_FLAG_ALL_CLIENTS | ED_FLAG_CELL_PUBLIC_AND_OWN | ED_FLAG_OTHER_CLIENTS | ED_FLAG_OWN_CLIENT);
626628
}
627629

628-
addComponentProperty(futype, componentTypeName, componentName, flags, isPersistent, isIdentifier,
629-
indexType, databaseLength, defaultStr, detailLevel, pScriptModule, pCompScriptDefModule);
630+
g_logComponentPropertys[pScriptModule->getName()].push_back(addComponentProperty(futype, componentTypeName, componentName, flags, isPersistent, isIdentifier,
631+
indexType, databaseLength, defaultStr, detailLevel, pScriptModule, pCompScriptDefModule));
630632

631633
pScriptModule->addComponentDescription(componentName.c_str(), pCompScriptDefModule);
632634
continue;
@@ -682,8 +684,8 @@ bool EntityDef::loadComponents(const std::string& defFilePath,
682684
flags |= (ED_FLAG_ALL_CLIENTS | ED_FLAG_CELL_PUBLIC_AND_OWN | ED_FLAG_OTHER_CLIENTS | ED_FLAG_OWN_CLIENT);
683685
}
684686

685-
addComponentProperty(futype, componentTypeName, componentName, flags, isPersistent, isIdentifier,
686-
indexType, databaseLength, defaultStr, detailLevel, pScriptModule, pCompScriptDefModule);
687+
g_logComponentPropertys[pScriptModule->getName()].push_back(addComponentProperty(futype, componentTypeName, componentName, flags, isPersistent, isIdentifier,
688+
indexType, databaseLength, defaultStr, detailLevel, pScriptModule, pCompScriptDefModule));
687689

688690
pScriptModule->addComponentDescription(componentName.c_str(), pCompScriptDefModule);
689691
}
@@ -1870,6 +1872,45 @@ bool EntityDef::loadAllComponentScriptModules(std::string entitiesPath, std::vec
18701872

18711873
setScriptModuleHasComponentEntity(pScriptModule, true);
18721874

1875+
{
1876+
std::vector<ScriptDefModulePtr>::iterator entityScriptModuleIter = EntityDef::__scriptModules.begin();
1877+
for (; entityScriptModuleIter != EntityDef::__scriptModules.end(); ++entityScriptModuleIter)
1878+
{
1879+
std::vector<PropertyDescription*>& componentPropertys = g_logComponentPropertys[(*entityScriptModuleIter)->getName()];
1880+
std::vector<PropertyDescription*>::iterator componentPropertysIter = componentPropertys.begin();
1881+
for (; componentPropertysIter != componentPropertys.end(); ++componentPropertysIter)
1882+
{
1883+
PropertyDescription* pComponentPropertyDescription = (*componentPropertysIter);
1884+
ScriptDefModule* pCompScriptModule = static_cast<EntityComponentType*>(pComponentPropertyDescription->getDataType())->pScriptDefModule();
1885+
1886+
if (pCompScriptModule->getName() != componentScriptName)
1887+
continue;
1888+
1889+
uint32 pflags = pComponentPropertyDescription->getFlags();
1890+
1891+
if (g_componentType == BASEAPP_TYPE)
1892+
{
1893+
pflags |= ENTITY_BASE_DATA_FLAGS;
1894+
}
1895+
else if (g_componentType == CELLAPP_TYPE)
1896+
{
1897+
pflags |= ENTITY_CELL_DATA_FLAGS;
1898+
}
1899+
else
1900+
{
1901+
pflags |= ENTITY_CLIENT_DATA_FLAGS;
1902+
}
1903+
1904+
pComponentPropertyDescription->setFlags(pflags);
1905+
1906+
if ((*entityScriptModuleIter)->findPropertyDescription(pComponentPropertyDescription->getName(), g_componentType) != pComponentPropertyDescription)
1907+
{
1908+
(*entityScriptModuleIter)->addPropertyDescription(pComponentPropertyDescription->getName(), pComponentPropertyDescription, g_componentType, true);
1909+
}
1910+
}
1911+
}
1912+
}
1913+
18731914
PyObject* pyClass =
18741915
PyObject_GetAttrString(pyModule, const_cast<char *>(componentScriptName.c_str()));
18751916

@@ -1932,6 +1973,7 @@ bool EntityDef::loadAllComponentScriptModules(std::string entitiesPath, std::vec
19321973
S_RELEASE(pyModule);
19331974
}
19341975

1976+
g_logComponentPropertys.clear();
19351977
return true;
19361978
}
19371979

kbe/src/lib/entitydef/scriptdef_module.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -486,17 +486,17 @@ void ScriptDefModule::autoMatchCompOwn()
486486
//-------------------------------------------------------------------------------------
487487
bool ScriptDefModule::addPropertyDescription(const char* attrName,
488488
PropertyDescription* propertyDescription,
489-
COMPONENT_TYPE componentType)
489+
COMPONENT_TYPE componentType, bool ignoreConflict)
490490
{
491-
if(hasMethodName(attrName))
491+
if(!ignoreConflict && hasMethodName(attrName))
492492
{
493493
ERROR_MSG(fmt::format("ScriptDefModule::addPropertyDescription: There is a method[{}] name conflict! componentType={}.\n",
494494
attrName, componentType));
495495

496496
return false;
497497
}
498498

499-
if (hasComponentName(attrName))
499+
if (!ignoreConflict && hasComponentName(attrName))
500500
{
501501
ERROR_MSG(fmt::format("ScriptDefModule::addPropertyDescription: There is a component[{}] name conflict!\n",
502502
attrName));

kbe/src/lib/entitydef/scriptdef_module.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ class ScriptDefModule : public RefCountable
106106

107107
bool addPropertyDescription(const char* attrName,
108108
PropertyDescription* propertyDescription,
109-
COMPONENT_TYPE componentType);
109+
COMPONENT_TYPE componentType, bool ignoreConflict = false);
110110

111111

112112
MethodDescription* findCellMethodDescription(const char* attrName);

kbe/src/server/baseapp/entity.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,9 +409,18 @@ void Entity::addPersistentsDataToStream(uint32 flags, MemoryStream* s)
409409
const char* attrname = propertyDescription->getName();
410410
if(propertyDescription->isPersistent() && (flags & propertyDescription->getFlags()) > 0)
411411
{
412+
bool isComponent = propertyDescription->getDataType()->type() == DATA_TYPE_ENTITY_COMPONENT;
413+
if (isComponent)
414+
{
415+
// 由于存在一种情况, 组件def中没有内容, 但有cell脚本,此时baseapp上无法判断他是否有cell属性,所以写celldata时没有数据写入
416+
EntityComponentType* pEntityComponentType = (EntityComponentType*)propertyDescription->getDataType();
417+
if (pEntityComponentType->pScriptDefModule()->getPropertyDescrs().size() == 0 && pEntityComponentType->pScriptDefModule()->getCellPropertyDescriptions().size() == 0)
418+
continue;
419+
}
420+
412421
PyObject *key = PyUnicode_FromString(attrname);
413422

414-
if(propertyDescription->getDataType()->type() != DATA_TYPE_ENTITY_COMPONENT /* 如果是组件类型,应该先从实体自身找到这个组件属性 */
423+
if(!isComponent /* 如果是组件类型,应该先从实体自身找到这个组件属性 */
415424
&& cellDataDict_ != NULL && PyDict_Contains(cellDataDict_, key) > 0)
416425
{
417426
PyObject* pyVal = PyDict_GetItemString(cellDataDict_, attrname);
@@ -446,7 +455,7 @@ void Entity::addPersistentsDataToStream(uint32 flags, MemoryStream* s)
446455
}
447456
else
448457
{
449-
if (propertyDescription->getDataType()->type() != DATA_TYPE_ENTITY_COMPONENT)
458+
if (!isComponent)
450459
{
451460
WARNING_MSG(fmt::format("{}::addPersistentsDataToStream: {} not found Persistent({}), use default values!\n",
452461
this->scriptName(), this->id(), attrname));

kbe/src/server/cellapp/entity.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,6 +1074,14 @@ void Entity::addCellDataToStream(COMPONENT_TYPE sendTo, uint32 flags, MemoryStre
10741074
PropertyDescription* propertyDescription = iter->second;
10751075
if((flags & propertyDescription->getFlags()) > 0)
10761076
{
1077+
// 由于存在一种情况, 组件def中没有内容, 但有cell脚本,此时baseapp上无法判断他是否有cell属性,所以写celldata时没有数据写入
1078+
if (propertyDescription->getDataType()->type() == DATA_TYPE_ENTITY_COMPONENT)
1079+
{
1080+
EntityComponentType* pEntityComponentType = (EntityComponentType*)propertyDescription->getDataType();
1081+
if (pEntityComponentType->pScriptDefModule()->getPropertyDescrs().size() == 0)
1082+
continue;
1083+
}
1084+
10771085
// DEBUG_MSG(fmt::format("Entity::addCellDataToStream: {}.\n", propertyDescription->getName()));
10781086
PyObject* pyVal = PyDict_GetItemString(cellData, propertyDescription->getName());
10791087

0 commit comments

Comments
 (0)