コード例 #1
0
        private unsafe static void TcpHandleRandomPointRequest(BinaryWriter writer, byte[] bytes)
        {
            RandomPointRequest request = Utils.FromBytes <RandomPointRequest>(bytes);

            lock (querylock)
            {
                if (!AmeisenNav.IsMapLoaded(request.MapId))
                {
                    LogQueue.Enqueue(new LogEntry("[MMAPS] ", ConsoleColor.Green, $"Loading Map: {request.MapId}", LogLevel.INFO));
                    AmeisenNav.LoadMap(request.MapId);
                }
            }

            fixed(float *pointerStart = request.A.ToArray())
            {
                float[] randomPoint;

                lock (querylock)
                {
                    randomPoint = request.MaxRadius > 0f ? AmeisenNav.GetRandomPointAround(request.MapId, pointerStart, request.MaxRadius)
                                                         : AmeisenNav.GetRandomPoint(request.MapId);
                }

                fixed(float *pRandomPoint = randomPoint)
                {
                    TcpSendData(writer, pRandomPoint, sizeof(Vector3));
                }
            }
        }
コード例 #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);
        }