Esempio n. 1
0
////////////////////////////////////////////////////////////////////////////////
// publishInternal
BcBool EvtPublisher::publishInternal( EvtID ID, const EvtBaseEvent& EventBase, BcSize EventSize, BcBool AllowProxy )
{
	BcAssert( BcIsGameThread() );
	BcUnusedVar( EventSize );

#if PSY_USE_PROFILER
	PSY_PROFILER_INSTANT_EVENT( boost::str( boost::format( "EvtPublisher::publishInternal( ID: %1%, Size: %2% )" ) % ID % EventSize ) );
#endif

	// Proxy event through all attached proxies if this event allows it.
	if( AllowProxy == BcTrue )
	{
		for( TProxyListIterator It( Proxies_.begin() ); It != Proxies_.end(); ++It )
		{	
			EvtProxy* pProxy( *It );
			eEvtReturn RetVal = pProxy->proxy( ID, EventBase, EventSize );

			switch( RetVal )
			{
			// Event passed. Publisher, or next proxy can deal with it.
			case evtRET_PASS:
				break;
			// Event blocked. If we are a parent, we want our child publisher to abort (normal behaviour).
			case evtRET_BLOCK:
				return BcFalse;
				break;
			// Unsupported enum value.
			default:
				BcBreakpoint;
				break;
			}
		}
	}

	// Update binding map before going ahead.
	updateBindingMap();
	
	// If we have a parent, publish to them first.
	BcBool ShouldPublish = BcTrue;
	
	if( pParent_ != NULL )
	{
		ShouldPublish = pParent_->publishInternal( ID, EventBase, EventSize );
	}

	// Only publish if the previous call to our parent allows us to.
	if( ShouldPublish == BcTrue )
	{
		// Find the appropriate binding list.
		TBindingListMapIterator BindingListMapIterator = BindingListMap_.find( ID );
		
		// Add list if we need to, and grab iterator.
		if( BindingListMapIterator != BindingListMap_.end() )
		{
			// Iterate over all bindings in list and call.
			TBindingList& BindingList = BindingListMapIterator->second;
			TBindingListIterator Iter = BindingList.begin();
			
			while( Iter != BindingList.end() )
			{
				EvtBinding& Binding = (*Iter);
				
				// Call binding and handle it's return.
				eEvtReturn RetVal = Binding( ID, EventBase );
				switch( RetVal )
				{
					case evtRET_PASS:
						++Iter;
						break;

					case evtRET_BLOCK:
						return BcFalse;
						break;

					case evtRET_REMOVE:
						Iter = BindingList.erase( Iter );
						break;
						
					default:
						BcBreakpoint;
						break;
				}
			}
		}
	}

	return BcTrue;
}
Esempio n. 2
0
////////////////////////////////////////////////////////////////////////////////
// publishInternal
BcBool EvtPublisher::publishInternal( EvtID ID, const EvtBaseEvent& EventBase, BcSize EventSize )
{
	BcAssert( BcIsGameThread() );
	BcUnusedVar( EventSize );
	
	/*
	{
		BcChar PrefixA = ( ID >> 24 ) & 0xff;
		BcChar PrefixB = ( ID >> 16 ) & 0xff;
		BcU32 Group = ( ID >> 8 ) & 0xff;
		BcU32 Item = ( ID ) & 0xff;
		
		BcPrintf( "EvtPublish: %x, \"%c%c\": Group=%u Item=%u\n", ID, PrefixA, PrefixB, Group, Item );
	}
	 //*/

	// Update binding map before going ahead.
	updateBindingMap();
	
	// If we have a parent, publish to them first.
	BcBool ShouldPublish = BcTrue;
	
	if( pParent_ != NULL )
	{
		ShouldPublish = pParent_->publishInternal( ID, EventBase, EventSize );
	}

	// Only publish if the previous call to our parent allows us to.
	if( ShouldPublish == BcTrue )
	{
		// Find the appropriate binding list.
		TBindingListMapIterator BindingListMapIterator = BindingListMap_.find( ID );
		
		// Add list if we need to, and grab iterator.
		if( BindingListMapIterator != BindingListMap_.end() )
		{
			// Iterate over all bindings in list and call.
			TBindingList& BindingList = BindingListMapIterator->second;
			TBindingListIterator Iter = BindingList.begin();
			
			while( Iter != BindingList.end() )
			{
				EvtBinding& Binding = (*Iter);
				
				// Call binding and handle it's return.
				eEvtReturn RetVal = Binding( ID, EventBase );
				switch( RetVal )
				{
					case evtRET_PASS:
						++Iter;
						break;

					case evtRET_BLOCK:
						return BcFalse;
						break;

					case evtRET_REMOVE:
						Iter = BindingList.erase( Iter );
						break;
						
					default:
						BcBreakpoint;
						break;
				}
			}
		}
	}

	return BcTrue;
}