Ejemplo n.º 1
0
//-------------------------------------------------------------------------------------
void Cellappmgr::updateCellapp(Network::Channel* pChannel, COMPONENT_ID componentID, 
	ENTITY_ID numEntities, float load, uint32 flags)
{
	Cellapp& cellapp = getCellapp(componentID);
	
	cellapp.load(load);
	cellapp.numEntities(numEntities);
	cellapp.flags(flags);
	
	updateBestCellapp();
}
Ejemplo n.º 2
0
//-------------------------------------------------------------------------------------
void Cellappmgr::reqRestoreSpaceInCell(Mercury::Channel* pChannel, MemoryStream& s) 
{
	std::string entityType;
	ENTITY_ID id;
	COMPONENT_ID componentID;
	SPACE_ID spaceID;

	s >> entityType;
	s >> id;
	s >> componentID;
	s >> spaceID;

	Mercury::Bundle* pBundle = Mercury::Bundle::ObjPool().createObject();
	ForwardItem* pFI = new ForwardItem();
	pFI->pHandler = NULL;
	
	pFI->pBundle = pBundle;
	(*pBundle).newMessage(CellappInterface::onRestoreSpaceInCellFromBaseapp);
	(*pBundle) << entityType;
	(*pBundle) << id;
	(*pBundle) << spaceID;
	(*pBundle) << componentID;

	(*pBundle).append(&s);
	s.opfini();

	DEBUG_MSG(boost::format("Cellappmgr::reqRestoreSpaceInCell: entityType=%1%, entityID=%2%, componentID=%3%, spaceID=%4%.\n") %
		entityType.c_str() % id % componentID % spaceID);

	updateBestCellapp();

	Components::ComponentInfos* cinfos = 
		Components::getSingleton().findComponent(CELLAPP_TYPE, bestCellappID_);

	if(cinfos == NULL || cinfos->pChannel == NULL)
	{
		WARNING_MSG("Cellappmgr::reqRestoreSpaceInCell: not found cellapp, message is buffered.\n");
		forward_cellapp_messagebuffer_.push(pFI);
		return;
	}
	else
	{
		(*pBundle).send(this->getNetworkInterface(), cinfos->pChannel);
		Mercury::Bundle::ObjPool().reclaimObject(pBundle);
		SAFE_RELEASE(pFI);
	}
}
Ejemplo n.º 3
0
//-------------------------------------------------------------------------------------
void Cellappmgr::reqCreateInNewSpace(Network::Channel* pChannel, MemoryStream& s) 
{
	std::string entityType;
	ENTITY_ID id;
	COMPONENT_ID componentID;

	s >> entityType;
	s >> id;
	s >> componentID;

	static SPACE_ID spaceID = 1;

	Network::Bundle* pBundle = Network::Bundle::ObjPool().createObject();
	(*pBundle).newMessage(CellappInterface::onCreateInNewSpaceFromBaseapp);
	(*pBundle) << entityType;
	(*pBundle) << id;
	(*pBundle) << spaceID++;
	(*pBundle) << componentID;

	(*pBundle).append(&s);
	s.done();

	DEBUG_MSG(fmt::format("Cellappmgr::reqCreateInNewSpace: entityType={0}, entityID={1}, componentID={2}.\n",
		entityType, id, componentID));

	updateBestCellapp();
	Components::ComponentInfos* cinfos = Components::getSingleton().findComponent(CELLAPP_TYPE, bestCellappID_);
	if(cinfos == NULL || cinfos->pChannel == NULL || cinfos->state != COMPONENT_STATE_RUN)
	{
		WARNING_MSG("Cellappmgr::reqCreateInNewSpace: not found cellapp, message is buffered.\n");
		ForwardItem* pFI = new ForwardItem();
		pFI->pHandler = NULL;
		pFI->pBundle = pBundle;
		forward_cellapp_messagebuffer_.push(pFI);
		return;
	}
	else
	{
		cinfos->pChannel->send(pBundle);
	}
}
Ejemplo n.º 4
0
//-------------------------------------------------------------------------------------
void Cellappmgr::reqCreateInNewSpace(Network::Channel* pChannel, MemoryStream& s) 
{
	std::string entityType;
	ENTITY_ID id;
	COMPONENT_ID componentID;
	bool hasClient;

	// 如果cellappIndex为0,则代表不强制指定cellapp
	// 非0的情况下,选择的cellapp可以用1,2,3,4来代替
	// 假如预期有4个cellapp, 假如不够4个, 只有3个, 那么4代表1
	uint32 cellappIndex = 0;

	s >> entityType;
	s >> id;
	s >> cellappIndex;
	s >> componentID;
	s >> hasClient;

	static SPACE_ID spaceID = 1;

	Network::Bundle* pBundle = Network::Bundle::createPoolObject();
	(*pBundle).newMessage(CellappInterface::onCreateInNewSpaceFromBaseapp);
	(*pBundle) << entityType;
	(*pBundle) << id;
	(*pBundle) << spaceID++;
	(*pBundle) << componentID;
	(*pBundle) << hasClient;

	(*pBundle).append(&s);
	s.done();

	uint32 cellappSize = cellapp_cids_.size();

	if (cellappSize > 0)
	{
		updateBestCellapp();

		// 选择特定的cellapp创建space
		if (cellappIndex > 0)
		{
			uint32 index = (cellappIndex - 1) % cellappSize;
			bestCellappID_ = cellapp_cids_[index];
		}
		else if (bestCellappID_ == 0 && numLoadBalancingApp() == 0)
		{
			ERROR_MSG(fmt::format("Cellappmgr::reqCreateInNewSpace: Unable to allocate cellapp for load balancing! entityType={}, entityID={}, componentID={}, cellappSize={}.\n",
				entityType, id, componentID, cellappSize));
		}
	}

	Components::ComponentInfos* cinfos = NULL;
	if (bestCellappID_ > 0)
		cinfos = Components::getSingleton().findComponent(CELLAPP_TYPE, bestCellappID_);

	if (cinfos == NULL || cinfos->pChannel == NULL || cinfos->state != COMPONENT_STATE_RUN)
	{
		WARNING_MSG("Cellappmgr::reqCreateInNewSpace: not found cellapp, message is buffered.\n");

		ForwardItem* pFI = new AppForwardItem();
		pFI->pHandler = NULL;
		pFI->pBundle = pBundle;

		if (cellappIndex == 0 || bestCellappID_ == 0)
			forward_anywhere_cellapp_messagebuffer_.push(pFI);
		else
			forward_cellapp_messagebuffer_.push(bestCellappID_, pFI);

		return;
	}
	else
	{
		cinfos->pChannel->send(pBundle);
	}

	std::map< COMPONENT_ID, Cellapp >::iterator cellapp_iter = cellapps_.find(bestCellappID_);
	DEBUG_MSG(fmt::format("Cellappmgr::reqCreateInNewSpace: entityType={}, entityID={}, componentID={}, cellapp(cid={}, load={}, numEntities={}).\n",
		entityType, id, componentID, bestCellappID_, cellapp_iter->second.load(), cellapp_iter->second.numEntities()));

	// 预先将实体数量增加
	if (cellapp_iter != cellapps_.end())
	{
		cellapp_iter->second.incNumEntities();
	}
}