Пример #1
0
        public void TestCollections2()
        {
            //
            // => Initialize
            //
            // ---------------                
            // |  P = 1,1,1  | (Root1)        
            // |  V = 2,2,2  |                
            // |  VP = V+P   |                
            // ---------------                
            //        
            // ---------------           ---------------
            // |  P = 3,3,3  | (Root2)   |  P = 5,5,5  | (Root3)    
            // |             |           |  V = P      |
            // |             |           |             |
            // ---------------           ---------------         
            var root1Collection = new ParameterCollection("Root1");
            var root2Collection = new ParameterCollection("Root2");
            var root3Collection = new ParameterCollection("Root3");

            var paramV = new ParameterKey<Vector3>("View");
            var paramP = new ParameterKey<Vector3>("Proj");
            var paramVP = new ParameterKey<Vector3>("ViewProj");

            root1Collection.Set(paramP, new Vector3(1, 1, 1));
            root1Collection.Set(paramV, new Vector3(2, 2, 2));
            root1Collection.AddDynamic(paramVP, ParameterDynamicValue.New(paramV, paramP, (ref Vector3 paramVArg, ref Vector3 paramPArg, ref Vector3 output) => output = paramVArg + paramPArg));

            root2Collection.Set(paramP, new Vector3(3, 3, 3));

            root3Collection.Set(paramP, new Vector3(5, 5, 5));
            root3Collection.AddDynamic(paramV, ParameterDynamicValue.New(paramP, (ref Vector3 paramPArg, ref Vector3 paramVArg) => paramVArg = paramPArg));

            //
            // => Add Root1 as a source of Root2
            //
            // ---------------                
            // |  P = 1,1,1  | (Root1)        
            // |  V = 2,2,2  |                
            // |  VP = V+P   |                
            // ---------------                
            //        |
            // ---------------           ---------------
            // |  P = 3,3,3  | (Root2)   |  P = 5,5,5  | (Root3)    
            // |  V = ^,^,^  |           |  V = P      |
            // |  VP= ^,^,^  |           |             |
            // ---------------           ---------------
            //
            // Root1: VP = 3,3,3
            // Root2: VP = 5,5,5
            //
            // Number of registered Dynamic Values: 3
            // Root1: 1 => VP = Root1.V + Root1.P 
            // Root2: 1 => VP = Root1.V + Root2.P
            // Root3: 1 => V = Root3.P
            root2Collection.AddSources(root1Collection);

            //
            // => Add Root2 and Root3 as source of child collection
            //
            // ---------------                
            // |  P = 1,1,1  | (Root1)        
            // |  V = 2,2,2  |                
            // |  VP = V+P   |                
            // ---------------                
            //        |
            // ---------------           ---------------
            // |  P = 3,3,3  | (Root2)   |  P = 5,5,5  | (Root3)    
            // |  V = ^,^,^  |         / |  V = P      |
            // |  VP= ^,^,^  |        /  |             |
            // ---------------       /   ---------------
            //        |             /
            // ---------------
            // |  P = ^,^,^  | (Child)    
            // |  V = ^,^,^  |
            // |  VP =^,^,^  |
            // ---------------
            //
            // Root1: VP = 3,3,3
            // Root2: VP = 5,5,5
            // Root3: V = 5,5,5
            // Child: VP = 10,10,10
            //
            // Number of registered Dynamic Values: 4
            // Root1: 1 => VP = Root1.V + Root1.P 
            // Root2: 1 => VP = Root1.V + Root2.P
            // Root3: 1 => V = Root3.P
            // Child: 1 => VP = Root3.V + Root3.P
            var childCollection = new ParameterCollection("Child");
            childCollection.AddSources(root2Collection, root3Collection);

            Assert.AreEqual(childCollection.Get(paramVP), new Vector3(10, 10, 10));

            //
            // => Overrides P in child
            //
            // ---------------                
            // |  P = 1,1,1  | (Root1)        
            // |  V = 2,2,2  |                
            // |  VP = V+P   |                
            // ---------------                
            //        |
            // ---------------           ---------------
            // |  P = 3,3,3  | (Root2)   |  P = 5,5,5  | (Root3)    
            // |  V = ^,^,^  |         / |  V = P      |
            // |  VP= ^,^,^  |        /  |             |
            // ---------------       /   ---------------
            //        |             /
            // ---------------
            // |  P = 4,4,4  | (Child)    
            // |  V = ^,^,^  |
            // |  VP =^,^,^  |
            // ---------------
            //
            // Root1: VP = 3,3,3
            // Root2: VP = 5,5,5
            // Root3: V = 5,5,5
            // Child: VP = 8,8,8
            //
            // Number of registered Dynamic Values: 5
            // Root1: 1 => VP = Root1.V + Root1.P 
            // Root2: 1 => VP = Root1.V + Root2.P
            // Root3: 1 => V = Root3.P
            // Child: 2 => V = Child.P, VP = Child.V + Child.P
            childCollection.Set(paramP, new Vector3(4, 4, 4));
            Assert.AreEqual(childCollection.Get(paramVP), new Vector3(8, 8, 8));

            //
            // => Overrides P in child
            //
            // ---------------                
            // |  P = 1,1,1  | (Root1)        
            // |  V = 2,2,2  |                
            // |  VP = V+P   |                
            // ---------------                
            //        |
            // ---------------           ---------------
            // |  P = 3,3,3  | (Root2)   |  P = 5,5,5  | (Root3)    
            // |  V = ^,^,^  |         / |  V = P      |
            // |  VP= ^,^,^  |        /  |             |
            // ---------------       /   ---------------
            //        |             /
            // ---------------
            // |  P = 4,4,4  | (Child)    
            // |  V = ^,^,^  |
            // |  VP = V-P   |
            // ---------------
            //
            // Root1: VP = 3,3,3
            // Root2: VP = 5,5,5
            // Root3: V = 5,5,5
            // Child: VP = 8,8,8
            //
            // Number of registered Dynamic Values: 5
            // Root1: 1 => VP = Root1.V + Root1.P 
            // Root2: 1 => VP = Root1.V + Root2.P
            // Root3: 1 => V = Root3.P
            // Child: 2 => V = Child.P, VP = Child.V - Child.P
            childCollection.AddDynamic(paramVP, ParameterDynamicValue.New(paramV, paramP, (ref Vector3 paramVArg, ref Vector3 paramPArg, ref Vector3 output) => output = paramVArg - paramPArg));
            Assert.AreEqual(root1Collection.Get(paramVP), new Vector3(3, 3, 3));
            Assert.AreEqual(root2Collection.Get(paramVP), new Vector3(5, 5, 5));
            Assert.AreEqual(root3Collection.Get(paramV), new Vector3(5, 5, 5));
            Assert.AreEqual(childCollection.Get(paramV), new Vector3(4, 4, 4));
            Assert.AreEqual(childCollection.Get(paramVP), new Vector3(0, 0, 0));
        }
Пример #2
0
        public void TestDynamicValues4()
        {
            //
            // => Set P and V on Root (1,1,1)
            //
            // ---------------
            // |   V = 1,2,3 | (Root)
            // |   P = 0,1,0 |
            // ---------------
            //        |
            // ---------------
            // |   V = ^,^,^ | (Child 0..10000)    
            // |   P = ^,^,^ |
            // |  VP =  V + P|
            // ---------------
            var collection = new ParameterCollection("Root");
            var paramV = new ParameterKey<Vector3>("View");
            var paramP = new ParameterKey<Vector3>("Proj");

            // Set paramV and paramP
            collection.Set(paramV, new Vector3(1, 2, 3));
            collection.Set(paramP, new Vector3(0, 1, 0));

            var paramViewProjDyn1 = new ParameterKey<Vector3>("ViewProjDyn1");
            var valueViewProjDyn1 = ParameterDynamicValue.New(paramV, paramP, (ref Vector3 paramVArg, ref Vector3 paramPArg, ref Vector3 output) => output = paramVArg + paramPArg);

            var childsCollection = new ParameterCollection[10000];
            for (int i = 0; i < childsCollection.Length; i++)
            {
                var childCollection = new ParameterCollection("Child " + i);
                childCollection.AddSources(collection);
                childCollection.AddDynamic(paramViewProjDyn1, valueViewProjDyn1);
                childsCollection[i] = childCollection;
            }

            for (int i = 0; i < childsCollection.Length; i++)
                Assert.AreEqual(childsCollection[i].Get(paramViewProjDyn1), new Vector3(1, 3, 3));

            //
            // => Modify P on Root
            //
            // ---------------
            // |   V = 1,2,3 | (Root)
            // |   P = 0,4,0 |
            // ---------------
            //        |
            // ---------------
            // |   V = ^,^,^ | (Child 0..10000)    
            // |   P = ^,^,^ |
            // |  VP =  V + P|
            // ---------------
            collection.Set(paramP, new Vector3(0, 4, 0));

            for (int i = 0; i < childsCollection.Length; i++)
                Assert.AreEqual(childsCollection[i].Get(paramViewProjDyn1), new Vector3(1, 6, 3));
        }
Пример #3
0
        public void TestDynamicArrayValues1()
        {
            //
            // => Initialize, set V and P
            //
            // -------------------------------
            // |  VArray = {1,2,3}           | (Test)
            // |  PArray = {0,1,0}           |
            // -------------------------------
            var collection = new ParameterCollection("Test");
            var paramVArray = new ParameterKey<float[]>("VArray",3);
            var paramPArray = new ParameterKey<float[]>("PArray",3);

            // Set paramV and paramP
            collection.SetArray(paramVArray, new float[] { 1, 2, 3 });
            collection.SetArray(paramPArray, new float[] { 0, 1, 0 });

            //
            // => Set VDyn1 and VDyn2
            //
            // -------------------------------
            // |  VArray = {1,2,3}           | (Test)
            // |  PArray = {0,1,0}           |
            // |  VPDynArray = VArray+PArray |
            // -------------------------------
            var paramVPDynArray = new ParameterKey<float[]>("VPDynArray", 3);
            // paramViewProjDyn2 = paramV - paramP
            collection.AddDynamic(paramVPDynArray, ParameterDynamicValue.New(paramVArray, paramPArray, 
                (ref float[] paramVArg, ref float[] paramPArg, ref float[] output) =>
                    {
                        for (int i = 0; i < 3; i++)
                            output[i] = paramVArg[i] + paramPArg[i];
                    }));


            float[] result;
            collection.Get(paramVPDynArray, out result);
            Assert.AreEqual(new Vector3(result), new Vector3(1, 3, 3));

            // Remove value from array
            collection.Remove(paramVPDynArray);
        }
Пример #4
0
        public void TestDynamicValues3()
        {
            //
            // => Initialize, set V and P
            //
            // ------------------------
            // |  V = 1,2,3           | (Test)
            // |  P = 0,1,0           |
            // ------------------------
            var collection = new ParameterCollection("Test");
            var paramV = new ParameterKey<Vector3>("View");
            var paramP = new ParameterKey<Vector3>("Proj");

            // Set paramV and paramP
            collection.Set(paramV, new Vector3(1, 2, 3));
            collection.Set(paramP, new Vector3(0, 1, 0));

            //
            // => Set VDyn1 and VDyn2
            //
            // ------------------------
            // |  V = 1,2,3           | (Test)
            // |  P = 0,1,0           |
            // |  VDyn1 = V + P       |
            // |  VDyn2 = V - P       |
            // ------------------------
            // VDyn1 = (1,3,3)
            // VDyn2 = (1,1,3)
            var paramViewProjDyn1 = new ParameterKey<Vector3>("ViewProjDyn1");
            var paramViewProjDyn2 = new ParameterKey<Vector3>("ViewProjDyn2");
            var valueViewProjDyn1 = ParameterDynamicValue.New(paramV, paramP, (ref Vector3 paramVArg, ref Vector3 paramPArg, ref Vector3 output) => output = paramVArg + paramPArg);
            collection.AddDynamic(paramViewProjDyn1, valueViewProjDyn1);

            // paramViewProjDyn2 = paramV - paramP
            collection.AddDynamic(paramViewProjDyn2, ParameterDynamicValue.New(paramP, paramV, (ref Vector3 paramPArg, ref Vector3 paramVArg, ref Vector3 output) => output = paramVArg - paramPArg));

            Assert.AreEqual(collection.Get(paramViewProjDyn1), new Vector3(1, 3, 3));
            Assert.AreEqual(collection.Get(paramViewProjDyn2), new Vector3(1, 1, 3));

            //
            // => Set VDyn1 and VDyn2
            //
            // ------------------------
            // |  V = 1,2,3           | (Test)
            // |  P = 0,1,0           |
            // |  VDyn1 = V + P       |
            // |  VDyn2 = V + P       |
            // ------------------------
            // VDyn1 = (1,3,3)
            // VDyn2 = (1,3,3)
            collection.AddDynamic(paramViewProjDyn2, valueViewProjDyn1);
            Assert.AreEqual(collection.Get(paramViewProjDyn2), new Vector3(1, 3, 3));

            //
            // => Remove all variables
            //
            // ------------------------
            // |                      | (Test)
            // |                      |
            // ------------------------
            collection.Remove(paramViewProjDyn1);
            collection.Remove(paramViewProjDyn2);
            collection.Remove(paramV);
            collection.Remove(paramP);

            Assert.AreEqual(collection.Count, 0);
        }
Пример #5
0
        public void TestDynamicValues2()
        {
            //
            // => Initialize
            //
            // ------------------------
            // |  V = 1,2,3           | (Test)
            // |  VDyn = V + (1,1,1)  |
            // ------------------------
            // VDyn = (2,3,4)
            var collection = new ParameterCollection("Test");
            var paramV = new ParameterKey<Vector3>("View");
            var paramViewDyn = new ParameterKey<Vector3>("ViewDyn");

            // Set paramV and paramViewDyn1
            collection.Set(paramV, new Vector3(1,2,3));
            collection.AddDynamic(paramViewDyn, ParameterDynamicValue.New(paramV, (ref Vector3 paramVArg, ref Vector3 output) => output = paramVArg + new Vector3(1, 1, 1)));

            // Check that value is correctly updated
            Assert.AreEqual(collection.Get(paramViewDyn), new Vector3(2, 3, 4));

            //
            // => Set V to (3, 2, 1)
            //
            // ------------------------
            // |  V = 3,2,1           | (Test)
            // |  VDyn = V + (1,1,1)  |
            // ------------------------
            // VDyn = (4,3,2)
            collection.Set(paramV, new Vector3(3, 2, 1));
            Assert.AreEqual(collection.Get(paramViewDyn), new Vector3(4, 3, 2));

            //
            // => Set VDyn = V + (2,2,2)
            //
            // ------------------------
            // |  V = 3,2,1           | (Test)
            // |  VDyn = V + (2,2,2)  |
            // ------------------------
            // VDyn = (5,4,3)
            collection.AddDynamic(paramViewDyn, ParameterDynamicValue.New(paramV, (ref Vector3 paramVArg, ref Vector3 output) => output = paramVArg + new Vector3(2, 2, 2)));

            Assert.AreEqual(collection.Get(paramViewDyn), new Vector3(5, 4, 3));

            // Should throw an InvalidOperationException, as paramV is used by paramViewDyn and
            // cannot be removed
            //Assert.Throws(typeof(InvalidOperationException), () => collection.Remove(paramV));

            // Remove all variables
            collection.Remove(paramViewDyn);
            collection.Remove(paramV);

            //
            // => Remove V and VDyn
            //
            // ------------------------
            // |                      | (Test)
            // |                      |
            // ------------------------
            Assert.AreEqual(collection.Count, 0);
        }
Пример #6
0
        public void TestDynamicValues1()
        {
            //
            // => Trying to initialize VDyn = V + (1,1,1)
            //
            // ------------------------
            // |                      | (Test)
            // |                      |
            // ------------------------
            var collection = new ParameterCollection("Test");
            var paramV = new ParameterKey<Vector3>("View");
            var paramViewDyn = new ParameterKey<Vector3>("ViewDyn");

            // Should throw an InvalidOperationException, as paramV is not present in the collection
            collection.AddDynamic(paramViewDyn,
                            ParameterDynamicValue.New(paramV,
                                                        (ref Vector3 paramVArg, ref Vector3 output) =>
                                                        output = paramVArg + new Vector3(1, 1, 1)));
        }
Пример #7
0
        public void TestDynamicValues5()
        {
            //
            // => Initialize
            //
            // ---------------                
            // |             | (Root1)        
            // |  V = 2,2,2  |                
            // |  VP = V+P   |                
            // ---------------                
            //      |
            // ---------------         
            // |             | (Root2)
            // |             |
            // |             |
            // ---------------
            var root1Collection = new ParameterCollection("Root1");
            var root2Collection = new ParameterCollection("Root2");

            var paramV = new ParameterKey<Vector3>("View");
            var paramP = new ParameterKey<Vector3>("Proj");
            var paramVP = new ParameterKey<Vector3>("ViewProj");

            root1Collection.Set(paramV, new Vector3(2, 2, 2));
            root1Collection.AddDynamic(paramVP, ParameterDynamicValue.New(paramV, paramP, (ref Vector3 paramVArg, ref Vector3 paramPArg, ref Vector3 output) => output = paramVArg + paramPArg));

            root2Collection.AddSources(root1Collection);

            // Add P = 3, 3, 3 into Root2
            root2Collection.Set(paramP, new Vector3(3, 3, 3));

            Assert.AreEqual(new Vector3(5, 5, 5), root2Collection.Get(paramVP));
        }
Пример #8
0
        public void TestCollectionsEngine()
        {
            // RPP   <-  EP  <-  EMP
            //  EFPD <-/          | 
            //           E   <-  EM   
            var paramV = new ParameterKey<Vector3>("View");
            var paramV2 = new ParameterKey<Vector3>("ViewProj");
            var dynV2 = ParameterDynamicValue.New(paramV, (ref Vector3 param1, ref Vector3 output) => { output = new Vector3(param1.X + 1.0f, param1.Y, param1.Z); });
            var dynV3 = ParameterDynamicValue.New(paramV, (ref Vector3 param1, ref Vector3 output) => { output = new Vector3(param1.X + 4.0f, param1.Y, param1.Z); });

            var renderPlugin = new ParameterCollection("RenderPlugin");
            var effectPassDefault = new ParameterCollection("EffectPassDefault");
            var effectPass = new ParameterCollection("EffectPass");
            var effectMeshPass = new ParameterCollection("EffectMeshPass");
            var renderMesh = new ParameterCollection("RenderMesh");
            var effect = new ParameterCollection("Effect");

            effectPassDefault.Set(paramV, new Vector3(2.0f, 2.0f, 2.0f));
            effectPassDefault.AddDynamic(paramV2, dynV2);

            effectPass.AddSources(effectPassDefault, renderPlugin);

            renderPlugin.Set(paramV, new Vector3(1.0f, 1.0f, 1.0f));

            Assert.AreEqual(new Vector3(2.0f, 1.0f, 1.0f), effectPass.Get(paramV2));

            renderMesh.AddSources(effect);

            effectMeshPass.AddSources(effectPass, renderMesh);


            Assert.AreEqual(new Vector3(2.0f, 1.0f, 1.0f), effectMeshPass.Get(paramV2));

            effect.AddDynamic(paramV2, dynV3);
            effect.Set(paramV, new Vector3(3.0f, 3.0f, 3.0f));

            Assert.AreEqual(new Vector3(7.0f, 3.0f, 3.0f), effectMeshPass.Get(paramV2));
        }