Пример #1
0
        public void TestCompileGradient()
        {
            int computations1, computations2;
            int width = 16, height = 16, depth = 16;
            var gradient    = new RuntimeLayer(new AlgorithmGradientInitial());
            var passthrough = new RuntimeLayer(new AlgorithmPassthrough());

            passthrough.SetInput(0, gradient);
            var i1 = gradient.GenerateData(0, 0, 0, width, height, depth, out computations1);

            var c1 = LayerCompiler.Compile(gradient).GenerateData(0, 0, 0, width, height, depth, out computations1);

            for (var x = 0; x < width; x++)
            {
                for (var y = 0; y < height; y++)
                {
                    for (var z = 0; z < depth; z++)
                    {
                        Assert.Equal(
                            i1[x + y * width + z * width * height],
                            c1[x + y * width + z * width * height],
                            "Value differs in gradient compare.");
                    }
                }
            }
        }
Пример #2
0
        public void ZoomSquareTest()
        {
            int computations1, computations2;
            int width = 16, height = 16, depth = 16;
            var gradient = new RuntimeLayer(new AlgorithmGradientInitial());
            var zoom     = new RuntimeLayer(new AlgorithmZoom2D {
                Mode = AlgorithmZoom2D.ZoomType.Square
            });

            zoom.SetInput(0, gradient);
            var i1 = gradient.GenerateData(0, 0, 0, width, height, depth, out computations1);
            var i2 = zoom.GenerateData(0, 0, 0, width, height, depth, out computations2);

            for (var i = 0; i < width; i++)
            {
                for (var j = 0; j < height; j++)
                {
                    for (var k = 0; k < depth; k++)
                    {
                        Assert.Equal(
                            i1[i / 2 + j / 2 * width + k / 2 * width * height],
                            i2[i + j * width + k * width * height]);
                    }
                }
            }
            //,
            //               "Square zoom is not working for (" + i + ", " + j + ", " + k + ").");
        }
Пример #3
0
        public static void TestAlgorithmIncrementWaterDistance4()
        {
            var algorithmInitial                 = new AlgorithmInitialBool();
            var algorithmZoom2DIteration1        = new AlgorithmZoom2D();
            var algorithmZoom2DIteration2        = new AlgorithmZoom2D();
            var algorithmZoom2DIteration3        = new AlgorithmZoom2D();
            var algorithmZoom2DIteration4        = new AlgorithmZoom2D();
            var algorithmIncrementWaterDistance1 = new AlgorithmIncrementWaterDistance()
            {
                Initial = true
            };
            var algorithmIncrementWaterDistance2 = new AlgorithmIncrementWaterDistance();
            var algorithmIncrementWaterDistance3 = new AlgorithmIncrementWaterDistance();
            var algorithmIncrementWaterDistance4 = new AlgorithmIncrementWaterDistance();
            var runtimeInitial                 = new RuntimeLayer(algorithmInitial);
            var runtimeZoom2DIteration1        = new RuntimeLayer(algorithmZoom2DIteration1);
            var runtimeZoom2DIteration2        = new RuntimeLayer(algorithmZoom2DIteration2);
            var runtimeZoom2DIteration3        = new RuntimeLayer(algorithmZoom2DIteration3);
            var runtimeZoom2DIteration4        = new RuntimeLayer(algorithmZoom2DIteration4);
            var runtimeIncrementWaterDistance1 = new RuntimeLayer(algorithmIncrementWaterDistance1);
            var runtimeIncrementWaterDistance2 = new RuntimeLayer(algorithmIncrementWaterDistance2);
            var runtimeIncrementWaterDistance3 = new RuntimeLayer(algorithmIncrementWaterDistance3);
            var runtimeIncrementWaterDistance4 = new RuntimeLayer(algorithmIncrementWaterDistance4);

            runtimeZoom2DIteration1.SetInput(0, runtimeInitial);
            runtimeIncrementWaterDistance1.SetInput(0, runtimeZoom2DIteration1);
            runtimeZoom2DIteration2.SetInput(0, runtimeIncrementWaterDistance1);
            runtimeIncrementWaterDistance2.SetInput(0, runtimeZoom2DIteration2);
            runtimeZoom2DIteration3.SetInput(0, runtimeIncrementWaterDistance2);
            runtimeIncrementWaterDistance3.SetInput(0, runtimeZoom2DIteration3);
            runtimeZoom2DIteration4.SetInput(0, runtimeIncrementWaterDistance3);
            runtimeIncrementWaterDistance4.SetInput(0, runtimeZoom2DIteration4);
            PerformSampling("AlgorithmIncrementWaterDistance (4 iterations)", runtimeIncrementWaterDistance4);
        }
Пример #4
0
        public static void TestAlgorithmInitialBool()
        {
            var algorithm = new AlgorithmInitialBool();
            var runtime   = new RuntimeLayer(algorithm);

            PerformSampling("AlgorithmInitialBool", runtime);
        }
Пример #5
0
        private void TestRuntimePassthrough(int xBorder, int yBorder)
        {
            int computations1, computations2;
            int width = 16, height = 16, depth = 16;
            var gradient    = new RuntimeLayer(new AlgorithmGradientInitial());
            var passthrough = new RuntimeLayer(new AlgorithmPassthrough {
                XBorder = xBorder, YBorder = yBorder
            });

            passthrough.SetInput(0, gradient);
            var i1 = gradient.GenerateData(0, 0, 0, width, height, depth, out computations1);
            var i2 = passthrough.GenerateData(0, 0, 0, width, height, depth, out computations2);

            for (var x = 0; x < width; x++)
            {
                for (var y = 0; y < height; y++)
                {
                    for (var z = 0; z < depth; z++)
                    {
                        Assert.Equal(i1[x + y * width + z * width * height], i2[x + y * width + z * width * height]);
                    }
                }
            }
            //, "Value differs in passthrough (" + xBorder + ", " + yBorder + ").");
        }
Пример #6
0
        public static void Main(string[] args)
        {
            // Create algorithm setup.
            var algorithmZoom1       = new RuntimeLayer(new AlgorithmZoom2D());
            var algorithmZoom2       = new RuntimeLayer(new AlgorithmZoom2D());
            var algorithmZoom3       = new RuntimeLayer(new AlgorithmZoom2D());
            var algorithmZoom4       = new RuntimeLayer(new AlgorithmZoom2D());
            var algorithmInitialLand = new RuntimeLayer(new AlgorithmInitialBool());

            algorithmZoom4.SetInput(0, algorithmInitialLand);
            algorithmZoom3.SetInput(0, algorithmZoom4);
            algorithmZoom2.SetInput(0, algorithmZoom3);
            algorithmZoom1.SetInput(0, algorithmZoom2);

            StorageLayer[] storage = null;
            Console.WriteLine("Storing...");
            using (var writer = new StreamWriter("WorldConfig.xml", false))
                StorageAccess.SaveStorage(
                    new StorageLayer[] { StorageAccess.FromRuntime(algorithmZoom1) }, writer);

            Console.WriteLine("Loading...");
            using (var reader = new StreamReader("WorldConfig.xml"))
                storage = StorageAccess.LoadStorage(reader);
            foreach (var l in storage)
            {
                Console.WriteLine(l.Algorithm.GetType().FullName);
            }
        }
        public void TestPositiveDoubling()
        {
            var inputA = new AlgorithmDebuggingInitialValueDelegate
            {
                GetValueForPosition = (x, y, z, i, j, k) =>
                {
                    return((int)(1));
                }
            };

            int computations;
            var increment = new AlgorithmIncrementWaterDistance();

            var runtimeInput = new RuntimeLayer(inputA);
            var runtimeTest  = new RuntimeLayer(increment);

            runtimeTest.SetInput(0, runtimeInput);

            var result = runtimeTest.GenerateData(0, 0, 0, 16, 16, 16, out computations);


            for (var i = 0; i < 16; i++)
            {
                for (var j = 0; j < 16; j++)
                {
                    for (var k = 0; k < 16; k++)
                    {
                        Assert.True(
                            result[i + j * 16 + k * 16 * 16] == 2);
                    }
                }
            }
        }
Пример #8
0
        public void TestForOCXOddAdjustmentShutterBug()
        {
            int computations;
            var input = new AlgorithmDebuggingInitialDelegate
            {
                ValueShouldBePlacedAt = (x, y, z) => true
            };
            var zoom = new AlgorithmZoom2D
            {
                Mode = AlgorithmZoom2D.ZoomType.Square
            };
            var runtimeInput = new RuntimeLayer(input);
            var runtimeZoom  = new RuntimeLayer(zoom);

            runtimeZoom.SetInput(0, runtimeInput);
            var result = runtimeZoom.GenerateData(1, 0, 0, 32, 32, 32, out computations);

            // We have filled the entire block, therefore this bug can be detected by checking
            // every odd row.
            for (var x = 1; x < 32; x += 2)
            {
                Assert.True(result[x + 0 * 32 + 0 * 32 * 32] == 1);
            }
            //, "OCX odd adjustment shutter bug is present, where every odd row is blank when main adjustment is an odd number.");
        }
Пример #9
0
 public RangedLayer(RuntimeLayer layer)
 {
     if (layer == null)
     {
         throw new ArgumentNullException("layer");
     }
     InitializeFromRuntime(this, layer);
 }
Пример #10
0
        public ExportForm(FlowElement flowElement)
        {
            InitializeComponent();

            this.m_Layer           = StorageAccess.ToRuntime((flowElement as AlgorithmFlowElement).Layer);
            this.m_Bitmap          = new Bitmap(1024 + 32, 1024 + 256);
            this.c_RenderBox.Image = this.m_Bitmap;
            this.c_Timer.Start();
        }
Пример #11
0
        /// <summary>
        /// Process an input runtime layer.
        /// </summary>
        /// <param name="ranged">The current ranged layer.</param>
        /// <param name="layer">The current runtime layer.</param>
        /// <param name="input">The input runtime layer.</param>
        /// <returns>The input ranged layer.</returns>
        private static RangedLayer ProcessInput(RangedLayer currentRanged, RuntimeLayer currentRuntime, RuntimeLayer inputRuntime)
        {
            // Set up the new ranged layer.
            var inputRanged = new RangedLayer();

            inputRanged.X      = currentRanged.X;
            inputRanged.Y      = currentRanged.Y;
            inputRanged.Z      = currentRanged.Z;
            inputRanged.Width  = currentRanged.Width;
            inputRanged.Height = currentRanged.Height;
            inputRanged.Depth  = currentRanged.Depth;
            inputRanged.Layer  = inputRuntime;

            // Determine if we need to adjust the width, height and depth.
            if (currentRuntime.Algorithm.InputWidthAtHalfSize[0])
            {
                inputRanged.Width = CreateDivideByTwo(inputRanged.Width);
            }
            if (currentRuntime.Algorithm.InputHeightAtHalfSize[0])
            {
                inputRanged.Height = CreateDivideByTwo(inputRanged.Height);
            }
            if (currentRuntime.Algorithm.InputDepthAtHalfSize[0])
            {
                inputRanged.Depth = CreateDivideByTwo(inputRanged.Depth);
            }

            // Determine if we need to adjust the X, Y or Z offsets.
            if (currentRuntime.Algorithm.RequiredXBorder[0] > 0)
            {
                inputRanged.X = CreateSubtraction(inputRanged.X, currentRuntime.Algorithm.RequiredXBorder[0]);
                //inputRanged.Width = CreateAddition(inputRanged.Width, currentRuntime.Algorithm.RequiredXBorder * 2);
            }
            if (currentRuntime.Algorithm.RequiredYBorder[0] > 0)
            {
                inputRanged.Y = CreateSubtraction(inputRanged.Y, currentRuntime.Algorithm.RequiredYBorder[0]);
                //inputRanged.Height = CreateAddition(inputRanged.Height, currentRuntime.Algorithm.RequiredYBorder * 2);
            }
            if (currentRuntime.Algorithm.RequiredZBorder[0] > 0)
            {
                inputRanged.Z = CreateSubtraction(inputRanged.Z, currentRuntime.Algorithm.RequiredZBorder[0]);
                //inputRanged.Depth = CreateAddition(inputRanged.Depth, currentRuntime.Algorithm.RequiredZBorder * 2);
            }

            // Process inputs recursively.
            var inputs = inputRuntime.GetInputs();

            inputRanged.Inputs = new RangedLayer[inputs.Length];
            for (var i = 0; i < inputs.Length; i++)
            {
                inputRanged.Inputs[i] = inputs[i] == null ? null : ProcessInput(inputRanged, inputRuntime, inputs[i]);
            }

            // Return the new layer.
            return(inputRanged);
        }
Пример #12
0
        public static void TestAlgorithmZoom2DIteration1()
        {
            var algorithmInitial          = new AlgorithmInitialBool();
            var algorithmZoom2DIteration1 = new AlgorithmZoom2D();
            var runtimeInitial            = new RuntimeLayer(algorithmInitial);
            var runtimeZoom2DIteration1   = new RuntimeLayer(algorithmZoom2DIteration1);

            runtimeZoom2DIteration1.SetInput(0, runtimeInitial);
            PerformSampling("AlgorithmZoom2D (1 iteration)", runtimeZoom2DIteration1);
        }
Пример #13
0
        public AnalyseForm(FlowElement flowElement)
        {
            InitializeComponent();

            this.m_Layer = StorageAccess.ToRuntime((flowElement as AlgorithmFlowElement).Layer);
            this.c_AnalysisAddOptionsMenu.Items.AddRange((
                                                             from assembly in AppDomain.CurrentDomain.GetAssemblies()
                                                             from type in assembly.GetTypes()
                                                             where typeof(AnalysisEngine).IsAssignableFrom(type) && !type.IsGenericType && !type.IsAbstract
                                                             select new TypeWrapper(type)).ToArray());
        }
Пример #14
0
 public TraceForm(FlowElement flowElement)
 {
     InitializeComponent();
     this.m_Layer = StorageAccess.ToRuntime((flowElement as AlgorithmFlowElement).Layer);
     this.c_FormZoomSize.Items.Add(new ZoomLevel {
         Level = 1
     });
     this.c_FormZoomSize.Items.Add(new ZoomLevel {
         Level = 2
     });
     this.c_FormZoomSize.SelectedIndex = 0;
 }
Пример #15
0
        public static IGenerator Compile(RuntimeLayer layer)
        {
            // TODO: Work out the tree of runtime layers to determine what to compile.
            // TODO: Determine the actual code to generate by using Mono.Cecil on the assemblies.
            // TODO: Generate the code and return the type for use.

            //Console.WriteLine("Tracing compilation...");

            var result = ProcessRuntimeLayer(layer);

            return(GenerateType(result));
        }
Пример #16
0
        public static void TestAlgorithmIncrementWaterDistance1()
        {
            var algorithmInitial = new AlgorithmInitialBool();
            var algorithmIncrementWaterDistance = new AlgorithmIncrementWaterDistance()
            {
                Initial = true
            };
            var runtimeInitial = new RuntimeLayer(algorithmInitial);
            var runtimeIncrementWaterDistance = new RuntimeLayer(algorithmIncrementWaterDistance);

            runtimeIncrementWaterDistance.SetInput(0, runtimeInitial);
            PerformSampling("AlgorithmIncrementWaterDistance", runtimeIncrementWaterDistance);
        }
Пример #17
0
        private static ProcessedResult ProcessRuntimeLayer(RuntimeLayer layer)
        {
            // Create our own processed result; a copy of our own state plus
            // somewhere to accumulate code.
            var result = new ProcessedResult();

            result.ProcessedCode = "";

            // Get a reference to the algorithm that the runtime layer is using.
            var algorithm = layer.Algorithm;

            if (algorithm == null)
            {
                throw new InvalidOperationException("Attempted to compile null runtime layer!");
            }

            // Use RangedLayer to work out the metrics.
            var        ranged = new RangedLayer(layer);
            Expression ix, iy, iz, iwidth, iheight, idepth, iouterx, ioutery, iouterz;

            RangedLayer.FindMaximumBounds(ranged, out ix, out iy, out iz, out iwidth, out iheight, out idepth, out iouterx, out ioutery, out iouterz);

            // Add __cwidth, __cheight and __cdepth declarations.
            result.Declarations += "int __cx = (int)((x - (" + ix.GetText(null) + ")));\n";
            result.Declarations += "int __cy = (int)((y - (" + iy.GetText(null) + ")));\n";
            result.Declarations += "int __cz = (int)((z - (" + iz.GetText(null) + ")));\n";
            result.Declarations += "int __cwidth = " + iwidth.GetText(null) + ";\n";
            result.Declarations += "int __cheight = " + iheight.GetText(null) + ";\n";
            result.Declarations += "int __cdepth = " + idepth.GetText(null) + ";\n";

            // Create the for loop that our calculations are done within.
            result.ProcessedCode += @"for (var k = (int)((" + iz.GetText(null) + ") - z); k < " + iouterz.GetText(null) + @"; k++)
for (var i = (int)((" + ix.GetText(null) + ") - x); i < " + iouterx.GetText(null) + @"; i++)
for (var j = (int)((" + iy.GetText(null) + ") - y); j < " + ioutery.GetText(null) + @"; j++)
{
";

            // Now add the code for the layer.
            var inputResult = CompileRuntimeLayer(layer, ranged, null);

            result.ProcessedCode     += inputResult.ProcessedCode;
            result.OutputVariableName = inputResult.OutputVariableName;
            result.OutputVariableType = inputResult.OutputVariableType;
            result.Declarations      += inputResult.Declarations;

            // Terminate the for loop and return the result.
            result.ProcessedCode += "}";
            return(result);
        }
Пример #18
0
 static ChunkProvider()
 {
     // Use StorageAccess to load reference to world generation.
     StorageLayer[] layers;
     using (var reader = new StreamReader(WORLD_CONFIG_FILE))
         layers = StorageAccess.LoadStorage(reader);
     foreach (var layer in layers)
     {
         if (layer.Algorithm is AlgorithmResult)
         {
             if ((layer.Algorithm as AlgorithmResult).DefaultForGame)
             {
                 m_ResultLayer = StorageAccess.ToRuntime(layer);
                 break;
             }
         }
     }
 }
 public Bitmap RenderTraceResult(
     RuntimeLayer layer,
     dynamic data,
     int width,
     int height,
     int depth)
 {
     Func<dynamic, Color> getColor;
     getColor = x => layer.Algorithm.GetColorForValue(
         this.m_StorageAccess.FromRuntime(layer),
         x);
     return this.m_IsometricBitmapRenderer.GenerateImage(
         data,
         getColor,
         width,
         height,
         depth);
 }
Пример #20
0
        /// <summary>
        /// Initializes the ranged layer from a runtime layer.
        /// </summary>
        private static void InitializeFromRuntime(RangedLayer ranged, RuntimeLayer layer)
        {
            // Set up the initial expressions.
            ranged.X      = new IdentifierExpression("x");
            ranged.Y      = new IdentifierExpression("y");
            ranged.Z      = new IdentifierExpression("z");
            ranged.Width  = new IdentifierExpression("width");
            ranged.Height = new IdentifierExpression("height");
            ranged.Depth  = new IdentifierExpression("depth");

            // Go through all of the inputs and process them.
            var inputs = layer.GetInputs();

            ranged.Inputs = new RangedLayer[inputs.Length];
            for (var i = 0; i < inputs.Length; i++)
            {
                ranged.Inputs[i] = inputs[i] == null ? null : ProcessInput(ranged, layer, inputs[i]);
            }
        }
Пример #21
0
        public void TestValueRetrievalAcrossBorder()
        {
            int computations;
            var inputA = new AlgorithmDebuggingInitialDelegate
            {
                ValueShouldBePlacedAt = (x, y, z) => (x >= 4 && x <= 6 && y >= 4 && y <= 6)
            };
            var test = new AlgorithmDebuggingDelegate
            {
                Delegate = (context, input, output, x, y, z, i, j, k, width, height, depth, ox, oy, oz) =>
                {
                    int v00 = input[((i - 1) + ox) + ((j - 1) + oy) * width + (k + oz) * width * height];
                    int v01 = input[((i - 1) + ox) + ((j + 0) + oy) * width + (k + oz) * width * height];
                    int v02 = input[((i - 1) + ox) + ((j + 1) + oy) * width + (k + oz) * width * height];
                    int v10 = input[((i + 0) + ox) + ((j - 1) + oy) * width + (k + oz) * width * height];
                    int v11 = input[((i + 0) + ox) + ((j + 0) + oy) * width + (k + oz) * width * height];
                    int v12 = input[((i + 0) + ox) + ((j + 1) + oy) * width + (k + oz) * width * height];
                    int v20 = input[((i + 1) + ox) + ((j - 1) + oy) * width + (k + oz) * width * height];
                    int v21 = input[((i + 1) + ox) + ((j + 0) + oy) * width + (k + oz) * width * height];
                    int v22 = input[((i + 1) + ox) + ((j + 1) + oy) * width + (k + oz) * width * height];

                    Assert.True(v00 == ((5 <= x && x <= 7 && 5 <= y && y <= 7) ? 1 : 0), "v00 != 1 when x == " + x + " && y == " + y + " && i == " + i + " && j == " + j);
                    Assert.True(v01 == ((5 <= x && x <= 7 && 4 <= y && y <= 6) ? 1 : 0), "v01 != 1 when x == " + x + " && y == " + y + " && i == " + i + " && j == " + j);
                    Assert.True(v02 == ((5 <= x && x <= 7 && 3 <= y && y <= 5) ? 1 : 0), "v02 != 1 when x == " + x + " && y == " + y + " && i == " + i + " && j == " + j);
                    Assert.True(v10 == ((4 <= x && x <= 6 && 5 <= y && y <= 7) ? 1 : 0), "v10 != 1 when x == " + x + " && y == " + y + " && i == " + i + " && j == " + j);
                    Assert.True(v11 == ((4 <= x && x <= 6 && 4 <= y && y <= 6) ? 1 : 0), "v11 != 1 when x == " + x + " && y == " + y + " && i == " + i + " && j == " + j);
                    Assert.True(v12 == ((4 <= x && x <= 6 && 3 <= y && y <= 5) ? 1 : 0), "v12 != 1 when x == " + x + " && y == " + y + " && i == " + i + " && j == " + j);
                    Assert.True(v20 == ((3 <= x && x <= 5 && 5 <= y && y <= 7) ? 1 : 0), "v20 != 1 when x == " + x + " && y == " + y + " && i == " + i + " && j == " + j);
                    Assert.True(v21 == ((3 <= x && x <= 5 && 4 <= y && y <= 6) ? 1 : 0), "v21 != 1 when x == " + x + " && y == " + y + " && i == " + i + " && j == " + j);
                    Assert.True(v22 == ((3 <= x && x <= 5 && 3 <= y && y <= 5) ? 1 : 0), "v22 != 1 when x == " + x + " && y == " + y + " && i == " + i + " && j == " + j);
                }
            };
            var runtimeInput = new RuntimeLayer(inputA);
            var runtimeTest  = new RuntimeLayer(test);

            runtimeTest.SetInput(0, runtimeInput);

            // Test this stuff.
            for (int i = -10; i < 10; i++)
            {
                runtimeTest.GenerateData(i, i, i, 10, 10, 10, out computations);
            }
        }
Пример #22
0
        public void TestValues()
        {
            int computations;

            for (int v = -50; v < 50; v++)
            {
                var gradient = new RuntimeLayer(new AlgorithmConstant {
                    Constant = v
                });
                var result = gradient.GenerateData(-1, -1, -1, 3, 3, 3, out computations);

                for (var i = 0; i < 3; i++)
                {
                    for (var j = 0; j < 3; j++)
                    {
                        for (var k = 0; k < 3; k++)
                        {
                            Assert.Equal(result[i + j * 3 + k * 3 * 3], v);
                        }
                    }
                }
            }
        }
Пример #23
0
        public void TestRange()
        {
            int computations;
            var gradient = new RuntimeLayer(new AlgorithmInitialBool());
            var result   = gradient.GenerateData(0, 0, 0, 16, 16, 16, out computations);

            for (var i = 0; i < 16; i++)
            {
                for (var j = 0; j < 16; j++)
                {
                    for (var k = 0; k < 16; k++)
                    {
                        if (result[i + j * 16 + k * 16 * 16] == 0)
                        {
                            continue;
                        }

                        Assert.True(
                            result[i + j * 16 + k * 16 * 16] == 0 ||
                            result[i + j * 16 + k * 16 * 16] == 1);
                    }
                }
            }
        }
Пример #24
0
        public static void Main(string[] args)
        {
            Layer        legacy                   = null;
            RuntimeLayer algorithmRuntime         = null;
            IGenerator   algorithmCompiled        = null;
            IGenerator   algorithmCompiledBuiltin = null;
            string       mode = "quadzoom";

            if (args.Length > 0)
            {
                mode = args[0];
            }

            // Create initial layers from both types.
            if (mode == "quadzoom")
            {
                legacy = new LayerZoom(new LayerZoom(new LayerZoom(new LayerZoom(new LayerInitialLand()))));
                var algorithmZoom1       = new RuntimeLayer(new AlgorithmZoom2D());
                var algorithmZoom2       = new RuntimeLayer(new AlgorithmZoom2D());
                var algorithmZoom3       = new RuntimeLayer(new AlgorithmZoom2D());
                var algorithmZoom4       = new RuntimeLayer(new AlgorithmZoom2D());
                var algorithmInitialLand = new RuntimeLayer(new AlgorithmInitialBool());
                algorithmZoom4.SetInput(0, algorithmInitialLand);
                algorithmZoom3.SetInput(0, algorithmZoom4);
                algorithmZoom2.SetInput(0, algorithmZoom3);
                algorithmZoom1.SetInput(0, algorithmZoom2);
                algorithmRuntime = algorithmZoom1;
#if !RANGED_LOGIC_TEST
                algorithmCompiled = LayerCompiler.Compile(algorithmRuntime);
#endif
                //algorithmCompiledBuiltin = new CompiledLayerBuiltin();
            }
            else if (mode == "doublezoom")
            {
                legacy = new LayerZoom(new LayerZoom(new LayerInitialLand()));
                var algorithmZoom1       = new RuntimeLayer(new AlgorithmZoom2D());
                var algorithmZoom2       = new RuntimeLayer(new AlgorithmZoom2D());
                var algorithmInitialLand = new RuntimeLayer(new AlgorithmInitialBool());
                algorithmZoom2.SetInput(0, algorithmInitialLand);
                algorithmZoom1.SetInput(0, algorithmZoom2);
                algorithmRuntime = algorithmZoom1;
#if !RANGED_LOGIC_TEST
                algorithmCompiled = LayerCompiler.Compile(algorithmRuntime);
#endif
            }
            else if (mode == "zoom")
            {
                legacy           = new LayerZoom(new LayerInitialLand());
                algorithmRuntime = new RuntimeLayer(new AlgorithmZoom2D());
                algorithmRuntime.SetInput(0, new RuntimeLayer(new AlgorithmInitialBool()));
#if !RANGED_LOGIC_TEST
                algorithmCompiled = LayerCompiler.Compile(algorithmRuntime);
#endif
            }
            else if (mode == "test")
            {
                var algorithmTest1    = new RuntimeLayer(new AlgorithmPassthrough());
                var algorithmTest2    = new RuntimeLayer(new AlgorithmPassthrough());
                var algorithmConstant = new RuntimeLayer(new AlgorithmConstant {
                    Constant = 5
                });
                algorithmTest2.SetInput(0, algorithmConstant);
                algorithmTest1.SetInput(0, algorithmTest2);
                algorithmRuntime = algorithmTest1;
#if !RANGED_LOGIC_TEST
                algorithmCompiled = LayerCompiler.Compile(algorithmRuntime);
#endif
            }
            else if (mode == "extend")
            {
                legacy           = null;
                algorithmRuntime = new RuntimeLayer(new AlgorithmExtend2D());
                algorithmRuntime.SetInput(0, new RuntimeLayer(new AlgorithmInitialBool()));
#if !RANGED_LOGIC_TEST
                algorithmCompiled = LayerCompiler.Compile(algorithmRuntime);
#endif
            }
            else if (mode == "land")
            {
                legacy           = new LayerInitialLand();
                algorithmRuntime = new RuntimeLayer(new AlgorithmInitialBool());
#if !RANGED_LOGIC_TEST
                algorithmCompiled = LayerCompiler.Compile(algorithmRuntime);
#endif
            }
            else
            {
                Console.WriteLine("usage: ProceduralGenPerformance.exe [doublezoom|zoom|land]");
                return;
            }

#if MODULO_SPEED_TEST
            for (int i = 0; i <= 10000000; i += 1)
            {
                if ((i & 71) < 0 || (i & 71) >= 10000000)
                {
                    Console.WriteLine("AND DOES NOT WORK FOR " + i + ".");
                }
            }
            int a            = 0;
            var andStartTime = DateTime.Now;
            for (int i = 0; i < 10000000; i += 1)
            {
                a = i & 71;
            }
            var andEndTime   = DateTime.Now;
            var modStartTime = DateTime.Now;
            for (int i = 0; i < 10000000; i += 1)
            {
                a = i % 71;
            }
            var modEndTime = DateTime.Now;
            Console.WriteLine("BITAND OPERATION TOOK: " + (andEndTime - andStartTime).TotalMilliseconds + "ms");
            Console.WriteLine("MODULO OPERATION TOOK: " + (modEndTime - modStartTime).TotalMilliseconds + "ms");
#endif

#if VERIFICATION
            #region Verification

            // Verify integrity between algorithms.
            try
            {
                int   vcomputations;
                int[] legacyData   = legacy.GenerateData(0, 0, 16, 16);
                int[] runtimeData  = algorithmRuntime.GenerateData(0, 0, 0, 16, 16, 1, out vcomputations);
                int[] compiledData = algorithmCompiled.GenerateData(0, 0, 0, 16, 16, 1, out vcomputations);
                if (runtimeData.Length != legacyData.Length)
                {
                    Console.WriteLine("STOP: Runtime data evaluation results in a " +
                                      "different array size than the legacy system.");
                    return;
                }
                if (compiledData.Length != legacyData.Length)
                {
                    Console.WriteLine("STOP: Compiled data evaluation results in a " +
                                      "different array size than the legacy system.");
                    return;
                }
                for (var i = 0; i < legacyData.Length; i++)
                {
                    if (runtimeData[i] != legacyData[i])
                    {
                        Console.WriteLine("WARNING: Runtime algorithm results in different data to legacy system.");
                        break;
                    }
                }
                for (var i = 0; i < legacyData.Length; i++)
                {
                    if (compiledData[i] != legacyData[i])
                    {
                        Console.WriteLine("WARNING: Compiled algorithm results in different data to legacy system.");
                        break;
                    }
                }
                for (var i = 0; i < legacyData.Length; i++)
                {
                    if (runtimeData[i] != compiledData[i])
                    {
                        Console.WriteLine("STOP: Runtime algorithm results in different data to compiled algorithm.");
                        for (var x = 0; x < 16; x++)
                        {
                            for (var y = 0; y < 16; y++)
                            {
                                if (runtimeData[x + y * 16] != compiledData[x + y * 16])
                                {
                                    Console.Write(compiledData[x + y * 16]);
                                }
                                else
                                {
                                    Console.Write(" ");
                                }
                            }
                            Console.WriteLine();
                        }
                        break;
                    }
                }
                Console.WriteLine("=== SAMPLE FROM RUNTIME =====");
                for (var x = 0; x < 16; x++)
                {
                    for (var y = 0; y < 16; y++)
                    {
                        Console.Write(runtimeData[x + y * 16]);
                    }
                    Console.WriteLine();
                }
                Console.WriteLine("=== SAMPLE FROM COMPILED ====");
                for (var x = 0; x < 16; x++)
                {
                    for (var y = 0; y < 16; y++)
                    {
                        Console.Write(compiledData[x + y * 16]);
                    }
                    Console.WriteLine();
                }
                Console.WriteLine("=============================");
            }
            catch
            {
                // The generation of data failed... could be a dodgy
                // algorithm implementation breaking.
                Console.WriteLine("Verification not possible (check algorithm implementations).");
            }

            #endregion
#endif

#if RANGED_LOGIC_TEST
            var ranged = new RangedLayer(algorithmRuntime);
            Console.WriteLine(ranged.GetPrintableStructure());

            ICSharpCode.NRefactory.CSharp.Expression ix, iy, iz, iwidth, iheight, idepth;
            RangedLayer.FindMaximumBounds(ranged, out ix, out iy, out iz, out iwidth, out iheight, out idepth);
            Console.WriteLine("The X expression is: " + ix.ToString());
            Console.WriteLine("The Y expression is: " + iy.ToString());
            Console.WriteLine("The Z expression is: " + iz.ToString());
            Console.WriteLine("The W expression is: " + iwidth.ToString());
            Console.WriteLine("The H expression is: " + iheight.ToString());
            Console.WriteLine("The D expression is: " + idepth.ToString());
            return;
#endif

            // Run tests to see how fast they are.
            for (int x = 0; x < 300; x++)
            {
                int computations    = 0;
                var legacyFailed    = false;
                var legacyStartTime = DateTime.Now;
                try
                {
                    if (legacy != null)
                    {
                        Console.WriteLine("Starting Test #" + x + " (legacy)");
                        for (int i = 0; i < 1000; i++)
                        {
                            legacy.GenerateData(0, 0, 128, 128);
                        }
                    }
                }
                catch
                {
                    legacyFailed = true;
                }
                var legacyEndTime = DateTime.Now;
                Console.WriteLine("Starting Test #" + x + " (algorithm runtime)");
                var algorithmRuntimeFailed    = false;
                var algorithmRuntimeStartTime = DateTime.Now;
                try
                {
                    for (int i = 0; i < 1000; i++)
                    {
                        algorithmRuntime.GenerateData(0, 0, 0, 128, 128, 1, out computations);
                    }
                }
                catch
                {
                    algorithmRuntimeFailed = true;
                }
                var algorithmRuntimeEndTime = DateTime.Now;
                Console.WriteLine("Starting Test #" + x + " (algorithm compiled)");
                var algorithmCompiledFailed    = false;
                var algorithmCompiledStartTime = DateTime.Now;
                try
                {
                    for (int i = 0; i < 1000; i++)
                    {
                        algorithmCompiled.GenerateData(0, 0, 0, 128, 128, 1, out computations);
                    }
                }
                catch
                {
                    algorithmCompiledFailed = true;
                }
                var algorithmCompiledEndTime          = DateTime.Now;
                var algorithmCompiledBuiltinStartTime = DateTime.Now;
                var algorithmCompiledBuiltinEndTime   = DateTime.Now;
                if (algorithmCompiledBuiltin != null)
                {
                    Console.WriteLine("Starting Test #" + x + " (algorithm compiled builtin)");
                    algorithmCompiledBuiltinStartTime = DateTime.Now;
                    for (int i = 0; i < 1000; i++)
                    {
                        algorithmCompiled.GenerateData(0, 0, 0, 128, 128, 1, out computations);
                    }
                    algorithmCompiledBuiltinEndTime = DateTime.Now;
                }

                // Because there are 1000 tests, and 1000 microseconds in a millisecond..
                Console.Write("Test #" + x);
                PrintStatus(
                    "LEGACY",
                    legacyFailed,
                    legacyStartTime,
                    legacyEndTime);
                PrintStatus(
                    "ALGORITHM RUNTIME",
                    algorithmRuntimeFailed,
                    algorithmRuntimeStartTime,
                    algorithmRuntimeEndTime);
                PrintStatus(
                    "ALGORITHM COMPILED",
                    algorithmCompiledFailed,
                    algorithmCompiledStartTime,
                    algorithmCompiledEndTime);
                PrintStatus(
                    "ALGORITHM COMPILED BUILTIN",
                    algorithmCompiledBuiltin != null,
                    algorithmCompiledBuiltinStartTime,
                    algorithmCompiledBuiltinEndTime);
                Console.WriteLine(
                    "LC%: " + ((legacyEndTime - legacyStartTime).TotalMilliseconds /
                               (algorithmCompiledEndTime - algorithmCompiledStartTime).TotalMilliseconds)
                    * 100 + "% "
                    );
            }
        }
Пример #25
0
        private void ValidateLayer(RuntimeLayer runtime)
        {
            Assert.DoesNotThrow(() =>
            {
                var compiled = LayerCompiler.Compile(runtime);

                int computations;
                var runtimeData = runtime.GenerateData(-10, -10, -10, 20, 20, 20, out computations);
                var compiledData = compiled.GenerateData(-10, -10, -10, 20, 20, 20, out computations);
                for (var x = 0; x < 20; x++)
                    for (var y = 0; y < 20; y++)
                        for (var z = 0; z < 20; z++)
                            Assert.Equal(runtimeData[x + y*20 + z*20*20], compiledData[x + y*20 + z*20*20]);
            });
        }
Пример #26
0
 private static void PerformOperationRecursively(Action <RuntimeLayer> operation, RuntimeLayer layer)
 {
     operation(layer);
     foreach (var input in layer.GetInputs())
     {
         if (input != null)
         {
             PerformOperationRecursively(operation, input);
         }
     }
 }
        public static Bitmap RenderTraceResult(
            RuntimeLayer layer,
            dynamic data,
            int width,
            int height,
            int depth)
        {
            int owidth  = width;
            int oheight = height;

            width  = 128 * TraceScale;
            height = 128 * TraceScale;
            depth  = 128 * TraceScale;

            Bitmap   b = new Bitmap(width, height);
            Graphics g = Graphics.FromImage(b);

            g.Clear(Color.White);
            g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixelGridFit;

            StorageLayer parent;

            if (layer.GetInputs().Length == 0)
            {
                parent = null;
            }
            else
            {
                parent = StorageAccess.FromRuntime(layer.GetInputs()[0]);
            }

            int[] render  = GetCellRenderOrder(RenderToNE, TraceRenderWidth, TraceRenderHeight);
            int   ztop    = layer.Algorithm.Is2DOnly ? 1 : 128;
            int   zbottom = 0;

            for (int z = zbottom; z < ztop; z++)
            {
                int rcx = width / 2 - 1;
                int rcy = height / 2 - (height / 2 - 1);
                int rw  = 2;
                int rh  = 1;
                for (int i = 0; i < render.Length; i++)
                {
                    // Calculate the X / Y of the tile in the grid.
                    int x = render[i] % TraceRenderWidth;
                    int y = render[i] / TraceRenderWidth;

                    // Calculate the render position on screen.
                    int rx = rcx + (int)((x - y) / 2.0 * rw);// (int)(x / ((RenderWidth + 1) / 2.0) * rw);
                    int ry = rcy + (x + y) * rh - (rh / 2 * (TraceRenderWidth + TraceRenderHeight)) - (z - zbottom) * 1;

                    while (true)
                    {
                        try
                        {
                            Color lc = layer.Algorithm.GetColorForValue(
                                parent,
                                data[x + y * owidth + z * owidth * oheight]);
                            SolidBrush sb = new SolidBrush(Color.FromArgb(lc.A, lc.R, lc.G, lc.B));
                            g.FillRectangle(
                                sb,
                                new Rectangle(rx, ry, rw, rh)
                                );
                            break;
                        }
                        catch (InvalidOperationException)
                        {
                            // Graphics can be in use elsewhere, but we don't care; just try again.
                        }
                    }
                }
            }

            return(b);
        }
Пример #28
0
        public void TestYSkew()
        {
            int computations;
            var input = new AlgorithmDebuggingInitialDelegate
            {
                ValueShouldBePlacedAt = (x, y, z) => (x == 0 && z == 0)
            };
            var passthrough       = new AlgorithmPassthrough();
            var runtimeInput      = new RuntimeLayer(input);
            var runtimePassthough = new RuntimeLayer(passthrough);

            runtimePassthough.SetInput(0, runtimeInput);

            // We need to check with various borders.
            for (var i = 0; i < 2; i++)
            {
                for (var j = 0; j < 2; j++)
                {
                    for (var k = 0; k < 2; k++)
                    {
                        passthrough.XBorder = i;
                        passthrough.YBorder = j;
                        passthrough.ZBorder = k;
                        var result = runtimePassthough.GenerateData(-16, 0, -16, 32, 32, 32, out computations);

                        // Test the area where we should be filled.
                        for (var y = 0; y < 32; y += 1)
                        {
                            Assert.True(result[16 + y * 32 + 16 * 32 * 32] == 1, "Skew present on the Y axis with borders (" + i + ", " + j + ", " + k + "), value missing.");
                        }

                        // Test the areas where we should not be filled.
                        for (var y = 0; y < 32; y += 1)
                        {
                            Assert.False(result[17 + y * 32 + 15 * 32 * 32] == 1, "Skew present on the Y axis with borders (" + i + ", " + j + ", " + k + "), value present at (1, " + y + ", -1).");
                        }
                        for (var y = 0; y < 32; y += 1)
                        {
                            Assert.False(result[16 + y * 32 + 15 * 32 * 32] == 1, "Skew present on the Y axis with borders (" + i + ", " + j + ", " + k + "), value present at (0, " + y + ", -1).");
                        }
                        for (var y = 0; y < 32; y += 1)
                        {
                            Assert.False(result[15 + y * 32 + 15 * 32 * 32] == 1, "Skew present on the Y axis with borders (" + i + ", " + j + ", " + k + "), value present at (-1, " + y + ", -1).");
                        }
                        for (var y = 0; y < 32; y += 1)
                        {
                            Assert.False(result[17 + y * 32 + 16 * 32 * 32] == 1, "Skew present on the Y axis with borders (" + i + ", " + j + ", " + k + "), value present at (1, " + y + ", 0).");
                        }
                        for (var y = 0; y < 32; y += 1)
                        {
                            Assert.False(result[15 + y * 32 + 16 * 32 * 32] == 1, "Skew present on the Y axis with borders (" + i + ", " + j + ", " + k + "), value present at (-1, " + y + ", 0).");
                        }
                        for (var y = 0; y < 32; y += 1)
                        {
                            Assert.False(result[17 + y * 32 + 17 * 32 * 32] == 1, "Skew present on the Y axis with borders (" + i + ", " + j + ", " + k + "), value present at (1, " + y + ", 1).");
                        }
                        for (var y = 0; y < 32; y += 1)
                        {
                            Assert.False(result[16 + y * 32 + 17 * 32 * 32] == 1, "Skew present on the Y axis with borders (" + i + ", " + j + ", " + k + "), value present at (0, " + y + ", 1).");
                        }
                        for (var y = 0; y < 32; y += 1)
                        {
                            Assert.False(result[15 + y * 32 + 17 * 32 * 32] == 1, "Skew present on the Y axis with borders (" + i + ", " + j + ", " + k + "), value present at (-1, " + y + ", 1).");
                        }
                    }
                }
            }
        }
Пример #29
0
        private static ProcessedResult CompileRuntimeLayer(RuntimeLayer layer, RangedLayer ranged, IAlgorithm parent)
        {
            // Create our own processed result; a copy of our own state plus
            // somewhere to accumulate code.
            var result = new ProcessedResult();

            result.ProcessedCode = "";

            // Get a reference to the algorithm that the runtime layer is using.
            var algorithm = layer.Algorithm;

            if (algorithm == null)
            {
                throw new InvalidOperationException("Attempted to compile null runtime layer!");
            }
            var algorithmType = algorithm.GetType();

            // If the runtime layer has inputs, we need to process them first.
            if (layer.Algorithm.InputTypes.Length > 0)
            {
                var inputs = layer.GetInputs();
                result.InputVariableNames = new string[inputs.Length];
                for (var i = 0; i < inputs.Length; i++)
                {
                    var inputResult = CompileRuntimeLayer(inputs[i], ranged.Inputs[i], layer.Algorithm);
                    result.ProcessedCode        += inputResult.ProcessedCode;
                    result.InputVariableNames[i] = inputResult.OutputVariableName;
                    result.Declarations         += inputResult.Declarations;
                }
            }

            // Create the storage array.
            result.OutputVariableName = GenerateRandomIdentifier();
            result.OutputVariableType = algorithm.OutputType.FullName;
            result.Declarations      += result.OutputVariableType + "[] " + result.OutputVariableName +
                                        " = new " + result.OutputVariableType + "[__cwidth * __cheight * __cdepth];\n";

            Console.WriteLine(ranged.ToString());

            // Add the conditional container.
            string code = "if (k >= (int)((" + ranged.Z.GetText(null) + ") - z) && i >= (int)((" + ranged.X.GetText(null) + ") - x) && j >= (int)((" + ranged.Y.GetText(null) + ") - y)" +
                          " && k < " + ranged.OuterZ.GetText(null) + " && i < " + ranged.OuterX.GetText(null) + " && j < " + ranged.OuterY.GetText(null) + @")
{
";

            /*result.Declarations += "Console.WriteLine(\"COMPILED: \" + " +
             *  "" + ranged.X + " + \" \" + " +
             *  "" + ranged.Y + " + \" \" + " +
             *  "" + ranged.Z + " + \" \" + " +
             *  "" + ranged.Width + " + \" \" + " +
             *  "" + ranged.Height + " + \" \" + " +
             *  "" + ranged.Depth + ");";*/

            // Refactor the method.
            AstBuilder astBuilder;
            var        method = DecompileUtil.GetAlgorithmCode(algorithmType, out astBuilder);

            AlgorithmRefactorer.InlineMethod(algorithm, method, result.OutputVariableName, result.InputVariableNames,
                                             "__cx", "__cy", "__cz",
                                             "__cwidth", "__cheight", "__cdepth");
            AlgorithmRefactorer.RemoveUsingStatements(astBuilder.CompilationUnit, result.UsingStatements);
            code += method.Body.GetText();

            // Terminate the conditional container and return.
            code += "computations += 1;";
            code += "}\n";
            result.ProcessedCode += code;
            return(result);
        }
Пример #30
0
 public static string GenerateCode(RuntimeLayer layer, bool optimize = true)
 {
     var result = ProcessRuntimeLayer(layer);
     return GenerateCode(result, optimize);
 }
Пример #31
0
 public RangedLayer(RuntimeLayer layer)
 {
     if (layer == null)
         throw new ArgumentNullException("layer");
     InitializeFromRuntime(this, layer);
 }
        private static Bitmap Regenerate3DImageForLayer(RuntimeLayer runtimeLayer, long ox, long oy, long oz, int width, int height, int depth, IGenerator compiledLayer = null)
        {
            int owidth  = width;
            int oheight = height;

            width  = 128;
            height = 192; // this affects bitmaps and rendering and stuff :(
            depth  = 128;

            // ARGHGHG FIXME
            Bitmap   b = new Bitmap(width, height);
            Graphics g = Graphics.FromImage(b);

            g.Clear(Color.White);
            g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixelGridFit;
            int     computations = 0;
            dynamic data;

            if (compiledLayer != null)
            {
                data = compiledLayer.GenerateData(ox, oy, oz, RenderWidth, RenderHeight, RenderDepth, out computations);
            }
            else
            {
                data = runtimeLayer.GenerateData(ox, oy, oz, RenderWidth, RenderHeight, RenderDepth, out computations);
            }

            StorageLayer parent;

            if (runtimeLayer.GetInputs().Length == 0)
            {
                parent = null;
            }
            else
            {
                parent = StorageAccess.FromRuntime(runtimeLayer.GetInputs()[0]);
            }

            int[] render  = GetCellRenderOrder(RenderToNE, RenderWidth, RenderHeight);
            int   ztop    = runtimeLayer.Algorithm.Is2DOnly ? 1 : RenderDepth;
            int   zbottom = 0;

            for (int z = zbottom; z < ztop; z++)
            {
                int rcx = width / 2 - 1;
                int rcy = height / 2 - 31;
                int rw  = 2;
                int rh  = 1;
                for (int i = 0; i < render.Length; i++)
                {
                    // Calculate the X / Y of the tile in the grid.
                    int x = render[i] % RenderWidth;
                    int y = render[i] / RenderWidth;

                    // Calculate the render position on screen.
                    int rx = rcx + (int)((x - y) / 2.0 * rw);// (int)(x / ((RenderWidth + 1) / 2.0) * rw);
                    int ry = rcy + (x + y) * rh - (rh / 2 * (RenderWidth + RenderHeight)) - (z - zbottom) * 1;

                    while (true)
                    {
                        try
                        {
                            Color lc = runtimeLayer.Algorithm.GetColorForValue(
                                parent,
                                data[x + y * owidth + z * owidth * oheight]);
                            SolidBrush sb = new SolidBrush(Color.FromArgb(lc.A, lc.R, lc.G, lc.B));
                            g.FillRectangle(
                                sb,
                                new Rectangle(rx, ry, rw, rh)
                                );
                            break;
                        }
                        catch (InvalidOperationException)
                        {
                            // Graphics can be in use elsewhere, but we don't care; just try again.
                        }
                    }
                }
            }

            return(b);
        }
Пример #33
0
        /// <summary>
        /// Backfills the ranged input layer to calculate the CalculationStart/End properties.
        /// </summary>
        /// <param name="currentRanged">The current ranged layer.</param>
        /// <param name="currentRuntime">The current runtime layer.</param>
        /// <param name="inputRanged">The input ranged layer.</param>
        /// <param name="idx">The index of the input layer in the parent layer.</param>
        private static void BackfillInput(
            RangedLayer currentRanged,
            RuntimeLayer currentRuntime,
            RangedLayer inputRanged,
            int idx,
            Expression mx,
            Expression my,
            Expression mz)
        {
            inputRanged.CalculationStartI = currentRanged.CalculationStartI.Clone();
            inputRanged.CalculationStartJ = currentRanged.CalculationStartJ.Clone();
            inputRanged.CalculationStartK = currentRanged.CalculationStartK.Clone();
            inputRanged.CalculationEndI = currentRanged.CalculationEndI.Clone();
            inputRanged.CalculationEndJ = currentRanged.CalculationEndJ.Clone();
            inputRanged.CalculationEndK = currentRanged.CalculationEndK.Clone();
            inputRanged.OffsetX = currentRanged.OffsetX.Clone();
            inputRanged.OffsetY = currentRanged.OffsetY.Clone();
            inputRanged.OffsetZ = currentRanged.OffsetZ.Clone();

            if (currentRuntime.Algorithm.RequiredXBorder[idx] > 0)
                inputRanged.CalculationStartI = CreateSubtraction(
                    inputRanged.CalculationStartI,
                    currentRuntime.Algorithm.RequiredXBorder[idx] * 2);
            if (currentRuntime.Algorithm.RequiredYBorder[idx] > 0)
                inputRanged.CalculationStartJ = CreateSubtraction(
                    inputRanged.CalculationStartJ,
                    currentRuntime.Algorithm.RequiredYBorder[idx] * 2);
            if (currentRuntime.Algorithm.RequiredZBorder[idx] > 0)
                inputRanged.CalculationStartK = CreateSubtraction(
                    inputRanged.CalculationStartK,
                    currentRuntime.Algorithm.RequiredZBorder[idx] * 2);

            if (currentRuntime.Algorithm.InputWidthAtHalfSize[idx])
                inputRanged.CalculationEndI = CreateDivideByTwo(inputRanged.CalculationEndI);
            if (currentRuntime.Algorithm.InputHeightAtHalfSize[idx])
                inputRanged.CalculationEndJ = CreateDivideByTwo(inputRanged.CalculationEndJ);
            if (currentRuntime.Algorithm.InputDepthAtHalfSize[idx])
                inputRanged.CalculationEndK = CreateDivideByTwo(inputRanged.CalculationEndK);

            inputRanged.OffsetI = DetermineRelativeOffsetForLayerFromXYZ(
                inputRanged.CalculationStartI,
                inputRanged.X,
                mx,
                "x");
            inputRanged.OffsetJ = DetermineRelativeOffsetForLayerFromXYZ(
                inputRanged.CalculationStartJ,
                inputRanged.Y,
                my,
                "y");
            inputRanged.OffsetK = DetermineRelativeOffsetForLayerFromXYZ(
                inputRanged.CalculationStartK,
                inputRanged.Z,
                mz,
                "z");

            // Run AST visitors over the expression to simplify.
            inputRanged.CalculationStartI = AstHelpers.OptimizeExpression(inputRanged.CalculationStartI);
            inputRanged.CalculationStartJ = AstHelpers.OptimizeExpression(inputRanged.CalculationStartJ);
            inputRanged.CalculationStartK = AstHelpers.OptimizeExpression(inputRanged.CalculationStartK);
            inputRanged.CalculationEndI = AstHelpers.OptimizeExpression(inputRanged.CalculationEndI);
            inputRanged.CalculationEndJ = AstHelpers.OptimizeExpression(inputRanged.CalculationEndJ);
            inputRanged.CalculationEndK = AstHelpers.OptimizeExpression(inputRanged.CalculationEndK);
            inputRanged.OffsetI = AstHelpers.OptimizeExpression(inputRanged.OffsetI);
            inputRanged.OffsetJ = AstHelpers.OptimizeExpression(inputRanged.OffsetJ);
            inputRanged.OffsetK = AstHelpers.OptimizeExpression(inputRanged.OffsetK);
            inputRanged.OffsetX = AstHelpers.OptimizeExpression(inputRanged.OffsetX);
            inputRanged.OffsetY = AstHelpers.OptimizeExpression(inputRanged.OffsetY);
            inputRanged.OffsetZ = AstHelpers.OptimizeExpression(inputRanged.OffsetZ);

            // Go through all of the inputs and backfill them.
            for (var i = 0; i < inputRanged.Inputs.Length; i++)
            {
                BackfillInput(inputRanged, inputRanged.Layer, inputRanged.Inputs[i], i, mx, my, mz);
            }
        }
Пример #34
0
 public static IGenerator Compile(RuntimeLayer layer, bool optimize = true)
 {
     var result = ProcessRuntimeLayer(layer);
     return GenerateType(result, optimize);
 }
Пример #35
0
        /// <summary>
        /// Initializes the ranged layer from a runtime layer.
        /// </summary>
        private static void InitializeFromRuntime(RangedLayer ranged, RuntimeLayer layer)
        {
            // Set up the initial expressions.
            ranged.X = new IdentifierExpression("x");
            ranged.Y = new IdentifierExpression("y");
            ranged.Z = new IdentifierExpression("z");
            ranged.Layer = layer;
            ranged.Width = new IdentifierExpression("width");
            ranged.Height = new IdentifierExpression("height");
            ranged.Depth = new IdentifierExpression("depth");
            ranged.OuterX = new BinaryOperatorExpression(
                ranged.X.Clone(),
                BinaryOperatorType.Add,
                ranged.Width.Clone());
            ranged.OuterY = new BinaryOperatorExpression(
                ranged.Y.Clone(),
                BinaryOperatorType.Add,
                ranged.Height.Clone());
            ranged.OuterZ = new BinaryOperatorExpression(
                ranged.Z.Clone(),
                BinaryOperatorType.Add,
                ranged.Depth.Clone());

            // Go through all of the inputs and process them.
            var inputs = layer.GetInputs();
            ranged.Inputs = new RangedLayer[inputs.Length];
            for (var i = 0; i < inputs.Length; i++)
            {
                ranged.Inputs[i] = inputs[i] == null ? null : ProcessInput(ranged, layer, inputs[i], i);
            }

            // Now we have to find the maximum values.
            Expression mx, my, mz, mwidth, mheight, mdepth, mouterx, moutery, mouterz;
            FindMaximumBounds(
                ranged,
                out mx,
                out my,
                out mz,
                out mwidth,
                out mheight,
                out mdepth,
                out mouterx,
                out moutery,
                out mouterz);

            // And recalculate back all of the calculation start / end values.
            ranged.CalculationStartI = DetermineCalculationStartForRootLayerFromMaximumBound(mx.Clone(), "x");
            ranged.CalculationStartJ = DetermineCalculationStartForRootLayerFromMaximumBound(my.Clone(), "y");
            ranged.CalculationStartK = DetermineCalculationStartForRootLayerFromMaximumBound(mz.Clone(), "z");
            ranged.CalculationEndI = mwidth.Clone();
            ranged.CalculationEndJ = mheight.Clone();
            ranged.CalculationEndK = mdepth.Clone();
            ranged.OffsetI = DetermineRelativeOffsetForLayerFromXYZ(ranged.CalculationStartI, ranged.X, mx, "x");
            ranged.OffsetJ = DetermineRelativeOffsetForLayerFromXYZ(ranged.CalculationStartJ, ranged.Y, my, "y");
            ranged.OffsetK = DetermineRelativeOffsetForLayerFromXYZ(ranged.CalculationStartK, ranged.Z, mz, "z");
            ranged.OffsetX = DetermineAbsoluteOffsetForRootLayerFromMaximumBound(mx.Clone(), "x");
            ranged.OffsetY = DetermineAbsoluteOffsetForRootLayerFromMaximumBound(my.Clone(), "y");
            ranged.OffsetZ = DetermineAbsoluteOffsetForRootLayerFromMaximumBound(mz.Clone(), "z");

            // Go through all of the inputs and backfill them.
            for (var i = 0; i < inputs.Length; i++)
            {
                BackfillInput(ranged, layer, ranged.Inputs[i], i, mx, my, mz);
            }
        }
Пример #36
0
        private static ProcessedResult ProcessRuntimeLayer(RuntimeLayer layer)
        {
            // Create our own processed result; a copy of our own state plus
            // somewhere to accumulate code.
            var result = new ProcessedResult();
            result.ProcessedCode = string.Empty;
            result.InitializationCode = string.Empty;

            // Get a reference to the algorithm that the runtime layer is using.
            var algorithm = layer.Algorithm;
            if (algorithm == null)
                throw new InvalidOperationException("Attempted to compile null runtime layer!");

            // Use RangedLayer to work out the metrics.
            var ranged = new RangedLayer(layer);
            Expression ix, iy, iz, iwidth, iheight, idepth, iouterx, ioutery, iouterz;
            RangedLayer.FindMaximumBounds(
                ranged,
                out ix,
                out iy,
                out iz,
                out iwidth,
                out iheight,
                out idepth,
                out iouterx,
                out ioutery,
                out iouterz);

            // Add __cwidth, __cheight and __cdepth declarations.
            result.Declarations += "int __cx = (int)(" + ix.GetText(null) + ");\n";
            result.Declarations += "int __cy = (int)(" + iy.GetText(null) + ");\n";
            result.Declarations += "int __cz = (int)(" + iz.GetText(null) + ");\n";
            result.Declarations += "int __cwidth = " + iwidth.GetText(null) + ";\n";
            result.Declarations += "int __cheight = " + iheight.GetText(null) + ";\n";
            result.Declarations += "int __cdepth = " + idepth.GetText(null) + ";\n";

            // Create the for loop that our calculations are done within.
            result.ProcessedCode +=
                "for (var k = 0; k < " + idepth.GetText(null) + @"; k++)" +
                "for (var i = 0; i < " + iwidth.GetText(null) + @"; i++)" +
                "for (var j = 0; j < " + iheight.GetText(null) + @"; j++)" +
                "{";

            // Now add the code for the layer.
            var inputResult = CompileRuntimeLayer(layer, ranged, null);
            result.ProcessedCode += inputResult.ProcessedCode;
            result.InitializationCode += inputResult.InitializationCode;
            result.OutputVariableName = inputResult.OutputVariableName;
            result.OutputVariableType = inputResult.OutputVariableType;
            result.Declarations += inputResult.Declarations;
            result.UsingStatements.AddRange(inputResult.UsingStatements);

            // Terminate the for loop and return the result.
            result.ProcessedCode += "}";
            return result;
        }
Пример #37
0
        /// <summary>
        /// Process an input runtime layer.
        /// </summary>
        /// <param name="ranged">The current ranged layer.</param>
        /// <param name="layer">The current runtime layer.</param>
        /// <param name="input">The input runtime layer.</param>
        /// <param name="idx">The index of the input layer in the parent layer.</param>
        /// <returns>The input ranged layer.</returns>
        private static RangedLayer ProcessInput(
            RangedLayer currentRanged,
            RuntimeLayer currentRuntime,
            RuntimeLayer inputRuntime,
            int idx)
        {
            // Set up the new ranged layer.
            var inputRanged = new RangedLayer();
            inputRanged.X = currentRanged.X;
            inputRanged.Y = currentRanged.Y;
            inputRanged.Z = currentRanged.Z;
            inputRanged.Width = currentRanged.Width;
            inputRanged.Height = currentRanged.Height;
            inputRanged.Depth = currentRanged.Depth;
            inputRanged.OuterX = currentRanged.OuterX;
            inputRanged.OuterY = currentRanged.OuterY;
            inputRanged.OuterZ = currentRanged.OuterZ;
            inputRanged.Layer = inputRuntime;

            // Determine if we need to adjust the width, height and depth.
            if (currentRuntime.Algorithm.InputWidthAtHalfSize[idx])
            {
                inputRanged.Width = CreateDivideByTwo(inputRanged.Width);
                inputRanged.OuterX = CreateDivideByTwo(inputRanged.OuterX);
            }

            if (currentRuntime.Algorithm.InputHeightAtHalfSize[idx])
            {
                inputRanged.Height = CreateDivideByTwo(inputRanged.Height);
                inputRanged.OuterY = CreateDivideByTwo(inputRanged.OuterY);
            }

            if (currentRuntime.Algorithm.InputDepthAtHalfSize[idx])
            {
                inputRanged.Depth = CreateDivideByTwo(inputRanged.Depth);
                inputRanged.OuterZ = CreateDivideByTwo(inputRanged.OuterZ);
            }

            // Determine if we need to adjust the X, Y or Z offsets.
            if (currentRuntime.Algorithm.RequiredXBorder[idx] > 0)
            {
                inputRanged.X = CreateSubtraction(
                    inputRanged.X,
                    currentRuntime.Algorithm.RequiredXBorder[idx]);
                inputRanged.Width = CreateAddition(
                    inputRanged.Width,
                    currentRuntime.Algorithm.RequiredXBorder[idx] * 2);
                inputRanged.OuterX = CreateAddition(
                    inputRanged.OuterX,
                    currentRuntime.Algorithm.RequiredXBorder[idx]);
            }

            if (currentRuntime.Algorithm.RequiredYBorder[idx] > 0)
            {
                inputRanged.Y = CreateSubtraction(
                    inputRanged.Y,
                    currentRuntime.Algorithm.RequiredYBorder[idx]);
                inputRanged.Height = CreateAddition(
                    inputRanged.Height,
                    currentRuntime.Algorithm.RequiredYBorder[idx] * 2);
                inputRanged.OuterY = CreateAddition(
                    inputRanged.OuterY,
                    currentRuntime.Algorithm.RequiredYBorder[idx]);
            }

            if (currentRuntime.Algorithm.RequiredZBorder[idx] > 0)
            {
                inputRanged.Z = CreateSubtraction(
                    inputRanged.Z,
                    currentRuntime.Algorithm.RequiredZBorder[idx]);
                inputRanged.Depth = CreateAddition(
                    inputRanged.Depth,
                    currentRuntime.Algorithm.RequiredZBorder[idx] * 2);
                inputRanged.OuterZ = CreateAddition(
                    inputRanged.OuterZ,
                    currentRuntime.Algorithm.RequiredZBorder[idx]);
            }

            // Process inputs recursively.
            var inputs = inputRuntime.GetInputs();
            inputRanged.Inputs = new RangedLayer[inputs.Length];
            for (var i = 0; i < inputs.Length; i++)
            {
                inputRanged.Inputs[i] =
                    inputs[i] == null
                        ? null
                        : ProcessInput(inputRanged, inputRuntime, inputs[i], i);
            }

            // Run AST visitors over the expression to simplify.
            inputRanged.X = AstHelpers.OptimizeExpression(inputRanged.X);
            inputRanged.Y = AstHelpers.OptimizeExpression(inputRanged.Y);
            inputRanged.Z = AstHelpers.OptimizeExpression(inputRanged.Z);
            inputRanged.Width = AstHelpers.OptimizeExpression(inputRanged.Width);
            inputRanged.Height = AstHelpers.OptimizeExpression(inputRanged.Height);
            inputRanged.Depth = AstHelpers.OptimizeExpression(inputRanged.Depth);
            inputRanged.OuterX = AstHelpers.OptimizeExpression(inputRanged.OuterX);
            inputRanged.OuterY = AstHelpers.OptimizeExpression(inputRanged.OuterY);
            inputRanged.OuterZ = AstHelpers.OptimizeExpression(inputRanged.OuterZ);

            // Return the new layer.
            return inputRanged;
        }
Пример #38
0
        private static ProcessedResult CompileRuntimeLayer(RuntimeLayer layer, RangedLayer ranged, IAlgorithm parent)
        {
            // Create our own processed result; a copy of our own state plus
            // somewhere to accumulate code.
            var result = new ProcessedResult();
            result.ProcessedCode = string.Empty;
            result.InitializationCode = string.Empty;

            // Get a reference to the algorithm that the runtime layer is using.
            var algorithm = layer.Algorithm;
            if (algorithm == null)
                throw new InvalidOperationException("Attempted to compile null runtime layer!");
            var algorithmType = algorithm.GetType();

            // If the runtime layer has inputs, we need to process them first.
            var inputs = layer.GetInputs();
            result.InputVariableNames = new string[inputs.Length];
            for (var i = 0; i < inputs.Length; i++)
            {
                var inputResult = CompileRuntimeLayer(inputs[i], ranged.Inputs[i], layer.Algorithm);
                result.ProcessedCode += inputResult.ProcessedCode;
                result.InitializationCode += inputResult.InitializationCode;
                result.InputVariableNames[i] = inputResult.OutputVariableName;
                result.Declarations += inputResult.Declarations;
                result.UsingStatements.AddRange(inputResult.UsingStatements);
            }

            // Create the storage array.
            result.OutputVariableName = GenerateRandomIdentifier();
            result.OutputVariableType = algorithm.OutputType.FullName;
            result.Declarations += result.OutputVariableType + "[] " + result.OutputVariableName +
                                   " = new " + result.OutputVariableType + "[__cwidth * __cheight * __cdepth];\n";

            // Add the conditional container.
            var code = "if (i >= " + ranged.CalculationStartI.GetText(null) + " && " +
                       "    j >= " + ranged.CalculationStartJ.GetText(null) + " && " +
                       "    k >= " + ranged.CalculationStartK.GetText(null) + " && " +
                       "    i <= " + ranged.CalculationEndI.GetText(null) + " && " +
                       "    j <= " + ranged.CalculationEndJ.GetText(null) + " && " +
                       "    k <= " + ranged.CalculationEndK.GetText(null) + ") {";

            // Refactor the method.
            AstBuilder astBuilder;
            var method = DecompileUtil.GetMethodCode(algorithmType, out astBuilder, "ProcessCell");
            MethodDeclaration initialize = null;
            try
            {
                initialize = DecompileUtil.GetMethodCode(algorithmType, out astBuilder, "Initialize");
            }
            catch (MissingMethodException)
            {
            }

            AlgorithmRefactorer.InlineMethod(
                algorithm,
                method,
                result.OutputVariableName,
                result.InputVariableNames,
                new ParenthesizedExpression(
                    new BinaryOperatorExpression(
                        new BinaryOperatorExpression(
                            new IdentifierExpression("x"),
                            BinaryOperatorType.Add,
                            ranged.OffsetX.Clone()),
                        BinaryOperatorType.Add,
                        new BinaryOperatorExpression(
                            new IdentifierExpression("i"),
                            BinaryOperatorType.Add,
                            ranged.OffsetI.Clone()))),
                new ParenthesizedExpression(
                    new BinaryOperatorExpression(
                        new BinaryOperatorExpression(
                            new IdentifierExpression("y"),
                            BinaryOperatorType.Add,
                            ranged.OffsetY.Clone()),
                        BinaryOperatorType.Add,
                        new BinaryOperatorExpression(
                            new IdentifierExpression("j"),
                            BinaryOperatorType.Add,
                            ranged.OffsetJ.Clone()))),
                new ParenthesizedExpression(
                    new BinaryOperatorExpression(
                        new BinaryOperatorExpression(
                            new IdentifierExpression("z"),
                            BinaryOperatorType.Add,
                            ranged.OffsetZ.Clone()),
                        BinaryOperatorType.Add,
                        new BinaryOperatorExpression(
                            new IdentifierExpression("k"),
                            BinaryOperatorType.Add,
                            ranged.OffsetK.Clone()))),
                new ParenthesizedExpression(
                    new BinaryOperatorExpression(
                        new IdentifierExpression("i"),
                        BinaryOperatorType.Add,
                        ranged.OffsetI.Clone())),
                new ParenthesizedExpression(
                    new BinaryOperatorExpression(
                        new IdentifierExpression("j"),
                        BinaryOperatorType.Add,
                        ranged.OffsetJ.Clone())),
                new ParenthesizedExpression(
                    new BinaryOperatorExpression(
                        new IdentifierExpression("k"),
                        BinaryOperatorType.Add,
                        ranged.OffsetK.Clone())),
                new IdentifierExpression("__cwidth"),
                new IdentifierExpression("__cheight"),
                new IdentifierExpression("__cdepth"),
                new PrimitiveExpression(0),
                new PrimitiveExpression(0),
                new PrimitiveExpression(0));
            if (initialize != null)
                AlgorithmRefactorer.InlineInitialize(algorithm, initialize);
            AlgorithmRefactorer.RemoveUsingStatements(astBuilder.CompilationUnit, result.UsingStatements);
            AlgorithmRefactorer.FactorOutAlgorithmFields(algorithmType, method, initialize, ref result.Declarations);
            code += method.Body.GetText();

            // Terminate the conditional container and return.
            code += "computations += 1;";
            code += "}\n";
            result.ProcessedCode += code;
            if (initialize != null)
                result.InitializationCode += initialize.Body.GetText();
            return result;
        }
Пример #39
0
 protected IGenerator CompileLayer(RuntimeLayer layer, bool optimize = true)
 {
     return LayerCompiler.Compile(layer, optimize);
 }
Пример #40
0
        private static Bitmap RenderPartial3D(RuntimeLayer layer, int sx, int sy, int sz, int width, int height, int depth)
        {
            var bitmap   = new Bitmap(width * 2, height * 3);
            var graphics = Graphics.FromImage(bitmap);

            graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixelGridFit;
            int[] data;
            try
            {
                int computations;
                data = layer.GenerateData(TemporaryCrapBecauseIDidNotReallyDesignThingsVeryWell.X + sx, TemporaryCrapBecauseIDidNotReallyDesignThingsVeryWell.Y + sy, TemporaryCrapBecauseIDidNotReallyDesignThingsVeryWell.Z + sz, width, height, depth, out computations);

                var render  = GetCellRenderOrder(RenderToNE, width, height);
                var ztop    = layer.Algorithm.Is2DOnly ? 1 : depth;
                var zbottom = 0;
                for (var z = zbottom; z < ztop; z++)
                {
                    var rcx = width / 2 - 1 + 16;
                    var rcy = height / 2 - 15 + 32;
                    var rw  = 2;
                    var rh  = 1;
                    for (var i = 0; i < render.Length; i++)
                    {
                        // Calculate the X / Y of the tile in the grid.
                        var x = render[i] % width;
                        var y = render[i] / width;

                        // Calculate the render position on screen.
                        var rx = rcx + (int)((x - y) / 2.0 * rw);// (int)(x / ((RenderWidth + 1) / 2.0) * rw);
                        var ry = rcy + (x + y) * rh - (rh / 2 * (width + height)) - (z - zbottom) * 1;

                        while (true)
                        {
                            try
                            {
                                Color lc;
                                if (layer.GetInputs().Length > 0)
                                {
                                    lc = layer.Algorithm.GetColorForValue(
                                        StorageAccess.FromRuntime(layer.GetInputs()[0]),
                                        data[x + y * width + z * width * height]);
                                }
                                else
                                {
                                    lc = layer.Algorithm.GetColorForValue(
                                        null,
                                        data[x + y * width + z * width * height]);
                                }
                                var sb = new SolidBrush(Color.FromArgb(lc.A, lc.R, lc.G, lc.B));
                                graphics.FillRectangle(
                                    sb,
                                    new Rectangle(rx, ry, rw, rh)
                                    );
                                break;
                            }
                            catch (InvalidOperationException)
                            {
                                // Graphics can be in use elsewhere, but we don't care; just try again.
                            }
                        }
                    }
                }
            }
            catch (Exception)
            {
            }

            return(bitmap);
        }
Пример #41
0
        public static void Main(string[] args)
        {
            var algorithmInitial                 = new AlgorithmInitialBool();
            var algorithmZoom2DIteration1        = new AlgorithmZoom2D();
            var algorithmZoom2DIteration2        = new AlgorithmZoom2D();
            var algorithmZoom2DIteration3        = new AlgorithmZoom2D();
            var algorithmZoom2DIteration4        = new AlgorithmZoom2D();
            var algorithmIncrementWaterDistance1 = new AlgorithmIncrementWaterDistance()
            {
                Initial = true
            };
            var algorithmIncrementWaterDistance2 = new AlgorithmIncrementWaterDistance();
            var algorithmIncrementWaterDistance3 = new AlgorithmIncrementWaterDistance();
            var algorithmIncrementWaterDistance4 = new AlgorithmIncrementWaterDistance();
            var runtimeInitial                 = new RuntimeLayer(algorithmInitial);
            var runtimeZoom2DIteration1        = new RuntimeLayer(algorithmZoom2DIteration1);
            var runtimeZoom2DIteration2        = new RuntimeLayer(algorithmZoom2DIteration2);
            var runtimeZoom2DIteration3        = new RuntimeLayer(algorithmZoom2DIteration3);
            var runtimeZoom2DIteration4        = new RuntimeLayer(algorithmZoom2DIteration4);
            var runtimeIncrementWaterDistance1 = new RuntimeLayer(algorithmIncrementWaterDistance1);
            var runtimeIncrementWaterDistance2 = new RuntimeLayer(algorithmIncrementWaterDistance2);
            var runtimeIncrementWaterDistance3 = new RuntimeLayer(algorithmIncrementWaterDistance3);
            var runtimeIncrementWaterDistance4 = new RuntimeLayer(algorithmIncrementWaterDistance4);

            runtimeZoom2DIteration1.SetInput(0, runtimeInitial);
            runtimeIncrementWaterDistance1.SetInput(0, runtimeZoom2DIteration1);
            runtimeZoom2DIteration2.SetInput(0, runtimeIncrementWaterDistance1);
            runtimeIncrementWaterDistance2.SetInput(0, runtimeZoom2DIteration2);
            runtimeZoom2DIteration3.SetInput(0, runtimeIncrementWaterDistance2);
            runtimeIncrementWaterDistance3.SetInput(0, runtimeZoom2DIteration3);
            runtimeZoom2DIteration4.SetInput(0, runtimeIncrementWaterDistance3);
            runtimeIncrementWaterDistance4.SetInput(0, runtimeZoom2DIteration4);

            runtimeInitial.Userdata                 = "runtimeInitial";
            runtimeZoom2DIteration1.Userdata        = "runtimeZoom2DIteration1";
            runtimeIncrementWaterDistance1.Userdata = "runtimeIncrementWaterDistance1";
            runtimeZoom2DIteration2.Userdata        = "runtimeZoom2DIteration2";
            runtimeIncrementWaterDistance2.Userdata = "runtimeIncrementWaterDistance2";
            runtimeZoom2DIteration3.Userdata        = "runtimeZoom2DIteration3";
            runtimeIncrementWaterDistance3.Userdata = "runtimeIncrementWaterDistance3";
            runtimeZoom2DIteration4.Userdata        = "runtimeZoom2DIteration4";
            runtimeIncrementWaterDistance4.Userdata = "runtimeIncrementWaterDistance4";

            EnableHandler = () =>
            {
                runtimeInitial.DataGenerated                 += HandleDataGenerated;
                runtimeZoom2DIteration1.DataGenerated        += HandleDataGenerated;
                runtimeIncrementWaterDistance1.DataGenerated += HandleDataGenerated;
                runtimeZoom2DIteration2.DataGenerated        += HandleDataGenerated;
                runtimeIncrementWaterDistance2.DataGenerated += HandleDataGenerated;
                runtimeZoom2DIteration3.DataGenerated        += HandleDataGenerated;
                runtimeIncrementWaterDistance3.DataGenerated += HandleDataGenerated;
                runtimeZoom2DIteration4.DataGenerated        += HandleDataGenerated;
                runtimeIncrementWaterDistance4.DataGenerated += HandleDataGenerated;
            };

            DisableHandler = () =>
            {
                runtimeInitial.DataGenerated                 -= HandleDataGenerated;
                runtimeZoom2DIteration1.DataGenerated        -= HandleDataGenerated;
                runtimeIncrementWaterDistance1.DataGenerated -= HandleDataGenerated;
                runtimeZoom2DIteration2.DataGenerated        -= HandleDataGenerated;
                runtimeIncrementWaterDistance2.DataGenerated -= HandleDataGenerated;
                runtimeZoom2DIteration3.DataGenerated        -= HandleDataGenerated;
                runtimeIncrementWaterDistance3.DataGenerated -= HandleDataGenerated;
                runtimeZoom2DIteration4.DataGenerated        -= HandleDataGenerated;
                runtimeIncrementWaterDistance4.DataGenerated -= HandleDataGenerated;
            };

            EnableHandler();

            var s = 64;
            var o = 10000000;
            int computations;

            runtimeIncrementWaterDistance4.GenerateData(-s + o, -s + o, -s + o, s * 2, s * 2, s * 2, out computations);
        }