Ejemplo n.º 1
0
	//----------------------------------------------------------------------
	void WorldTime::fireWorldTimeCame()
	{
		while(true)
		{
			// Process the first listener - the listener 
			// with earliest activation time.
			Listeners::Iterator it = mListeners.getIterator();
			if(!it.hasMoreElements())
				break; // no listeners to process

			Time activationTime = it.peekNextKey();
			if(activationTime > mCurrentTime)
				break; // all required listeners have been processed

			WorldTimeListener* listener = it.peekNextValue();
			Time period = listener->mPeriod;
			Time nextActivationTime;
			if(period != Time::INFINITY)
				nextActivationTime = activationTime + period;
			else
				nextActivationTime = Time::INFINITY; // next activation time = never

			// Call the listener.
			WorldTimeEvent evt(activationTime, nextActivationTime);
			listener->worldTimeCame(evt);
			nextActivationTime = evt.getNextActivationTime();

			// The worldTriggered function could remove the listener, 
			// so we check if the iterator points to the same listener yet.
			if(!it.hasMoreElements() || it.peekNextValue() != listener)
				continue; // process next listener

			// Remove the listener from the ordered list,
			// increase the activation time by period,
			// and insert the listener to the ordered list again.
			_removeListener(listener);
			if(nextActivationTime != Time::INFINITY)
			{
				_addListener(listener, nextActivationTime, period);
			}
		}
	}
Ejemplo n.º 2
0
bool Object::removeListener(uint32_t code, void (*fn)())
{
  Delegate0<> del(fn);
  return _removeListener(code, NULL, (const void*)&del, OBJECT_EVENT_HANDLER_VOID);
}
Ejemplo n.º 3
0
	//----------------------------------------------------------------------
	void WorldTime::_addListener(WorldTimeListener* _listener, const Time& _firstActivation, const Time& _period)
	{
		_removeListener(_listener);
		_listener->mPeriod = _period;
		_listener->mElementHandle = mListeners.add(_listener, _firstActivation);
	}
Ejemplo n.º 4
0
bool Object::removeListener(uint32_t code, void (*fn)(Event*))
{
  Delegate1<Event*> del(fn);
  return _removeListener(code, NULL, (const void*)&del, OBJECT_EVENT_HANDLER_EVENTPTR);
}