예제 #1
0
ActorId ActorManager::AddActor(StrongActorPtr pActor) {
	ActorId id;
	// if an actor already exists, do not create
	StrongActorPtr actorTest = GetActorByName(pActor->GetIp(),pActor->GetName());
	if (actorTest == NULL) {
		id = pActor->GetId();
		// No id affected yet
		if (id == -1) {
			id = GetNextLastId();
			pActor->SetId(id);
			m_ActorMap[id] = pActor;
			//alternative
			//m_ActorMap.insert(std::pair<ActorId, Actor>(id, actor));
			// add the actor for this Ip
			m_ActorsByIpMap[pActor->GetIp()].push_back(pActor);
		}
	}
	else {
		id = actorTest->GetId();
	}
	return id;
}
예제 #2
0
void ActorManager::RemoveActor(ActorId id) {
	m_ActorMap.erase(id);
	//
	StrongActorPtr actor = GetActor(id);
	std::list<StrongActorPtr> actorList = m_ActorsByIpMap[actor->GetIp()];
	for (std::list<StrongActorPtr>::iterator i = actorList.begin(); i != actorList.end(); ++i) {
		StrongActorPtr pActor = *i;
		if (pActor->GetName().compare(actor->GetName()) == 0) {
			actorList.erase(i);			
			//we break the iterator but we leave ah ah.
			break;
		}
	}
}