Exemplo n.º 1
0
        public void Draw([CallerMemberName] string member = "", [CallerLineNumber] int line = 0, [CallerFilePath] string file = "")
        {
            if (!m_enabled)
            {
                return;
            }

            var profiler = ThreadProfiler;

            profiler.Stopwatch.Restart();

            var drawProfiler = m_selectedProfiler;

            if (drawProfiler != null)
            {
                int lastFrameIndex;
                using (drawProfiler.LockHistory(out lastFrameIndex))
                {
                    int frameToDraw = m_useCustomFrame ? m_selectedFrame : lastFrameIndex;
                    Draw(drawProfiler, lastFrameIndex, frameToDraw);
                }

                profiler.ProfileCustomValue("Profiler.Draw", member, line, file, 0, MyTimeSpan.FromMiliseconds(profiler.Stopwatch.Elapsed.TotalMilliseconds), null, null);
            }
        }
Exemplo n.º 2
0
        public override void PrepareForDraw()
        {
            base.PrepareForDraw();

            if (MyDebugDrawSettings.DEBUG_DRAW_GRID_DIRTY_BLOCKS)
            {
                MyTimeSpan delay = MyTimeSpan.FromMiliseconds(1500);
                using (m_tmpRemoveList.GetClearToken())
                {
                    foreach (var b in m_dirtyBlocks)
                    {
                        if ((MySandboxGame.Static.UpdateTime - b.Value) > delay)
                        {
                            m_tmpRemoveList.Add(b.Key);
                        }
                    }
                    foreach (var b in m_tmpRemoveList)
                    {
                        m_dirtyBlocks.Remove(b);
                    }
                }

                foreach (var block in m_cubeGrid.DirtyBlocks)
                {
                    m_dirtyBlocks[block] = MySandboxGame.Static.UpdateTime;
                }
            }
        }
Exemplo n.º 3
0
        public void ReadAndClear(MyTimeSpan currentTime, out Value sum, out int count, out Value min, out Value max, out Value last, out MyStatTypeEnum type, out int decimals, out MyTimeSpan inactivityMs)
        {
            Lock.Enter();
            try
            {
                inactivityMs = MyTimeSpan.Zero;

                if (Count <= 0) // Nothing was written
                {
                    // Load delta, increment it and save it
                    var delta = IntToDeltaTime(-Count);
                    delta += Count < 0 ? currentTime - LastClear : MyTimeSpan.FromMiliseconds(1);
                    Count  = -DeltaTimeToInt(delta);

                    inactivityMs = delta;
                    LastClear    = currentTime; // Nothing was written, postpone clear
                }
                else
                {
                    if (currentTime >= (LastRefresh + MyTimeSpan.FromMiliseconds(RefreshRate)))
                    {
                        DrawSum     = Sum;
                        DrawCount   = Count;
                        DrawMin     = Min;
                        DrawMax     = Max;
                        DrawLast    = Last;
                        LastRefresh = currentTime;

                        if (ClearRate == -1) // Clear with refresh
                        {
                            Count = 0;
                            ClearUnsafe();
                        }
                    }

                    if (ClearRate != -1 && currentTime >= (LastClear + MyTimeSpan.FromMiliseconds(ClearRate)))
                    {
                        Count = 0;
                        ClearUnsafe();
                        LastClear = currentTime;
                    }
                }

                type     = Type;
                decimals = NumDecimals;
            }
            finally
            {
                Lock.Exit();
            }

            // No need lock, not accessed anywhere else outside read
            sum   = DrawSum;
            count = DrawCount;
            min   = DrawMin;
            max   = DrawMax;
            last  = DrawLast;
        }
Exemplo n.º 4
0
        private static void OnReserveAreaRequest(ref ReserveAreaMsg msg, MyNetworkClient sender)
        {
            if (!Sync.IsServer)
            {
                return;
            }

            if (!m_reservedAreas.ContainsKey(msg.ReservationName))
            {
                m_reservedAreas.Add(msg.ReservationName, new Dictionary <long, ReservedAreaData>());
            }

            var  reservations      = m_reservedAreas[msg.ReservationName];
            bool reservedBySomeone = false;

            MyPlayer.PlayerId requestId = new MyPlayer.PlayerId(sender.SteamUserId, msg.SenderSerialId);

            foreach (var r in reservations)
            {
                var  currentReservation = r.Value;
                var  sqDist             = (currentReservation.WorldPosition - msg.Position).LengthSquared();
                bool inRadius           = sqDist <= currentReservation.Radius * currentReservation.Radius;

                if (inRadius)
                {
                    reservedBySomeone = true;
                    break;
                }
            }

            if (!reservedBySomeone)
            {
                reservations[AreaReservationCounter++] = new ReservedAreaData()
                {
                    WorldPosition    = msg.Position,
                    Radius           = msg.Radius,
                    ReservationTimer = MySandboxGame.Static.UpdateTime + MyTimeSpan.FromMiliseconds(msg.ReservationTimeMs),
                    ReserverId       = requestId,
                };

                var allMsg = new ReserveAreaAllMsg()
                {
                    Id              = AreaReservationCounter,
                    Position        = msg.Position,
                    Radius          = msg.Radius,
                    ReservationName = msg.ReservationName,
                };

                Sync.Layer.SendMessageToAll(ref allMsg, MyTransportMessageEnum.Success);
                Sync.Layer.SendMessage(ref msg, sender.SteamUserId, MyTransportMessageEnum.Success);
            }
            else
            {
                Sync.Layer.SendMessage(ref msg, sender.SteamUserId, MyTransportMessageEnum.Failure);
            }
        }
Exemplo n.º 5
0
        public void Commit([CallerMemberName] string member = "", [CallerLineNumber] int line = 0, [CallerFilePath] string file = "")
        {
            var profiler = ThreadProfiler;

            profiler.Stopwatch.Restart();
            if (!Paused)
            {
                profiler.CommitFrame();
            }
            else
            {
                profiler.ClearFrame();
            }
            profiler.ProfileCustomValue("Profiler.Commit", member, line, file, 0, MyTimeSpan.FromMiliseconds(profiler.Stopwatch.ElapsedMilliseconds), null, null);
        }
        protected MyBehaviorTreeState TryReserveAreaAroundEntity([BTParam] string areaName, [BTParam] float radius, [BTParam] int timeMs)
        {
            var logic = Bot.HumanoidLogic;
            MyBehaviorTreeState retStatus = MyBehaviorTreeState.FAILURE;

            if (logic != null)
            {
                switch (logic.ReservationStatus)
                {
                case Logic.MyReservationStatus.NONE:
                    logic.ReservationStatus   = Logic.MyReservationStatus.WAITING;
                    logic.ReservationAreaData = new MyAiTargetManager.ReservedAreaData()
                    {
                        WorldPosition    = Bot.HumanoidEntity.WorldMatrix.Translation,
                        Radius           = radius,
                        ReservationTimer = MyTimeSpan.FromMiliseconds(timeMs),
                        ReserverId       = new World.MyPlayer.PlayerId(Bot.Player.Id.SteamId, Bot.Player.Id.SerialId)
                    };
                    MyAiTargetManager.OnAreaReservationResult += AreaReservationHandler;
                    MyAiTargetManager.Static.RequestAreaReservation(areaName, Bot.HumanoidEntity.WorldMatrix.Translation, radius, timeMs, Bot.Player.Id.SerialId);
                    m_reservationTimeOut    = MySandboxGame.Static.UpdateTime + MyTimeSpan.FromSeconds(RESERVATION_WAIT_TIMEOUT_SECONDS);
                    logic.ReservationStatus = Logic.MyReservationStatus.WAITING;
                    retStatus = MyBehaviorTreeState.RUNNING;
                    break;

                case Logic.MyReservationStatus.SUCCESS:
                    retStatus = MyBehaviorTreeState.SUCCESS;
                    break;

                case Logic.MyReservationStatus.FAILURE:
                    retStatus = MyBehaviorTreeState.FAILURE;
                    break;

                case Logic.MyReservationStatus.WAITING:
                    if (m_reservationTimeOut < MySandboxGame.Static.UpdateTime)
                    {
                        retStatus = MyBehaviorTreeState.FAILURE;
                    }
                    else
                    {
                        retStatus = MyBehaviorTreeState.RUNNING;
                    }
                    break;
                }
            }
            return(retStatus);
        }
Exemplo n.º 7
0
 public static void CustomValue(string name, float value, float customTimeMs, string timeFormat = null, string valueFormat = null, [CallerMemberName] string member = "", [CallerLineNumber] int line = 0, [CallerFilePath] string file = "")
 {
     MyRenderProxy.GetRenderProfiler().ProfileCustomValue(name, value, MyTimeSpan.FromMiliseconds(customTimeMs), timeFormat, valueFormat, member, line, file);
 }
Exemplo n.º 8
0
        private static void OnReserveAreaRequest(string reservationName, Vector3D position, float radius, long reservationTimeMs, int senderSerialId)
        {
            EndpointId sender;

            if (MyEventContext.Current.IsLocallyInvoked)
            {
                sender = new EndpointId(Sync.MyId);
            }
            else
            {
                sender = MyEventContext.Current.Sender;
            }

            if (!m_reservedAreas.ContainsKey(reservationName))
            {
                m_reservedAreas.Add(reservationName, new Dictionary <long, ReservedAreaData>());
            }

            var  reservations      = m_reservedAreas[reservationName];
            bool reservedBySomeone = false;

            MyPlayer.PlayerId requestId = new MyPlayer.PlayerId(sender.Value, senderSerialId);

            foreach (var r in reservations)
            {
                var  currentReservation = r.Value;
                var  sqDist             = (currentReservation.WorldPosition - position).LengthSquared();
                bool inRadius           = sqDist <= currentReservation.Radius * currentReservation.Radius;

                if (inRadius)
                {
                    reservedBySomeone = true;
                    break;
                }
            }

            if (!reservedBySomeone)
            {
                reservations[AreaReservationCounter++] = new ReservedAreaData()
                {
                    WorldPosition    = position,
                    Radius           = radius,
                    ReservationTimer = MySandboxGame.Static.UpdateTime + MyTimeSpan.FromMiliseconds(reservationTimeMs),
                    ReserverId       = requestId,
                };

                MyMultiplayer.RaiseStaticEvent(s => MyAiTargetManager.OnReserveAreaAllSuccess, AreaReservationCounter, reservationName, position, radius);

                if (MyEventContext.Current.IsLocallyInvoked)
                {
                    OnReserveAreaSuccess(position, radius, senderSerialId);
                }
                else
                {
                    MyMultiplayer.RaiseStaticEvent(s => MyAiTargetManager.OnReserveAreaSuccess, position, radius, senderSerialId, sender);
                }
            }
            else
            {
                if (MyEventContext.Current.IsLocallyInvoked)
                {
                    OnReserveAreaFailure(position, radius, senderSerialId);
                }
                else
                {
                    MyMultiplayer.RaiseStaticEvent(s => MyAiTargetManager.OnReserveAreaFailure, position, radius, senderSerialId, sender);
                }
            }
        }
Exemplo n.º 9
0
 static MyTimeSpan?ToTime(this float customTime)
 {
     return(MyTimeSpan.FromMiliseconds(customTime));
 }
Exemplo n.º 10
0
 private MyTimeSpan IntToDeltaTime(int v)
 {
     return(MyTimeSpan.FromMiliseconds(v / 1000.0f));
 }
Exemplo n.º 11
0
 public static void End(float customValue, float customTimeMs, string timeFormat = null, string valueFormat = null, [CallerMemberName] string member = "", [CallerLineNumber] int line = 0, [CallerFilePath] string file = "")
 {
     Profiler.EndProfilingBlock(customValue, MyTimeSpan.FromMiliseconds(customTimeMs), timeFormat, valueFormat, member, line, file);
 }