Ejemplo n.º 1
0
//-------------------------------------------------------------------------------------
PyObject* EntityMailbox::__unpickle__(PyObject* self, PyObject* args)
{
	ENTITY_ID eid = 0;
	COMPONENT_ID componentID = 0;
	COMPONENT_TYPE componentType;
	ENTITY_SCRIPT_UID utype = 0, type = 0;

	Py_ssize_t size = PyTuple_Size(args);
	if(size != 4)
	{
		ERROR_MSG("EntityMailbox::__unpickle__: args is error! size != 4.\n");
		S_Return;
	}

	if(!PyArg_ParseTuple(args, "iKHH", &eid, &componentID, &utype, &type))
	{
		ERROR_MSG("EntityMailbox::__unpickle__: args is error!\n");
		S_Return;
	}

	ScriptDefModule* sm = EntityDef::findScriptModule(utype);
	if(sm == NULL)
	{
		ERROR_MSG("EntityMailbox::__unpickle__: not found utype %ld!\n", utype);
		S_Return;
	}

	// Mercury::Channel* pChannel = NULL;
	componentType = ENTITY_MAILBOX_COMPONENT_TYPE_MAPPING[(ENTITY_MAILBOX_TYPE)type];
	
#ifdef KBE_SERVER
	// 如果组件类别和组件ID和当前服务器相同, 则说明这个entity在本服务器上存在, 那么直接返回entity的实例
	if(componentType == g_componentType)
	{
		PyObject* entity = __getEntityFunc(componentID, eid);
		if(entity != NULL)
		{
			Py_INCREF(entity);
			return entity;
		}
	}
	else
	{
		Components::ComponentInfos* pcomponent = Components::getSingleton().findComponent(componentType, componentID);
		if(pcomponent != NULL)
		{
			// pChannel = pcomponent->pChannel;
		}
		else
		{
			ERROR_MSG("EntityMailbox::__unpickle__: not found %s%ld!\n", COMPONENT_NAME[componentType], componentID);
			S_Return;
		}
	}
#else
	PyObject* entity = __getEntityFunc(componentID, eid);
	if(entity != NULL)
	{
		Py_INCREF(entity);
		return entity;
	}
#endif

	return new EntityMailbox(sm, NULL, componentID, eid, (ENTITY_MAILBOX_TYPE)type);
}
Ejemplo n.º 2
0
//-------------------------------------------------------------------------------------
PyObject* EntityMailbox::tryGetEntity(COMPONENT_ID componentID, ENTITY_ID entityID)
{
	return __getEntityFunc(componentID, entityID);
}