public static Bitmap RegenerateImageForLayer(StorageLayer layer, long ox, long oy, long oz, int width, int height, int depth, bool compiled = false)
        {
            var runtime = StorageAccess.ToRuntime(layer);

            //if (compiled)
            //    return Regenerate3DImageForLayer(runtime, ox, oy, oz, width, height, depth, StorageAccess.ToCompiled(layer));
            //else
            return(Regenerate3DImageForLayer(runtime, ox, oy, oz, width, height, depth));
        }
Beispiel #2
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();
        }
Beispiel #3
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());
        }
Beispiel #4
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;
 }
Beispiel #5
0
 private static RuntimeLayer CreateLayerFromConfig(string path, GenerationRequest request)
 {
     // Use StorageAccess to load reference to world generation.
     StorageLayer[] layers;
     using (var reader = new StreamReader(path))
         layers = StorageAccess.LoadStorage(reader);
     foreach (var layer in layers)
     {
         if ((layer.Algorithm is AlgorithmResult) &&
             (layer.Algorithm as AlgorithmResult).Name == request.LayerName &&
             ((layer.Algorithm as AlgorithmResult).ShowInMakeMeAWorld ||
              (layer.Algorithm as AlgorithmResult).PermitInMakeMeAWorld))
         {
             return(StorageAccess.ToRuntime(layer));
         }
     }
     return(null);
 }
Beispiel #6
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;
             }
         }
     }
 }
        private void PerformMeasurements()
        {
            // Settings.
            var iterations   = 1000;
            var warningLimit = 100000; // 0.1s
            var badLimit     = 300000; // 0.3s

            // Perform conversions.
            var        runtime  = StorageAccess.ToRuntime(this.m_Layer);
            IGenerator compiled = null;

            try
            {
                compiled = StorageAccess.ToCompiled(runtime);
            }
            catch (Exception)
            {
                // Failed to compile layer.
            }

            // First check how long it takes for the runtime layer to do 1000 operations of 8x8x8.
            var runtimeStart        = DateTime.Now;
            var runtimeComputations = 0;

            for (var i = 0; i < iterations; i++)
            {
                runtime.GenerateData(0, 0, 0, 8, 8, 8, out runtimeComputations);
            }
            var runtimeEnd = DateTime.Now;

            // Now check how long it takes the compiled layer to do 1000 operations of 8x8x8.
            var compiledStart        = DateTime.Now;
            var compiledComputations = 0;

            if (compiled != null)
            {
                try
                {
                    for (var i = 0; i < iterations; i++)
                    {
                        compiled.GenerateData(0, 0, 0, 8, 8, 8, out compiledComputations);
                    }
                }
                catch
                {
                    compiled = null;
                }
            }
            var compiledEnd = DateTime.Now;

            // Determine the per-operation cost.
            var runtimeCost  = runtimeEnd - runtimeStart;
            var compiledCost = compiledEnd - compiledStart;
            var runtimeus    = Math.Round((runtimeCost.TotalMilliseconds / iterations) * 1000, 0); // Microseconds.
            var compiledus   = Math.Round((compiledCost.TotalMilliseconds / iterations) * 1000, 0);

            // Define colors and determine values.
            var okay          = new SolidBrush(Color.LightGreen);
            var warning       = new SolidBrush(Color.Orange);
            var bad           = new SolidBrush(Color.IndianRed);
            var runtimeColor  = okay;
            var compiledColor = okay;

            if (runtimeus > warningLimit)
            {
                runtimeColor = warning;
            }
            if (compiledus > warningLimit)
            {
                compiledColor = warning;
            }
            if (runtimeus > badLimit)
            {
                runtimeColor = bad;
            }
            if (compiledus > badLimit)
            {
                compiledColor = bad;
            }

            // Draw performance measurements.
            Bitmap bitmap;

            if (runtimeComputations != compiledComputations && compiled != null)
            {
                bitmap = new Bitmap(128, 48);
            }
            else
            {
                bitmap = new Bitmap(128, 32);
            }
            var graphics = Graphics.FromImage(bitmap);
            var font     = new Font(SystemFonts.DefaultFont, FontStyle.Bold);

            graphics.Clear(Color.Black);
            if (runtimeComputations != compiledComputations && compiled != null)
            {
                graphics.DrawString("Computation mismatch!", font, bad, new PointF(0, 0));
                graphics.DrawString("Runtime:", font, runtimeColor, new PointF(0, 16));
                graphics.DrawString(runtimeComputations + "c", font, runtimeColor, new PointF(70, 16));
                if (compiled != null)
                {
                    graphics.DrawString("Compiled:", font, compiledColor, new PointF(0, 32));
                    graphics.DrawString(compiledComputations + "c", font, compiledColor, new PointF(70, 32));
                }
                else
                {
                    graphics.DrawString("Unable to compile.", font, bad, new PointF(0, 32));
                }
            }
            else
            {
                graphics.DrawString("Runtime:", font, runtimeColor, new PointF(0, 0));
                graphics.DrawString(runtimeus + "\xB5s", font, runtimeColor, new PointF(70, 0));
                if (compiled != null)
                {
                    graphics.DrawString("Compiled:", font, compiledColor, new PointF(0, 16));
                    graphics.DrawString(compiledus + "\xB5s", font, compiledColor, new PointF(70, 16));
                }
                else
                {
                    graphics.DrawString("Unable to compile.", font, bad, new PointF(0, 16));
                }
            }
            if (this.m_AdditionalInformation != null)
            {
                this.m_AdditionalInformation.Dispose();
            }
            this.m_AdditionalInformation = bitmap;

            // TEMPORARY: Use the compiled layer to re-render the output.
            if (compiled != null)
            {
                this.m_CompiledBitmap = AlgorithmFlowImageGeneration.RegenerateImageForLayer(this.m_Layer,
                                                                                             TemporaryCrapBecauseIDidNotReallyDesignThingsVeryWell.X,
                                                                                             TemporaryCrapBecauseIDidNotReallyDesignThingsVeryWell.Y,
                                                                                             TemporaryCrapBecauseIDidNotReallyDesignThingsVeryWell.Z,
                                                                                             64, 64, 64, true);
            }
        }