@@ -21,7 +21,7 @@ public class NodeContainer : ThingOwner, IList<string>, IList<Thing>, IDictionar
2121 {
2222 public class NodeRenderingInfoForRot4
2323 {
24- public List < ( string ? , Thing , List < RenderInfo > ) > ? this [ Rot4 rot ]
24+ public ReadOnlyDictionary < string , ReadOnlyCollection < RenderInfo > > ? this [ Rot4 rot ]
2525 {
2626 get => nodeRenderingInfos [ rot . AsInt ] ;
2727 set => nodeRenderingInfos [ rot . AsInt ] = value ;
@@ -30,7 +30,7 @@ public void Reset()
3030 {
3131 for ( int i = 0 ; i < nodeRenderingInfos . Length ; i ++ ) nodeRenderingInfos [ i ] = null ;
3232 }
33- public readonly List < ( string ? , Thing , List < RenderInfo > ) > ? [ ] nodeRenderingInfos = new List < ( string ? , Thing , List < RenderInfo > ) > ? [ 4 ] ;
33+ public readonly ReadOnlyDictionary < string , ReadOnlyCollection < RenderInfo > > ? [ ] nodeRenderingInfos = new ReadOnlyDictionary < string , ReadOnlyCollection < RenderInfo > > ? [ 4 ] ;
3434 }
3535
3636 public NodeContainer ( Thing proccesser ) : base ( proccesser as INodeProccesser )
@@ -369,16 +369,25 @@ public override void ExposeData()
369369 //if (Scribe.mode == LoadSaveMode.PostLoadInit) needUpdate = false;
370370 }
371371
372+ public void CachedRootNodeNeedUpdate ( )
373+ {
374+ cachedRootNode = null ;
375+ for ( int i = Count - 1 ; i >= 0 ; i -- )
376+ {
377+ ( this [ i ] as INodeProccesser ) ? . ChildNodes ? . CachedRootNodeNeedUpdate ( ) ;
378+ }
379+ }
380+
372381
373- public List < ( string ? , Thing , List < RenderInfo > ) > GetNodeRenderingInfos ( Rot4 rot , out bool updated , Graphic ? subGraphic = null )
382+ public ReadOnlyDictionary < string , ReadOnlyCollection < RenderInfo > > GetNodeRenderingInfos ( Rot4 rot , out bool updated , Graphic ? subGraphic = null )
374383 {
375384 UpdateNode ( ) ;
376385 updated = false ;
377386 if ( ! UnityData . IsInMainThread ) throw new InvalidOperationException ( "not in main thread" ) ;
378- List < ( string ? , Thing , List < RenderInfo > ) > ? nodeRenderingInfos = this . nodeRenderingInfo [ rot ] ;
379- if ( nodeRenderingInfos != null ) return nodeRenderingInfos ;
387+ ReadOnlyDictionary < string , ReadOnlyCollection < RenderInfo > > ? readOnlyNodeRenderingInfos = this . nodeRenderingInfo [ rot ] ;
388+ if ( readOnlyNodeRenderingInfos != null ) return readOnlyNodeRenderingInfos ;
380389 updated = true ;
381- nodeRenderingInfos = new List < ( string ? , Thing , List < RenderInfo > ) > ( Count + 1 ) ;
390+ Dictionary < string , List < RenderInfo > > nodeRenderingInfos = new Dictionary < string , List < RenderInfo > > ( Count + 1 ) ;
382391 Thing parent = ( Thing ) Proccesser ;
383392
384393 //if (Prefs.DevMode)
@@ -396,67 +405,65 @@ public override void ExposeData()
396405
397406
398407 //ORIGIN
399- subGraphic = ( subGraphic ?? parent . Graphic ) ? . GetGraphic_ChildNode ( ) ? . SubGraphic ?? subGraphic ?? parent . Graphic ;
400- if ( subGraphic != null )
401- {
402- RenderingTools . StartOrEndDrawCatchingBlock = true ;
403- try
404- {
405- subGraphic . Draw ( Vector3 . zero , rot , parent ) ;
406- nodeRenderingInfos . Add ( ( null , parent , RenderingTools . RenderInfos ! ) ) ;
407- }
408- catch ( Exception ex )
409- {
410- Log . Error ( ex . ToString ( ) ) ;
411- }
412- RenderingTools . StartOrEndDrawCatchingBlock = false ;
413- }
414-
415- for ( int i = 0 ; i < this . Count ; i ++ )
416- {
417- Thing child = this [ i ] ;
418408
419- if ( child != null )
420- {
421- nodeRenderingInfos . Add ( ( ( ( IList < string > ) this ) [ i ] , child , new List < RenderInfo > ( ) ) ) ;
422- }
423- }
424409
425410 Dictionary < string , object ? > cachingData = new Dictionary < string , object ? > ( ) ;
426411
427- nodeRenderingInfos = Proccesser . PreGenRenderInfos ( nodeRenderingInfos , rot , subGraphic , cachingData ) ?? nodeRenderingInfos ;
412+ HashSet < string > ? ChildForDraw = Proccesser . PreGenRenderInfos ( rot , cachingData ) ;
428413
429- for ( int i = 0 ; i < nodeRenderingInfos . Count ; i ++ )
414+ subGraphic = ( subGraphic ?? parent . Graphic ) ? . GetGraphic_ChildNode ( ) ? . SubGraphic ?? subGraphic ?? parent . Graphic ;
415+ if ( ChildForDraw != null )
430416 {
431- string ? id = nodeRenderingInfos [ i ] . Item1 ;
432- Thing child = nodeRenderingInfos [ i ] . Item2 ;
433- List < RenderInfo > infos = nodeRenderingInfos [ i ] . Item3 ?? new List < RenderInfo > ( ) ;
434- if ( child != null && id != null )
417+ if ( subGraphic != null && ChildForDraw . Contains ( "" ) )
435418 {
436419 RenderingTools . StartOrEndDrawCatchingBlock = true ;
437420 try
438421 {
439- Rot4 rotCache = child . Rotation ;
440- child . Rotation = new Rot4 ( ( rot . AsInt + rotCache . AsInt ) & 3 ) ;
441- #if V13 || V14
442- child . DrawAt ( Vector3 . zero ) ;
443- #else
444- child . DrawNowAt ( Vector3 . zero ) ;
445- #endif
446- child . Rotation = rotCache ;
447- infos . AddRange ( RenderingTools . RenderInfos ) ;
422+ subGraphic . Draw ( Vector3 . zero , rot , parent ) ;
423+ nodeRenderingInfos [ "" ] = RenderingTools . RenderInfos ! ;
448424 }
449425 catch ( Exception ex )
450426 {
451427 Log . Error ( ex . ToString ( ) ) ;
452428 }
453429 RenderingTools . StartOrEndDrawCatchingBlock = false ;
454- nodeRenderingInfos [ i ] = ( id , child , infos ) ;
430+ }
431+
432+ foreach ( string id in ChildForDraw )
433+ {
434+ Thing ? child = this [ id ] ;
435+ if ( child != null && id != null )
436+ {
437+ RenderingTools . StartOrEndDrawCatchingBlock = true ;
438+ try
439+ {
440+ Rot4 rotCache = child . Rotation ;
441+ child . Rotation = new Rot4 ( ( rot . AsInt + rotCache . AsInt ) & 3 ) ;
442+ #if V13 || V14
443+ child . DrawAt ( Vector3 . zero ) ;
444+ #else
445+ child . DrawNowAt ( Vector3 . zero ) ;
446+ #endif
447+ child . Rotation = rotCache ;
448+ nodeRenderingInfos [ id ] = RenderingTools . RenderInfos ! ;
449+ }
450+ catch ( Exception ex )
451+ {
452+ Log . Error ( ex . ToString ( ) ) ;
453+ }
454+ RenderingTools . StartOrEndDrawCatchingBlock = false ;
455+ }
455456 }
456457 }
457458 nodeRenderingInfos = Proccesser . PostGenRenderInfos ( nodeRenderingInfos , rot , subGraphic , cachingData ) ?? nodeRenderingInfos ;
458- this . nodeRenderingInfo [ rot ] = nodeRenderingInfos ;
459- return nodeRenderingInfos ;
459+ Dictionary < string , ReadOnlyCollection < RenderInfo > > mid = new Dictionary < string , ReadOnlyCollection < RenderInfo > > ( nodeRenderingInfos . Count ) ;
460+ foreach ( var kv in nodeRenderingInfos )
461+ {
462+ mid [ kv . Key ] = new ReadOnlyCollection < RenderInfo > ( kv . Value ) ;
463+ }
464+ readOnlyNodeRenderingInfos = new ReadOnlyDictionary < string , ReadOnlyCollection < RenderInfo > > ( mid ) ;
465+ this . nodeRenderingInfo [ rot ] = readOnlyNodeRenderingInfos ;
466+ return readOnlyNodeRenderingInfos ;
460467 }
461468
462469
@@ -466,7 +473,7 @@ public override void ExposeData()
466473 /// <returns></returns>
467474 public void UpdateNode ( ) => internal_UpdateNode ( ) ;
468475
469- internal void internal_UpdateNode ( INodeProccesser ? actionNode = null )
476+ private void internal_UpdateNode ( INodeProccesser ? actionNode = null )
470477 {
471478
472479
@@ -550,17 +557,17 @@ internal void internal_UpdateNode(INodeProccesser? actionNode = null)
550557 }
551558
552559 bool reset = true ;
560+
553561 foreach ( Thing ? node in prveChilds . Values )
554562 {
555563 NodeContainer ? container = ( node as INodeProccesser ) ? . ChildNodes ;
556- if ( container != null && container . NeedUpdate )
564+ if ( container != null && container . NeedUpdate && ! this . Contains ( node ) )
557565 {
558566 container . internal_UpdateNode ( actionNode ) ;
559- reset = false ;
560567 }
561568 }
562569
563- foreach ( Thing ? node in diff . Values )
570+ foreach ( Thing ? node in this . Values )
564571 {
565572 NodeContainer ? container = ( node as INodeProccesser ) ? . ChildNodes ;
566573 if ( container != null && container . NeedUpdate )
@@ -569,6 +576,7 @@ internal void internal_UpdateNode(INodeProccesser? actionNode = null)
569576 reset = false ;
570577 }
571578 }
579+
572580 ReadOnlyDictionary < string , Thing > prveChildsReadOnly = new ReadOnlyDictionary < string , Thing > ( prveChilds ) ;
573581 proccess . PostUpdateChilds ( actionNode , cachingData , prveChildsReadOnly , out bool notUpdateTexture ) ;
574582 if ( reset && ! notUpdateTexture )
@@ -620,7 +628,7 @@ public override int GetCountCanAccept(Thing? item, bool canMergeWithExistingStac
620628 if ( item ? . Destroyed ?? false ) return 0 ;
621629 if ( item ? . holdingOwner != null ) return 0 ;
622630 if ( IsChildOf ( item ) ) return 0 ;
623- if ( Proccesser != null && Proccesser . AllowNode ( item , currentKey . Item1 ) )
631+ if ( Proccesser . AllowNode ( item , currentKey . Item1 ) )
624632 {
625633 return base . GetCountCanAccept ( item , false ) ;
626634 }
@@ -778,7 +786,7 @@ public override bool TryAdd(Thing? item, bool canMergeWithExistingStacks = true)
778786 }
779787 if ( proccesser != null )
780788 {
781- proccesser . ChildNodes . cachedRootNode = null ;
789+ proccesser . ChildNodes . CachedRootNodeNeedUpdate ( ) ;
782790 proccesser . Added ( this , currentKey . Item1 , true ) ;
783791 }
784792 //NeedUpdate = true;
@@ -1026,7 +1034,7 @@ public override bool Remove(Thing? item)
10261034 item . holdingOwner = null ;
10271035 if ( proccesser != null )
10281036 {
1029- proccesser . ChildNodes . cachedRootNode = null ;
1037+ proccesser . ChildNodes . CachedRootNodeNeedUpdate ( ) ;
10301038 proccesser . Removed ( this , key , true ) ;
10311039 }
10321040 //NeedUpdate = true;
0 commit comments