예제 #1
0
 private void RaiseCommStatsUpdateEvent(object sender, CommStatsEventArgs args)
 {
     CommStats = args;
     StatsEvent?.Invoke(this, new CommStatsEventArgs()
     {
         ID = CommStats.ID,
         CompleteProfilesReceived = CommStats.CompleteProfilesReceived,
         ProfileRate   = CommStats.ProfileRate,
         BytesReceived = CommStats.BytesReceived,
         Evicted       = CommStats.Evicted,
         DataRate      = CommStats.DataRate,
         BadPackets    = CommStats.BadPackets,
         GoodPackets   = CommStats.GoodPackets
     });
 }
        private void StatsThread()
        {
            long lastCheck = timeBase.ElapsedMilliseconds;
            long bytesReceivedSinceLastCheck    = 0;
            long profilesReceivedSinceLastCheck = 0;

            while (true)
            {
                try
                {
                    token.ThrowIfCancellationRequested();
                    Task.Delay(200, token).Wait(token);
                    long   now         = timeBase.ElapsedMilliseconds;
                    double dataRate    = (bytesReceived - bytesReceivedSinceLastCheck) * 1000.0 / (now - lastCheck);
                    long   profileRate = (CompleteProfilesReceivedCount - profilesReceivedSinceLastCheck) * 1000 /
                                         (now - lastCheck);

                    commStats.ID = scanHead.ID;
                    commStats.CompleteProfilesReceived = CompleteProfilesReceivedCount;
                    commStats.ProfileRate   = profileRate;
                    commStats.BytesReceived = bytesReceived;
                    commStats.Evicted       = evictedForTimeout + IncompleteProfilesReceivedCount;
                    commStats.DataRate      = dataRate;
                    commStats.BadPackets    = BadPacketsCount;
                    commStats.GoodPackets   = goodPackets;

                    StatsEvent?.Invoke(this, new CommStatsEventArgs()
                    {
                        ID = commStats.ID,
                        CompleteProfilesReceived = commStats.CompleteProfilesReceived,
                        ProfileRate   = commStats.ProfileRate,
                        BytesReceived = commStats.BytesReceived,
                        Evicted       = commStats.Evicted,
                        DataRate      = commStats.DataRate,
                        BadPackets    = commStats.BadPackets,
                        GoodPackets   = commStats.GoodPackets
                    });

                    lastCheck = now;
                    bytesReceivedSinceLastCheck    = bytesReceived;
                    profilesReceivedSinceLastCheck = CompleteProfilesReceivedCount;
                }
                catch (OperationCanceledException)
                {
                    break;
                }
            }
        }
    public void OnEventRaised(GameEvent ge)
    {
        if (ge is BasicGameEvent && basicResponse.GetPersistentEventCount() >= 1)
        {
            basicResponse.Invoke();
        }

        if (ge is FloatGameEvent && floatResponse.GetPersistentEventCount() >= 1)
        {
            floatResponse.Invoke(((FloatGameEvent)ge).SentFloat);
        }

        if (ge is StatsGameEvent && statsResponse.GetPersistentEventCount() >= 1)
        {
            statsResponse.Invoke(((StatsGameEvent)ge).SentStats, ((StatsGameEvent)ge).SentFloat);
        }
    }
예제 #4
0
        public override void OnActionReceived(ActionBuffers actionBuffers)
        {
            var actions = actionBuffers.ContinuousActions.Array;

            vehicle.Motor.value    = actions[0];
            vehicle.Steering.value = actions[1];

            Vector3 fwd = vehicle.transform.forward;
            Vector3 pos = vehicle.transform.position;

            bool  chunkAdded = road.OnUpdate(pos);
            Frame frame      = road.AgentFrame;

            stats.action0          = actions[0];
            stats.action1          = actions[1];
            stats.speed            = Vector3.Dot(frame.Forward, vehicle.Rigidbody.velocity);
            stats.steer            = vehicle.Steering.CrntNormValue;
            stats.offset           = frame.LocalPosition(pos).x;
            stats.orientation      = Vector3.SignedAngle(frame.Forward, fwd, frame.Up);
            stats.collisions       = vehicle.CollisionCount;
            vehicle.CollisionCount = 0;

            updateTime = chunkAdded ? Time.time : updateTime;
            bool hasTimedOut = Time.time - updateTime > timeout;

            if (hasTimedOut || IsOffMesh())
            {
                AddReward(-1);
                ResetAgent();
            }
            else
            {
                float offRoad = Mathf.Abs(stats.offset) - Chunk.RoadExtent + 1;
                stats.reward  = offRoad > 0 ? -offRoad : stats.speed * 0.02f;
                stats.reward -= stats.collisions * 0.5f;
                AddReward(stats.reward);
            }

            StatsEvent?.Invoke(name, stats);
        }