Register for your free account! | Forgot your password?

Go Back   elitepvpers > MMORPGs > Conquer Online 2 > CO2 Programming
You last visited: Today at 10:35

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



[MiniRelease] Queue system

Discussion on [MiniRelease] Queue system within the CO2 Programming forum part of the Conquer Online 2 category.

Reply
 
Old   #1
 
elite*gold: 21
Join Date: Jul 2005
Posts: 9,193
Received Thanks: 5,376
[MiniRelease] Queue system

Ok so I discovered and slightly fell in love with the concept of queue's semi recently but was consistently annoyed by certain lack of functions they had.

Namely the ability to remove things prematurely that I did not want in the queue.

So tonight I was bored and wrote up a VERY simple queue system. It's NOT perfect but it seems to work in my initial tests.


It's storing objects so you can use it to store ANY VALUE YOU LIKE! Just be sure you are checking the type you are holding before you try to process it..




EXAMPLES OF HOW TO USE!


Simply add the reference to your project and then add it to your 'using' statements wherever you plan to setup the queue.

Personally I have it in my map structure to hold ground items (that way I can remove them from the server based on timeout in order they are dropped OR remove them when looted regardless of where they are in the queue)



Code:
using Queuing;
Now to setup you simply do something like...

Code:
Queueing.Queue Items = new Queueing.Queue();
Congratz! your queue is now setup! You will notice there are a few options to use...


Count: returns number of objects in the queue currently
Peek(): returns but does NOT remove the first object in the queue (next to be processed). Use for checks
Dequeue(): returns and removes the first object in queue (next to be processed)
Queue(object): adds the specified object to the END of the queue (LAST to be processed)
Remove(object): Removes the specified object from the queue regardless of its position.


Now! be sure to interpret the data that you are receiving back from the queue. You can do this with simple if checks.

Eg:

if(!(ItemsQueue.Peek is GroundItem)
return;

Be sure to convert your returned data into this type also!

eg:

GroundItem I = (GroundItem) ItemsQueue.Dequeue();


It's not obfuscated so feel free to decompose and offer criticism. It's simply a dictionary which adds/returns based on current object count. Nothing fancy at all.

I'm just starting to write some dll's (had never done it before) so maybe next time I'll do something more useful.


<edit>

Updated file: I was dumb and did a couple things wrong for the Remove(object) method. It works now. Please provide input and anything else you'd like to see done with it or other methods you'd like added.

Anyone have suggestions for dynamic handling of types? objects were the best way I could envision holding data but I wasn't sure if there is something better in C# to use to define what should be held or w/e.
pro4never is offline  
Thanks
3 Users
Old 10/12/2010, 14:26   #2
 
elite*gold: 0
Join Date: Feb 2009
Posts: 259
Received Thanks: 159
is and
Code:
         System.Collections.Queue Items = new System.Collections.Queue();
teroareboss1 is offline  
Old 10/12/2010, 15:21   #3
 
elite*gold: 0
Join Date: Sep 2008
Posts: 1,683
Received Thanks: 505
This should not be in the Conquer Online section but somewhere around the programming section.
Basser is offline  
Old 10/12/2010, 15:44   #4


 
Korvacs's Avatar
 
elite*gold: 20
Join Date: Mar 2006
Posts: 6,125
Received Thanks: 2,518
Moved.
Korvacs is offline  
Old 10/12/2010, 17:01   #5
 
elite*gold: 21
Join Date: Jul 2005
Posts: 9,193
Received Thanks: 5,376
Quote:
Originally Posted by teroareboss1 View Post
is and
Code:
         System.Collections.Queue Items = new System.Collections.Queue();
That's the queue system already in C# actually.

@ Basser/Korv.

Thanks for cleaning up the duplicate threads. Was hella tired when I posted. My bad.
pro4never is offline  
Old 10/12/2010, 22:03   #6
 
elite*gold: 20
Join Date: Aug 2007
Posts: 1,749
Received Thanks: 2,198
Although I've never felt the need for it, I guess combining the features of a list with the features of a queue is a pretty good idea. I wonder why Microsoft didn't think of it though. They could call it something like.. queued list?
IAmHawtness is offline  
Old 10/13/2010, 20:51   #7
 
elite*gold: 0
Join Date: Jan 2007
Posts: 656
Received Thanks: 541
Quote:
Originally Posted by IAmHawtness View Post
Although I've never felt the need for it, I guess combining the features of a list with the features of a queue is a pretty good idea. I wonder why Microsoft didn't think of it though. They could call it something like.. queued list?
I acctually use queues for a few things :P
Trigorio is offline  
Old 10/13/2010, 20:55   #8
 
elite*gold: 20
Join Date: Aug 2007
Posts: 1,749
Received Thanks: 2,198
Quote:
Originally Posted by Trigorio View Post
I acctually use queues for a few things :P
So do I, but I've never really felt the need to remove a specific object inside a queue
IAmHawtness is offline  
Old 10/13/2010, 20:59   #9
 
elite*gold: 0
Join Date: Jan 2007
Posts: 656
Received Thanks: 541
Quote:
Originally Posted by IAmHawtness View Post
So do I, but I've never really felt the need to remove a specific object inside a queue
Don't think I have either. Can't remember.
Trigorio is offline  
Old 10/13/2010, 21:06   #10


 
Korvacs's Avatar
 
elite*gold: 20
Join Date: Mar 2006
Posts: 6,125
Received Thanks: 2,518
This would be useful for say.... items stored on a floor queued for default removal (1 minute) and then removing it early if someone picks it up, i also created something like this for that specific purpose.
Korvacs is offline  
Old 10/13/2010, 23:14   #11
 
elite*gold: 21
Join Date: Jul 2005
Posts: 9,193
Received Thanks: 5,376
Quote:
Originally Posted by Korvacs View Post
This would be useful for say.... items stored on a floor queued for default removal (1 minute) and then removing it early if someone picks it up, i also created something like this for that specific purpose.
Yupp, that's exactly what I created this for.
pro4never is offline  
Old 10/13/2010, 23:42   #12
 
elite*gold: 0
Join Date: Jun 2009
Posts: 787
Received Thanks: 314
Hows this any different than the System.Collections(.Generic) Queue?
_tao4229_ is offline  
Old 10/13/2010, 23:50   #13


 
Korvacs's Avatar
 
elite*gold: 20
Join Date: Mar 2006
Posts: 6,125
Received Thanks: 2,518
The standard Queue doesnt allow you to remove items from any point in the Queue, just from the front. This allows you to remove items at any point in the Queue.
Korvacs is offline  
Old 10/14/2010, 00:24   #14
 
elite*gold: 0
Join Date: Jun 2009
Posts: 787
Received Thanks: 314
Code:
            Queue q = new Queue();
            q.Enqueue("Item 1"); // add our items
            q.Enqueue("Item 2");
            q.Enqueue("Item 3");
            Console.WriteLine(q.Peek()); // Item 1
            Console.WriteLine(q.Dequeue()); // Item 1

            q.Remove("Item 2"); // Removes Item 2 (currently the first item in the Queue)

            Console.WriteLine(q.Peek()); // key not present in dictionary exception
            Console.WriteLine(q.Dequeue()); // ^
Also:

Code:
public class Queue<T> {
  public void Enqueue(T obj);
  public T Dequeue();
}
/// Queue<string> q = new Queue<string>();
/// q.Enqueue("Hi");
/// string greeting = q.Dequeue();
And another edit:

I decided to have my hand at it and came up with this:

Code:
    public class Queue<T>
    {
        private LinkedListNode<T> First = null;
        private LinkedListNode<T> Last = null;
        private int m_Count;

        public int Count { get { return m_Count; } }

        public void Enqueue(T obj)
        {
            lock (this)
            {
                if (First == null)
                {
                    First = new LinkedListNode<T>(obj);
                    Last = First;
                }
                else
                {
                    LinkedListNode<T> node = new LinkedListNode<T>(obj);
                    Last.Next = node;
                    Last = node;
                }
                m_Count++;
            }
        }
        public T Dequeue()
        {
            lock (this)
            {
                if (First == null)
                {
                    throw new Exception("No elements left in the Queue");
                }
                else
                {
                    LinkedListNode<T> node = First.Next;
                    T retn = First.Value;

                    First = node;
                    m_Count--;
                    return retn;
                }
            }
        }
        public T Peek()
        {
            lock (this)
            {
                if (First == null)
                {
                    throw new Exception("No elements left in the Queue");
                }
                else
                {
                    return First.Value;
                }
            }
        }

        public bool Remove(T value)
        {
            lock (this)
            {
                if (First.Value.Equals(value))
                {
                    First = First.Next;
                    m_Count--;
                    return true;
                }

                LinkedListNode<T> node = First;
                while (node != null && node.Next != null)
                {
                    if (node.Next.Value.Equals(value))
                    {
                        node.Next = node.Next.Next;
                        m_Count--;
                        return true;
                    }
                    node = node.Next;
                }
                return false;
            }
        }
    }
    public class LinkedListNode<T>
    {
        public T Value;
        public LinkedListNode<T> Next;
        public LinkedListNode(T value)
        {
            Value = value;
        }
    }
_tao4229_ is offline  
Thanks
1 User
Old 10/22/2010, 06:10   #15
 
InfamousNoone's Avatar
 
elite*gold: 20
Join Date: Jan 2008
Posts: 2,012
Received Thanks: 2,882
**** Saint, you beat me to it. By a couple days it looks like too.
InfamousNoone is offline  
Thanks
1 User
Reply


Similar Threads Similar Threads
Queue system bugged :S
09/14/2009 - Silkroad Online - 3 Replies
guys this is really starting to annoy me, 3 days ago my premuim finished and i have been trying to log on to activate the new one... i havent got anywhere near logging in ! i open 4 clients, 3 with my main 1 with my staller, my staller goes in but my ain doesnt ! and it still keeps writing (requestion user confirmation)... when i check my netstat -n in the command promt it says that my main connects to server .29/.28 ... my staller connects to .68, my staller got in less that 1 hour :S ?...
The queue system is failing!
04/22/2009 - Conquer Online 2 - 8 Replies
So 2 viruses in the past few weeks(only that I have caught). And I have seen several reposts.
Topic Queue System
08/09/2007 - CO2 Guides & Templates - 0 Replies
New feature as been implemented!Topic Queue system for all CO2 release sections! CO2 Socket Theories CO2 Guides & Templates CO2 Weapon, Armor, Effects & Interface edits CO2 Exploits, Hacks & Tools CO2 Scams CO2 Bots & MacrosMods & Globals get to look over all new threads first before approval is given. Please do not submit more than once on making of a new thread. After We approve the thread, it will come up.



All times are GMT +2. The time now is 10:35.


Powered by vBulletin®
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2024 elitepvpers All Rights Reserved.