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


C++ EventListener::Handle方法代码示例

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


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

示例1: Trigger

bool EventManager::Trigger(const Event *event) const
{
	// TODO: validate type

	// trigger events for wildcard listeners first
	EventListenerMap::const_iterator wildcardItor = m_registry.find(EVENT_TYPE_WILDCARD);
	if (wildcardItor != m_registry.end())
	{
		const EventListenerTable &table = wildcardItor->second;
		for (EventListenerTable::const_iterator i = table.begin(); i != table.end(); ++i)
		{
			EventListener *listener = *i;
			listener->Handle(event);
		}
	}

	// find the listener list for the event type
	EventListenerMap::const_iterator itor = m_registry.find(event->GetTypeOf());
	if (itor == m_registry.end())
		return false;

	bool result = false;

	// trigger the event in each listener
	const EventListenerTable &table = itor->second;
	for (EventListenerTable::const_iterator i = table.begin(); i != table.end(); ++i)
	{
		EventListener *listener = *i;
		if (listener->Handle(event))
		{
			// only return true if a listener signals they handled the event
			result = true;
		}
	}

	return result;
}
开发者ID:gered,项目名称:MyGameFramework,代码行数:37,代码来源:eventmanager.cpp

示例2: ProcessQueue

bool EventManager::ProcessQueue()
{
	EventListenerMap::const_iterator wildcardItor = m_registry.find(EVENT_TYPE_WILDCARD);

	// swap active queues and empty the new queue
	uint queueToProcess = m_activeQueue;
	m_activeQueue = (m_activeQueue + 1) % NUM_EVENT_QUEUES;
	m_queues[m_activeQueue].clear();

	// process the queue!
	EventQueue &queue = m_queues[queueToProcess];
	while (queue.size() > 0)
	{
		// pop the next event off the queue
		const Event *event = queue.front();
		queue.pop_front();

		EVENT_TYPE type = event->GetTypeOf();

		// process wildcard listeners first (if any)
		if (wildcardItor != m_registry.end())
		{
			const EventListenerTable &table = wildcardItor->second;
			for (EventListenerTable::const_iterator i = table.begin(); i != table.end(); ++i)
			{
				EventListener *listener = *i;
				listener->Handle(event);
			}
		}

		EventListenerMap::const_iterator listenerItor = m_registry.find(type);
		if (listenerItor != m_registry.end())
		{
			const EventListenerTable &table = listenerItor->second;
			for (EventListenerTable::const_iterator i = table.begin(); i != table.end(); ++i)
			{
				EventListener *listener = *i;
				if (listener->Handle(event))
					break;                      // don't let other listeners handle the event if this one signals it handled it
			}
		}

		SAFE_DELETE(event);
	}

	// if there are any events left in the queue, push them onto the active queue
	if (queue.size() != 0)
	{
		while (queue.size() > 0)
		{
			// to preserve sequencing, go bottom-up on the remainder of the queue that was processed
			// inserting them at the head of the active queue
			const Event *event = queue.back();
			queue.pop_back();
			m_queues[m_activeQueue].push_front(event);
		}

		return false;
	}
	else
		return true;
}
开发者ID:gered,项目名称:MyGameFramework,代码行数:62,代码来源:eventmanager.cpp


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