Exemplo n.º 1
0
        void TrackEpisodeProgress(Object sender, EventArgs args)
        {
            // Add all non-void events to current state
            currentEpisode.Events.UnionWith(
                eventTrackers.ConvertAll(l => l.Value())
                .FindAll(e => e != DrivingEvent.NONE));

            // If episode complete, complete and push state object
            if (stopwatch.ElapsedMilliseconds > currentEpisode.EpisodeSize)
            {
                // Create in-game notifications
                UI.Notify("Episode Complete");
                UI.Notify(String.Format("[{0}] Avg Speed: {1}", currentEpisode.EpisodeID, metricTrackers["avg_speed"].Value()));
                UI.Notify(String.Format("[{0}] Avg Road Alignment: {1}", currentEpisode.EpisodeID, metricTrackers["avg_road_alignment"].Value()));
                foreach (var driveEvent in currentEpisode.Events)
                {
                    UI.Notify(String.Format("[{0}] {1}", currentEpisode.EpisodeID, driveEvent.ToString()), true);
                }

                // Update state object, and store
                currentEpisode.AvgSpeed         = metricTrackers["avg_speed"].Value();
                currentEpisode.AvgRoadAlignment = metricTrackers["avg_road_alignment"].Value();

                EpisodeTracker.AddObservation(currentEpisode);
                currentEpisode = new GameEpisode(currentEpisode.EpisodeID + 1);

                // Trigger episode completion event
                stopwatch.Restart();
                EpisodeReset.Invoke(null, null);
            }
        }
Exemplo n.º 2
0
        public GameTrackerScript()
        {
            EpisodeTracker = new RollingTimeSeries <GameEpisode>(1024);

            // Setup trackers
            eventTrackers = new List <IDrivingEventTracker> {
                new TimeSinceEventTracker(this, Hash.GET_TIME_SINCE_PLAYER_DROVE_AGAINST_TRAFFIC, DrivingEvent.DRIVING_AGAINST_TRAFFIC),
                new TimeSinceEventTracker(this, Hash.GET_TIME_SINCE_PLAYER_DROVE_ON_PAVEMENT, DrivingEvent.DRIVING_ON_PAVEMENT),
                new TimeSinceEventTracker(this, Hash.GET_TIME_SINCE_PLAYER_HIT_PED, DrivingEvent.HIT_PEDESTRIAN),
                new TimeSinceEventTracker(this, Hash.GET_TIME_SINCE_PLAYER_HIT_VEHICLE, DrivingEvent.HIT_VEHICLE),
                new CollisionTracker(this),
                // Experimental
                new RanLightsTracker(this)
            };
            metricTrackers = new Dictionary <String, IDrivingMetricTracker>
            {
                { "avg_speed", new SpeedTracker(this) },
                { "avg_road_alignment", new RoadAlignmentTracker(this) }
            };

            serverThread = new Thread(new ThreadStart(Server.StartHost));
            serverThread.Start();

            Tick += TrackEpisodeProgress;

            stopwatch      = Stopwatch.StartNew();
            currentEpisode = new GameEpisode(0);
        }