Author Topic: [RESOURCE] LIHO/HILO Queue  (Read 4936 times)

except that that would work just fine
Code: [Select]
function HTQueueSO::onAdd(%this)
{
%this.head = -1;
%this.tail = 0;
}
function HTQueueSO::push(%this,%value)
{
  %this.value[%this.head++] = %value;
}

function HTQueueSO::pop(%this)
{
  if (%this.head < %this.tail)
  {
    return "";
  }

  %value = %this.value[%this.tail];

  %this.value[%this.tail] = "";
  %this.tail++;

  if (%this.tail > %this.head)
  {
    %this.head = -1;
    %this.tail = 0;
  }

  return %value;
}

I just found that Blockland has a default QueueSO class.

Code: [Select]
%queue = New_QueueSO(%size) - %size must be between 1 (inclusive) and 10000
QueueSO::push(%queue, %val)
QueueSO::pop(%queue)
QueueSO::dumpVals(%queue)

I just found that Blockland has a default QueueSO class.

Code: [Select]
%queue = New_QueueSO(%size) - %size must be between 1 (inclusive) and 10000
QueueSO::push(%queue, %val)
QueueSO::pop(%queue)
QueueSO::dumpVals(%queue)

You tripped me out so bad. I thought Blockland actually had a QueueSO class that I never knew about.

 :cookieMonster:

Well, a Torquescript class anyway. So it's really just a scriptobject.

:cookieMonster:

Well, a Torquescript class anyway. So it's really just a scriptobject.

It's some mod you have defining it. It's not there by default.

What's the entire point of this Queue stuff?

It's some mod you have defining it. It's not there by default.

No I found it in the source code.

I just found that Blockland has a default QueueSO class.

It's not defined unless you actually start a server beforehand.

It's not defined unless you actually start a server beforehand.

Yes, I should have mentioned that I found it in the server scripts.

Well that's unfortunate. Here's a (very slightly modified) version that you can use as a client, too. It works the same exact way the default one does.

Code: [Select]
function New_QueueSO(%size) {
  if(%size <= 1 || %size > 10000) {
    error("ERROR: New_QueueSO() - invalid size \'" @ %size @ "\'");
    return;
  }
  %ret = new ScriptObject() {
    class = "QueueSO";
    size = %size;
    head = 0;
    tail = 0;
  };
  if(isObject(MissionCleanup))
    MissionCleanup.add(%ret);
  for(%i = 0; %i < %size; %i++) {
    %ret.val[%i] = 0;
  }
  return %ret;
}

function QueueSO::push(%obj, %val) {
  %obj.val[%obj.head] = %val;
  %obj.head = (%obj.head+1) % %obj.size;
  %obj.val[%obj.head] = 0;
  if(%obj.head == %obj.tail)
    %obj.tail = (%obj.tail + 1) % %obj.size;
}

function QueueSO::pop(%obj) {
  if(%obj.head != %obj.tail) {
    %obj.head--;
    if(%obj.head < 0)
      %obj.head = %obj.size - 1;
    %ret = %obj.val[%obj.head];
    %obj.val[%obj.head] = 0;
  }
  return %ret;
}

function QueueSO::dumpVals(%obj) {
  for(%i = 0; %i < %obj.size; %i++) {
    %line = %i @ ": " @ %obj.val[%i];
    if(%obj.head == %i)
      %line = %line @ " <Head";
    if(%obj.tail == %i)
      %line = %line @ " <Tail";
    echo(%line);
  }
}