brnkhy / MapzenGo

Pokemon Go clone using Unity3D & Mapzen/OpenStreetMap
http://www.barankahyaoglu.com
MIT License
198 stars 59 forks source link

Performance tip: Determine layers to load dynamically #37

Open erikvullings opened 7 years ago

erikvullings commented 7 years ago

Currently, you specify in Unity (TileManager script) the layers to load. Alternatively, you could determine them automatically, so the user will never load more layers than he actually needs, based on the XmlTags that are in use. I.e.

In TileManager.cs:

        private void InitLayers()
        {
            var layers = new List<string>();
            foreach (Factory plugin in _plugins)
            {
                if (layers.Contains(plugin.XmlTag)) continue;
                layers.Add(plugin.XmlTag);
            }
            _mapzenLayers = string.Join(",", layers.ToArray());
        }
brnkhy commented 7 years ago

Oh yea that's a neat idea, adding that right away, thanks!

brnkhy commented 7 years ago

actually just realized this will create some new issues.

i.e. If I run it with just road layers using cached dynamic tile manager. It's save that tile, just like a full data document and next time I run it with all factories running, there'll be just road data from previous run. doing a detailed check on cached files isn't easy/fast either. This shouldn't be a problem when you know what you're doing of course but I'm quite sure lots of dev won't notice this and freak out. or we'll have to extend our extremely simple caching as well.... that's a LOT of work.

erikvullings commented 7 years ago

Nice catch - indeed, you are right. However, you could probably solve this quite easily in CachedDynamicTileManager.LoadTile.

Instead of

var tilePath = Path.Combine(CacheFolderPath, tileTms.x + "_" + tileTms.y);

use

var tilePath = Path.Combine(CacheFolderPath, _mapzenLayers.Replace(',', '_') + "_" + tileTms.x + "_" + tileTms.y);

In this case, whenever you change the Mapzen layers, you will get them again. (And in my HoloLens project, I've also added a command for clearing the cache).

brnkhy commented 7 years ago

Well that looks like the simplest solution but we can't just keep adding stuff to file names :) Guess we'll eventually need something like an index file for caches. Also Roman is currently working on a cache viewer editor window and he'll add "clear" there as well. We can keep adding those stuff (index file management etc) there as well.

brnkhy commented 7 years ago

should use "contains" while checking the file, I'll probably close this after that