From 6eb915c129fc90c6f4c82ae097dd6ffad5239efc Mon Sep 17 00:00:00 2001 From: chai Date: Mon, 25 Jan 2021 14:28:30 +0800 Subject: +scripts --- Client/Assets/Scripts/XUtliPoolLib/SimpleQueue.cs | 80 +++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 Client/Assets/Scripts/XUtliPoolLib/SimpleQueue.cs (limited to 'Client/Assets/Scripts/XUtliPoolLib/SimpleQueue.cs') diff --git a/Client/Assets/Scripts/XUtliPoolLib/SimpleQueue.cs b/Client/Assets/Scripts/XUtliPoolLib/SimpleQueue.cs new file mode 100644 index 00000000..8781c147 --- /dev/null +++ b/Client/Assets/Scripts/XUtliPoolLib/SimpleQueue.cs @@ -0,0 +1,80 @@ +using System; + +namespace XUtliPoolLib +{ + public class SimpleQueue + { + public bool HasData + { + get + { + return this.Root != null; + } + } + + private IQueueObject Root = null; + + private IQueueObject Last = null; + + public void Clear() + { + IQueueObject next; + for (IQueueObject queueObject = this.Root; queueObject != null; queueObject = next) + { + next = queueObject.next; + queueObject.next = null; + } + this.Root = null; + this.Last = null; + } + + public void Enqueue(IQueueObject obj) + { + bool flag = obj != null; + if (flag) + { + obj.next = null; + bool flag2 = this.Root == null; + if (flag2) + { + this.Root = obj; + this.Last = this.Root; + } + else + { + bool flag3 = this.Last != null; + if (flag3) + { + this.Last.next = obj; + this.Last = obj; + } + else + { + XSingleton.singleton.AddErrorLog("queue state error", null, null, null, null, null); + } + } + } + else + { + XSingleton.singleton.AddWarningLog("can not enqueue null object", null, null, null, null, null); + } + } + + public T Dequeue() where T : IQueueObject, new() + { + IQueueObject queueObject = null; + bool flag = this.Root != null; + if (flag) + { + queueObject = this.Root; + this.Root = this.Root.next; + } + bool flag2 = this.Root == null; + if (flag2) + { + this.Last = null; + } + return (T)((object)queueObject); + } + } +} -- cgit v1.1-26-g67d0