From 385d789c969b39c3972fc79a00f06be650b4b110 Mon Sep 17 00:00:00 2001
From: ALEXTANG <574809918@qq.com>
Date: Thu, 20 Apr 2023 19:33:35 +0800
Subject: [PATCH 1/5] Create GameTickWatcher.meta
---
Assets/GameScripts/HotFix/GameBase/GameTickWatcher.meta | 3 +++
1 file changed, 3 insertions(+)
create mode 100644 Assets/GameScripts/HotFix/GameBase/GameTickWatcher.meta
diff --git a/Assets/GameScripts/HotFix/GameBase/GameTickWatcher.meta b/Assets/GameScripts/HotFix/GameBase/GameTickWatcher.meta
new file mode 100644
index 00000000..cdcc2e6b
--- /dev/null
+++ b/Assets/GameScripts/HotFix/GameBase/GameTickWatcher.meta
@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: b062b3e32edd4536a4308a3d180842e0
+timeCreated: 1681989133
\ No newline at end of file
From 069c5b93e0b5aa29d55c4fa85fd1c3a3e6ff1690 Mon Sep 17 00:00:00 2001
From: ALEXTANG <574809918@qq.com>
Date: Thu, 20 Apr 2023 19:34:01 +0800
Subject: [PATCH 2/5] [+] GameTickWacher
[+] GameTickWacher
---
.../GameTickWatcher/GameTickWatcher.cs | 40 +++++++++++++++++++
.../GameTickWatcher/GameTickWatcher.cs.meta | 3 ++
.../GameBase/{ => Singleton}/Singleton.cs | 9 ++++-
.../{ => Singleton}/Singleton.cs.meta | 0
4 files changed, 50 insertions(+), 2 deletions(-)
create mode 100644 Assets/GameScripts/HotFix/GameBase/GameTickWatcher/GameTickWatcher.cs
create mode 100644 Assets/GameScripts/HotFix/GameBase/GameTickWatcher/GameTickWatcher.cs.meta
rename Assets/GameScripts/HotFix/GameBase/{ => Singleton}/Singleton.cs (70%)
rename Assets/GameScripts/HotFix/GameBase/{ => Singleton}/Singleton.cs.meta (100%)
diff --git a/Assets/GameScripts/HotFix/GameBase/GameTickWatcher/GameTickWatcher.cs b/Assets/GameScripts/HotFix/GameBase/GameTickWatcher/GameTickWatcher.cs
new file mode 100644
index 00000000..b97f7cac
--- /dev/null
+++ b/Assets/GameScripts/HotFix/GameBase/GameTickWatcher/GameTickWatcher.cs
@@ -0,0 +1,40 @@
+using TEngine;
+
+namespace GameBase
+{
+ ///
+ /// 用来在多线程下检测耗时。
+ ///
+ public struct GameTickWatcher
+ {
+ private long _startTick;
+
+ public GameTickWatcher()
+ {
+ _startTick = System.DateTime.Now.Ticks;
+ }
+
+ public void Refresh()
+ {
+ _startTick = System.DateTime.Now.Ticks;
+ }
+
+ ///
+ /// 获取用时。
+ ///
+ ///
+ public float ElapseTime()
+ {
+ long endTick = System.DateTime.Now.Ticks;
+ return (float)((endTick - _startTick) / 10000) / 1000.0f;
+ }
+
+ ///
+ /// 输出用时。
+ ///
+ public void LogUsedTime()
+ {
+ Log.Info($"Used Time: {this.ElapseTime()}");
+ }
+ }
+}
\ No newline at end of file
diff --git a/Assets/GameScripts/HotFix/GameBase/GameTickWatcher/GameTickWatcher.cs.meta b/Assets/GameScripts/HotFix/GameBase/GameTickWatcher/GameTickWatcher.cs.meta
new file mode 100644
index 00000000..e05fddec
--- /dev/null
+++ b/Assets/GameScripts/HotFix/GameBase/GameTickWatcher/GameTickWatcher.cs.meta
@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: 7320165f7aa147a998a30fe2f7a5a5c2
+timeCreated: 1681989139
\ No newline at end of file
diff --git a/Assets/GameScripts/HotFix/GameBase/Singleton.cs b/Assets/GameScripts/HotFix/GameBase/Singleton/Singleton.cs
similarity index 70%
rename from Assets/GameScripts/HotFix/GameBase/Singleton.cs
rename to Assets/GameScripts/HotFix/GameBase/Singleton/Singleton.cs
index b8987757..2f14742f 100644
--- a/Assets/GameScripts/HotFix/GameBase/Singleton.cs
+++ b/Assets/GameScripts/HotFix/GameBase/Singleton/Singleton.cs
@@ -2,9 +2,14 @@
namespace GameBase
{
- public class Singleton where T:new()
+ ///
+ /// 通用单例。
+ ///
+ /// 泛型T。
+ public class Singleton where T : new()
{
private static T _instance;
+
public static T Instance
{
get
@@ -19,4 +24,4 @@ namespace GameBase
}
}
}
-}
+}
\ No newline at end of file
diff --git a/Assets/GameScripts/HotFix/GameBase/Singleton.cs.meta b/Assets/GameScripts/HotFix/GameBase/Singleton/Singleton.cs.meta
similarity index 100%
rename from Assets/GameScripts/HotFix/GameBase/Singleton.cs.meta
rename to Assets/GameScripts/HotFix/GameBase/Singleton/Singleton.cs.meta
From ec174377827b4544e56ca4730c1bb17747d6ff51 Mon Sep 17 00:00:00 2001
From: ALEXTANG <574809918@qq.com>
Date: Thu, 20 Apr 2023 19:34:13 +0800
Subject: [PATCH 3/5] [+] Loom
[+] Loom
---
Assets/GameScripts/HotFix/GameBase/Loom.meta | 8 +
.../GameScripts/HotFix/GameBase/Loom/Loom.cs | 190 ++++++++++++++++++
.../HotFix/GameBase/Loom/Loom.cs.meta | 11 +
3 files changed, 209 insertions(+)
create mode 100644 Assets/GameScripts/HotFix/GameBase/Loom.meta
create mode 100644 Assets/GameScripts/HotFix/GameBase/Loom/Loom.cs
create mode 100644 Assets/GameScripts/HotFix/GameBase/Loom/Loom.cs.meta
diff --git a/Assets/GameScripts/HotFix/GameBase/Loom.meta b/Assets/GameScripts/HotFix/GameBase/Loom.meta
new file mode 100644
index 00000000..e104ca98
--- /dev/null
+++ b/Assets/GameScripts/HotFix/GameBase/Loom.meta
@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: dab5f3e08b4367d41b801af29d381ca8
+folderAsset: yes
+DefaultImporter:
+ externalObjects: {}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/GameScripts/HotFix/GameBase/Loom/Loom.cs b/Assets/GameScripts/HotFix/GameBase/Loom/Loom.cs
new file mode 100644
index 00000000..e020612e
--- /dev/null
+++ b/Assets/GameScripts/HotFix/GameBase/Loom/Loom.cs
@@ -0,0 +1,190 @@
+using UnityEngine;
+using System.Collections.Generic;
+using System;
+using System.Threading;
+using System.Linq;
+
+/*******************************************************************************
+ //开启一个Loom进程
+ Loom.RunAsync(() =>
+ {
+ aucThread = new Thread(ReceiveMsg);
+ aucThread.Start();
+ }
+
+ //进程调用主线程方法
+ MainPack pack = (MainPack)MainPack.Descriptor.Parser.ParseFrom(buffer, 0, len);
+ Loom.QueueOnMainThread((param) =>
+ {
+ UdpHandleResponse(pack);
+ }, null);
+
+ *******************************************************************************/
+namespace GameBase
+{
+
+ ///
+ /// Loom多线程通信。
+ ///
+ ///
+ public class Loom : MonoBehaviour
+ {
+ public Dictionary TokenSourcesDictionary = new Dictionary();
+ private static readonly int MaxThreads = 8;
+ private static int _numThreads;
+ private static Loom _current;
+
+ public static Loom Current
+ {
+ get
+ {
+ Initialize();
+ return _current;
+ }
+ }
+
+ public void Awake()
+ {
+ _current = this;
+ _initialized = true;
+ }
+
+ protected void OnDestroy()
+ {
+ }
+
+ private static bool _initialized;
+
+ private static void Initialize()
+ {
+ if (!_initialized)
+ {
+ if (!Application.isPlaying)
+ {
+ return;
+ }
+
+ _initialized = true;
+
+ var obj = new GameObject("[Loom]");
+
+ _current = obj.AddComponent();
+
+ DontDestroyOnLoad(obj);
+ }
+ }
+
+ public struct NoDelayedQueueItem
+ {
+ public Action