static Grid RenderFlatGrid(Dictionary <string, string> gsa2names, Dictionary <string, RectList> name2rects, int rangeX, int rangeY, int rangeZ) { int width = rangeX * 64; int height = rangeZ * 64; Grid grid = RasterLib.RasterApi.CreateGrid(width, height, 1, 4); IPainter painter = RasterLib.RasterApi.Painter; for (int z = -rangeZ; z <= rangeZ; z++) { //for (int y = 0; y <= rangeY; y++) int y = 0; { for (int x = -rangeX; x <= rangeX; x++) { GridSpaceAddress gsa = new GridSpaceAddress(x, y, z); if (gsa2names.ContainsKey(gsa.ToString())) { string name = gsa2names[gsa.ToString()]; RectList cellRects = name2rects[name]; Console.WriteLine("Rendering " + name); Grid tempGrid = new Grid(64, 64, 64, 4); RasterLib.RasterApi.Renderer.RenderRectsToGrid(cellRects, tempGrid, 0, 0, 0); BirdsEye(tempGrid, grid, (x + rangeX) * 64 / 2, (z + rangeZ) * 64 / 2); } } } } GC.Collect(); return(grid); }
static Grid RenderNetGrid(Dictionary <string, string> gsa2names, Dictionary <string, RectList> name2rects, int rangeX, int rangeY, int rangeZ) { int width = rangeX * 64 * 2; int height = rangeY * 64 * 2; int depth = rangeZ * 64 * 2; Grid grid = RasterLib.RasterApi.CreateGrid(width, 64, depth, 4); int ox = width / 2; int oz = depth / 2; IPainter painter = RasterLib.RasterApi.Painter; for (int z = -rangeZ; z <= rangeZ; z++) { //for (int y = 0; y <= rangeY; y++) int y = 0; { for (int x = -rangeX; x <= rangeX; x++) { GridSpaceAddress gsa = new GridSpaceAddress(x, y, z); if (gsa2names.ContainsKey(gsa.ToString())) { string name = gsa2names[gsa.ToString()]; RectList cellRects = name2rects[name]; Console.WriteLine("Rendering " + name); RasterLib.RasterApi.Renderer.RenderRectsToGrid(cellRects, grid, x * 64 + ox, y * 64, z * 64 + oz); } } } } GC.Collect(); return(grid); }
public string GetResponse(string data) { GridSpaceAddress gsa; if ((gsa = GridSpaceAddress.TryParse(data)) != null) { string worldName = WebServer.gridspace.GetName(gsa.ToString()); return("" + worldName); } return(""); }
public static void DrawGrid(Dictionary <string, string> gsa2names, int avx, int avy, int avz, int ox, int oy, int oz, int rangeX, int rangeY, int rangeZ) { for (int z = -rangeZ; z <= rangeZ; z++) { for (int x = -rangeX; x <= rangeX; x++) { if ((x + ox) == avx && (z + oz) == avz) { Console.Write(String.Format("{0,-10}", "vvvvvvv")); } else { Console.Write(String.Format("{0,-10}", " ")); } } Console.WriteLine(); for (int x = -rangeX; x <= rangeX; x++) { string gsa = GridSpaceAddress.MakeString(x + ox, 0 + oy, z + oz); if (gsa2names.ContainsKey(gsa)) { Console.Write(String.Format("{0,-10}", gsa2names[gsa])); } else { Console.Write(String.Format("{0,-10}", "" + (x + ox) + ",0," + (z + oz))); } } Console.WriteLine(); for (int x = -rangeX; x <= rangeX; x++) { Console.Write(String.Format("{0,-10}", "" + (x + ox) + ",0," + (z + oz))); } Console.WriteLine(); for (int x = -rangeX; x <= rangeX; x++) { if ((x + ox) == avx && (z + oz) == avz) { Console.Write(String.Format("{0,-10}", "^^^^^^^")); } else { Console.Write(String.Format("{0,-10}", " ")); } } Console.WriteLine(); } }
public string GetResponse(string data) { GridSpaceAddress gsa; data = data.TrimStart('?'); string[] parts = data.Split('&'); if (parts.Length != 2) { return("FAIL"); } string gsaAddress = null; string name = null; foreach (string param in parts) { string[] paramParts = param.Split('='); string p_name = paramParts[0]; string p_data = paramParts[1]; if (p_name == "gsa") { gsaAddress = p_data; } if (p_name == "name") { name = p_data; } } if (gsaAddress == null || name == null) { return("fail"); } if ((gsa = GridSpaceAddress.TryParse(gsaAddress)) != null) { string gsaStr = gsa.ToString(); WebServer.gridspace.SetName(gsaStr, name); WebServer.gridspace.SaveDictionary(WebServer.megagrid_name); return("OK"); } return(""); }
static void Main(string[] args) { Console.WriteLine("Server Tests"); GridSpaceAddress gsa = new GridSpaceAddress(0, 0, 0); ServerLib.MegaGridClient client = new MegaGridClient("http://localhost:3838"); string name = client.RequestNameAtGSA(gsa); Console.WriteLine("\nGrid at (0,0,0) = '{0}'", name); string serializedRectsStr = client.RequestRects(name); Console.WriteLine("\nSerialized rects\n" + serializedRectsStr); RectList rects = Pivot.ToRects(serializedRectsStr); Console.WriteLine("\nRects\n" + rects); while (true) { Console.WriteLine("Live:{0}\n{1}", name, client.RequestLive(name)); Thread.Sleep(250); } }
static void Main(string[] args) { //const string URL = "http://localhost:3838/api/simulation?GateTimer"; //Connect to simulation server and display grid bool done = false; int x = 0; int y = 0; int z = 0; char _lastKey = ' '; ServerLib.MegaGridClient client = new MegaGridClient("http://localhost:3838"); while (!done) { if (Console.KeyAvailable) { ConsoleKeyInfo key = Console.ReadKey(); _lastKey = key.KeyChar; if (_lastKey == 27) { done = true; } switch (_lastKey) { case 'a': x--; break; case 'd': x++; break; case 'w': z++; break; case 's': z--; break; case 'e': y++; break; case 'q': y--; break; } } GridSpaceAddress gsa = new GridSpaceAddress(x, y, z); string name = client.RequestNameAtGSA(gsa); string rectsStr = client.RequestRects(name); SerializedRects srects = new SerializedRects(rectsStr); Console.WriteLine(srects.SerializedData); //RectList rects = Pivot.ToRects(srects); //Console.WriteLine(rects); try { string response = RequestData("http://localhost:3838/api/simulation?" + name); Console.Out.WriteLine(response); } catch (Exception e) { Console.Out.WriteLine("-----------------"); Console.Out.WriteLine(e.Message); } Thread.Sleep(1000); Console.WriteLine("GSA: " + gsa.ToString() + " = '" + name + "'"); } }
static void Main(string[] args) { int rangeX = 10; int rangeY = 1; int rangeZ = 10; string[,] stringGrid = new string[rangeX * 2, rangeZ * 2]; ServerLib.MegaGridClient client = new MegaGridClient("http://localhost:3838"); Dictionary <string, string> gsa2names = client.GetNames(rangeX * 2, rangeY, rangeZ * 3); Dictionary <string, RectList> name2rects = client.Names2Rects(gsa2names); Console.WriteLine("Names and Rectangles resolved."); int avX = 0; int avY = 0; int avZ = 0; int viewX = 0; int viewY = 0; int viewZ = 0; char _lastKey = ' '; bool done = false; string name = "Roads"; bool recordString = false; while (!done) { Console.Clear(); //TextGrid.DrawGrid(stringGrid); TextGrid.DrawGrid(gsa2names, avX, avY, avZ, viewX, viewY, viewZ, rangeX, rangeY, rangeZ); if (Console.KeyAvailable) { ConsoleKeyInfo key = Console.ReadKey(); _lastKey = key.KeyChar; if (recordString) { if (_lastKey == '\r') { recordString = false; } else { name += _lastKey; } } else { if (_lastKey == 27) { done = true; } switch (_lastKey) { case '/': recordString = true; name = ""; break; case 'o': break; case 'a': avX--; break; case 'd': avX++; break; case 's': avZ++; break; case 'w': avZ--; break; case 'j': viewX--; break; case 'l': viewX++; break; case 'i': viewZ++; break; case 'k': viewZ--; break; case ' ': name = gsa2names[GridSpaceAddress.MakeString(avX, avY, avZ)]; break; case '\b': { GridSpaceAddress gsa = new GridSpaceAddress(avX, avY, avZ); gsa2names[gsa.ToString()] = name; client.RequestSetNameAtGSA(gsa, name); break; } } } } Console.WriteLine("Clipboard: '" + name + "'"); Thread.Sleep(25); } }