public void SimplifyNeighborData()
    {
        ModuleData.Current = this.Modules;
        const int height = 12;
        int       count  = 0;
        var       center = new Vector3i(0, height / 2, 0);

        int p = 0;

        foreach (var module in this.Modules)
        {
            var map  = new InfiniteMap(height);
            var slot = map.GetSlot(center);
            try {
                slot.Collapse(module);
            }
            catch (CollapseFailedException exception) {
                throw new InvalidOperationException("Module " + module.Name + " creates a failure at relative position " + (exception.Slot.Position - center) + ".");
            }
            for (int direction = 0; direction < 6; direction++)
            {
                var neighbor = slot.GetNeighbor(direction);
                int unoptimizedNeighborCount = module.PossibleNeighbors[direction].Count;
                module.PossibleNeighbors[direction].Intersect(neighbor.Modules);
                count += unoptimizedNeighborCount - module.PossibleNeighbors[direction].Count;
            }
            module.PossibleNeighborsArray = module.PossibleNeighbors.Select(ms => ms.ToArray()).ToArray();
            p++;
            EditorUtility.DisplayProgressBar("Simplifying... " + count, module.Name, (float)p / this.Modules.Length);
        }
        Debug.Log("Removed " + count + " impossible neighbors.");
        EditorUtility.ClearProgressBar();
        EditorUtility.SetDirty(this);
    }
Exemplo n.º 2
0
    public void SimplifyNeighborData()
    {
        int count  = 0;
        var center = new Vector3i(0, 3, 0);

        int p = 0;

        foreach (var module in Module.All)
        {
            var map  = new InfiniteMap(6);
            var slot = map.GetSlot(center);
            try {
                slot.Collapse(module);
            }
            catch (CollapseFailedException exception) {
                this.BuildAllSlots();
                throw new InvalidOperationException("Module " + module.Name + " creates a failure at relative position " + (exception.Slot.Position - center) + ".");
            }
            for (int direction = 0; direction < 6; direction++)
            {
                var neighbor = slot.GetNeighbor(direction);
                int unoptimizedNeighborCount = module.PossibleNeighbors[direction].Length;
                module.PossibleNeighbors[direction] = module.PossibleNeighbors[direction].Where(m => neighbor.Modules.Contains(m)).ToArray();
                count += unoptimizedNeighborCount - module.PossibleNeighbors[direction].Length;
            }
            p++;
            EditorUtility.DisplayProgressBar("Simplifying... " + count, module.Name, (float)p / this.Modules.Length);
        }
        Debug.Log("Removed " + count + " impossible neighbors.");
        EditorUtility.ClearProgressBar();
    }
Exemplo n.º 3
0
 public void Initialize()
 {
     this.Clear();
     this.Map = new InfiniteMap(this.MapHeight);
     if (this.BoundaryConstraints != null && this.BoundaryConstraints.Any())
     {
         this.Map.ApplyBoundaryConstraints(this.BoundaryConstraints);
     }
 }
Exemplo n.º 4
0
 public void Initialize()
 {
     ModuleData.Current = this.ModuleData.Modules;
     this.Clear();
     this.Map = new InfiniteMap(this.MapHeight);
     if (this.ApplyBoundaryConstraints && this.BoundaryConstraints != null && this.BoundaryConstraints.Any())
     {
         this.Map.ApplyBoundaryConstraints(this.BoundaryConstraints);
     }
     this.cullingData = this.GetComponent <CullingData>();
     this.cullingData.Initialize();
 }
Exemplo n.º 5
0
    void Start()
    {
        this.generatedChunks = new HashSet <Vector3Int>();
        this.mapBehaviour    = this.GetComponent <MapBehaviour>();
        this.mapBehaviour.Initialize();
        this.map = this.mapBehaviour.Map;
        this.generate();
        this.mapBehaviour.BuildAllSlots();

        this.thread = new Thread(this.generatorThread);
        this.thread.Start();
    }
Exemplo n.º 6
0
    public void Clear()
    {
        var children = new List <Transform>();

        foreach (Transform child in this.transform)
        {
            children.Add(child);
        }
        foreach (var child in children)
        {
            GameObject.DestroyImmediate(child.gameObject);
        }
        this.Map = null;
    }
Exemplo n.º 7
0
    void Start()
    {
        this.chunkVisibility = new Dictionary <Vector3i, bool>();
        this.mapBehaviour    = this.GetComponent <MapBehaviour>();
        this.mapBehaviour.Initialize();
        this.map = this.mapBehaviour.Map;
        this.generate();
        this.mapBehaviour.BuildAllSlots();

        this.showQueue = new Queue <Vector3i>();
        this.hideQueue = new Queue <Vector3i>();

        this.thread = new Thread(this.generatorThread);
        this.thread.Start();
    }
Exemplo n.º 8
0
        private void GenerateButton_Click(object sender, EventArgs e)
        {
            StopRunner();
            var width  = Convert.ToInt32(WidthTextBox.Text);
            var height = Convert.ToInt32(HeightTextBox.Text);

            if (InfiniteMapCheckBox.Checked)
            {
                Map = new InfiniteMap(2);
            }
            else
            {
                Map = new FiniteMap2D(width, height);
            }
            var rng = new Random();

            switch (CurrentAlgorithm)
            {
            case MazeGenerationAlgorithm.GrowingTree:
                GrowingTreeMazeGenerator = new GrowingTreeMazeGenerator(Map, rng);
                MazeGenerator            = GrowingTreeMazeGenerator;
                break;

            case MazeGenerationAlgorithm.Kruskal:
                KruskalMazeGenerator = new KruskalMazeGenerator(Map, rng);
                MazeGenerator        = KruskalMazeGenerator;
                break;

            case MazeGenerationAlgorithm.RecursiveDivision:
                RecursiveDivisionMazeGenerator = new RecursiveDivisionMazeGenerator(Map, rng);
                MazeGenerator = RecursiveDivisionMazeGenerator;
                break;

            case MazeGenerationAlgorithm.BinaryTree:
                BinaryTreeMazeGenerator = new BinaryTreeMazeGenerator(Map, rng);
                MazeGenerator           = BinaryTreeMazeGenerator;
                break;

            case MazeGenerationAlgorithm.AldousBroder:
                AldousBroderMazeGenerator = new AldousBroderMazeGenerator(Map, rng);
                MazeGenerator             = AldousBroderMazeGenerator;
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
            SyncAllGeneratorParameters();
            var activeCellsGenerator = new ActiveCellsMazeGeneratorDecorator(MazeGenerator);
            var displayMap           = new AsFiniteMapDecorator(Map, Map.Size ?? new Point(width, height));

            MapRenderer = new PictureBoxMapRenderer(displayMap, MainPictureBox);
            Runner      = new MazeGenerationRunner(activeCellsGenerator, MapRenderer, CurrentGeneratorDelay, CurrentRendererDelay, true);
            var generatorSteps = 0;
            var rendererSteps  = 0;

            Runner.AfterGenerate += results => { generatorSteps++; };
            Runner.BeforeRender  += results =>
            {
                if (TrackChanges && results.Results.Count > 0)
                {
                    displayMap.Offset = displayMap.Size / 2 - results.Results[0].Point;
                }
            };
            Runner.AfterRender += results => { rendererSteps++; };
            Runner.Start();
        }
Exemplo n.º 9
0
 void Awake()
 {
     spriteCicle = GetComponent <InfiniteMap>();
 }