Skip to content

Commit 415bb2e

Browse files
committed
优化初始化速度
1 parent 57201f7 commit 415bb2e

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

Assets/Plugins/Slua_Managed/LuaSvr.cs

+21-9
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
// init will not use reflection to speed up the speed
2525
//#define USE_STATIC_BINDER
2626

27+
using System.Diagnostics;
28+
2729
namespace SLua
2830
{
2931
using System;
@@ -156,20 +158,30 @@ static internal IEnumerator doBind(IntPtr L,Action<int> _tick,Action complete)
156158

157159
tick (0);
158160
var list = collectBindInfo ();
159-
160-
tick (2);
161-
162-
int bindProgress = 2;
161+
const int bindProgressStart = 5;
162+
tick (bindProgressStart);
163+
164+
int bindProgress = bindProgressStart;
163165
int lastProgress = bindProgress;
166+
Stopwatch sw = Stopwatch.StartNew();
167+
const int millisecondsPerFrame = 1000;
168+
int nextframeMilliseconds = millisecondsPerFrame;
169+
//Debug.Log("reg count=" + list.Count);
164170
for (int n = 0; n < list.Count; n++)
165171
{
166172
Action<IntPtr> action = list[n];
167173
action(L);
168-
bindProgress = (int)(((float)n / list.Count) * 98.0) + 2;
169-
if (_tick!=null && lastProgress != bindProgress && bindProgress % 5 == 0) {
170-
lastProgress = bindProgress;
171-
tick (bindProgress);
172-
yield return null;
174+
bindProgress = (int)(((float)n / list.Count) * (100-bindProgressStart)) + bindProgressStart;
175+
176+
if (_tick!=null && lastProgress != bindProgress && bindProgress > lastProgress)
177+
{
178+
lastProgress = bindProgress;
179+
if (sw.ElapsedMilliseconds > nextframeMilliseconds)
180+
{
181+
nextframeMilliseconds += millisecondsPerFrame;
182+
tick(bindProgress);
183+
yield return null;
184+
}
173185
}
174186
}
175187

0 commit comments

Comments
 (0)