예제 #1
0
        public static bool ReadFrontierFile()
        {
            if (!LoadEnabled)
            {
                return(false);
            }
            var filename = "scripts/NavMesh/Frontier.mesh";

            try {
                using (BinaryReader r = Codec.Reader(filename)) {
                    int magic = r.ReadInt32();
                    if (magic != versionBytes)
                    {
                        Log($"Wrong magic bytes {magic:X}");
                        return(false);
                    }
                    // let EndOfStreamException tell us when to stop
                    while (true)
                    {
                        Ungrown.Enqueue((NodeHandle)r.ReadInt64());
                    }
                }
            } catch (EndOfStreamException) {
                return(true);
            } catch (IOException) {
                return(false);
            } catch (ObjectDisposedException) {
                return(false);
            }
        }
예제 #2
0
        public override void OnTick()
        {
            if ((!Enabled) || aborted != 0)
            {
                return;
            }
            PlayerNode = Call <bool>(IS_PED_IN_FLYING_VEHICLE, Self) || Call <bool>(IS_PED_SWIMMING, Self)
                                ? Handle(PlayerPosition)
                                : Handle(PutOnGround(PlayerPosition, 1f));
            if (PlayerNode != prevNode)
            {
                AddEdge(prevNode, PlayerNode);
            }
            prevNode     = PlayerNode;
            PlayerRegion = Region(PlayerNode);
            DrawStatus();

            if (started == 0)
            {
                started = GameTime;
                saved   = GameTime;
            }
            else if (GameTime - started < 100 || !CanControlCharacter())
            {
                UI.DrawText(.45f, .65f, $"Cutscene...");
            }
            else
            {
                if (SaveEnabled && GameTime - saved > 33000)
                {
                    saved = GameTime;
                    Task.Run(SaveToFile);
                }
                // UI.DrawText($"NavMesh: {Ungrown.Count}/{AllEdges.Count}", color: IsGrown(PlayerNode) ? Color.White : Color.Orange);
                int        msPerFrame = (int)(1000 / InstantFPS);
                uint       msPerGrow  = (uint)Max(15, 35 - msPerFrame);
                NodeHandle handle     = AimNode();
                if (!IsGrown(handle))
                {
                    Ungrown.Enqueue(handle);
                }
                DrawEdges(handle, 100);
                if (!IsGrown(PlayerNode))
                {
                    Grow(PlayerNode, msPerGrow);
                }
                else if (Ungrown.TryDequeue(out NodeHandle first))
                {
                    // DrawLine(HeadPosition(Self), Position(first), Color.Orange);
                    Grow(first, msPerGrow);
                }
                else
                {
                    /*
                     * Grow(Flood(PlayerNode, 10000, 20, default, Edges)
                     *      .Without(IsGrown)
                     *      .FirstOrDefault(), msPerGrow);
                     */
                }
            }
            AllNodes.PageOut(100, Max(0, TotalTime.ElapsedMilliseconds - 60000));
        }