Esempio n. 1
0
        public static GridNode Create(Vector2 center, GridScene gridScene, NavCellDefinition navCell)
        {
            var def = new GridNode
            {
                _center = center,
                Center = center + gridScene.Min,

                _navCellDefinition = navCell,
                _gridScene = gridScene
            };
            return def;
        }
Esempio n. 2
0
        public static GridNode Create(Vector2 center, GridScene gridScene, NavCellDefinition navCell)
        {
            var def = new GridNode
            {
                _center = center,
                Center  = center + gridScene.Min,

                _navCellDefinition = navCell,
                _gridScene         = gridScene
            };

            return(def);
        }
Esempio n. 3
0
        public static GridScene Create(Scene scene, Scene.NavMesh mesh, NavZone zone)
        {
            var gridScene = new GridScene();

            gridScene.SceneSNO        = mesh.SceneSnoId;
            gridScene.WorldId         = mesh.WorldId;
            gridScene.LevelAreaSNO    = mesh.LevelAreaSnoId;
            gridScene.Name            = scene.Name;
            gridScene.NameHash        = GridProvider.GetSceneNameHash(mesh, zone);
            gridScene.Min             = zone.ZoneMin;
            gridScene.Max             = zone.ZoneMax;
            gridScene.Center          = (gridScene.Max + gridScene.Min) / 2;
            gridScene.SceneDefinition = GridProvider.SceneDefinitions[mesh.SceneSnoId];
            gridScene.BaseHeight      = mesh.BaseHeight;

            //#region GridNodes

            var         gridNodes       = new List <GridNode>();
            var         sceneDimensions = zone.ZoneMax - zone.ZoneMin;
            const float searchBeginning = GridProvider.GridNodeBoxSize / 2;

            for (var x = searchBeginning; x <= sceneDimensions.X; x = x + GridProvider.GridNodeBoxSize)
            {
                for (var y = searchBeginning; y <= sceneDimensions.Y; y = y + GridProvider.GridNodeBoxSize)
                {
                    var cell = gridScene.SceneDefinition.NavCellDefinitions.FirstOrDefault(c => c.IsInCell(x, y));
                    if (cell != null)
                    {
                        var gridNode = GridNode.Create(new Vector2(x, y), gridScene, cell);
                        gridNodes.Add(gridNode);
                    }
                }
            }
            gridScene.GridNodes = gridNodes;
            //#endregion

            return(gridScene);
        }
Esempio n. 4
0
        public static GridScene Create(Scene scene, Scene.NavMesh mesh, NavZone zone)
        {
            var gridScene = new GridScene();
            gridScene.SceneSNO = mesh.SceneSnoId;
            gridScene.WorldId = mesh.WorldId;
            gridScene.LevelAreaSNO = mesh.LevelAreaSnoId;
            gridScene.Name = scene.Name;
            gridScene.NameHash = GridProvider.GetSceneNameHash(mesh, zone);
            gridScene.Min = zone.ZoneMin;
            gridScene.Max = zone.ZoneMax;
            gridScene.Center = (gridScene.Max + gridScene.Min) / 2;
            gridScene.SceneDefinition = GridProvider.SceneDefinitions[mesh.SceneSnoId];
            gridScene.BaseHeight = mesh.BaseHeight;

            //#region GridNodes

            var gridNodes = new List<GridNode>();
            var sceneDimensions = zone.ZoneMax - zone.ZoneMin;
            const float searchBeginning = GridProvider.GridNodeBoxSize / 2;
            for (var x = searchBeginning; x <= sceneDimensions.X; x = x + GridProvider.GridNodeBoxSize)
            {
                for (var y = searchBeginning; y <= sceneDimensions.Y; y = y + GridProvider.GridNodeBoxSize)
                {
                    var cell = gridScene.SceneDefinition.NavCellDefinitions.FirstOrDefault(c => c.IsInCell(x, y));
                    if (cell != null)
                    {
                        var gridNode = GridNode.Create(new Vector2(x, y), gridScene, cell);
                        gridNodes.Add(gridNode);
                    }
                }
            }
            gridScene.GridNodes = gridNodes;
            //#endregion

            return gridScene;
        }
Esempio n. 5
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;
            }
        }