Browse Source

Updated default node caching

CPKreuz 1 year ago
parent
commit
b6ed90087e

+ 7 - 0
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/ImageLayerNode.cs

@@ -19,6 +19,13 @@ public class ImageLayerNode : LayerNode, IReadOnlyImageNode
     private Paint blendPaint = new Paint();
     private Paint maskPaint = new Paint() { BlendMode = DrawingApi.Core.Surface.BlendMode.DstIn };
 
+    // Handled by overriden CacheChanged
+    protected override bool AffectedByAnimation => false;
+
+    protected override bool AffectedByChunkResolution => true;
+
+    protected override bool AffectedByChunkToUpdate => true;
+
     public ImageLayerNode(VecI size)
     {
         LockTransparency = CreateInput<bool>("LockTransparency", "LOCK_TRANSPARENCY", false);

+ 9 - 3
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/Node.cs

@@ -23,7 +23,13 @@ public abstract class Node : IReadOnlyNode, IDisposable
     public Image? CachedResult { get; private set; }
 
     public virtual string InternalName { get; }
+    
+    protected virtual bool AffectedByAnimation { get; }
+    
+    protected virtual bool AffectedByChunkResolution { get; }
 
+    protected virtual bool AffectedByChunkToUpdate { get; }
+    
     protected Node()
     {
         InternalName = $"PixiEditor.{GetType().Name}";
@@ -51,9 +57,9 @@ public abstract class Node : IReadOnlyNode, IDisposable
     
     protected virtual bool CacheChanged(RenderingContext context)
     {
-        return !context.FrameTime.Equals(_lastFrameTime)
-               || context.Resolution != _lastResolution
-               || context.ChunkToUpdate != _lastChunkPos
+        return (!context.FrameTime.Equals(_lastFrameTime) && AffectedByAnimation)
+               || (context.Resolution != _lastResolution && AffectedByChunkResolution)
+               || (context.ChunkToUpdate != _lastChunkPos && AffectedByChunkToUpdate)
                || inputs.Any(x => x.CacheChanged);
     }