summaryrefslogtreecommitdiff
path: root/Client/Assets/Scripts/XMainClient/XEventPool.cs
blob: 099be4dde04036278fd39828c3de35ec3aea2f57 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
using System;
using System.Collections.Generic;
using XUtliPoolLib;

namespace XMainClient
{
	internal class XEventPool<T> where T : XEventArgs, new()
	{
		private static Queue<T> _pool = null;

		public static void Clear()
		{
			bool flag = XEventPool<T>._pool != null;
			if (flag)
			{
				XEventPool<T>._pool.Clear();
				XEventPool<T>._pool = null;
			}
		}

		public static T GetEvent()
		{
			bool flag = XEventPool<T>._pool == null;
			if (flag)
			{
				XEventPool<T>._pool = new Queue<T>();
				XSingleton<XEventMgr>.singleton.RegisterEventPool(new EventPoolClear(XEventPool<T>.Clear));
			}
			bool flag2 = XEventPool<T>._pool.Count > 0;
			T result;
			if (flag2)
			{
				T t = XEventPool<T>._pool.Dequeue();
				bool flag3 = t == null;
				if (flag3)
				{
					XSingleton<XDebug>.singleton.AddErrorLog("XEvent Type should be ", typeof(T).ToString(), " but is ", t.ToString(), null, null);
				}
				t.Token = XSingleton<XCommon>.singleton.UniqueToken;
				result = t;
			}
			else
			{
				result = Activator.CreateInstance<T>();
			}
			return result;
		}

		public static void Recycle(T args)
		{
			XEventPool<T>._pool.Enqueue(args);
		}
	}
}