Beispiel #1
0
//-------------------------------------------------------------------------------------
void EntityComponent::initProperty(bool isReload)
{
	ScriptDefModule::PROPERTYDESCRIPTION_MAP* oldpropers = NULL;
	if (isReload)
	{
		ScriptDefModule* pOldScriptDefModule =
		EntityDef::findOldScriptModule(pComponentDescrs_->getName());

		if (!pOldScriptDefModule)
		{
			ERROR_MSG(fmt::format("{}::initProperty: not found old_module!\n",
				pComponentDescrs_->getName()));

			KBE_ASSERT(false && "EntityComponent::initProperty: not found old_module");
		}

		oldpropers = &pOldScriptDefModule->getPropertyDescrs();
	}

	const ScriptDefModule::PROPERTYDESCRIPTION_MAP* pPropertyDescrs = pChildPropertyDescrs();

	ScriptDefModule::PROPERTYDESCRIPTION_MAP::const_iterator iter = pPropertyDescrs->begin();
	for (; iter != pPropertyDescrs->end(); ++iter)
	{
		PropertyDescription* propertyDescription = iter->second;
		DataType* dataType = propertyDescription->getDataType();

		if (oldpropers)
		{
			ScriptDefModule::PROPERTYDESCRIPTION_MAP::iterator olditer = oldpropers->find(iter->first);
			if (olditer != oldpropers->end())
			{
			if (strcmp(olditer->second->getDataType()->getName(),
				propertyDescription->getDataType()->getName()) == 0 &&
				strcmp(olditer->second->getDataType()->getName(),
					propertyDescription->getDataType()->getName()) == 0)
				continue;
			}
		}

		if (dataType)
		{
			PyObject* defObj = propertyDescription->newDefaultVal();
			PyObject_SetAttrString(static_cast<PyObject*>(this),
			propertyDescription->getName(), defObj);
			Py_DECREF(defObj);

			/* DEBUG_MSG(fmt::format("EntityComponent::"#CLASS": added [{}] property ref={}.\n",	
			propertyDescription->getName(), defObj->ob_refcnt));*/
		}
		else
		{
			ERROR_MSG(fmt::format("EntityComponent::initProperty: {} dataType is NULL.\n",
				propertyDescription->getName()));
		}
	}
}
Beispiel #2
0
//-------------------------------------------------------------------------------------
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();
}
Beispiel #3
0
//-------------------------------------------------------------------------------------
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);
}