private void test() { Point st = Point.Empty; Point en = Point.Empty; bool[,] m = load("paths/maze.astar", out st, out en); //st = new Point(200, 0); //en = new Point(999, 999); //st = new Point(3, 0); //en = new Point(7, 9); for (int x = 0; x < 1000; x++) { for (int y = 0; y < 1000; y++) { Block *b = translateToPointer(x, y); (*b).TypeID = (short)(m[x, y] ? Globals.RESOURCE_WOOD : Globals.TERRAIN_GRASS); } } updateConcreteMatrix(); IPathfinderContext ctx = Pathfinder.ASCreateContext(p_Width, p_Height); while (true) { int time = Environment.TickCount; List <Point> path = Pathfinder.ASSearch( ctx, st, en, p_ConcreteMatrix); Console.WriteLine((Environment.TickCount - time) + "ms for " + path.Count + " items"); for (int c = 0; c < path.Count; c++) { Point p = path[c]; Block *bl = translateToPointer(p.X, p.Y); (*bl).Selected = true; } break; } }
private void pathfindBench() { int total = 0; int ticks = 0; while (true) { break; int time = Environment.TickCount; List <Point> path = Pathfinder.ASSearch( Point.Empty, new Point(p_Width - 1, p_Height - 1), p_ConcreteMatrix, p_Width, p_Height); time = Environment.TickCount - time; total += time; Console.WriteLine("Time: " + time + "ms for " + path.Count + " points"); Console.WriteLine("Average: " + (total / (++ticks)) + "ms"); } }
private unsafe void pathTest(Point mousePosition, MouseButtons button) { Block * matrix = Map.GetBlockMatrix(); VisibleBlock vBlock = default(VisibleBlock); try { vBlock = p_MapRenderer.GetBlockAtPoint(p_Window.Context, mousePosition); } catch { return; } Point blockLocation = new Point( vBlock.BlockX, vBlock.BlockY); Block *block = vBlock.Block; if (block == (Block *)0) { return; } // if (button == MouseButtons.None) { return; } Block *ptr = matrix; Block *ptrEnd = ptr + (Map.Width * Map.Height); while (ptr != ptrEnd) { (*(ptr++)).Selected = false; } if (button == MouseButtons.Left) { pathStart = blockLocation; return; } if (button == MouseButtons.Right) { List <Point> path = Pathfinder.ASSearch( pathStart, blockLocation, Map.GetConcreteMatrix(true), Map.Width, Map.Height); if (path.Count == 0) { MessageBox.Show("Path not found!"); } foreach (Point p in path) { Block *b = matrix + (p.Y * Map.Width) + p.X; if ((*b).TypeID == Globals.TERRAIN_WATER) { break; } (*b).Selected = true; } } }
public Game(GameWindow wnd) { p_Window = wnd; /*hook crash events at the first opportunity.*/ Application.ThreadException += handleCrash; /*fullscreen*/ p_Window.Shown += delegate(object s, EventArgs e) { //p_Window.ToggleFullscreen(); p_Window.Focus(); p_Window.BringToFront(); cmd("warp 0 0"); cmd("zoom 0 0"); cmd("toggle debug"); cmd("toggle debug full"); cmd("toggle fog"); cmd("toggle los"); testCode(); }; /*initialize hotloader*/ p_Hotloader = new Hotloader(); /*initialize the camera*/ p_Camera = new Camera(this); /*initialize map*/ p_Map = new Map(this, 1000, 1000); p_MapRenderer = new MapRenderer(this, p_Map, p_Camera); /*setup camera position*/ p_Camera.ZoomAbs(32); p_Camera.MoveCenter(250, 250); /*init sub-systems*/ initUI(); initMouse(); initPlayers(); initLogic(); initDebug(); initDraw(); /*hook events*/ p_Cursor.HookEvents(); wnd.Click += handleMouseClick; wnd.MouseWheel += handleMouseScroll; wnd.MouseMove += handleMouseMove; wnd.MouseUp += handleMouseUp; wnd.KeyDown += handleKeyDown; wnd.KeyUp += handleKeyUp; wnd.Resize += handleResize; wnd.GotFocus += handleFocusChanged; wnd.LostFocus += handleFocusChanged; unsafe { IPathfinderContext ctx = Pathfinder.ASCreateContext(p_Map.Width, p_Map.Height); while (true) { break; int time = Environment.TickCount; //break; List <Point> lol = Pathfinder.ASSearch( ctx, Point.Empty, new Point(p_Map.Width - 1, p_Map.Height - 1), p_Map.GetConcreteMatrix(true)); Console.WriteLine((Environment.TickCount - time) + "ms for " + lol.Count + " items"); } } wnd.HookCoreEvents(); p_Camera.EnableMargin = true; p_Camera.SetMargin(10, 10); }