CEventPump.stepEvents Member

Syntax

object.stepEvents();

Returns

Remarks

See Also

Source Code

function ep_stepevents()
{
var i = 0;
var st, en, e;
st = new Date();
while (i < this.eventsPerStep)
{
if (this.queuePointer >= this.queue.length)
break;
e = this.queue[this.queuePointer++];
if (e.type == "yield")
break;
this.routeEvent(e);
i++;
}
while (i < this.eventsPerStep)
{
if (this.bulkQueuePointer >= this.bulkQueue.length)
break;
e = this.bulkQueue[this.bulkQueuePointer++];
if (e.type == "yield")
break;
this.routeEvent(e);
i++;
}
en = new Date();
// i == number of items handled this time.
// We only want to do this if we handled at least 25% of our step-limit
// and if we have a sane interval between st and en (not zero).
if ((i * 4 >= this.eventsPerStep) && (en - st > 0))
{
// Calculate the number of events that can be processed in 400ms.
var newVal = (400 * i) / (en - st);
// If anything skews it majorly, limit it to a minimum value.
if (newVal < 10)
newVal = 10;
// Adjust the step-limit based on this "target" limit, but only do a
// 25% change (underflow filter).
this.eventsPerStep += Math.round((newVal - this.eventsPerStep) / 4);
}
// Clean up if we've handled a lot, or the queue is small.
if ((this.queuePointer >= this.FORCE_CLEANUP_PTR) ||
(this.queue.length <= this.MAX_AUTO_CLEANUP_LEN))
{
this.queue.splice(0, this.queuePointer);
this.queuePointer = 0;
}
// Clean up if we've handled a lot, or the queue is small.
if ((this.bulkQueuePointer >= this.FORCE_CLEANUP_PTR) ||
(this.bulkQueue.length <= this.MAX_AUTO_CLEANUP_LEN))
{
this.bulkQueue.splice(0, this.bulkQueuePointer);
this.bulkQueuePointer = 0;
}
return i;
}