Skip to content

Commit

Permalink
log nodes/segments updating.
Browse files Browse the repository at this point in the history
  • Loading branch information
kianzarrin committed Dec 20, 2022
1 parent 4b7e3df commit ddefeb5
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 2 deletions.
5 changes: 3 additions & 2 deletions NodeController/LifeCycle/SerializableDataExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,9 @@ public static void BeforeNetMangerAfterDeserialize() {
public static void Load() {
try {
Log.Called();
Log.Info(Helpers.WhatIsCurrentThread());
Log.Debug(Helpers.WhatIsCurrentThread());
Log.Debug("SimulationPaused=" + SimulationManager.instance.SimulationPaused);
Log.Debug($"[before] NetManger to update {NodeManager.CountUpdatingNodes()} nodes and {SegmentEndManager.CountUpdatingSegments()} segments.");
byte[] data = SerializableData.LoadData(DATA_ID);
if (data != null) {
LoadingVersion = 2;
Expand All @@ -114,7 +115,7 @@ public static void Load() {
NodeManager.ValidateAndHeal(true);
NodeManager.Instance.OnLoad();
SegmentEndManager.Instance.OnLoad();

Log.Info($"[after] NetManger to update {NodeManager.CountUpdatingNodes()} nodes and {SegmentEndManager.CountUpdatingSegments()} segments.");
NCLifeCycle.LoadingStage = NCLifeCycle.Stage.DataLoaded;
Log.Succeeded();
} catch(Exception ex) { ex.Log(); }
Expand Down
10 changes: 10 additions & 0 deletions NodeController/Manager/NodeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -235,5 +235,15 @@ public static void ValidateAndHeal(bool showError1) {
Instance.Validate(m2, true);
SegmentEndManager.Instance.Validate(m2, true);
}

public static int CountUpdatingNodes() {
int ret = 0;
if (NetManager.instance.m_nodesUpdated) {
foreach (var block in NetManager.instance.m_updatedNodes) {
ret += EnumBitMaskExtensions.CountOnes(block);
}
}
return ret;
}
}
}
9 changes: 9 additions & 0 deletions NodeController/Manager/SegmentEndManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,5 +180,14 @@ public void Heal() {
buffer[i] = null;
}
}
public static int CountUpdatingSegments() {
int ret = 0;
if (NetManager.instance.m_segmentsUpdated) {
foreach (var block in NetManager.instance.m_updatedSegments) {
ret += EnumBitMaskExtensions.CountOnes(block);
}
}
return ret;
}
}
}
28 changes: 28 additions & 0 deletions NodeController/Patches/NetManager/UpdateNodeSegmentPatch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#if DEBUG
namespace NodeController.Patches._NetManager;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HarmonyLib;
using KianCommons;
using KianCommons.Patches;

//[HarmonyPatch2(typeof(NetManager), typeof(UpdateNode))]
static class UpdateNodePatch {
delegate void UpdateNode(ushort node, ushort fromSegment, int level);
static void Prefix(ushort node, ushort fromSegment, int level) {
Log.Called("node:" + node, "fromSegment:" + fromSegment, "level:" + level);
Log.Stack();
}
}

//[HarmonyPatch2(typeof(NetManager), typeof(UpdateSegment))]
static class UpdateSegmentPatch {
delegate void UpdateSegment(ushort segment);
static void Prefix(ushort segment) {
Log.Called("segment:" + segment);
Log.Stack();
}
}
#endif

0 comments on commit ddefeb5

Please sign in to comment.