public DirectBitmap RenderRegionTile(DataReader.Region region)
        {
            var watch = System.Diagnostics.Stopwatch.StartNew();

            var bitmap = new DirectBitmap(_pixelSize, _pixelSize);

            watch.Stop();
            LOG.Debug($"Init'd image for {region.Id} in " + (watch.ElapsedMilliseconds) + " ms");

            // Draw the terrain.
            LOG.Debug($"Rendering region {region.Id}");
            watch.Restart();
            _regionRenderer.RenderTileFrom(region, bitmap);
            watch.Stop();
            LOG.Info($"Completed render for {region.Id} in " + (watch.ElapsedMilliseconds) + " ms");

            return(bitmap);
        }
示例#2
0
        // This really doesn't belong here, but where should it be?
        public void RemoveDeadTiles(DataReader.RDBMap rdbMap, IEnumerable <string> superTiles)
        {
            LOG.Info("Checking for base region tiles that need to be removed.");

            var files = Directory.EnumerateFiles(_tileFolder.FullName);

            var order = string.Join(string.Empty, _tileNameFormat.Split('{')
                                    .Where(str => str.Contains("}"))
                                    .Select(str => str[0])
                                    );
            var region_tile_regex = new Regex("/" + PrepareTileFilename(Regex.Replace(_tileNameFormat, "{[XYZ]}", "([0-9]+)")) + "$");

            var counter = 0;

            Parallel.ForEach(files, PARALLELISM_OPTIONS, (filename) => {
                var oldPriority = Thread.CurrentThread.Priority;
                Thread.CurrentThread.Priority = ThreadPriority.BelowNormal;

                var match = region_tile_regex.Match(filename);

                if (!match.Success)
                {
                    return;
                }

                int x, y, z;
                switch (order)
                {
                case "XYZ":
                    x = int.Parse(match.Groups[1].Value);
                    y = int.Parse(match.Groups[2].Value);
                    z = int.Parse(match.Groups[3].Value);
                    break;

                case "XZY":
                    x = int.Parse(match.Groups[1].Value);
                    z = int.Parse(match.Groups[2].Value);
                    y = int.Parse(match.Groups[3].Value);
                    break;

                case "YXZ":
                    y = int.Parse(match.Groups[1].Value);
                    x = int.Parse(match.Groups[2].Value);
                    z = int.Parse(match.Groups[3].Value);
                    break;

                case "YZX":
                    y = int.Parse(match.Groups[1].Value);
                    z = int.Parse(match.Groups[2].Value);
                    x = int.Parse(match.Groups[3].Value);
                    break;

                case "ZXY":
                    z = int.Parse(match.Groups[1].Value);
                    x = int.Parse(match.Groups[2].Value);
                    y = int.Parse(match.Groups[3].Value);
                    break;

                //case "ZYX":
                default:
                    z = int.Parse(match.Groups[1].Value);
                    y = int.Parse(match.Groups[2].Value);
                    x = int.Parse(match.Groups[3].Value);
                    break;
                }

                // Delete all region tiles for regions that have been explicitly removed from the DB.  For the new guy: this does not remove regions that are simply just offline.
                if (z == 1)
                {
                    DataReader.Region region = null;

                    try {
                        region = rdbMap.GetRegionByLocation(x, y);
                    }
                    catch (KeyNotFoundException) {
                        // Don't care
                    }

                    if (region == null)
                    {
                        // Remove the region tile.
                        try {
                            File.Delete(filename);
                            counter++;
                        }
                        catch (IOException) {
                            // File was in use.  Skip for now.
                            LOG.Warn($"Attempted removal of {filename} failed as file was in-use.");
                        }
                    }
                }
                else
                {
                    // Check the super tiles for posible removals.  Not a high likelyhood on a growing grid, but will happen in all other cases.
                    var key = TileTreeNode.MakeId(x, y, z);
                    if (!superTiles.Contains(key))
                    {
                        try {
                            File.Delete(filename);
                            counter++;
                        }
                        catch (IOException) {
                            // File was in use.  Skip for now.
                            LOG.Warn($"Attempted removal of {filename} failed as file was in-use.");
                        }
                    }
                }

                Thread.CurrentThread.Priority = oldPriority;
            });

            if (counter > 0)
            {
                LOG.Info($"Deleted {counter} region tiles for removed regions and consequent super tiles.");
            }


            // Go clean up the uuid reverse lookup folder.
            if (_reverseLookupFolder != null)
            {
                counter = 0;

                var uuid_regex = new Regex("/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$");
                files = Directory.EnumerateFiles(_reverseLookupFolder.FullName);
                Parallel.ForEach(files, PARALLELISM_OPTIONS, (filename) => {
                    var match = uuid_regex.Match(filename);

                    if (!match.Success)
                    {
                        return;
                    }

                    // Delete all uuid lookup files for regions that have been explicitly removed from the DB.  For the new guy: this does not remove regions that are simply just offline.
                    var uuid = Guid.Parse(match.Value.Substring(1));
                    if (!rdbMap.GetRegionUUIDs().Contains(uuid))
                    {
                        // Remove the file.
                        try {
                            File.Delete(filename);
                            counter++;
                        }
                        catch (IOException) {
                            // File was in use.  Skip for now.
                            LOG.Warn($"Attempted removal of {filename} failed as file was in-use.");
                        }
                    }
                });

                if (counter > 0)
                {
                    LOG.Info($"Deleted {counter} uuid lookup files for removed regions.");
                }
            }

            // Go clean up the raw image folder.
            if (_rawImageFolder != null)
            {
                counter = 0;

                var raw_image_regex = new Regex("/[^/]+.tiff$");
                files = Directory.EnumerateFiles(_rawImageFolder.FullName);
                Parallel.ForEach(files, PARALLELISM_OPTIONS, (filename) => {
                    var match = raw_image_regex.Match(filename);

                    if (!match.Success)
                    {
                        return;
                    }

                    // Delete all uuid lookup files for regions that have been explicitly removed from the DB.  For the new guy: this does not remove regions that are simply just offline.
                    var key = match.Value.Substring(1, match.Value.Length - 6);
                    if (!superTiles.Contains(key))
                    {
                        // Remove the file.
                        try {
                            File.Delete(filename);
                            counter++;
                        }
                        catch (IOException) {
                            // File was in use.  Skip for now.
                            LOG.Warn($"Attempted removal of {filename} failed as file was in-use.");
                        }
                    }
                });

                if (counter > 0)
                {
                    LOG.Info($"Deleted {counter} raw image files for removed super tiles.");
                }
            }
        }