示例#1
0
        public static SpawnArea Instantiate(Region region, TileFlag filter, SpawnValidator validator, bool cache)
        {
            string name = region.Name;

            if (region.IsDefault || string.IsNullOrWhiteSpace(name))
            {
                name = "Default";
            }

            TileFlag[] filters = GetFilters(filter);

            int hash = GetHashCode(region.Map, name, filters, validator);

            if (!_Cache.TryGetValue(hash, out SpawnArea o) || o == null)
            {
                o = new SpawnArea(region.Map, name, filters, validator);

                if (cache)
                {
                    _Cache[hash] = o;
                }

                o.Invalidate();
            }

            return(o);
        }
示例#2
0
        private SpawnArea(Map facet, string region, TileFlag[] filters, SpawnValidator validator)
        {
            _Points = new HashSet <Point3D>();

            Facet     = facet;
            Region    = region;
            Filters   = filters;
            Validator = validator;
        }
示例#3
0
        private static int GetHashCode(Map facet, string region, IEnumerable <TileFlag> filters, SpawnValidator validator)
        {
            unchecked
            {
                int hash = region.Length;

                for (var index = 0; index < region.Length; index++)
                {
                    var c = region[index];

                    hash = unchecked ((hash * 397) ^ Convert.ToInt32(c));
                }

                hash = (hash * 397) ^ facet.MapID;
                hash = (hash * 397) ^ facet.MapIndex;

                TileFlag filter = TileFlag.None;

                foreach (TileFlag 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);
            }
        }
示例#4
0
        private static int GetHashCode(Map facet, string region, IEnumerable <TileFlag> filters, SpawnValidator validator)
        {
            unchecked
            {
                var hash = region.Length;

                hash = region.Aggregate(hash, (v, c) => unchecked ((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);
            }
        }