// static
// Make sRenderInfoReportTimer expire so the next call to idle() will scan and query a new region
// called via LLViewerRegion::setCapabilitiesReceived() boost signals when the capabilities
// are returned for a new LLViewerRegion, and is the earliest time to get render info
void LLAvatarRenderInfoAccountant::expireRenderInfoReportTimer(const LLUUID& region_id)
{
	if (logRenderInfo())
	{
		LL_INFOS() << "LRI: Viewer has new region capabilities, clearing global render info timer" 
			<< " and timer for region " << region_id
			<< LL_ENDL;
	}

	// Reset the global timer so it will scan regions immediately
	sRenderInfoReportTimer.reset();
	
	LLViewerRegion* regionp = LLWorld::instance().getRegionFromID(region_id);
	if (regionp)
	{	// Reset the region's timer so it will request data immediately
		regionp->getRenderInfoRequestTimer().reset();
	}
}
// static
// Called every frame - send render weight requests to every region
void LLAvatarRenderInfoAccountant::idle()
{
	if (sRenderInfoReportTimer.hasExpired())
	{
		const F32 SECS_BETWEEN_REGION_SCANS   =  5.f;		// Scan the region list every 5 seconds
		const F32 SECS_BETWEEN_REGION_REQUEST = 60.0;		// Update each region every 60 seconds
	
		S32 num_avs = LLCharacter::sInstances.size();

		if (logRenderInfo())
		{
			LL_INFOS() << "LRI: Scanning all regions and checking for render info updates"
				<< LL_ENDL;
		}

		// Check all regions and see if it's time to fetch/send data
		for (LLWorld::region_list_t::const_iterator iter = LLWorld::getInstance()->getRegionList().begin();
				iter != LLWorld::getInstance()->getRegionList().end(); ++iter)
		{
			LLViewerRegion* regionp = *iter;
			if (regionp &&
				regionp->isAlive() &&
				regionp->capabilitiesReceived() &&						// Region has capability URLs available
				regionp->getRenderInfoRequestTimer().hasExpired())		// Time to make request
			{
				sendRenderInfoToRegion(regionp);
				getRenderInfoFromRegion(regionp);

				// Reset this regions timer, moving to longer intervals if there are lots of avatars around
				regionp->getRenderInfoRequestTimer().resetWithExpiry(SECS_BETWEEN_REGION_REQUEST + (2.f * num_avs));
			}
		}

		// We scanned all the regions, reset the request timer.
		sRenderInfoReportTimer.resetWithExpiry(SECS_BETWEEN_REGION_SCANS);
	}

	/* Singu TODO: RenderAutoMuteFunctions
	static LLCachedControl<U32> render_auto_mute_functions(gSavedSettings, "RenderAutoMuteFunctions", 0);
	static U32 prev_render_auto_mute_functions = (U32) -1;
	if (prev_render_auto_mute_functions != render_auto_mute_functions)
	{
		prev_render_auto_mute_functions = render_auto_mute_functions;

		// Adjust menus
		BOOL show_items = (BOOL)(render_auto_mute_functions & 0x04);
		gMenuAvatarOther->setItemVisible( std::string("Normal"), show_items);
		gMenuAvatarOther->setItemVisible( std::string("Always use impostor"), show_items);
		gMenuAvatarOther->setItemVisible( std::string("Never use impostor"), show_items);
		gMenuAvatarOther->setItemVisible( std::string("Impostor seperator"), show_items);
		
		gMenuAttachmentOther->setItemVisible( std::string("Normal"), show_items);
		gMenuAttachmentOther->setItemVisible( std::string("Always use impostor"), show_items);
		gMenuAttachmentOther->setItemVisible( std::string("Never use impostor"), show_items);
		gMenuAttachmentOther->setItemVisible( std::string("Impostor seperator"), show_items);

		if (!show_items)
		{	// Turning off visual muting
			for (std::vector<LLCharacter*>::iterator iter = LLCharacter::sInstances.begin();
					iter != LLCharacter::sInstances.end(); ++iter)
			{	// Make sure all AVs have the setting cleared
				LLVOAvatar* inst = (LLVOAvatar*) *iter;
				inst->setCachedVisualMute(false);
			}
		}
	}*/
}