Game Development Community

Using a Simset as a Queue?

by Scott Johnson · in Torque Game Builder · 09/17/2006 (10:14 pm) · 4 replies

I'm looking to implement my own "command queue" for my game objects.

I am trying to determine the best implementation using TS.

I will want to implement both a LIFO, and FIFO queue, most likely with a priority capability.

My thought was that a simset at first glance seems like a good candidate, but I think there maybe a way using a simobject, with some dynamic arrays...

Has anyone gone down this road already? I would be keen on any implementation suggestions.

Thanks in advance.

#1
09/17/2006 (11:31 pm)
A SimSet already works as a FIFO queue with no further work necessary. It wouldn't take too much work to wrap one as a LIFO queue (just pull from the tail instead of the head). All arrays in TS are dynamic, but I'd stay away from them for these types of implementations. Of course, you are always free to implement your own data structures in the engine, or in script using ScriptObject types.
#2
09/17/2006 (11:47 pm)
Thanks Ben,

I will avoid the arrays, as the Simset does seem to be the ticket.

So If I were to use some namespaces.. (just psuedo coding here..)

queue::enQueue(%value)
queue::deQueue() (return the value from the queue)
queue.type = (FIFO | LIFO) // use this internally in dequeue to determine which end to pull from.

and then

%myQ = new simSet { class = "queue"; type="LIFO"; };

%myQ.enQueue("somevalue");

echo(%myQ.deQueue); // should return "somevalue" back.

of course implementing these functions to interact with the simSet will be necessary..

Does this sound reasonable?

I understand that I can implement this in the code (once I purchase that license)... for now I do want just a script solution, at some point in the future it should make it easier to port some of my script code into engine code.
#3
09/18/2006 (6:49 am)
Yes, I think that looks very reasonable with the exception that I don't think SimSet supports a class namespace. Try it out first. If it doesn't, then you'll just need to make this little modification:

%myQ = new SimObject()
{
    class = "Queue";
    data = new SimSet();
    type = "LIFO";
}

Does it make sense how you would then use this to get where you're going?

I would just do it in script too, no need to excuse yourself.

EDIT: I forgot to put the "class" in the code sample
#4
09/18/2006 (7:54 am)
I'll give it a whirl,

Now that you mention simSet possibly not supporting class, I think I've read that before, but I will go ahead and experiment (why not, this is all a big experiment anyhow :) )


Thanks for the help Ben.