当前位置: 首页>>代码示例>>C++>>正文


C++ Filter::getOne方法代码示例

本文整理汇总了C++中Filter::getOne方法的典型用法代码示例。如果您正苦于以下问题:C++ Filter::getOne方法的具体用法?C++ Filter::getOne怎么用?C++ Filter::getOne使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Filter的用法示例。


在下文中一共展示了Filter::getOne方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1:

std::set<Entity*> EntityManager::getEntities(const Filter& filter)
{
	std::set<Entity*> entities;
	if (!filter.getOne().empty())
	{
		for (auto& iter : filter.getOne())
			getEntities(iter, entities);
	}
	if (!filter.getAll().empty())
	{
		auto iter = filter.getAll().begin();
		Type typeId = *iter;
		std::set<Entity*> suspects;
		getEntities(typeId, suspects);
		if (!suspects.empty())
		{
			iter++;
			for (; iter != filter.getAll().end(); ++iter)
			{
				typeId = *iter;
				std::set<Entity*> ents;
				getEntities(typeId, ents);
				if (ents.empty())
				{
					suspects.clear();
					break;
				}
				std::set<Entity*> newSuspects;
				for (auto& siter : suspects)
				{
					if (ents.find(siter) != ents.end())
						newSuspects.insert(siter);
				}
				suspects = newSuspects;
			}
		}
		// if there's no "one of" requirement, add all these entities
		if (filter.getOne().empty())
			entities = suspects;
		else
		{
			std::set<Entity*> newEntities;
			// otherwise, we have to check that the entity exists in both sets
			for (auto iter = entities.begin(); iter != entities.end(); ++iter)
			{
				if (suspects.end() != suspects.find(*iter))
					newEntities.insert(*iter);
			}
			entities = newEntities;
		}
	}
	if (!filter.getExcept().empty())
	{
		std::set<Entity*> excluded;
		// add all entities that don't have those things in
		for (auto iter = m_componentTypeToEntities.begin(); iter != m_componentTypeToEntities.end(); ++iter)
		{
			for (auto fIter = filter.getExcept().begin(); fIter != filter.getExcept().end(); ++fIter)
			{
				if (fIter->isDerivedFrom(iter->first))
					excluded.insert(iter->second.begin(), iter->second.end());
			}
		}
		if (filter.getAll().empty() && filter.getOne().empty())
			entities = excluded;
		else
		{
			std::set<Entity*> newEntities;
			// otherwise, we have to check that the entity exists in both sets
			for (auto iter = entities.begin(); iter != entities.end(); ++iter)
			{
				if (excluded.end() != excluded.find(*iter))
					newEntities.insert(*iter);
			}
			entities = newEntities;
		}
	}
	return entities;
}
开发者ID:simsea,项目名称:mojito,代码行数:79,代码来源:EntityManager.cpp


注:本文中的Filter::getOne方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。