Skip to content

Commit ba92c90

Browse files
v0.7.5
v0.7.5
2 parents 7a0e9c2 + c468acc commit ba92c90

File tree

21 files changed

+433
-179
lines changed

21 files changed

+433
-179
lines changed

CHANGE.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
## All Versions
22

3-
### 0.7.5beta1 (September 25 2022)
3+
### 0.7.5beta (September 25 2022)
44

5+
- **Updated** ILRuntime to v2.1.0
6+
- **Optimized** code register workflow
57
- **Optimized** JStream buffer strategy
68
- **Optimized** ClassBind performance and GC
79
- **Optimized** JEngine Initialize procedure and performance

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
</p>
3939

4040

41-
# JENGINE v0.7.5beta1
41+
# JENGINE v0.7.5
4242

4343
**JEngine is an out-of-the-box framework designed for Unity developers. It encapsulates powerful functions. Beginners can also get started quickly and easily create games that can be updated hotly.**
4444

@@ -116,6 +116,8 @@ For new projects, you only need to pull a copy of the JEngine source code, then
116116
117117
## v0.7.5 New Features
118118
119+
- **Updated** ILRuntime to v2.1.0
120+
- **Optimized** code register workflow
119121
- **Optimized** JStream buffer strategy
120122
- **Optimized** ClassBind performance and GC
121123
- **Optimized** JEngine Initialize procedure and performance

README_zh_cn.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939

4040

4141

42-
# JENGINE v0.7.5beta1
42+
# JENGINE v0.7.5
4343

4444
JEngine是针对Unity开发者设计的**开箱即用**的框架,封装了强大的功能,小白也能**快速上手****轻松制作**可以**热更新的游戏**
4545

@@ -147,6 +147,10 @@ JEngine非常适合中小型项目,尤其是对于独立游戏开发者而言
147147

148148
## v0.7.5 最新功能
149149

150+
- **更新**ILRuntimev2.1.0
151+
152+
- **优化**适配代码注册流程
153+
150154
- **优化**JStream缓冲池策略
151155

152156
- **优化**ClassBind性能及GC

UnityProject/Assets/Dependencies/ILRuntime/ILRuntime/CLR/Method/ILMethod.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,11 @@ public sealed class ILMethod : IMethod
2727
ExceptionHandler[] exceptionHandler, exceptionHandlerR;
2828
KeyValuePair<string, IType>[] genericParameters;
2929
IType[] genericArguments;
30+
ILMethod genericDefinition;
3031
Dictionary<int, int[]> jumptables, jumptablesR;
3132
bool isDelegateInvoke;
33+
bool isEventAdd, isEventRemove;
34+
int eventFieldIndex;
3235
bool jitPending;
3336
ILRuntimeMethodInfo refletionMethodInfo;
3437
ILRuntimeConstructorInfo reflectionCtorInfo;
@@ -157,6 +160,7 @@ public Mono.Collections.Generic.Collection<Mono.Cecil.Cil.VariableDefinition> Va
157160

158161
public IType[] GenericArugmentsArray { get { return genericArguments; } }
159162

163+
public ILMethod GenericDefinition { get { return genericDefinition; } }
160164
public bool ShouldUseRegisterVM
161165
{
162166
get
@@ -347,6 +351,27 @@ public bool IsDelegateInvoke
347351
}
348352
}
349353

354+
public bool IsEventAdd
355+
{
356+
get
357+
{
358+
return isEventAdd;
359+
}
360+
}
361+
362+
public bool IsEventRemove
363+
{
364+
get
365+
{
366+
return isEventRemove;
367+
}
368+
}
369+
370+
public int EventFieldIndex
371+
{
372+
get { return eventFieldIndex; }
373+
}
374+
350375
public bool IsStatic
351376
{
352377
get { return def.IsStatic; }
@@ -797,6 +822,13 @@ unsafe void InitToken(ref OpCode code, object token, Dictionary<Mono.Cecil.Cil.I
797822
}
798823
}
799824

825+
public void SetEventAddOrRemove(bool isEventAdd, bool isEventRemove, int fieldIdx)
826+
{
827+
this.isEventRemove = isEventRemove;
828+
this.isEventAdd = isEventAdd;
829+
eventFieldIndex = fieldIdx;
830+
}
831+
800832
internal int GetTypeTokenHashCode(object token)
801833
{
802834
var t = appdomain.GetType(token, declaringType, this);
@@ -928,6 +960,7 @@ public IMethod MakeGenericMethod(IType[] genericArguments)
928960
ILMethod m = new ILMethod(def, declaringType, appdomain, jitFlags);
929961
m.genericParameters = genericParameters;
930962
m.genericArguments = genericArguments;
963+
m.genericDefinition = this;
931964
if (m.def.ReturnType.IsGenericParameter)
932965
{
933966
m.ReturnType = m.FindGenericArgument(m.def.ReturnType.Name);

UnityProject/Assets/Dependencies/ILRuntime/ILRuntime/CLR/TypeSystem/ILType.cs

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -716,52 +716,70 @@ public IMethod GetMethod ( string name, int paramCount, bool declaredOnly = fals
716716
}
717717
}
718718

719-
void InitializeMethods ()
719+
void InitializeMethods()
720720
{
721-
methods = new Dictionary<string, List<ILMethod>> ();
722-
constructors = new List<ILMethod> ();
723-
if ( definition == null )
721+
methods = new Dictionary<string, List<ILMethod>>();
722+
constructors = new List<ILMethod>();
723+
if (definition == null)
724724
return;
725-
if ( definition.HasCustomAttributes )
725+
if (definition.HasCustomAttributes)
726726
{
727-
for ( int i = 0; i < definition.CustomAttributes.Count; i++ )
727+
for (int i = 0; i < definition.CustomAttributes.Count; i++)
728728
{
729729
int f;
730-
if ( definition.CustomAttributes [ i ].GetJITFlags ( AppDomain, out f ) )
730+
if (definition.CustomAttributes[i].GetJITFlags(AppDomain, out f))
731731
{
732732
this.jitFlags = f;
733733
break;
734734
}
735735
}
736736
}
737-
foreach ( var i in definition.Methods )
737+
foreach (var i in definition.Methods)
738738
{
739-
if ( i.IsConstructor )
739+
if (i.IsConstructor)
740740
{
741-
if ( i.IsStatic )
742-
staticConstructor = new ILMethod ( i, this, appdomain, jitFlags );
741+
if (i.IsStatic)
742+
staticConstructor = new ILMethod(i, this, appdomain, jitFlags);
743743
else
744-
constructors.Add ( new ILMethod ( i, this, appdomain, jitFlags ) );
744+
constructors.Add(new ILMethod(i, this, appdomain, jitFlags));
745745
}
746746
else
747747
{
748748
List<ILMethod> lst;
749-
if ( !methods.TryGetValue ( i.Name, out lst ) )
749+
if (!methods.TryGetValue(i.Name, out lst))
750750
{
751-
lst = new List<ILMethod> ();
752-
methods [ i.Name ] = lst;
751+
lst = new List<ILMethod>();
752+
methods[i.Name] = lst;
753753
}
754-
var m = new ILMethod ( i, this, appdomain, jitFlags );
755-
lst.Add ( m );
754+
var m = new ILMethod(i, this, appdomain, jitFlags);
755+
lst.Add(m);
756+
}
757+
}
758+
759+
foreach (var i in definition.Events)
760+
{
761+
int fieldIdx = -1;
762+
InitializeFields();
763+
if(i.AddMethod.IsStatic)
764+
staticFieldMapping.TryGetValue(i.Name,out fieldIdx);
765+
else
766+
fieldMapping.TryGetValue(i.Name, out fieldIdx);
767+
if (methods.TryGetValue(i.AddMethod.Name, out var lst))
768+
{
769+
lst[0].SetEventAddOrRemove(true, false, fieldIdx);
770+
}
771+
if (methods.TryGetValue(i.RemoveMethod.Name, out lst))
772+
{
773+
lst[0].SetEventAddOrRemove(false, true, fieldIdx);
756774
}
757775
}
758776

759-
if ( !appdomain.SuppressStaticConstructor && !staticConstructorCalled )
777+
if (!appdomain.SuppressStaticConstructor && !staticConstructorCalled)
760778
{
761779
staticConstructorCalled = true;
762-
if ( staticConstructor != null && ( !TypeReference.HasGenericParameters || IsGenericInstance ) )
780+
if (staticConstructor != null && (!TypeReference.HasGenericParameters || IsGenericInstance))
763781
{
764-
appdomain.Invoke ( staticConstructor, null, null );
782+
appdomain.Invoke(staticConstructor, null, null);
765783
}
766784
}
767785
}

UnityProject/Assets/Dependencies/ILRuntime/ILRuntime/Reflection/ILRuntimeFieldInfo.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,13 +165,20 @@ public override object[] GetCustomAttributes(Type attributeType, bool inherit)
165165
return res.ToArray();
166166
}
167167

168+
public override object GetRawConstantValue()
169+
{
170+
return definition.Constant;
171+
}
172+
168173
public override object GetValue(object obj)
169174
{
170175
unsafe
171176
{
172177
ILTypeInstance ins;
173178
if (isStatic)
174179
{
180+
if (definition.HasConstant)
181+
return definition.Constant;
175182
ins = ilType.StaticInstance;
176183
}
177184
else

UnityProject/Assets/Dependencies/ILRuntime/ILRuntime/Runtime/CLRBinding/BindingCodeGenerator.cs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -648,8 +648,8 @@ internal static List<string> GenerateDelegateBinding(List<Type> types, string ou
648648
{
649649
var mi = i.GetMethod("Invoke");
650650
var miParameters = mi.GetParameters();
651-
if (mi.ReturnType == typeof(void) && miParameters.Length == 0)
652-
continue;
651+
//if (mi.ReturnType == typeof(void) && miParameters.Length == 0)
652+
// continue;
653653

654654
string clsName, realClsName, paramClsName, paramRealClsName;
655655
bool isByRef, paramIsByRef;
@@ -704,8 +704,9 @@ public static void Register(ILRuntime.Runtime.Enviorment.AppDomain app)
704704
mi.ReturnType.GetClassName(out paramClsName, out paramRealClsName, out paramIsByRef);
705705
sb.Append(paramRealClsName);
706706
sb.AppendLine("> ();");
707+
sb.AppendLine();
707708
}
708-
else
709+
else if (miParameters.Length != 0)
709710
{
710711
sb.Append(" app.DelegateManager.RegisterMethodDelegate<");
711712
first = true;
@@ -721,8 +722,8 @@ public static void Register(ILRuntime.Runtime.Enviorment.AppDomain app)
721722
sb.Append(paramRealClsName);
722723
}
723724
sb.AppendLine("> ();");
725+
sb.AppendLine();
724726
}
725-
sb.AppendLine();
726727

727728
sb.Append(" app.DelegateManager.RegisterDelegateConvertor<");
728729
sb.Append(realClsName);
@@ -763,10 +764,14 @@ public static void Register(ILRuntime.Runtime.Enviorment.AppDomain app)
763764
sb.Append(", ");
764765
mi.ReturnType.GetClassName(out paramClsName, out paramRealClsName, out paramIsByRef);
765766
sb.Append(paramRealClsName);
767+
sb.Append(">)act)(");
766768
}
767769
else
768770
{
769-
sb.Append(" ((Action<");
771+
if (miParameters.Length != 0)
772+
sb.Append(" ((Action<");
773+
else
774+
sb.Append(" ((Action");
770775
first = true;
771776
foreach (var j in miParameters)
772777
{
@@ -779,8 +784,11 @@ public static void Register(ILRuntime.Runtime.Enviorment.AppDomain app)
779784
j.ParameterType.GetClassName(out paramClsName, out paramRealClsName, out paramIsByRef);
780785
sb.Append(paramRealClsName);
781786
}
787+
if (miParameters.Length != 0)
788+
sb.Append(">)act)(");
789+
else
790+
sb.Append(")act)(");
782791
}
783-
sb.Append(">)act)(");
784792
first = true;
785793
foreach (var j in miParameters)
786794
{

UnityProject/Assets/Dependencies/ILRuntime/ILRuntime/Runtime/CLRBinding/BindingGeneratorExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ internal static bool ShouldSkipMethod(this Type type, MethodBase i)
3939
if (i.IsSpecialName)
4040
{
4141
string[] t = i.Name.Split('_');
42-
//if (t[0] == "add" || t[0] == "remove")
43-
// return true;
42+
if (t[0] == "add" || t[0] == "remove")
43+
return false;
4444
if (t[0] == "get" || t[0] == "set")
4545
{
4646
Type[] ts;

UnityProject/Assets/Dependencies/ILRuntime/ILRuntime/Runtime/Debugger/DebugService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ unsafe internal void CheckShouldBreak(ILMethod method, ILIntepreter intp, int ip
469469
}
470470
StackObject* basePointer = ResolveCurrentFrameBasePointer(intp, method, ip);
471471

472-
int methodHash = m.GetHashCode();
472+
int methodHash = m.IsGenericInstance ? m.GenericDefinition.GetHashCode() : m.GetHashCode();
473473
BreakpointInfo[] lst = null;
474474

475475
lock (activeBreakpoints)

0 commit comments

Comments
 (0)