Exemple #1
0
        public static List <Vector3> GetPath(Vector3 start, Vector3 end, int mapId, PathRequestFlags flags, string clientIp)
        {
            int            pathSize;
            List <Vector3> path = new List <Vector3>();

            Stopwatch sw = new Stopwatch();

            sw.Start();

            lock (maplock)
            {
                if (!AmeisenNav.IsMapLoaded(mapId))
                {
                    AmeisenNav.LoadMap(mapId);
                }

                unsafe
                {
                    fixed(float *pointerStart = start.ToArray())
                    fixed(float *pointerEnd = end.ToArray())
                    {
                        float *path_raw = AmeisenNav.GetPath(mapId, pointerStart, pointerEnd, &pathSize);

                        // postprocess the raw path to a list of Vector3
                        // the raw path looks like this:
                        // [ x1, y1, z1, x2, y2, z2, ...]
                        for (int i = 0; i < pathSize * 3; i += 3)
                        {
                            path.Add(new Vector3(path_raw[i], path_raw[i + 1], path_raw[i + 2]));
                        }
                    }
                }
            }

            if (flags.HasFlag(PathRequestFlags.NaturalSteeringBehavior))
            {
                path = NaturalSteeringBehavior.Perform(path);
            }

            if (flags.HasFlag(PathRequestFlags.ChaikinCurve))
            {
                path = ChaikinCurve.Perform(path);
            }

            //// bugged atm path = NodeReduction.Perform(path);

            sw.Stop();
            LogQueue.Enqueue(new LogEntry($"[{clientIp}] ", ConsoleColor.Green, $"Building Path with {path.Count} Nodes took {sw.ElapsedMilliseconds}ms ({sw.ElapsedTicks} ticks)", LogLevel.INFO));

            return(path);
        }
Exemple #2
0
        public static List <Vector3> GetPath(Vector3 start, Vector3 end, float maxRadius, int mapId, MovementType movementType, PathRequestFlags flags, string clientIp)
        {
            int            pathSize;
            List <Vector3> path = new List <Vector3>();

            Stopwatch sw = new Stopwatch();

            sw.Start();

            lock (querylock)
            {
                if (!AmeisenNav.IsMapLoaded(mapId))
                {
                    AmeisenNav.LoadMap(mapId);
                }

                unsafe
                {
                    fixed(float *pointerStart = start.ToArray())
                    fixed(float *pointerEnd = end.ToArray())
                    {
                        switch (movementType)
                        {
                        case MovementType.MoveToPosition:
                            float[] movePath = AmeisenNav.GetPath(mapId, pointerStart, pointerEnd, &pathSize);

                            for (int i = 0; i < pathSize * 3; i += 3)
                            {
                                path.Add(new Vector3(movePath[i], movePath[i + 1], movePath[i + 2]));
                            }

                            if (flags.HasFlag(PathRequestFlags.ChaikinCurve))
                            {
                                path = ChaikinCurve.Perform(path);
                            }
                            break;

                        case MovementType.MoveAlongSurface:
                            float[] surfacePath = AmeisenNav.MoveAlongSurface(mapId, pointerStart, pointerEnd);
                            path.Add(new Vector3(surfacePath[0], surfacePath[1], surfacePath[2]));
                            break;

                        case MovementType.CastMovementRay:
                            if (AmeisenNav.CastMovementRay(mapId, pointerStart, pointerEnd))
                            {
                                // return end if target is in line of sight
                                path.Add(end);
                            }
                            else
                            {
                                // return none if target is not in line of sight
                                path.Clear();
                            }
                            break;

                        case MovementType.GetRandomPoint:
                            float[] randomPoint = AmeisenNav.GetRandomPoint(mapId);
                            path.Add(new Vector3(randomPoint[0], randomPoint[1], randomPoint[2]));
                            break;

                        case MovementType.GetRandomPointAround:
                            float[] randomPointAround = AmeisenNav.GetRandomPointAround(mapId, pointerStart, maxRadius);
                            path.Add(new Vector3(randomPointAround[0], randomPointAround[1], randomPointAround[2]));
                            break;
                        }
                    }
                }
            }

            sw.Stop();
            LogQueue.Enqueue(new LogEntry($"[{clientIp}] ", ConsoleColor.Green, $"{movementType} with {path.Count}/{Settings.MaxPointPathCount} Nodes took {sw.ElapsedMilliseconds}ms ({sw.ElapsedTicks} ticks)", LogLevel.INFO));
            return(path);
        }