public static SpawnZone Instantiate(Region region, TileFlag filter, SpawnZoneValidator validator, bool cache) { var name = region.Name; if (region.IsDefault || String.IsNullOrWhiteSpace(name)) { name = "Default"; } var filters = GetFilters(filter); var hash = GetHashCode(region.Map, name, filters, validator); SpawnZone o; if (!_Cache.TryGetValue(hash, out o) || o == null) { o = new SpawnZone(region.Map, name, filters, validator); if (cache) { _Cache[hash] = o; } o.Invalidate(); } return(o); }
private SpawnZone(Map facet, string region, TileFlag[] filters, SpawnZoneValidator validator) { _ImageLock = new object(); _ImageBGLock = new object(); _ImageFGLock = new object(); _Points = new Dictionary <int, Point3D>(); Facet = facet; Region = region; Filters = filters; Validator = validator; }
private static int GetHashCode(Map facet, string region, IEnumerable <TileFlag> filters, SpawnZoneValidator validator) { unchecked { var hash = region.Length; hash = region.Aggregate(hash, (v, c) => (v * 397) ^ Convert.ToInt32(c)); hash = (hash * 397) ^ facet.MapID; hash = (hash * 397) ^ facet.MapIndex; var filter = TileFlag.None; foreach (var f in filters) { filter |= f; } if (filter != TileFlag.None) { hash = (hash * 397) ^ (int)(((long)filter >> 0) & 0x7FFFFFFF); hash = (hash * 397) ^ (int)(((long)filter >> 32) & 0x7FFFFFFF); } if (validator != null) { hash = (hash * 397) ^ validator.GetHashCode(); } return(hash); } }