diff --git a/1.3/Assemblies/RW_NodeTree.dll b/1.3/Assemblies/RW_NodeTree.dll index 9c6d965..13b684b 100644 Binary files a/1.3/Assemblies/RW_NodeTree.dll and b/1.3/Assemblies/RW_NodeTree.dll differ diff --git a/1.4/Assemblies/RW_NodeTree.dll b/1.4/Assemblies/RW_NodeTree.dll index 11b7940..81d299c 100644 Binary files a/1.4/Assemblies/RW_NodeTree.dll and b/1.4/Assemblies/RW_NodeTree.dll differ diff --git a/1.5/Assemblies/RW_NodeTree.dll b/1.5/Assemblies/RW_NodeTree.dll index fb852ab..a64e954 100644 Binary files a/1.5/Assemblies/RW_NodeTree.dll and b/1.5/Assemblies/RW_NodeTree.dll differ diff --git a/src/RW_NodeTree/CompBasicNodeComp.cs b/src/RW_NodeTree/CompBasicNodeComp.cs index 6fb4850..84a9d8d 100644 --- a/src/RW_NodeTree/CompBasicNodeComp.cs +++ b/src/RW_NodeTree/CompBasicNodeComp.cs @@ -80,9 +80,10 @@ public virtual void PostFX(RenderTexture tar) { } /// update event /// /// update event action node - protected virtual bool PreUpdateNode(CompChildNodeProccesser actionNode, Dictionary cachedDataToPostUpatde, Dictionary prveChilds) + protected virtual void PreUpdateNode(CompChildNodeProccesser actionNode, Dictionary cachedDataToPostUpatde, Dictionary prveChilds, out bool blockEvent, out bool notUpdateTexture) { - return false; + blockEvent = false; + notUpdateTexture = false; } /// @@ -90,9 +91,10 @@ protected virtual bool PreUpdateNode(CompChildNodeProccesser actionNode, Diction /// /// update event action node /// stope bubble - protected virtual bool PostUpdateNode(CompChildNodeProccesser actionNode, Dictionary cachedDataFromPerUpdate, Dictionary prveChilds) + protected virtual void PostUpdateNode(CompChildNodeProccesser actionNode, Dictionary cachedDataFromPerUpdate, Dictionary prveChilds, out bool blockEvent, out bool notUpdateTexture) { - return false; + blockEvent = false; + notUpdateTexture = false; } /// @@ -161,8 +163,8 @@ protected virtual List VerbToolRegiestInfoUpdate(Type owner return result; } - internal bool internal_PreUpdateNode(CompChildNodeProccesser actionNode, Dictionary cachedDataToPostUpatde, Dictionary prveChilds) => PreUpdateNode(actionNode, cachedDataToPostUpatde, prveChilds); - internal bool internal_PostUpdateNode(CompChildNodeProccesser actionNode, Dictionary cachedDataFromPerUpdate, Dictionary prveChilds) => PostUpdateNode(actionNode, cachedDataFromPerUpdate, prveChilds); + internal void internal_PreUpdateNode(CompChildNodeProccesser actionNode, Dictionary cachedDataToPostUpatde, Dictionary prveChilds, out bool blockEvent, out bool notUpdateTexture) => PreUpdateNode(actionNode, cachedDataToPostUpatde, prveChilds, out blockEvent, out notUpdateTexture); + internal void internal_PostUpdateNode(CompChildNodeProccesser actionNode, Dictionary cachedDataFromPerUpdate, Dictionary prveChilds, out bool blockEvent, out bool notUpdateTexture) => PostUpdateNode(actionNode, cachedDataFromPerUpdate, prveChilds, out blockEvent, out notUpdateTexture); internal bool internal_AllowNode(Thing node, string id = null) => AllowNode(node, id); internal void internal_Added(NodeContainer container, string id, bool success, Dictionary cachedData) => Added(container, id, success, cachedData); internal void internal_Removed(NodeContainer container, string id, bool success, Dictionary cachedData) => Removed(container, id, success, cachedData); diff --git a/src/RW_NodeTree/CompChildNodeProccesser.cs b/src/RW_NodeTree/CompChildNodeProccesser.cs index b34bdcc..dd7ae9c 100644 --- a/src/RW_NodeTree/CompChildNodeProccesser.cs +++ b/src/RW_NodeTree/CompChildNodeProccesser.cs @@ -353,7 +353,7 @@ public static bool CheckVerbDatasVaildityAndAdapt(Type ownerType, Thing thing, r /// public void ResetRenderedTexture() { - for (int i = 0; i < nodeRenderingInfos.Length; i++) nodeRenderingInfos[i] = null; + nodeRenderingInfo.Reset(); try { if (parent.Spawned && parent.def.drawerType >= DrawerType.MapMeshOnly) parent.DirtyMapMesh(parent.Map); @@ -509,7 +509,7 @@ internal void PostFX(RenderTexture tar) UpdateNode(); updated = false; - if (this.nodeRenderingInfos[rot.AsInt] != null) return this.nodeRenderingInfos[rot.AsInt]; + if (this.nodeRenderingInfo[rot] != null) return this.nodeRenderingInfo[rot]; updated = true; List<(string, Thing, List)> nodeRenderingInfos = new List<(string, Thing, List)>(ChildNodes.Count + 1); @@ -528,7 +528,7 @@ internal void PostFX(RenderTexture tar) //ORIGIN - subGraphic = ((subGraphic ?? parent.Graphic)?.GetGraphic_ChildNode() as Graphic_ChildNode)?.SubGraphic ?? subGraphic; + subGraphic = (subGraphic ?? parent.Graphic)?.GetGraphic_ChildNode()?.SubGraphic ?? subGraphic ?? parent.Graphic; if (subGraphic != null) { RenderingTools.StartOrEndDrawCatchingBlock = true; @@ -609,7 +609,7 @@ internal void PostFX(RenderTexture tar) Log.Error(ex.ToString()); } } - this.nodeRenderingInfos[rot.AsInt] = nodeRenderingInfos; + this.nodeRenderingInfo[rot] = nodeRenderingInfos; return nodeRenderingInfos; } @@ -786,11 +786,26 @@ public static implicit operator CompChildNodeProccesser(Thing thing) } #endregion + + public class NodeRenderingInfoForRot4 + { + public List<(string, Thing, List)> this[Rot4 rot] + { + get => nodeRenderingInfos[rot.AsInt]; + set => nodeRenderingInfos[rot.AsInt] = value; + } + public void Reset() + { + for (int i = 0; i < nodeRenderingInfos.Length; i++) nodeRenderingInfos[i] = null; + } + public readonly List<(string, Thing, List)>[] nodeRenderingInfos = new List<(string, Thing, List)>[4]; + } + private CompChildNodeProccesser cachedRootNode; private NodeContainer childNodes; - private readonly List<(string, Thing, List)>[] nodeRenderingInfos = new List<(string, Thing, List)>[4]; + private readonly NodeRenderingInfoForRot4 nodeRenderingInfo = new NodeRenderingInfoForRot4(); private readonly Dictionary> regiestedNodeVerbToolInfos = new Dictionary>(); diff --git a/src/RW_NodeTree/Graphic_ChildNode.cs b/src/RW_NodeTree/Graphic_ChildNode.cs index 251a1c9..e586058 100644 --- a/src/RW_NodeTree/Graphic_ChildNode.cs +++ b/src/RW_NodeTree/Graphic_ChildNode.cs @@ -123,7 +123,7 @@ public override Material MatAt(Rot4 rot, Thing thing = null) if (comp_ChildNodeProccesser != currentProccess) return SubGraphic?.MatAt(rot, thing); - (Material material, Texture2D texture, RenderTexture cachedRenderTarget) = renderingCache[rot]; + (Material material, Texture2D texture, RenderTexture cachedRenderTarget) = defaultRenderingCache[rot]; List<(string, Thing, List)> commands = comp_ChildNodeProccesser.GetNodeRenderingInfos(rot, out bool needUpdate, subGraphic); if (!needUpdate && material != null) goto ret; @@ -147,7 +147,7 @@ public override Material MatAt(Rot4 rot, Thing thing = null) material.shader = shader; } material.mainTexture = texture; - renderingCache[rot] = (material, texture, cachedRenderTarget); + defaultRenderingCache[rot] = (material, texture, cachedRenderTarget); ret:; @@ -158,7 +158,7 @@ public override Material MatAt(Rot4 rot, Thing thing = null) while (graphic != null && graphic != this) { graphic.drawSize = size; - graphic = graphic.SubGraphic(); + graphic = graphic.GetSubGraphic(); } this.drawSize = size; @@ -283,7 +283,7 @@ private class OffScreenRenderingCache public RenderTexture cachedRenderTargetNorth, cachedRenderTargetEast, cachedRenderTargetSouth, cachedRenderTargetWest; } - private readonly OffScreenRenderingCache renderingCache = new OffScreenRenderingCache(); + private readonly OffScreenRenderingCache defaultRenderingCache = new OffScreenRenderingCache(); private CompChildNodeProccesser currentProccess = null; private Graphic subGraphic = null; } diff --git a/src/RW_NodeTree/NodeContainer.cs b/src/RW_NodeTree/NodeContainer.cs index e8f6114..0224b47 100644 --- a/src/RW_NodeTree/NodeContainer.cs +++ b/src/RW_NodeTree/NodeContainer.cs @@ -189,6 +189,7 @@ public override void ExposeData() internal bool internal_UpdateNode(CompChildNodeProccesser actionNode = null) { bool StopEventBubble = false; + bool NotUpdateTexture = false; CompChildNodeProccesser proccess = this.Comp; if(proccess == null) return StopEventBubble; @@ -224,7 +225,9 @@ internal bool internal_UpdateNode(CompChildNodeProccesser actionNode = null) { try { - StopEventBubble = comp.internal_PreUpdateNode(actionNode, cachingData, new Dictionary(prveChilds)) || StopEventBubble; + comp.internal_PreUpdateNode(actionNode, cachingData, new Dictionary(prveChilds), out bool blockEvent, out bool notUpdateTexture); + StopEventBubble |= blockEvent; + NotUpdateTexture |= notUpdateTexture; } catch (Exception ex) { @@ -262,8 +265,8 @@ internal bool internal_UpdateNode(CompChildNodeProccesser actionNode = null) state = stateCode.r; bool reset = true; - if (StopEventBubble) return StopEventBubble; - foreach (Thing node in prveChilds.Values) + if (StopEventBubble) goto ret; + foreach (Thing node in this.Values) { NodeContainer container = ((CompChildNodeProccesser)node)?.ChildNodes; if (container != null && container.NeedUpdate) @@ -273,8 +276,9 @@ internal bool internal_UpdateNode(CompChildNodeProccesser actionNode = null) } } - foreach (Thing node in diff.Values) + foreach (string id in diff.Keys) { + Thing node = prveChilds.TryGetValue(id); NodeContainer container = ((CompChildNodeProccesser)node)?.ChildNodes; if (container != null && container.NeedUpdate) { @@ -282,24 +286,26 @@ internal bool internal_UpdateNode(CompChildNodeProccesser actionNode = null) //reset = false; } } - if (StopEventBubble) return StopEventBubble; + if (StopEventBubble) goto ret; foreach (CompBasicNodeComp comp in proccess.AllNodeComp) { try { - StopEventBubble = comp.internal_PostUpdateNode(actionNode, cachingData, new Dictionary(prveChilds)) || StopEventBubble; + comp.internal_PostUpdateNode(actionNode, cachingData, new Dictionary(prveChilds), out bool blockEvent, out bool notUpdateTexture); + StopEventBubble |= blockEvent; + NotUpdateTexture |= notUpdateTexture; } catch (Exception ex) { Log.Error(ex.ToString()); } } - + ret:; if (reset) { proccess.ResetVerbs(); - proccess.ResetRenderedTexture(); + if (!NotUpdateTexture) proccess.ResetRenderedTexture(); } return StopEventBubble; } diff --git a/src/RW_NodeTree/Tools/NodeHelper.cs b/src/RW_NodeTree/Tools/NodeHelper.cs index 498ae35..3609a32 100644 --- a/src/RW_NodeTree/Tools/NodeHelper.cs +++ b/src/RW_NodeTree/Tools/NodeHelper.cs @@ -18,7 +18,7 @@ public static class NodeHelper /// /// current graphic /// sub graphic - public static Graphic SubGraphic(this Graphic parent) + public static Graphic GetSubGraphic(this Graphic parent) { if(parent != null) { @@ -45,23 +45,77 @@ public static Graphic SubGraphic(this Graphic parent) return null; } + /// + /// if graphic has sub graphic, It will return that; + /// + /// current graphic + /// sub graphic + public static void SetSubGraphic(this Graphic parent, Graphic graphic) + { + if(parent != null) + { + Type type = parent.GetType(); + AccessTools.FieldRef subGraphic; + //FieldInfo subGraphic; + if (!TypeFieldInfos.TryGetValue(type, out subGraphic)) + { + try + { + subGraphic = AccessTools.FieldRefAccess(type, "subGraphic"); + } + catch { } + //subGraphic = parent?.GetType().GetField("subGraphic", AccessTools.all); + TypeFieldInfos.Add(type, subGraphic); + } + //= parent?.GetType().GetField("subGraphic", AccessTools.all); + if (subGraphic != null) + { + subGraphic(parent) = graphic; + //return subGraphic.GetValue(parent) as Graphic; + } + } + } + /// /// get /// /// /// - public static Graphic GetGraphic_ChildNode(this Graphic parent) + public static Graphic_ChildNode GetGraphic_ChildNode(this Graphic parent) { - Graphic graphic = parent; + while (parent != null && !(parent is Graphic_ChildNode)) + { + parent = parent.GetSubGraphic(); + } + //if (Prefs.DevMode) Log.Message(" parent = " + parent + " graphic = " + graphic); + return parent as Graphic_ChildNode; + } + + + /// + /// get + /// + /// + /// + public static Graphic GetParentOfGraphic_ChildNode(this Graphic parent) + { + Graphic graphic = parent.GetSubGraphic(); while (graphic != null && !(graphic is Graphic_ChildNode)) { parent = graphic; - graphic = graphic.SubGraphic(); + graphic = graphic.GetSubGraphic(); } //if (Prefs.DevMode) Log.Message(" parent = " + parent + " graphic = " + graphic); - return graphic ?? parent; + return parent; } + /// + /// get + /// + /// + /// + public static void SetGraphic_ChildNode(this Graphic parent, Graphic_ChildNode graphic) => parent.GetParentOfGraphic_ChildNode()?.SetSubGraphic(graphic); + private static readonly Dictionary> TypeFieldInfos = new Dictionary>(); //private static Dictionary TypeFieldInfos = new Dictionary(); }