Skip to content

merge #495

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 15, 2023
Merged

merge #495

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@
</p>



# JENGINE v0.8.0f6

![Alt](https://repobeats.axiom.co/api/embed/d085b73402ea8b3e88deb98cb4074afd95528c0d.svg "Repobeats analytics image")


**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 in runtime.**

The ```master``` branch is the latest version that the developers think can be used normally and will not have too many problems. It is recommended to use and has the most powerful functions (also it fixes the bugs in the old versions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,16 @@ private void OnDestroy()
/// </summary>
private readonly List<IntPtr> _onceTaskItems = new List<IntPtr>(100);

/// <summary>
/// no gc search for awake objs
/// </summary>
private readonly HashSet<IntPtr> _awakeObjs = new HashSet<IntPtr>();

/// <summary>
/// no gc search for start objs
/// </summary>
private readonly HashSet<IntPtr> _startObjs = new HashSet<IntPtr>();

/// <summary>
/// Create lifecycle item
/// </summary>
Expand Down Expand Up @@ -238,6 +248,7 @@ public void AddAwakeItem<T>(T instance, MethodInfo method) where T : class
_awakeItems.Add(GetLifeCycleItem(in ptr, in address,
() => method?.Invoke(instance, ConstMgr.NullObjects),
() => true));
_awakeObjs.Add((IntPtr)ptr);
}

/// <summary>
Expand All @@ -251,6 +262,7 @@ public void AddStartItem<T>(T instance, MethodInfo method) where T : class
_startItems.Add(GetLifeCycleItem(in ptr, in address,
() => method?.Invoke(instance, ConstMgr.NullObjects),
() => true));
_startObjs.Add((IntPtr)ptr);
}

/// <summary>
Expand All @@ -275,8 +287,7 @@ public void AddUpdateItem(object instance, MethodInfo method)
/// <param name="method"></param>
/// <param name="parent"></param>
/// <param name="cond"></param>
public void AddUpdateItem<T>(T instance, MethodInfo method, GameObject parent, Func<bool> cond = null)
where T : class
public void AddUpdateItem<T>(T instance, MethodInfo method, GameObject parent, Func<bool> cond = null) where T : class
{
void* ptr = UnsafeUtility.PinGCObjectAndGetAddress(instance, out var address);
_updateItems.Add(GetLifeCycleItem(in ptr, in address,
Expand Down Expand Up @@ -351,12 +362,11 @@ public void AddLateUpdateItem(object instance, MethodInfo method)
/// <param name="method"></param>
/// <param name="parent"></param>
/// <param name="cond"></param>
public void AddLateUpdateItem<T>(T instance, MethodInfo method, GameObject parent, Func<bool> cond = null)
where T : class
public void AddLateUpdateItem<T>(T instance, MethodInfo method, GameObject parent, Func<bool> cond = null) where T : class
{
void* ptr = UnsafeUtility.PinGCObjectAndGetAddress(instance, out var address);
_lateUpdateItems.Add(GetLifeCycleItem(in ptr, in address,
() => method?.Invoke(instance, ConstMgr.NullObjects),
() => method?.Invoke(instance, ConstMgr.NullObjects),
() => cond == null ? parent.activeInHierarchy : parent.activeInHierarchy && cond.Invoke()));
}

Expand Down Expand Up @@ -398,12 +408,11 @@ public void AddFixedUpdateItem(object instance, MethodInfo method)
/// <param name="method"></param>
/// <param name="parent"></param>
/// <param name="cond"></param>
public void AddFixedUpdateItem<T>(T instance, MethodInfo method, GameObject parent, Func<bool> cond = null)
where T : class
public void AddFixedUpdateItem<T>(T instance, MethodInfo method, GameObject parent, Func<bool> cond = null) where T : class
{
void* ptr = UnsafeUtility.PinGCObjectAndGetAddress(instance, out var address);
_fixedUpdateItems.Add(GetLifeCycleItem(in ptr, in address,
() => method?.Invoke(instance, ConstMgr.NullObjects),
() => method?.Invoke(instance, ConstMgr.NullObjects),
() => cond == null ? parent.activeInHierarchy : parent.activeInHierarchy && cond.Invoke()));
}

Expand Down Expand Up @@ -509,8 +518,9 @@ public void RemoveTask<T>(T instance) where T : class
/// <param name="items"></param>
/// <param name="removeAfterInvoke"></param>
/// <param name="ignoreCondition"></param>
/// <param name="iterate"></param>
private void ExecuteItems(List<IntPtr> items, in bool removeAfterInvoke = true,
IgnoreCondFunc ignoreCondition = null)
IgnoreCondFunc ignoreCondition = null, Action<LifeCycleItem> iterate = null)
{
int count = items.Count;
//遍历
Expand Down Expand Up @@ -556,6 +566,7 @@ private void ExecuteItems(List<IntPtr> items, in bool removeAfterInvoke = true,
try
{
item->Action?.Invoke();
iterate?.Invoke(*item);
}
catch (Exception ex)
{
Expand Down Expand Up @@ -617,8 +628,8 @@ private bool InstancesContains(in LifeCycleItem* item)
/// <returns></returns>
private bool IgnoreWithInInstances(in LifeCycleItem* item)
{
return _awakeItems.Contains((IntPtr)item)
|| _startItems.Contains((IntPtr)item);
return _awakeObjs.Contains(item->InstancePtr)
|| _startObjs.Contains(item->InstancePtr);
}

/// <summary>
Expand Down Expand Up @@ -687,7 +698,8 @@ private void LateUpdate()
_instances.Add(item->InstancePtr);
}

ExecuteItems(_awakeItems);
ExecuteItems(_awakeItems,
iterate: il => _awakeObjs.Remove(il.InstancePtr));
}

//如果有start
Expand All @@ -705,9 +717,10 @@ private void LateUpdate()
_instances.Add(item->InstancePtr);
}
}

//调用start,并记录本帧处理的对象
ExecuteItems(_startItems, true, InstancesContains);
ExecuteItems(_startItems, true, InstancesContains,
iterate: il => _startObjs.Remove(il.InstancePtr));
}
else
{
Expand All @@ -718,8 +731,8 @@ private void LateUpdate()
item = (LifeCycleItem*)_startItems[i];
_instances.Add(item->InstancePtr);
}

ExecuteItems(_startItems);
ExecuteItems(_startItems, iterate: il => _startObjs.Remove(il.InstancePtr));
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Linq;
using System.Threading.Tasks;
using JEngine.Core;
using UnityEditor;
Expand Down Expand Up @@ -35,8 +36,11 @@ private static async void DoChange()
DynamicGI.UpdateEnvironment();
}

var initJEngine = GameObject.Find("InitJEngine");
var comp = initJEngine.GetComponent<InitJEngine>();
var comp = Object.FindFirstObjectByType<InitJEngine>();
if (comp == null)
{
Debug.LogWarning("没有找到InitJEngine脚本,无法检验秘钥是否正确");
}
var key = comp.key;
var k = PlayerPrefs.GetString($"{prefix}.EncryptPassword", "");
if (string.IsNullOrEmpty(k))
Expand Down