|
从源码上看所有的类型序列化前都会isSameType之类的, 在Entity和组件中会检查所有的同步字段, 这个是不是消耗有点大,在组件的addToServerStream函数中有一段: uint16 count = (uint16)pPropertyDescrs->size();
(*mstream) << count;
ScriptDefModule::PROPERTYDESCRIPTION_MAP::const_iterator iter = pPropertyDescrs->begin();
for (; iter != pPropertyDescrs->end(); ++iter)
{
PyObject* pyVal = PyObject_GetAttrString(this, propertyDescription->getName());
if (pyVal)
{
if (!propertyDescription->getDataType()->isSameType(pyVal))
{
CRITICAL_MSG(fmt::format("EntityComponent::addToServerStream: {} type(curr_py: {} != {}) error! name={}, utype={}, owner={}, ownerID={}, domain={}.\n",
propertyDescription->getName(), (pyVal ? pyVal->ob_type->tp_name : "unknown"), propertyDescription->getDataType()->getName(),
pComponentDescrs_ ? pComponentDescrs_->getName() : "", pComponentDescrs_ ? pComponentDescrs_->getUType() : 0,
owner()->ob_type->tp_name, ownerID(), COMPONENT_NAME_EX(componentType())));
}
else
{
(*mstream) << pPropertyDescription_->getUType();
(*mstream) << propertyDescription->getUType();
propertyDescription->addToStream(mstream, pyVal);
}
Py_DECREF(pyVal);
}
....
}
这里检查是基于什么考虑的呢? 如果类型不一致, 同步数据就已经错乱了, 在for外面的count还是原来那么多, 但是写入的实际数量却不是的了, 在接收的端的createFromStream的时候直接会异常了
如果是没办法避免错误或者不应该出现这种错误, 还不如直接别检测了不是更快
|
|