Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Cn-mjt44 committed May 1, 2024
1 parent cfa6be1 commit c4e69a4
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 28 deletions.
Binary file modified 1.3/Assemblies/RW_NodeTree.dll
Binary file not shown.
Binary file modified 1.4/Assemblies/RW_NodeTree.dll
Binary file not shown.
Binary file modified 1.5/Assemblies/RW_NodeTree.dll
Binary file not shown.
14 changes: 8 additions & 6 deletions src/RW_NodeTree/CompBasicNodeComp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,19 +80,21 @@ public virtual void PostFX(RenderTexture tar) { }
/// update event
/// </summary>
/// <param name="actionNode">update event action node</param>
protected virtual bool PreUpdateNode(CompChildNodeProccesser actionNode, Dictionary<string, object> cachedDataToPostUpatde, Dictionary<string, Thing> prveChilds)
protected virtual void PreUpdateNode(CompChildNodeProccesser actionNode, Dictionary<string, object> cachedDataToPostUpatde, Dictionary<string, Thing> prveChilds, out bool blockEvent, out bool notUpdateTexture)
{
return false;
blockEvent = false;
notUpdateTexture = false;
}

/// <summary>
/// update event
/// </summary>
/// <param name="actionNode">update event action node</param>
/// <returns>stope bubble</returns>
protected virtual bool PostUpdateNode(CompChildNodeProccesser actionNode, Dictionary<string, object> cachedDataFromPerUpdate, Dictionary<string, Thing> prveChilds)
protected virtual void PostUpdateNode(CompChildNodeProccesser actionNode, Dictionary<string, object> cachedDataFromPerUpdate, Dictionary<string, Thing> prveChilds, out bool blockEvent, out bool notUpdateTexture)
{
return false;
blockEvent = false;
notUpdateTexture = false;
}

/// <summary>
Expand Down Expand Up @@ -161,8 +163,8 @@ protected virtual List<VerbToolRegiestInfo> VerbToolRegiestInfoUpdate(Type owner
return result;
}

internal bool internal_PreUpdateNode(CompChildNodeProccesser actionNode, Dictionary<string, object> cachedDataToPostUpatde, Dictionary<string, Thing> prveChilds) => PreUpdateNode(actionNode, cachedDataToPostUpatde, prveChilds);
internal bool internal_PostUpdateNode(CompChildNodeProccesser actionNode, Dictionary<string, object> cachedDataFromPerUpdate, Dictionary<string, Thing> prveChilds) => PostUpdateNode(actionNode, cachedDataFromPerUpdate, prveChilds);
internal void internal_PreUpdateNode(CompChildNodeProccesser actionNode, Dictionary<string, object> cachedDataToPostUpatde, Dictionary<string, Thing> prveChilds, out bool blockEvent, out bool notUpdateTexture) => PreUpdateNode(actionNode, cachedDataToPostUpatde, prveChilds, out blockEvent, out notUpdateTexture);
internal void internal_PostUpdateNode(CompChildNodeProccesser actionNode, Dictionary<string, object> cachedDataFromPerUpdate, Dictionary<string, Thing> 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<string, object> cachedData) => Added(container, id, success, cachedData);
internal void internal_Removed(NodeContainer container, string id, bool success, Dictionary<string, object> cachedData) => Removed(container, id, success, cachedData);
Expand Down
25 changes: 20 additions & 5 deletions src/RW_NodeTree/CompChildNodeProccesser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ public static bool CheckVerbDatasVaildityAndAdapt(Type ownerType, Thing thing, r
/// </summary>
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);
Expand Down Expand Up @@ -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<RenderInfo>)> nodeRenderingInfos = new List<(string, Thing, List<RenderInfo>)>(ChildNodes.Count + 1);

Expand All @@ -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;
Expand Down Expand Up @@ -609,7 +609,7 @@ internal void PostFX(RenderTexture tar)
Log.Error(ex.ToString());
}
}
this.nodeRenderingInfos[rot.AsInt] = nodeRenderingInfos;
this.nodeRenderingInfo[rot] = nodeRenderingInfos;
return nodeRenderingInfos;
}

Expand Down Expand Up @@ -786,11 +786,26 @@ public static implicit operator CompChildNodeProccesser(Thing thing)
}
#endregion


public class NodeRenderingInfoForRot4
{
public List<(string, Thing, List<RenderInfo>)> 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<RenderInfo>)>[] nodeRenderingInfos = new List<(string, Thing, List<RenderInfo>)>[4];
}

private CompChildNodeProccesser cachedRootNode;

private NodeContainer childNodes;

private readonly List<(string, Thing, List<RenderInfo>)>[] nodeRenderingInfos = new List<(string, Thing, List<RenderInfo>)>[4];
private readonly NodeRenderingInfoForRot4 nodeRenderingInfo = new NodeRenderingInfoForRot4();

private readonly Dictionary<Type, List<VerbToolRegiestInfo>> regiestedNodeVerbToolInfos = new Dictionary<Type, List<VerbToolRegiestInfo>>();

Expand Down
8 changes: 4 additions & 4 deletions src/RW_NodeTree/Graphic_ChildNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<RenderInfo>)> commands = comp_ChildNodeProccesser.GetNodeRenderingInfos(rot, out bool needUpdate, subGraphic);
if (!needUpdate && material != null) goto ret;
Expand All @@ -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:;

Expand All @@ -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;

Expand Down Expand Up @@ -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;
}
Expand Down
22 changes: 14 additions & 8 deletions src/RW_NodeTree/NodeContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -224,7 +225,9 @@ internal bool internal_UpdateNode(CompChildNodeProccesser actionNode = null)
{
try
{
StopEventBubble = comp.internal_PreUpdateNode(actionNode, cachingData, new Dictionary<string, Thing>(prveChilds)) || StopEventBubble;
comp.internal_PreUpdateNode(actionNode, cachingData, new Dictionary<string, Thing>(prveChilds), out bool blockEvent, out bool notUpdateTexture);
StopEventBubble |= blockEvent;
NotUpdateTexture |= notUpdateTexture;
}
catch (Exception ex)
{
Expand Down Expand Up @@ -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)
Expand All @@ -273,33 +276,36 @@ 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)
{
StopEventBubble = container.internal_UpdateNode(actionNode) || StopEventBubble;
//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<string, Thing>(prveChilds)) || StopEventBubble;
comp.internal_PostUpdateNode(actionNode, cachingData, new Dictionary<string, Thing>(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;
}
Expand Down
64 changes: 59 additions & 5 deletions src/RW_NodeTree/Tools/NodeHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static class NodeHelper
/// </summary>
/// <param name="parent">current graphic</param>
/// <returns>sub graphic</returns>
public static Graphic SubGraphic(this Graphic parent)
public static Graphic GetSubGraphic(this Graphic parent)
{
if(parent != null)
{
Expand All @@ -45,23 +45,77 @@ public static Graphic SubGraphic(this Graphic parent)
return null;
}

/// <summary>
/// if graphic has sub graphic, It will return that;
/// </summary>
/// <param name="parent">current graphic</param>
/// <returns>sub graphic</returns>
public static void SetSubGraphic(this Graphic parent, Graphic graphic)
{
if(parent != null)
{
Type type = parent.GetType();
AccessTools.FieldRef<Graphic, Graphic> subGraphic;
//FieldInfo subGraphic;
if (!TypeFieldInfos.TryGetValue(type, out subGraphic))
{
try
{
subGraphic = AccessTools.FieldRefAccess<Graphic>(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;
}
}
}

/// <summary>
/// get
/// </summary>
/// <param name="parent"></param>
/// <returns></returns>
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;
}


/// <summary>
/// get
/// </summary>
/// <param name="parent"></param>
/// <returns></returns>
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;
}

/// <summary>
/// get
/// </summary>
/// <param name="parent"></param>
/// <returns></returns>
public static void SetGraphic_ChildNode(this Graphic parent, Graphic_ChildNode graphic) => parent.GetParentOfGraphic_ChildNode()?.SetSubGraphic(graphic);

private static readonly Dictionary<Type, AccessTools.FieldRef<Graphic, Graphic>> TypeFieldInfos = new Dictionary<Type, AccessTools.FieldRef<Graphic, Graphic>>();
//private static Dictionary<Type, FieldInfo> TypeFieldInfos = new Dictionary<Type, FieldInfo>();
}
Expand Down

0 comments on commit c4e69a4

Please sign in to comment.