示例#1
0
        public static SceneDefinition Create(Scene.NavMesh mesh, NavZone zone, NavZoneDef navZoneDef)
        {
            var filePath = string.Format("{0}{1}.json", SCENES_PATH, mesh.SceneSnoId);

            if (USE_DISK_CACHE)
            {
                if (File.Exists(filePath))
                {
                    var fileContent = File.ReadAllText(filePath);
                    if (!string.IsNullOrWhiteSpace(fileContent))
                    {
                        var savedScene = JsonSerializer.Deserialize <SceneDefinition>(fileContent);
                        if (savedScene != null)
                        {
                            return(savedScene);
                        }
                    }
                }
            }
            var sceneDefinition = new SceneDefinition {
                SceneSNO = mesh.SceneSnoId
            };

            #region NavCells
            var cachedNavCells = new List <NavCellDefinition>();
            var sceneNavCells  = navZoneDef.NavCells.ToList();

            if (sceneNavCells.Count > 0)
            {
                cachedNavCells.AddRange(sceneNavCells.Select(NavCellDefinition.Create));
            }
            sceneDefinition.NavCellDefinitions = cachedNavCells;
            #endregion


            if (USE_DISK_CACHE)
            {
                var serializedScene = JsonSerializer.Serialize(sceneDefinition);
                File.WriteAllText(filePath, serializedScene);
            }
            Logger.Warn("[GridProvider] Added SceneDefinition {0} (Dimensions: {1}, NavCells: {2})", sceneDefinition.SceneSNO, zone.ZoneMax - zone.ZoneMin, sceneDefinition.NavCellDefinitions.Count);
            return(sceneDefinition);
        }
示例#2
0
        public static SceneDefinition Create(Scene.NavMesh mesh, NavZone zone, NavZoneDef navZoneDef)
        {
            var filePath = string.Format("{0}{1}.json", SCENES_PATH, mesh.SceneSnoId);
            if (USE_DISK_CACHE)
            {
                if (File.Exists(filePath))
                {
                    var fileContent = File.ReadAllText(filePath);
                    if (!string.IsNullOrWhiteSpace(fileContent))
                    {
                        var savedScene = JsonSerializer.Deserialize<SceneDefinition>(fileContent);
                        if (savedScene != null)
                        {
                            return savedScene;
                        }
                    }
                }
            }
            var sceneDefinition = new SceneDefinition { SceneSNO = mesh.SceneSnoId };

            #region NavCells
            var cachedNavCells = new List<NavCellDefinition>();
            var sceneNavCells = navZoneDef.NavCells.ToList();

            if (sceneNavCells.Count > 0)
            {
                cachedNavCells.AddRange(sceneNavCells.Select(NavCellDefinition.Create));
            }
            sceneDefinition.NavCellDefinitions = cachedNavCells;
            #endregion


            if (USE_DISK_CACHE)
            {

                var serializedScene = JsonSerializer.Serialize(sceneDefinition);
                File.WriteAllText(filePath, serializedScene);
            }
            Logger.Warn("[GridProvider] Added SceneDefinition {0} (Dimensions: {1}, NavCells: {2})", sceneDefinition.SceneSNO, zone.ZoneMax - zone.ZoneMin, sceneDefinition.NavCellDefinitions.Count);
            return sceneDefinition;
        }
示例#3
0
        public static void Update()
        {
            if (_isUpdateRunning)
            {
                return;
            }
            _isUpdateRunning = true;
            lock (_updateLock)
            {
                using (new PerformanceLogger("[GridProvider] Update", true))
                {
                    var discoveredScenes = new List <GridScene>();
                    foreach (var scene in ZetaDia.Scenes)
                    {
                        if (!scene.IsValid)
                        {
                            continue;
                        }

                        var mesh = scene.Mesh;
                        if (mesh == null || !mesh.IsValid)
                        {
                            continue;
                        }

                        var name = scene.Name.ToLowerInvariant();
                        if (string.IsNullOrWhiteSpace(name) || name.Contains("filler") || name.Contains("fillscene") || name.Contains("buffer"))
                        {
                            continue;
                        }

                        var zone = mesh.Zone;
                        if (zone == null || !zone.IsValid)
                        {
                            continue;
                        }

                        var sceneNameHash = GetSceneNameHash(mesh, zone);

                        if (CachedScenes.ContainsKey(sceneNameHash))
                        {
                            continue;
                        }

                        if (!SceneDefinitions.ContainsKey(mesh.SceneSnoId))
                        {
                            using (new PerformanceLogger("SceneDefinition.Create", true))
                            {
                                var navZoneDef = zone.NavZoneDef;
                                if (navZoneDef == null || !navZoneDef.IsValid)
                                {
                                    continue;
                                }

                                var sceneDefinition = SceneDefinition.Create(mesh, zone, navZoneDef);
                                if (sceneDefinition != null)
                                {
                                    SceneDefinitions.Add(mesh.SceneSnoId, sceneDefinition);
                                }
                            }
                        }
                        GridScene cachedScene;
                        using (new PerformanceLogger("GridScene.Create", true))
                        {
                            cachedScene = GridScene.Create(scene, mesh, zone);
                        }
                        CachedScenes.Add(sceneNameHash, cachedScene);
                        discoveredScenes.Add(cachedScene);
                        Logger.Info("[GridProvider] Added Scene {0} at {1})", cachedScene.Name, cachedScene.Min);
                    }
                    using (new PerformanceLogger("MainGrid.Instance.Update", true))
                    {
                        MainGrid.Instance.Update(discoveredScenes.SelectMany(s => s.GridNodes));
                    }
                }
                _isUpdateRunning = false;
            }
        }