示例#1
0
文件: World.cs 项目: rbarraud/blarg4
        public uint Checksum()
        {
            uint sum = 0;

            sum ^= randomValue;
            sum ^= (uint)currentTick;
            sum ^= map.Checksum();
            sum ^= (uint)_entities.Count;
            foreach (var ent in _entities)
            {
                sum ^= ent.Checksum();
            }
            return(sum);
        }
示例#2
0
        // Rebuild the reachability array.
        public void ComputeReachability()
        {
            reachability = new int[map.width / granularity, map.depth / granularity];
            // Walk every element in the map, and flood-fill from any with a 0 region.
            var next_reachability_tag = 1;

            for (var z = 0; z < map.depth / granularity; z += 1)
            {
                for (var x = 0; x < map.width / granularity; x += 1)
                {
                    if (reachability[x, z] != 0)
                    {
                        // Already visited.
                        continue;
                    }
                    if (!MapPassable(x * granularity, z * granularity))
                    {
                        reachability[x, z] = impassibleTag;
                        continue;
                    }
                    var watch = new System.Diagnostics.Stopwatch();
                    watch.Start();
                    ComputeReachabilityFrom(x * granularity, z * granularity, next_reachability_tag);
                    watch.Stop();
                    UnityEngine.Debug.Log(string.Format("Took {0}s to build reachability region {1}", watch.Elapsed, next_reachability_tag));
                    next_reachability_tag += 1;
                }
            }

            // Recalculate the checksum.
            checksum = map.Checksum();
            for (int x = 0; x < reachability.GetLength(0); x += 1)
            {
                for (int z = 0; z < reachability.GetLength(1); z += 1)
                {
                    checksum ^= (uint)reachability[x, z];
                }
            }
        }