Skip to content

optimized JBehaviour loop + fixed nino demo error #448

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 1 commit into from
Dec 5, 2022
Merged
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
Binary file not shown.
Binary file not shown.
8 changes: 5 additions & 3 deletions UnityProject/HotUpdateScripts/JEngine/Core/JBehaviour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ private static async void JBehavioursLoop()
{
Stopwatch sw = new Stopwatch();
JBehaviour jb;
float duration, time;
for(; ; )
{
if (!Application.isPlaying) break;
Expand All @@ -177,7 +178,6 @@ private static async void JBehavioursLoop()
jb.Frequency = 1;
}

int duration;
if (jb.FrameMode)//等待
{
duration = (int)(jb.Frequency / ((float)Application.targetFrameRate <= 0 ? GameStats.FPS : Application.targetFrameRate) * 1000f);
Expand All @@ -193,7 +193,9 @@ private static async void JBehavioursLoop()
duration = 1;
}

if (Time.realtimeSinceStartup - jb.CurTime < duration / 1000f)
duration /= 1000f;

if (Time.realtimeSinceStartup - jb.CurTime < duration)
{
continue;
}
Expand All @@ -215,7 +217,7 @@ private static async void JBehavioursLoop()
sw.Stop();

//操作时间
var time = sw.ElapsedMilliseconds / 1000f + duration / 1000f + 0.001f;
time = sw.ElapsedMilliseconds / 1000f + 0.001f + duration;
jb.LoopCounts++;
jb.LoopDeltaTime = time;
jb.TotalTime += time;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void Awake()
});
_list.Add(new NinoTestData
{
sex = NinoTestData.Sex.Male,
sex = NinoTestData.Sex.Female,
name = "B",
id = 1,
isHasPet = true
Expand Down Expand Up @@ -93,7 +93,7 @@ public void Awake()
};
_arr[1] = new NinoTestData
{
sex = NinoTestData.Sex.Male,
sex = NinoTestData.Sex.Female,
name = "D",
id = 3,
isHasPet = false
Expand All @@ -102,8 +102,8 @@ public void Awake()
buf = Serializer.Serialize(_arr);
Log.Print($"Nino 将_arr数据序列化为了 {buf.Length} bytes");

var _arr2 = Deserializer.Deserialize<List<NinoTestData>>(buf);
Log.Print($"Nino 反序列化了一个_arr2,内部有{_arr2.Count}个元素");
var _arr2 = Deserializer.Deserialize<NinoTestData[]> (buf);
Log.Print($"Nino 反序列化了一个_arr2,内部有{_arr2.Length}个元素");
Log.Print($"_arr2[0].sex = {_arr2[0].sex}\n" +
$"_arr2[0].name = {_arr2[0].name}\n" +
$"_arr2[0].id = {_arr2[0].id}\n" +
Expand Down