Permalink
Browse files

plugin transform input pins perform their own IsChanged check now, ad…

…ded test for it too
  • Loading branch information...
tebjan committed Feb 6, 2014
1 parent 4ab3439 commit 6ad2628d3af5119f0154baf781088cfa667a7fde
@@ -3,6 +3,8 @@
using VVVV.PluginInterfaces.V1;
using VVVV.PluginInterfaces.V2;
using VVVV.Utils.Streams;
+using VVVV.Utils.VMath;
+using SlimDX;
namespace VVVV.Hosting.Pins.Input
{
@@ -41,6 +43,116 @@ public override bool Sync()
}
}
+ class BufferedInputMatrix4x4IOStream : MemoryIOStream<Matrix4x4>
+ {
+ private readonly IInStream<Matrix4x4> FInStream;
+
+ public BufferedInputMatrix4x4IOStream(IInStream<Matrix4x4> inStream)
+ {
+ FInStream = inStream;
+ }
+
+ public override bool Sync()
+ {
+ IsChanged = FInStream.Sync();
+ if (IsChanged)
+ {
+ var buffer = MemoryPool<Matrix4x4>.GetArray();
+ try
+ {
+ var anySliceChanged = this.Length != FInStream.Length;
+ this.Length = FInStream.Length;
+
+ using (var reader = FInStream.GetReader())
+ using (var writer = this.GetWriter())
+ {
+ while (!reader.Eos)
+ {
+ var offset = reader.Position;
+ int numSlicesRead = reader.Read(buffer, 0, buffer.Length);
+ if (!anySliceChanged)
+ {
+ for (int i = 0; i < numSlicesRead; i++)
+ {
+ var previousSlice = this.Buffer[offset + i];
+ var newSlice = buffer[i];
+ if (newSlice != previousSlice)
+ {
+ anySliceChanged = true;
+ break;
+ }
+ }
+ }
+ writer.Write(buffer, 0, numSlicesRead);
+ }
+ }
+
+ IsChanged = anySliceChanged;
+ }
+ finally
+ {
+ MemoryPool<Matrix4x4>.PutArray(buffer);
+ }
+ }
+ return base.Sync();
+ }
+ }
+
+ class BufferedInputMatrixIOStream : MemoryIOStream<Matrix>
+ {
+ private readonly IInStream<Matrix> FInStream;
+
+ public BufferedInputMatrixIOStream(IInStream<Matrix> inStream)
+ {
+ FInStream = inStream;
+ }
+
+ public override bool Sync()
+ {
+ IsChanged = FInStream.Sync();
+ if (IsChanged)
+ {
+ var buffer = MemoryPool<Matrix>.GetArray();
+ try
+ {
+ var anySliceChanged = this.Length != FInStream.Length;
+ this.Length = FInStream.Length;
+
+ using (var reader = FInStream.GetReader())
+ using (var writer = this.GetWriter())
+ {
+ while (!reader.Eos)
+ {
+ var offset = reader.Position;
+ int numSlicesRead = reader.Read(buffer, 0, buffer.Length);
+ if (!anySliceChanged)
+ {
+ for (int i = 0; i < numSlicesRead; i++)
+ {
+ var previousSlice = this.Buffer[offset + i];
+ var newSlice = buffer[i];
+ if (newSlice != previousSlice)
+ {
+ anySliceChanged = true;
+ break;
+ }
+ }
+ }
+ writer.Write(buffer, 0, numSlicesRead);
+ }
+ }
+
+ IsChanged = anySliceChanged;
+ }
+ finally
+ {
+ MemoryPool<Matrix>.PutArray(buffer);
+ }
+ }
+ return base.Sync();
+ }
+ }
+
[ComVisible(false)]
class InputIOStream<T> : IIOStream<T>
{
@@ -5,8 +5,10 @@
using VVVV.Hosting.Pins.Output;
using VVVV.PluginInterfaces.V1;
using VVVV.PluginInterfaces.V2;
-using VVVV.Utils.Streams;
using VVVV.PluginInterfaces.V2.NonGeneric;
+using VVVV.Utils.Streams;
+using VVVV.Utils.VMath;
+using SlimDX;
namespace VVVV.Hosting.IO
{
@@ -72,9 +74,15 @@ public SpreadRegistry()
return GenericIOContainer.Create(context, factory, spread, null, s => s.Flush());
}
}
+
var container = factory.CreateIOContainer(typeof(IInStream<>).MakeGenericType(context.DataType), attribute, false);
var pinType = typeof(DiffInputPin<>).MakeGenericType(context.DataType);
- spread = Activator.CreateInstance(pinType, factory, container.GetPluginIO(), container.RawIOObject) as ISpread;
+ if (context.DataType == typeof(Matrix4x4)) //special diff pin for transform pins until IsChanged gets fixed in delphi
+ spread = new DiffInputPin<Matrix4x4>(factory, container.GetPluginIO() as IPluginIn, new BufferedInputMatrix4x4IOStream(container.RawIOObject as IInStream<Matrix4x4>));
+ else if (context.DataType == typeof(Matrix))
+ spread = new DiffInputPin<Matrix>(factory, container.GetPluginIO() as IPluginIn, new BufferedInputMatrixIOStream(container.RawIOObject as IInStream<Matrix>));
+ else
+ spread = Activator.CreateInstance(pinType, factory, container.GetPluginIO(), container.RawIOObject) as ISpread;
if (attribute.AutoValidate)
return IOContainer.Create(context, spread, container, s => s.Sync());
else
Oops, something went wrong.

0 comments on commit 6ad2628

Please sign in to comment.