//------------------------------------------------------------------------------------- void Base::createCellData(void) { if(!scriptModule_->hasCell() || !installCellDataAttr()) { if(scriptModule_->getCellPropertyDescriptions().size() > 0) { if(!scriptModule_->hasCell()) { WARNING_MSG(fmt::format("{}::createCellData: do not create cellData, cannot find the cellapp script({})!\n", scriptModule_->getName(), scriptModule_->getName())); } } return; } ScriptDefModule::PROPERTYDESCRIPTION_MAP& propertyDescrs = scriptModule_->getCellPropertyDescriptions(); ScriptDefModule::PROPERTYDESCRIPTION_MAP::const_iterator iter = propertyDescrs.begin(); for(; iter != propertyDescrs.end(); ++iter) { PropertyDescription* propertyDescription = iter->second; DataType* dataType = propertyDescription->getDataType(); if(dataType) { PyObject* pyObj = propertyDescription->newDefaultVal(); PyDict_SetItemString(cellDataDict_, propertyDescription->getName(), pyObj); Py_DECREF(pyObj); } else { ERROR_MSG(fmt::format("{}::createCellData: {} PropertyDescription the dataType is NULL.\n", this->scriptName(), propertyDescription->getName())); } SCRIPT_ERROR_CHECK(); } // 初始化cellEntity的位置和方向变量 PyObject* position = PyTuple_New(3); PyTuple_SET_ITEM(position, 0, PyFloat_FromDouble(0.0)); PyTuple_SET_ITEM(position, 1, PyFloat_FromDouble(0.0)); PyTuple_SET_ITEM(position, 2, PyFloat_FromDouble(0.0)); PyObject* direction = PyTuple_New(3); PyTuple_SET_ITEM(direction, 0, PyFloat_FromDouble(0.0)); PyTuple_SET_ITEM(direction, 1, PyFloat_FromDouble(0.0)); PyTuple_SET_ITEM(direction, 2, PyFloat_FromDouble(0.0)); PyDict_SetItemString(cellDataDict_, "position", position); PyDict_SetItemString(cellDataDict_, "direction", direction); Py_DECREF(position); Py_DECREF(direction); SCRIPT_ERROR_CHECK(); }
//------------------------------------------------------------------------------------- void Base::onBackupCellData(Mercury::Channel* pChannel, MemoryStream& s) { isGetingCellData_ = false; std::string strCellData; uint32 cellDataLength; PyObject* cellData = NULL; s >> cellDataLength; if(cellDataLength > 0) { strCellData.assign((char*)(s.data() + s.rpos()), cellDataLength); s.read_skip(cellDataLength); cellData = script::Pickler::unpickle(strCellData); KBE_ASSERT(cellData != NULL); } installCellDataAttr(cellData); S_RELEASE(cellData); }
//------------------------------------------------------------------------------------- void Base::createCellData(void) { if(!installCellDataAttr()) return; ScriptDefModule::PROPERTYDESCRIPTION_MAP& propertyDescrs = scriptModule_->getCellPropertyDescriptions(); ScriptDefModule::PROPERTYDESCRIPTION_MAP::const_iterator iter = propertyDescrs.begin(); for(; iter != propertyDescrs.end(); iter++) { PropertyDescription* propertyDescription = iter->second; DataType* dataType = propertyDescription->getDataType(); if(dataType) { PyObject* pyObj = propertyDescription->newDefaultVal(); PyDict_SetItemString(cellDataDict_, propertyDescription->getName(), pyObj); } else { ERROR_MSG("Base::createCellData: %s PropertyDescription the dataType is NULL.\n", propertyDescription->getName()); } } // 初始化cellEntity的位置和方向变量 PyObject* position = PyTuple_New(3); PyTuple_SET_ITEM(position, 0, PyFloat_FromDouble(0.0)); PyTuple_SET_ITEM(position, 1, PyFloat_FromDouble(0.0)); PyTuple_SET_ITEM(position, 2, PyFloat_FromDouble(0.0)); PyObject* direction = PyTuple_New(3); PyTuple_SET_ITEM(direction, 0, PyFloat_FromDouble(0.0)); PyTuple_SET_ITEM(direction, 1, PyFloat_FromDouble(0.0)); PyTuple_SET_ITEM(direction, 2, PyFloat_FromDouble(0.0)); PyDict_SetItemString(cellDataDict_, "position", position); PyDict_SetItemString(cellDataDict_, "direction", direction); }