From 57201f76b88ab485d0c186a3db9e89db725a660b Mon Sep 17 00:00:00 2001 From: stallboy Date: Wed, 20 Jan 2021 16:07:28 +0800 Subject: [PATCH 1/2] =?UTF-8?q?Vector3.Angle=E5=8E=BB=E9=99=A4alloc?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/Plugins/Slua_Managed/LuaValueType.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Assets/Plugins/Slua_Managed/LuaValueType.cs b/Assets/Plugins/Slua_Managed/LuaValueType.cs index e894ca19..cfd71cdb 100644 --- a/Assets/Plugins/Slua_Managed/LuaValueType.cs +++ b/Assets/Plugins/Slua_Managed/LuaValueType.cs @@ -150,6 +150,8 @@ function Matrix3x3.Mul(m,v) end end +local Vector3Tmp1 +local Vector3Tmp2 do local Raw=UnityEngine.Vector3 Vector3={__typename='Vector3',__raw=Raw} @@ -290,7 +292,12 @@ function Vector3.Clone(self) end function Vector3.Angle(a,b) - local dot = Vector3.Dot(Vector3.Normalize(a), Vector3.Normalize(b)) + Vector3Tmp1:Set(a[1], a[2], a[3]) + Vector3.Normalized(Vector3Tmp1) + Vector3Tmp2:Set(b[1], b[2], b[3]) + Vector3.Normalized(Vector3Tmp2) + + local dot = Vector3.Dot(Vector3Tmp1, Vector3Tmp2) return acos(dot)*ToAngle end @@ -548,6 +555,9 @@ function Vector3.Project( vector,normal ) inherite(Vector3,Raw) setmetatable(Vector3,Vector3) + + Vector3Tmp1 = Vector3.New(0,0,0) + Vector3Tmp2 = Vector3.New(0,0,0) end do From 415bb2e0434891bdf954c180e90340eaf8244ee1 Mon Sep 17 00:00:00 2001 From: stallboy Date: Fri, 29 Oct 2021 14:02:34 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=88=9D=E5=A7=8B?= =?UTF-8?q?=E5=8C=96=E9=80=9F=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/Plugins/Slua_Managed/LuaSvr.cs | 30 +++++++++++++++++++-------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/Assets/Plugins/Slua_Managed/LuaSvr.cs b/Assets/Plugins/Slua_Managed/LuaSvr.cs index 8a261e35..e1af171a 100644 --- a/Assets/Plugins/Slua_Managed/LuaSvr.cs +++ b/Assets/Plugins/Slua_Managed/LuaSvr.cs @@ -24,6 +24,8 @@ // init will not use reflection to speed up the speed //#define USE_STATIC_BINDER +using System.Diagnostics; + namespace SLua { using System; @@ -156,20 +158,30 @@ static internal IEnumerator doBind(IntPtr L,Action _tick,Action complete) tick (0); var list = collectBindInfo (); - - tick (2); - - int bindProgress = 2; + const int bindProgressStart = 5; + tick (bindProgressStart); + + int bindProgress = bindProgressStart; int lastProgress = bindProgress; + Stopwatch sw = Stopwatch.StartNew(); + const int millisecondsPerFrame = 1000; + int nextframeMilliseconds = millisecondsPerFrame; + //Debug.Log("reg count=" + list.Count); for (int n = 0; n < list.Count; n++) { Action action = list[n]; action(L); - bindProgress = (int)(((float)n / list.Count) * 98.0) + 2; - if (_tick!=null && lastProgress != bindProgress && bindProgress % 5 == 0) { - lastProgress = bindProgress; - tick (bindProgress); - yield return null; + bindProgress = (int)(((float)n / list.Count) * (100-bindProgressStart)) + bindProgressStart; + + if (_tick!=null && lastProgress != bindProgress && bindProgress > lastProgress) + { + lastProgress = bindProgress; + if (sw.ElapsedMilliseconds > nextframeMilliseconds) + { + nextframeMilliseconds += millisecondsPerFrame; + tick(bindProgress); + yield return null; + } } }