public static Maze LoadMazeFromWalls(List<MazeWall> walls, int width, int height) { Maze m = new Maze(width, height, InnerMapType.BitArreintjeFast); //-1 for stupid black pixel thing :o for (int y = 0; y < m.Height - 1; y++) { for (int x = 0; x < m.Width - 1; x++) { m.innerMap[x, y] = true; } } foreach (var wall in walls) { if (wall.ystart == wall.yend) { //Horizontal for (int x = wall.xstart; x <= wall.xend; x++) { m.innerMap[x, wall.ystart] = false; } } else { //Vertical for (int y = wall.ystart; y <= wall.yend; y++) { m.innerMap[wall.xstart, y] = false; } } } return m; }
private void button25_Click(object sender, EventArgs e) { int sizezzz = int.Parse(comboBox4.SelectedItem.ToString().Replace(".", "")); //Passing an int into the action like this is faster because else it will get stuck on the heap/stack or w/e I guess :o var actionToRun = new Action<int>((size) => { Algorithm curalg = new AlgorithmBacktrackSmartMemory(); Stopwatch w = new Stopwatch(); w.Start(); //int size = (int)Math.Pow(2.0, 19.0); DebugMSG("Generating maze of size: " + size); DebugMSG("Saved size it should be: " + Math.Pow((double)size, 2.0) / 1024.0 / 1024.0 / 8.0 + " mb"); DebugMSG("Or in GB: " + Math.Pow((double)size, 2.0) / 1024.0 / 1024.0 / 1024.0 / 8.0 + " gb"); lastMegaTerrorMaze = curalg.Generate(size, size, InnerMapType.Hybrid, 1337, (x, y, cur, tot) => { curXInMaze = x; curYInMaze = y; currentStepsToCalcPercentage = cur; totalStepsToCalcPercentage = tot; }); w.Stop(); DebugMSG("Generating time: " + w.Elapsed.TotalSeconds); TrimAndGCCollect(); }); Task.Run(() => { actionToRun(sizezzz); TrimAndGCCollect(); }); }
private void button29_Click(object sender, EventArgs e) { lastMegaTerrorMaze = null; lastMegaTerrorMazePath = null; lastMegaTerrorMazePathPos = null; lastMegaTerrorMazeQuatroDirections = null; TrimAndGCCollect(); }
private void button45_Click(object sender, EventArgs e) { int sizezzz = int.Parse(comboBox4.SelectedItem.ToString().Replace(".", "")); Task.Run(() => { Action<int, int> callback = (cur, tot) => { this.curMazeLineSaving = cur; this.mazeLinesToSave = tot; }; //This is just a mocked maze that is not actually being read by the Testje function. That's why the size doesn't matter. var maze = new Maze(16, 16, InnerMapType.BooleanArray); var w = Stopwatch.StartNew(); maze.Testje(sizezzz, callback, 256, false, DebugMSG); DebugMSG("Saving time: " + w.Elapsed.TotalSeconds + " seconds."); }); }
public void GenerateMaze() { if (indexBuffer != null) indexBuffer.Dispose(); if (vertexBuffer != null) vertexBuffer.Dispose(); Algorithm alg; int randomnumber = curMazeWidth < 2048 ? random.Next(3) : random.Next(2); if (randomnumber == 0) alg = new AlgorithmBacktrack(); else if (randomnumber == 1) alg = new AlgorithmDivision(); else alg = new AlgorithmKruskal(); lastAlgorithm = alg.GetType().Name; currentMaze = alg.Generate(curMazeWidth, curMazeHeight, InnerMapType.BitArreintjeFast, null); var walls = currentMaze.GenerateListOfMazeWalls(); currentPath = PathFinderDepthFirst.GoFind(currentMaze.InnerMap, null); determiner = new LineOfSightDeterminer(currentMaze.InnerMap, currentPath); curChaseCameraPoint = null; VertexPositionNormalTexture[] vertices = new VertexPositionNormalTexture[walls.Count * 8]; int[] indices = new int[walls.Count * 12]; int curVertice = 0; int curIndice = 0; foreach (var wall in walls) { //int factorHeight = 10; //int factorWidth = 10; WallModel model = new WallModel(wall); model.GoGenerateVertices(vertices, indices, ref curVertice, ref curIndice); } wallsCount = walls.Count; vertexBuffer = new VertexBuffer(GraphicsDevice, VertexPositionNormalTexture.VertexDeclaration, vertices.Length, BufferUsage.WriteOnly); indexBuffer = new IndexBuffer(GraphicsDevice, IndexElementSize.ThirtyTwoBits, indices.Length, BufferUsage.WriteOnly); vertexBuffer.SetData(vertices); indexBuffer.SetData(indices); GeneratePath(currentPath); }