Ejemplo n.º 1
0
long JMChattControl::GetImageIndexByPoint(Point point)
{
	long i=0;
	stCHATT_DATA* pChattData = null;
	Rectangle rtElementBox;


	for(i=__stScreenInfo.nViewAreaStartIndex ; i <= __stScreenInfo.nViewAreaEndIndex ; i++) {
		pChattData = (stCHATT_DATA*)(__pArrayChattData->GetAt(i));


		rtElementBox = ChangeRightRectangleToNormal(pChattData->rtElementBox);


		if( rtElementBox.Contains(point) ) {
			return i;
		}
	}
	return -1;
}
void WorldEntityManager::SyncRegions(Vector3 center, float range)
{
	Rectangle selectionRect = Rectangle(center.x - range, center.z - range, range * 2, range * 2);
	
	set<EntityPtr> newRegions;
	for (const EntityPtr & region : m_entityRegions) {
		Vector3 regionPosition = region->GetComponent<Components::Position>("Position")->Pos;
		if (selectionRect.Contains(regionPosition.x, regionPosition.z)) {
			newRegions.insert(region);
		}
	}
	// Only sync if the two sets are not equal
	if (newRegions != m_loadedEntityRegions) {
		// uncache entities that fall outside of the new region set
		for (auto & region : m_loadedEntityRegions) {
			if (newRegions.count(region) == 0) {
				m_quadTree.Remove(RegionArea(region));
			}
		}
		// cache entities in regions that haven't been loaded yet
		for (auto & region : newRegions) {
			if (m_loadedEntityRegions.count(region) == 0) {
				// Add the entities to the quadTree
				for (auto & entityID : region->GetComponent<Components::EntityRegion>("EntityRegion")->Entities) {
					EntityPtr entity;
					if (Find(entityID, entity)) {
						Vector3 pos3D = entity->GetComponent<Components::Position>("Position")->Pos;
						Vector2 pos2D = Vector2(pos3D.x, pos3D.z);
						m_quadTree.Insert(pos2D, entityID);
					}
				}
				m_loadedEntityRegions.insert(region);
			}
		}
		// load the new regions
		m_loadedEntityRegions = newRegions;
	}
}