Skip to content

Commit

Permalink
v0.7.4
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonXuDeveloper committed Sep 22, 2022
1 parent b4ef258 commit b4670c4
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 129 deletions.
10 changes: 10 additions & 0 deletions CHANGE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
## All Versions

### 0.7.4 (September 22 2022)

- Bug **fixed**
- **Imported ** high performance C# library Nino
- **Optimized** JBehaviour performance and GC
- **Optimized** MonoBehaviour update logics and GC
- **Optimized** blockwised decrypt intepret module's allocated memroy size and GC



### 0.7.3 (July 14 2022)

- Bug **fixed**
Expand Down
13 changes: 6 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
</p>


# JENGINE v0.7.3
# JENGINE v0.7.4

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

Expand Down Expand Up @@ -114,14 +114,13 @@ For new projects, you only need to pull a copy of the JEngine source code, then
## v0.7.3 New Features
## v0.7.4 New Features
- Bug **fixed**
- **Updated** ILRuntime
- **Updated** Bundle Master
- **Enhanced** JBehaviour performance
- **Enhanced** ClassBind runtime performance
- **Almost no GC allocation** async wait method
- **Imported ** high performance C# library Nino
- **Optimized** JBehaviour performance and GC
- **Optimized** MonoBehaviour update logics and GC
- **Optimized** blockwised decrypt intepret module's allocated memroy size and GC
[Click here to see the change log](CHANGE.md)
Expand Down
12 changes: 6 additions & 6 deletions README_zh_cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@



# JENGINE v0.7.3
# JENGINE v0.7.4

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

Expand Down Expand Up @@ -145,19 +145,19 @@ JEngine非常适合中小型项目,尤其是对于独立游戏开发者而言
**如果你觉得JEngine对你有帮助,请给该框架一个Star!**


## v0.7.3 最新功能
## v0.7.4 最新功能

- Bug**修复**

- **更新**ILRuntime

- **更新**Bundle Master
- **接入**高性能C#库Nino

- **优化**JBehaviour性能
- **优化**JBehaviour性能及GC

- **优化**ClassBind运行性能
- **优化**MonoBehaviour循环逻辑及GC

- **几乎无GC的**异步延时等待
- **优化**分块解密解释执行所占用的内存及产生的GC

[点击此处查看历史版本功能(英文)](CHANGE.md)

Expand Down
120 changes: 4 additions & 116 deletions UnityProject/Assets/Dependencies/JEngine/Core/Manager/TimeMgr.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
using System.Threading;
using System.Collections.Generic;
using System.Collections.Concurrent;
using System.Threading.Tasks;
using Timer = System.Threading.Timer;

namespace JEngine.Core
Expand All @@ -37,128 +38,15 @@ namespace JEngine.Core
/// </summary>
public static partial class TimeMgr
{
/// <summary>
/// 线程安全字典
/// </summary>
private static readonly ConcurrentDictionary<int, Stack<TimerWorker>> Timers =
new ConcurrentDictionary<int, Stack<TimerWorker>>();

/// <summary>
/// 计时器任务对象
/// </summary>
private class TimerWorker
{
/// <summary>
/// 计时器
/// </summary>
private readonly Timer _timer;
/// <summary>
/// 该任务使用哪个ETTask来设置回调
/// </summary>
private readonly int _index;
/// <summary>
/// 延迟
/// </summary>
private readonly int _ms;
/// <summary>
/// 上下文
/// </summary>
private SynchronizationContext _ctx;
/// <summary>
/// 是否开始了
/// </summary>
private bool _hasStart;

/// <summary>
/// 构造一个任务,延迟是delay毫秒
/// </summary>
/// <param name="delay"></param>
/// <param name="ctx"></param>
public TimerWorker(int delay, SynchronizationContext ctx)
{
_ms = delay;
_index = Tasks.Count;
_ctx = ctx;
_hasStart = false;
Tasks.Add(ETTask.Create(true));
_timer = new Timer(__ =>
{
if (!_hasStart || Tasks[_index] == null) return;
_ctx?.Send(_ => { Tasks[_index]?.SetResult(); }, null);
}, null, _ms,
Timeout.Infinite);
}

/// <summary>
/// 开始在一个指定上下文里等待
/// </summary>
/// <param name="context"></param>
public void Start(SynchronizationContext context)
{
_ctx = context;
if (Tasks[_index] == null)
{
Tasks[_index] = ETTask.Create(true);
}

_hasStart = true;
_timer.Change(_ms, Timeout.Infinite);
}

/// <summary>
/// 等待任务完成
/// </summary>
public async ETTask WaitForFinish()
{
await Tasks[_index];
Tasks[_index] = null;
_hasStart = false;
}
}

/// <summary>
/// 全部ETTask,用于存等待的结果的
/// </summary>
private static readonly List<ETTask> Tasks = new List<ETTask>(10);

/// <summary>
/// Delay for delay ms
/// </summary>
/// <param name="delayInMs"></param>
/// <returns></returns>
public static async ETTask Delay(int delayInMs)
public static async Task Delay(int delayInMs)
{
//当前线程的同步上下文
SynchronizationContext cur = SynchronizationContext.Current;
//获取任务
TimerWorker worker = null;
//先看有没有缓存过
if (Timers.TryGetValue(delayInMs, out var timers))
{
//有的话有没有空的
if (timers.Count > 0)
{
//取
worker = timers.Pop();
}
}
//创建
else
{
Timers[delayInMs] = new Stack<TimerWorker>(10);
}

if (worker == null)
{
worker = new TimerWorker(delayInMs, cur);
}

//开始
worker.Start(cur);
//等
await worker.WaitForFinish();
//存
Timers[delayInMs].Push(worker);
//TODO 待重做
await Task.Delay(delayInMs);
}
}
}
Binary file not shown.
Binary file not shown.

0 comments on commit b4670c4

Please sign in to comment.