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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
|
using System;
using System.Collections.Generic;
using XUtliPoolLib;
namespace XMainClient
{
internal sealed class XEventMgr : XSingleton<XEventMgr>
{
private XTimerMgr.ElapsedEventHandler _dispatchDelayEventCb = null;
private List<EventPoolClear> m_eventPoolClearCb = new List<EventPoolClear>();
private Dictionary<uint, List<XComponent.ComponentEventHandler>> m_EventHandlerMap = new Dictionary<uint, List<XComponent.ComponentEventHandler>>();
private List<XComponent.ComponentEventHandler> m_CacheEventHandlerList = null;
private SmallBufferPool<XComponent.ComponentEventHandler> m_eventPool = new SmallBufferPool<XComponent.ComponentEventHandler>();
private BlockInfo[] blockInit = new BlockInfo[]
{
new BlockInfo(4, 512),
new BlockInfo(8, 1024),
new BlockInfo(16, 1024)
};
public XEventMgr()
{
this._dispatchDelayEventCb = new XTimerMgr.ElapsedEventHandler(this.DispatchDelayEvent);
}
public override bool Init()
{
this.m_eventPool.Init(this.blockInit, 4);
return true;
}
public void GetBuffer(ref SmallBuffer<XComponent.ComponentEventHandler> sb, int size)
{
this.m_eventPool.GetBlock(ref sb, size, 0);
}
public void ReturnBuffer(ref SmallBuffer<XComponent.ComponentEventHandler> sb)
{
this.m_eventPool.ReturnBlock(ref sb);
}
public int GetAllocCount()
{
return this.m_eventPool.allocBlockCount;
}
public void BeginRegisterEvent(uint componentID)
{
this.m_CacheEventHandlerList = null;
bool flag = this.m_EventHandlerMap.TryGetValue(componentID, out this.m_CacheEventHandlerList);
if (flag)
{
this.m_CacheEventHandlerList = null;
}
else
{
this.m_CacheEventHandlerList = new List<XComponent.ComponentEventHandler>();
this.m_EventHandlerMap.Add(componentID, this.m_CacheEventHandlerList);
}
}
public void EndRegisterEvent()
{
this.m_CacheEventHandlerList = null;
}
public void RegisterEvent(XEventDefine eventID, XComponent.XEventHandler handler)
{
bool flag = this.m_CacheEventHandlerList != null;
if (flag)
{
int num = XFastEnumIntEqualityComparer<XEventDefine>.ToInt(eventID);
int count = this.m_CacheEventHandlerList.Count;
for (int i = 0; i < count; i++)
{
XComponent.ComponentEventHandler componentEventHandler = this.m_CacheEventHandlerList[i];
bool flag2 = componentEventHandler.eventIndex == num;
if (flag2)
{
return;
}
}
XComponent.ComponentEventHandler item = default(XComponent.ComponentEventHandler);
item.eventIndex = num;
item.handler = handler;
this.m_CacheEventHandlerList.Add(item);
}
}
public bool OnEvent(uint componentID, XEventArgs e)
{
List<XComponent.ComponentEventHandler> list = null;
bool flag = this.m_EventHandlerMap.TryGetValue(componentID, out list);
if (flag)
{
int num = XFastEnumIntEqualityComparer<XEventDefine>.ToInt(e.ArgsDefine);
int count = list.Count;
for (int i = 0; i < count; i++)
{
XComponent.ComponentEventHandler componentEventHandler = list[i];
bool flag2 = componentEventHandler.eventIndex == num;
if (flag2)
{
bool flag3 = componentEventHandler.handler != null;
if (flag3)
{
return componentEventHandler.handler(e);
}
}
}
}
return false;
}
public bool FireEvent(XEventArgs args)
{
return this.DispatchEvent(args);
}
public uint FireEvent(XEventArgs args, float delay)
{
bool flag = delay <= 0f;
uint result;
if (flag)
{
this.DispatchEvent(args);
result = 0u;
}
else
{
result = XSingleton<XTimerMgr>.singleton.SetTimer(delay, this._dispatchDelayEventCb, args);
}
return result;
}
public void CancelDelayEvent(uint token)
{
XSingleton<XTimerMgr>.singleton.KillTimer(token);
}
private void DispatchDelayEvent(object o)
{
this.DispatchEvent(o as XEventArgs);
}
private bool DispatchEvent(XEventArgs args)
{
bool result = false;
bool flag = args.Firer != null && (!args.Firer.Deprecated || args.DepracatedPass);
if (flag)
{
result = args.Firer.DispatchEvent(args);
}
bool flag2 = !args.ManualRecycle;
if (flag2)
{
args.Recycle();
}
return result;
}
public void RegisterEventPool(EventPoolClear epc)
{
this.m_eventPoolClearCb.Add(epc);
}
public void Clear()
{
for (int i = 0; i < this.m_eventPoolClearCb.Count; i++)
{
EventPoolClear eventPoolClear = this.m_eventPoolClearCb[i];
bool flag = eventPoolClear != null;
if (flag)
{
eventPoolClear();
}
}
this.m_eventPoolClearCb.Clear();
this.m_EventHandlerMap.Clear();
}
}
}
|