Queue Control - Quartz Composer Tip

Some months ago, when the Snow Leopard OS came out, one of the funny things, to me at least, was the "mouse ribbon" example. It felt like Apple had been paying a bit of attention to the underground, because it was basically a twist on so many quad structure writing things that had been done in the past year.

The thing that was problematic about it, as written, is that when the queue value was raised, it would never contract when a lower value was given afterwards. This meant that once your "line" was a certain length, it was stuck at that length. One could use some of the structure patches to shorten it back up to the current queue value, but the javascript patch would still be holding the higher value; not good for performance.

This is the stock code, in question:

_Queue = []

function (__structure Queue) main (__number Value[2], __index Size)
{
var result = new Object();
_Queue.push([Value[0], Value[1], 0])
if (_Queue.length > Size) _Queue.shift()
result.Queue = _Queue;
return result;
}


The problem with that code is that shift command is always adding one element per frame. So, at best, it would always leave the structure the same size.

This is the problem part:
_Queue.push([Value[0], Value[1], 0])
if (_Queue.length > Size) _Queue.shift()
result.Queue = _Queue;

Steve Mokris (a.k.a smokris), graciously pointed out the "splice" function to me.
_Queue.push([Value[0], Value[1], 0]);
if (_Queue.length > Size) _Queue.splice(0,_Queue.length-Size);
result.Queue = _Queue;

The logic in this example is correct, and will actually reduce the queue.

So, going past the 2D queue that doesn't contract, provided by Apple, this is what the code looks like for a 3D queue that WILL contract.

_Queue = []

function (__structure Queue) main (__number Value[3], __index Size)
{
var result = new Object();
_Queue.push([Value[0], Value[1], Value[2]]);
if (_Queue.length > Size) _Queue.splice(0,_Queue.length-Size); result.Queue = _Queue;
return result;
}

I'm posting an example qtz to the Box widget on the sidebar of the site.