public static void Flush() { lock (SectorMap.s_lock) { s_instance = null; } }
public static SectorMap FromName(string settingName, ResourceManager resourceManager) { if (settingName != SectorMap.DefaultSetting) { throw new ArgumentException("Only OTU setting is currently supported."); } lock (typeof(SectorMap)) { if (s_OTU == null) { List <SectorMetafileEntry> files = new List <SectorMetafileEntry> { new SectorMetafileEntry(@"~/res/legend.xml", new List <string> { "meta" }), new SectorMetafileEntry(@"~/res/sectors.xml", new List <string> { "OTU" }), new SectorMetafileEntry(@"~/res/ZhodaniCoreRoute.xml", new List <string> { "ZCR" }) }; s_OTU = new SectorMap(files, resourceManager); } } return(s_OTU); }
public static void Flush() { lock (typeof(SectorMap)) { s_OTU = null; } }
public static SectorMap GetInstance(ResourceManager resourceManager) { lock (SectorMap.s_lock) { if (s_instance == null) { List <SectorMetafileEntry> files = new List <SectorMetafileEntry> { // Meta new SectorMetafileEntry(@"~/res/Sectors/Meta/legend.xml", new List <string> { "meta" }), // OTU - Default Milieu new SectorMetafileEntry(@"~/res/Sectors/M1105/M1105.xml", new List <string> { "OTU" }), new SectorMetafileEntry(@"~/res/Sectors/Zhodani Core Route/ZhodaniCoreRoute.xml", new List <string> { "ZCR" }), new SectorMetafileEntry(@"~/res/Sectors/Orion OB1/orion.xml", new List <string> { "OrionOB1" }), // OTU - Other Milieu new SectorMetafileEntry(@"~/res/Sectors/IW/iw.xml", new List <string> { "OTU" }), new SectorMetafileEntry(@"~/res/Sectors/M0/M0.xml", new List <string> { "OTU" }), new SectorMetafileEntry(@"~/res/Sectors/M990/M990.xml", new List <string> { "OTU" }), new SectorMetafileEntry(@"~/res/Sectors/M1120/M1120.xml", new List <string> { "OTU" }), new SectorMetafileEntry(@"~/res/Sectors/M1201/M1201.xml", new List <string> { "OTU" }), new SectorMetafileEntry(@"~/res/Sectors/M1248/M1248.xml", new List <string> { "OTU" }), new SectorMetafileEntry(@"~/res/Sectors/M1900/M1900.xml", new List <string> { "OTU" }), // Non-OTU new SectorMetafileEntry(@"~/res/Sectors/Faraway/faraway.xml", new List <string> { "Faraway" }), }; s_instance = new SectorMap(files, resourceManager); } } return(s_instance); }
public Sector Resolve(SectorMap sectorMap) { if (sectorMap == null) { throw new ArgumentNullException("sectorMap"); } return(sectorMap.FromLocation(SectorCoords.X, SectorCoords.Y)); }
public void Resolve(SectorMap sectorMap, out Sector sector, out Subsector subsector) { if (sectorMap == null) { throw new ArgumentNullException("sectorMap"); } sector = null; subsector = null; sector = sectorMap.FromLocation(SectorLocation.X, SectorLocation.Y); if (sector != null) { subsector = sector[Index]; } }
public HexSelector(SectorMap map, ResourceManager resourceManager, Location location, int jump) { if (map == null) throw new ArgumentNullException("map"); if (resourceManager == null) throw new ArgumentNullException("resourceManager"); if (jump < 0 || jump > 36) throw new ArgumentOutOfRangeException("jump", jump, "jump must be between 0 and 36 inclusive"); m_map = map; m_resourceManager = resourceManager; m_location = location; m_jump = jump; }
public RectSelector(SectorMap map, ResourceManager resourceManager, RectangleF rect) { if (map == null) { throw new ArgumentNullException("map"); } if (resourceManager == null) { throw new ArgumentNullException("resourceManager"); } m_map = map; m_resourceManager = resourceManager; m_rect = rect; }
public void Resolve(SectorMap sectorMap, ResourceManager resourceManager, out Sector sector, out World world) { if (sectorMap == null) { throw new ArgumentNullException("sectorMap"); } sector = null; world = null; sector = sectorMap.FromLocation(Sector.X, Sector.Y); if (sector != null) { WorldCollection worlds = sector.GetWorlds(resourceManager, cacheResults: true); if (worlds != null) { world = worlds[World.X, World.Y]; } } }
public HexSelector(SectorMap map, ResourceManager resourceManager, Location location, int jump) { if (map == null) { throw new ArgumentNullException("map"); } if (resourceManager == null) { throw new ArgumentNullException("resourceManager"); } if (jump < 0 || jump > 36) { throw new ArgumentOutOfRangeException("jump", jump, "jump must be between 0 and 36 inclusive"); } m_map = map; m_resourceManager = resourceManager; m_location = location; m_jump = jump; }
public RectSelector(SectorMap map, ResourceManager resourceManager, RectangleF rect) { if (map == null) throw new ArgumentNullException("map"); if (resourceManager == null) throw new ArgumentNullException("resourceManager"); m_map = map; m_resourceManager = resourceManager; m_rect = rect; }
public void Resolve(SectorMap sectorMap, ResourceManager resourceManager, out Sector sector, out World world) { if (sectorMap == null) throw new ArgumentNullException("sectorMap"); sector = null; world = null; sector = sectorMap.FromLocation(Sector.X, Sector.Y); if (sector == null) return; WorldCollection worlds = sector.GetWorlds(resourceManager, cacheResults: true); if (worlds != null) world = worlds[World.X, World.Y]; }
public static void PopulateDatabase(ResourceManager resourceManager, StatusCallback callback) { // Lock on this class rather than the cacheResults. Tile requests are not // blocked but we don't index twice. lock (typeof(SearchEngine)) { // NOTE: This (re)initializes a static data structure used for // resolving names into sector locations, so needs to be run // before any other objects (e.g. Worlds) are loaded. SectorMap map = SectorMap.FromName(SectorMap.DefaultSetting, resourceManager); using (var connection = DBUtil.MakeConnection()) { SqlCommand sqlCommand; // // Repopulate the tables - locally first // FUTURE: will need to batch this up rather than keep it in memory! // DataTable dt_sectors = new DataTable(); for (int i = 0; i < 3; ++i) { dt_sectors.Columns.Add(new DataColumn()); } DataTable dt_subsectors = new DataTable(); for (int i = 0; i < 4; ++i) { dt_subsectors.Columns.Add(new DataColumn()); } DataTable dt_worlds = new DataTable(); for (int i = 0; i < 6; ++i) { dt_worlds.Columns.Add(new DataColumn()); } callback("Parsing data..."); foreach (Sector sector in map.Sectors) { if (!sector.Tags.Contains("OTU")) { continue; } foreach (Name name in sector.Names) { DataRow row = dt_sectors.NewRow(); row.ItemArray = new object[] { sector.X, sector.Y, name.Text }; dt_sectors.Rows.Add(row); } foreach (Subsector subsector in sector.Subsectors) { DataRow row = dt_subsectors.NewRow(); row.ItemArray = new object[] { sector.X, sector.Y, subsector.Index, subsector.Name }; dt_subsectors.Rows.Add(row); } #if DEBUG if (!sector.Selected) { continue; } #endif // NOTE: May need to page this at some point WorldCollection worlds = sector.GetWorlds(resourceManager, cacheResults: false); if (worlds == null) { continue; } foreach (World world in worlds) { DataRow row = dt_worlds.NewRow(); row.ItemArray = new object[] { sector.X, sector.Y, world.X, world.Y, world.Name != null && world.Name.Length > 0 ? (object)world.Name : (object)DBNull.Value, world.UWP }; dt_worlds.Rows.Add(row); } } // // Rebuild the tables with fresh schema // string[] rebuild_schema = { "IF EXISTS(SELECT 1 FROM sys.objects WHERE OBJECT_ID = OBJECT_ID(N'sectors') AND type = (N'U')) DROP TABLE sectors", "CREATE TABLE sectors(x int NOT NULL,y int NOT NULL,name nvarchar(50) NULL)", "CREATE NONCLUSTERED INDEX sector_name ON sectors ( name ASC ) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)", "IF EXISTS(SELECT 1 FROM sys.objects WHERE OBJECT_ID = OBJECT_ID(N'subsectors') AND type = (N'U')) DROP TABLE subsectors", "CREATE TABLE subsectors (sector_x int NOT NULL, sector_y int NOT NULL, subsector_index char(1) NOT NULL, name nvarchar(50) NULL )", "CREATE NONCLUSTERED INDEX subsector_name ON subsectors ( name ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)", "IF EXISTS(SELECT 1 FROM sys.objects WHERE OBJECT_ID = OBJECT_ID(N'worlds') AND type = (N'U')) DROP TABLE worlds", "CREATE TABLE worlds( sector_x int NOT NULL, sector_y int NOT NULL, hex_x int NOT NULL, hex_y int NOT NULL, name nvarchar(50) NULL, uwp nchar(9) NULL )", "CREATE NONCLUSTERED INDEX world_name ON worlds ( name ASC ) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)", "CREATE NONCLUSTERED INDEX world_uwp ON worlds ( uwp ASC ) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)", }; callback("Rebuilding schema..."); foreach (string cmd in rebuild_schema) { sqlCommand = new SqlCommand(cmd, connection); sqlCommand.ExecuteNonQuery(); } // // And shovel the data into the database en masse // using (var bulk = new SqlBulkCopy(connection, SqlBulkCopyOptions.TableLock, null)) { callback(String.Format("Writing {0} sectors...", dt_sectors.Rows.Count)); bulk.BatchSize = dt_sectors.Rows.Count; bulk.DestinationTableName = "sectors"; bulk.WriteToServer(dt_sectors); bulk.Close(); } using (var bulk = new SqlBulkCopy(connection, SqlBulkCopyOptions.TableLock, null)) { callback(String.Format("Writing {0} subsectors...", dt_subsectors.Rows.Count)); bulk.BatchSize = dt_subsectors.Rows.Count; bulk.DestinationTableName = "subsectors"; bulk.WriteToServer(dt_subsectors); bulk.Close(); } using (var bulk = new SqlBulkCopy(connection, SqlBulkCopyOptions.TableLock, null)) { callback(String.Format("Writing {0} worlds...", dt_worlds.Rows.Count)); bulk.BatchSize = 4096; bulk.DestinationTableName = "worlds"; bulk.WriteToServer(dt_worlds); bulk.Close(); } } callback("Complete!"); } }
public Milieu(SectorMap map, string milieu) { this.map = map; this.milieu = milieu; }
public static SectorMap GetInstance(ResourceManager resourceManager) { lock (SectorMap.s_lock) { if (s_instance == null) { List<SectorMetafileEntry> files = new List<SectorMetafileEntry> { // Meta new SectorMetafileEntry(@"~/res/legend.xml", new List<string> { "meta" } ), // OTU - Default Milieu new SectorMetafileEntry(@"~/res/sectors.xml", new List<string> { "OTU" } ), new SectorMetafileEntry(@"~/res/ZhodaniCoreRoute.xml", new List<string> { "ZCR" } ), // OTU - Other Milieu new SectorMetafileEntry(@"~/res/Sectors/M1000/m1000.xml", new List<string> {} ), // Non-OTU new SectorMetafileEntry(@"~/res/faraway.xml", new List<string> { "Faraway" } ), }; s_instance = new SectorMap(files, resourceManager); } } return s_instance; }
public RectSelector(SectorMap.Milieu map, ResourceManager resourceManager, RectangleF rect, bool slop = true) { if (map == null) throw new ArgumentNullException("map"); if (resourceManager == null) throw new ArgumentNullException("resourceManager"); this.map = map; this.resourceManager = resourceManager; this.rect = rect; Slop = slop; SlopFactor = 0.25f; }
public Sector Resolve(SectorMap sectorMap) { if (sectorMap == null) throw new ArgumentNullException("sectorMap"); return sectorMap.FromLocation(SectorCoords.X, SectorCoords.Y); }
public static void PopulateDatabase(ResourceManager resourceManager, StatusCallback callback) { // Lock to prevent indexing twice, without blocking tile requests. lock (SearchEngine.s_lock) { // NOTE: This (re)initializes a static data structure used for // resolving names into sector locations, so needs to be run // before any other objects (e.g. Worlds) are loaded. SectorMap map = SectorMap.GetInstance(resourceManager); using (var connection = DBUtil.MakeConnection()) { SqlCommand sqlCommand; // // Repopulate the tables - locally first // FUTURE: will need to batch this up rather than keep it in memory! // DataTable dt_sectors = new DataTable(); for (int i = 0; i < SECTORS_COLUMNS.Length; ++i) { dt_sectors.Columns.Add(new DataColumn()); } DataTable dt_subsectors = new DataTable(); for (int i = 0; i < SUBSECTORS_COLUMNS.Length; ++i) { dt_subsectors.Columns.Add(new DataColumn()); } DataTable dt_worlds = new DataTable(); for (int i = 0; i < WORLDS_COLUMNS.Length; ++i) { dt_worlds.Columns.Add(new DataColumn()); } DataTable dt_labels = new DataTable(); for (int i = 0; i < LABELS_COLUMNS.Length; ++i) { dt_labels.Columns.Add(new DataColumn()); } // Map of (milieu, string) => [ points ... ] Dictionary <Tuple <string, string>, List <Point> > labels = new Dictionary <Tuple <string, string>, List <Point> >(); Action <string, string, Point> AddLabel = (string milieu, string text, Point coords) => { if (text == null) { return; } text = SanifyLabel(text); var key = Tuple.Create(milieu, text); if (!labels.ContainsKey(key)) { labels.Add(key, new List <Point>()); } labels[key].Add(coords); }; callback("Parsing data..."); foreach (Sector sector in map.Sectors) { // TODO: Index alternate milieu if (!sector.Tags.Contains("OTU") && !sector.Tags.Contains("Faraway")) { continue; } foreach (Name name in sector.Names) { DataRow row = dt_sectors.NewRow(); row.ItemArray = new object[] { sector.CanonicalMilieu, sector.X, sector.Y, name.Text }; dt_sectors.Rows.Add(row); } if (!string.IsNullOrEmpty(sector.Abbreviation)) { DataRow row = dt_sectors.NewRow(); row.ItemArray = new object[] { sector.CanonicalMilieu, sector.X, sector.Y, sector.Abbreviation }; dt_sectors.Rows.Add(row); } foreach (Subsector subsector in sector.Subsectors) { DataRow row = dt_subsectors.NewRow(); row.ItemArray = new object[] { sector.CanonicalMilieu, sector.X, sector.Y, subsector.Index, subsector.Name }; dt_subsectors.Rows.Add(row); } foreach (Border border in sector.Borders.Where(b => b.ShowLabel)) { AddLabel( sector.CanonicalMilieu, border.GetLabel(sector), Astrometrics.LocationToCoordinates(new Location(sector.Location, border.LabelPosition))); } foreach (Label label in sector.Labels) { AddLabel( sector.CanonicalMilieu, label.Text, Astrometrics.LocationToCoordinates(new Location(sector.Location, label.Hex))); } #if DEBUG if (!sector.Selected) { continue; } #endif // NOTE: May need to page this at some point WorldCollection worlds = sector.GetWorlds(resourceManager, cacheResults: false); if (worlds == null) { continue; } var world_query = from world in worlds where !world.IsPlaceholder select world; foreach (World world in world_query) { DataRow row = dt_worlds.NewRow(); row.ItemArray = new object[] { sector.CanonicalMilieu, world.Coordinates.X, world.Coordinates.Y, sector.X, sector.Y, world.X, world.Y, string.IsNullOrEmpty(world.Name) ? (object)DBNull.Value : (object)world.Name, world.UWP, world.Remarks, world.PBG, string.IsNullOrEmpty(world.Zone) ? "G" : world.Zone, world.Allegiance, sector.Names.Count > 0 ? (object)sector.Names[0] : (object)DBNull.Value }; dt_worlds.Rows.Add(row); } } foreach (KeyValuePair <Tuple <string, string>, List <Point> > entry in labels) { string milieu = entry.Key.Item1; string name = entry.Key.Item2; List <Point> points = entry.Value; Point avg = new Point( (int)Math.Round(points.Select(p => p.X).Average()), (int)Math.Round(points.Select(p => p.Y).Average())); Point min = new Point(points.Select(p => p.X).Min(), points.Select(p => p.Y).Min()); Point max = new Point(points.Select(p => p.X).Max(), points.Select(p => p.Y).Max()); Size size = new Size(max.X - min.X, max.Y - min.Y); int radius = Math.Max(size.Width, size.Height); DataRow row = dt_labels.NewRow(); row.ItemArray = new object[] { milieu, avg.X, avg.Y, radius, name }; dt_labels.Rows.Add(row); } // // Rebuild the tables with fresh schema // const string INDEX_OPTIONS = " WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)"; const string DROP_TABLE_IF_EXISTS = "IF EXISTS(SELECT 1 FROM sys.objects WHERE OBJECT_ID = OBJECT_ID(N'{0}') AND type = (N'U')) DROP TABLE {0}"; string[] rebuild_schema = { string.Format(DROP_TABLE_IF_EXISTS, "sectors"), "CREATE TABLE sectors (" + string.Join(",", SECTORS_COLUMNS) + ")", "CREATE NONCLUSTERED INDEX sector_name ON sectors ( name ASC )" + INDEX_OPTIONS, "CREATE NONCLUSTERED INDEX sector_milieu ON sectors ( milieu ASC )" + INDEX_OPTIONS, string.Format(DROP_TABLE_IF_EXISTS, "subsectors"), "CREATE TABLE subsectors (" + string.Join(",", SUBSECTORS_COLUMNS) + ")", "CREATE NONCLUSTERED INDEX subsector_name ON subsectors ( name ASC )" + INDEX_OPTIONS, "CREATE NONCLUSTERED INDEX subsector_milieu ON subsectors ( milieu ASC )" + INDEX_OPTIONS, string.Format(DROP_TABLE_IF_EXISTS, "worlds"), "CREATE TABLE worlds (" + string.Join(",", WORLDS_COLUMNS) + ")", "CREATE NONCLUSTERED INDEX world_name ON worlds ( name ASC )" + INDEX_OPTIONS, "CREATE NONCLUSTERED INDEX world_uwp ON worlds ( uwp ASC )" + INDEX_OPTIONS, "CREATE NONCLUSTERED INDEX world_pbg ON worlds ( pbg ASC )" + INDEX_OPTIONS, "CREATE NONCLUSTERED INDEX world_alleg ON worlds ( alleg ASC )" + INDEX_OPTIONS, "CREATE NONCLUSTERED INDEX world_sector_name ON worlds ( sector_name ASC )" + INDEX_OPTIONS, "CREATE NONCLUSTERED INDEX world_milieu ON worlds ( milieu ASC )" + INDEX_OPTIONS, string.Format(DROP_TABLE_IF_EXISTS, "labels"), "CREATE TABLE labels (" + string.Join(",", LABELS_COLUMNS) + ")", "CREATE NONCLUSTERED INDEX name ON labels ( name ASC )" + INDEX_OPTIONS, "CREATE NONCLUSTERED INDEX milieu ON labels ( milieu ASC )" + INDEX_OPTIONS, }; callback("Rebuilding schema..."); foreach (string cmd in rebuild_schema) { sqlCommand = new SqlCommand(cmd, connection); sqlCommand.ExecuteNonQuery(); } // // And shovel the data into the database en masse // Action <string, DataTable, int> BulkInsert = (string name, DataTable table, int batchSize) => { using (var bulk = new SqlBulkCopy(connection, SqlBulkCopyOptions.TableLock, null)) { callback($"Writing {table.Rows.Count} {name}..."); bulk.BatchSize = batchSize; bulk.DestinationTableName = name; bulk.WriteToServer(table); } }; BulkInsert("sectors", dt_sectors, dt_sectors.Rows.Count); BulkInsert("subsectors", dt_subsectors, dt_subsectors.Rows.Count); BulkInsert("worlds", dt_worlds, 4096); BulkInsert("labels", dt_labels, dt_labels.Rows.Count); } callback("Complete!"); } }
public static Milieu ForMilieu(ResourceManager resourceManager, string milieu) => new Milieu(SectorMap.GetInstance(resourceManager), milieu);
public void Resolve(SectorMap sectorMap, out Sector sector, out Subsector subsector) { if (sectorMap == null) throw new ArgumentNullException("sectorMap"); sector = null; subsector = null; sector = sectorMap.FromLocation(SectorLocation.X, SectorLocation.Y); if (sector != null) subsector = sector[Index]; }