Skip to content

Commit

Permalink
merge v0.8.0f6
Browse files Browse the repository at this point in the history
v0.8.0f6
  • Loading branch information
JasonXuDeveloper authored May 27, 2023
2 parents 6f5c35d + f902ddb commit 3a355ae
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 172 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
</a>
<a style="text-decoration:none">
<img src="https://www.codefactor.io/repository/github/jasonxudeveloper/jengine/badge" alt="badge" />
</a>
</a>[README_zh_cn.md](README_zh_cn.md)
<br>
<br>
<a href="https://xgamedev.net/"><strong>Documentation »</strong></a>
Expand All @@ -31,7 +31,7 @@



# JENGINE v0.8.0f5
# JENGINE v0.8.0f6

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

Expand Down
2 changes: 1 addition & 1 deletion README_zh_cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@



# JENGINE v0.8.0f5
# JENGINE v0.8.0f6

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,8 +357,10 @@ public static void LoadScene(string path, bool additive = false, string package
{
SceneOperationHandle handle = GetPackage(package)
.LoadSceneAsync(path, additive ? LoadSceneMode.Additive : LoadSceneMode.Single);
handle.Task.Wait();
RemoveUnusedAssets();
handle.Task.ContinueWith((_, __) => RemoveUnusedAssets()
, null);
_ = handle.Task;
Log.PrintWarning("LoadScene will not wait for scene loading complete. Use LoadSceneAsync instead.");
}

public static async Task LoadSceneAsync(string path, bool additive = false, string package = null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@

using System;
using UnityEngine;
using System.Threading;
using Unity.Collections;
using System.Reflection;
using System.Collections.Generic;
using Unity.Collections.LowLevel.Unsafe;
Expand Down Expand Up @@ -53,7 +55,24 @@ private struct LifeCycleItem

public static LifeCycleItem* Create(in void* instancePtr, in ulong gcAddr, Action action, Func<bool> cond)
{
LifeCycleItem* item = (LifeCycleItem*)Pool.Allocate(sizeof(LifeCycleItem));
byte* ptr = UsageList;
LifeCycleItem* item = ItemList;
byte* max = ptr + MaxSize;
while (ptr < max)
{
if (*ptr == 0)
{
*ptr = 1;
break;
}

ptr++;
item++;
}

if (ptr == max)
throw new Exception("LifeCycleMgr: LifeCycleItem is full!");

item->InstancePtr = (IntPtr)instancePtr;
item->_instanceGCHandleAddress = gcAddr;
item->_actionPtr = UnsafeUtility.PinGCObjectAndGetAddress(action, out item->_actionGCHandleAddress);
Expand All @@ -72,7 +91,7 @@ public void Dispose()
UnsafeUtility.ReleaseGCObject(_condGCHandleAddress);
fixed (LifeCycleItem* ptr = &this)
{
Pool.Free((byte*)ptr);
UsageList[ptr - ItemList] = 0;
}
}
}
Expand Down Expand Up @@ -100,12 +119,27 @@ public static void Initialize()
/// 单例
/// </summary>
public static LifeCycleMgr Instance => _instance;


/// <summary>
/// 非托管内存
/// </summary>
private static readonly LifeCycleItem* ItemList =
(LifeCycleItem*)UnsafeUtility.Malloc(sizeof(LifeCycleItem) * MaxSize, 4, Allocator.Persistent);

/// <summary>
/// 使用列表
/// </summary>
private static readonly byte* UsageList = (byte*)UnsafeUtility.Malloc(MaxSize, 4, Allocator.Persistent);

/// <summary>
/// 最大数量
/// </summary>
private const int MaxSize = 10000;

/// <summary>
/// 非托管内存池
/// 最多同时10240个被占用的任务(480KB内存)
/// 锁
/// </summary>
private static readonly UnmanagedMemoryPool Pool = new UnmanagedMemoryPool(sizeof(LifeCycleItem) * 10240);
private static SpinLock _createLock;

/// <summary>
/// unity周期
Expand All @@ -120,6 +154,19 @@ private void Awake()

_ignoreWithoutInInstancesFunc = IgnoreWithoutInInstances;
_ignoreWithInInstancesFunc = IgnoreWithInInstances;
GC.AddMemoryPressure(sizeof(LifeCycleItem) * MaxSize);
GC.AddMemoryPressure(MaxSize);
}

/// <summary>
/// 清理非托管
/// </summary>
private void OnDestroy()
{
UnsafeUtility.Free(ItemList, Allocator.Persistent);
UnsafeUtility.Free(UsageList, Allocator.Persistent);
GC.RemoveMemoryPressure(sizeof(LifeCycleItem) * MaxSize);
GC.RemoveMemoryPressure(MaxSize);
}

/// <summary>
Expand Down Expand Up @@ -175,7 +222,20 @@ private void Awake()
/// <param name="action"></param>
/// <param name="cond"></param>
private static IntPtr GetLifeCycleItem(in void* addr, in ulong gcAddr, Action action,
Func<bool> cond) => (IntPtr)LifeCycleItem.Create(in addr, in gcAddr, action, cond);
Func<bool> cond)
{
bool gotLock = false;
try
{
_createLock.Enter(ref gotLock);
return
(IntPtr)LifeCycleItem.Create(in addr, in gcAddr, action, cond);
}
finally
{
if (gotLock) _createLock.Exit();
}
}

/// <summary>
/// Add awake task
Expand Down Expand Up @@ -576,12 +636,12 @@ private bool IgnoreWithInInstances(in LifeCycleItem* item)
/// remove obj from instances
/// </summary>
private Predicate<IntPtr> RemoveInstanceIfContainsPredicate => RemoveInstanceIfContains;

/// <summary>
/// execute once task
/// </summary>
private bool _onceTaskExecuting;

/// <summary>
/// 处理只调用一次的任务
/// </summary>
Expand Down

This file was deleted.

This file was deleted.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "com.jasonxudeveloper.jengine",
"version": "0.8.0f5",
"version": "0.8.0f6",
"displayName": "JEngine",
"description": "The solution that allows unity games update in runtime.",
"license": "MIT",
Expand Down

0 comments on commit 3a355ae

Please sign in to comment.