Exemple #1
0
    void UpdatePlayback()
    {
        if (play)
        {
            currentLine = performanceFile.lines[currentRecordLine];

            if (mode == PlaybackMode.Online) //online
            {
                if (playerNumber == 0)
                {
                    gameEngine.userManager.me.SetPlayerPosition(currentLine.p1HeadPosition, currentLine.p1LeftHandPosition, currentLine.p1RightHandPosition);
                    gameEngine.userManager.me.SetPlayerRotation(currentLine.p1HeadRotation, currentLine.p1LeftHandRotation, currentLine.p1RightHandRotation);
                }
                else
                {
                    gameEngine.userManager.me.SetPlayerPosition(currentLine.p2HeadPosition, currentLine.p2LeftHandPosition, currentLine.p2RightHandPosition);
                    gameEngine.userManager.me.SetPlayerRotation(currentLine.p2HeadRotation, currentLine.p2LeftHandRotation, currentLine.p2RightHandRotation);
                }
            }
            else  //offline
            {
                if (currentViz != currentLine.Condition)
                {
                    Debug.Log("Changing viz to : " + currentLine.Condition);
                    gameEngine.userManager.ChangeVisualisationMode(currentLine.Condition, gameEngine, false);
                    currentViz = currentLine.Condition;
                }
                gameEngine.userManager.usersPlaying[1].SetPlayerPosition(currentLine.p1HeadPosition, currentLine.p1LeftHandPosition, currentLine.p1RightHandPosition);
                gameEngine.userManager.usersPlaying[1].SetPlayerRotation(currentLine.p1HeadRotation, currentLine.p1LeftHandRotation, currentLine.p1RightHandRotation);
                gameEngine.userManager.usersPlaying[2].SetPlayerPosition(currentLine.p2HeadPosition, currentLine.p2LeftHandPosition, currentLine.p2RightHandPosition);
                gameEngine.userManager.usersPlaying[2].SetPlayerRotation(currentLine.p2HeadRotation, currentLine.p2LeftHandRotation, currentLine.p2RightHandRotation);
            }

            gameEngine.uiHandler.playbackTime.text = "Playback Time : " + (currentLine.Time / 1000).ToString() + " / " + performanceMaxTime;
            gameEngine.uiHandler.currentViz.text   = "Current viz : " + currentLine.Condition;

            // the loop is set to run at 60fps, the record file has 60fps, so we need to read 1 lines per frame * desired speed
            floatTimeTracker += (double)gameEngine.targetFrameRate / (double)gameEngine.gameData.saveFileFrequency * playbackSpeed;
            currentRecordLine = (int)floatTimeTracker;  // we round the frame number

            if (floatTimeTracker >= performanceFile.lines.Count)
            {
                floatTimeTracker  = 0;
                currentRecordLine = 0;
            }
            else if (floatTimeTracker < 0)
            {
                floatTimeTracker  = performanceFile.lines.Count - 1;
                currentRecordLine = performanceFile.lines.Count - 1;
            }
        }
    }
Exemple #2
0
    void LoadPerfData()
    {
        Debug.Log("Loading Performance File at " + performanceFilePath);
        StreamReader reader = new StreamReader(performanceFilePath);

        using (CsvReader csv = new CsvReader(reader))
        {
            playbackManager.performanceFile       = new PerformanceFile();
            playbackManager.performanceFile.lines = new List <PerformanceLine>();

            if (playbackManager.showMedianPlayback)
            {
                playbackManager.medianPerformanceFile       = new MedianPerformanceFile();
                playbackManager.medianPerformanceFile.lines = new List <MedianPerformanceLine>();
            }


            csv.Read();
            csv.ReadHeader();
            csv.Configuration.Delimiter = ",";
            //csv.Configuration.MissingFieldFound = null;

            NumberFormatInfo cul = new CultureInfo("en-US").NumberFormat;
            while (csv.Read())
            {
                PerformanceLine record = new PerformanceLine()
                {
                    SessionID = csv.GetField <int>(0),
                    //TimeStamp = double.TryParse(csv.GetField<string>(1)),
                    Time           = csv.GetField <double>(2),
                    Condition      = csv.GetField <string>(4),
                    p1HeadPosition = new Vector3(float.Parse(csv.GetField(5), cul),
                                                 float.Parse(csv.GetField(6), cul),
                                                 float.Parse(csv.GetField(7), cul)),
                    p1HeadRotation = new Quaternion(float.Parse(csv.GetField(8), cul),
                                                    float.Parse(csv.GetField(9), cul),
                                                    float.Parse(csv.GetField(10), cul),
                                                    float.Parse(csv.GetField(11), cul)),
                    p1LeftHandPosition = new Vector3(float.Parse(csv.GetField(12), cul),
                                                     float.Parse(csv.GetField(13), cul),
                                                     float.Parse(csv.GetField(14), cul)),
                    p1LeftHandRotation = new Quaternion(float.Parse(csv.GetField(15), cul),
                                                        float.Parse(csv.GetField(16), cul),
                                                        float.Parse(csv.GetField(17), cul),
                                                        float.Parse(csv.GetField(18), cul)),
                    p1RightHandPosition = new Vector3(float.Parse(csv.GetField(19), cul),
                                                      float.Parse(csv.GetField(20), cul),
                                                      float.Parse(csv.GetField(21), cul)),
                    p1RightHandRotation = new Quaternion(float.Parse(csv.GetField(22), cul),
                                                         float.Parse(csv.GetField(23), cul),
                                                         float.Parse(csv.GetField(24), cul),
                                                         float.Parse(csv.GetField(25), cul)),

                    p2HeadPosition = new Vector3(float.Parse(csv.GetField(26), cul),
                                                 float.Parse(csv.GetField(27), cul),
                                                 float.Parse(csv.GetField(28), cul)),
                    p2HeadRotation = new Quaternion(float.Parse(csv.GetField(29), cul),
                                                    float.Parse(csv.GetField(30), cul),
                                                    float.Parse(csv.GetField(31), cul),
                                                    float.Parse(csv.GetField(32), cul)),
                    p2LeftHandPosition = new Vector3(float.Parse(csv.GetField(33), cul),
                                                     float.Parse(csv.GetField(34), cul),
                                                     float.Parse(csv.GetField(35), cul)),
                    p2LeftHandRotation = new Quaternion(float.Parse(csv.GetField(36), cul),
                                                        float.Parse(csv.GetField(37), cul),
                                                        float.Parse(csv.GetField(38), cul),
                                                        float.Parse(csv.GetField(39), cul)),
                    p2RightHandPosition = new Vector3(float.Parse(csv.GetField(40), cul),
                                                      float.Parse(csv.GetField(41), cul),
                                                      float.Parse(csv.GetField(42), cul)),
                    p2RightHandRotation = new Quaternion(float.Parse(csv.GetField(43), cul),
                                                         float.Parse(csv.GetField(44), cul),
                                                         float.Parse(csv.GetField(45), cul),
                                                         float.Parse(csv.GetField(46), cul))
                };
                if (record != null)
                {
                    //Debug.Log(record.SessionID+", "+record.Time+", "+record.p1HeadPosition);
                    playbackManager.performanceFile.lines.Add(record);
                }

                if (playbackManager.showMedianPlayback)
                {
                    MedianPerformanceLine medianRecord = new MedianPerformanceLine()
                    {
                        //Time = csv.GetField<double>(2),
                        m1HeadPosition = new Vector3(float.Parse(csv.GetField(47), cul),
                                                     float.Parse(csv.GetField(48), cul),
                                                     float.Parse(csv.GetField(49), cul)),
                        m1LeftHandPosition = new Vector3(float.Parse(csv.GetField(50), cul),
                                                         float.Parse(csv.GetField(51), cul),
                                                         float.Parse(csv.GetField(52), cul)),
                        m1RightHandPosition = new Vector3(float.Parse(csv.GetField(53), cul),
                                                          float.Parse(csv.GetField(54), cul),
                                                          float.Parse(csv.GetField(55), cul)),
                        m2HeadPosition = new Vector3(float.Parse(csv.GetField(56), cul),
                                                     float.Parse(csv.GetField(57), cul),
                                                     float.Parse(csv.GetField(58), cul)),
                        m2LeftHandPosition = new Vector3(float.Parse(csv.GetField(59), cul),
                                                         float.Parse(csv.GetField(60), cul),
                                                         float.Parse(csv.GetField(61), cul)),
                        m2RightHandPosition = new Vector3(float.Parse(csv.GetField(62), cul),
                                                          float.Parse(csv.GetField(63), cul),
                                                          float.Parse(csv.GetField(64), cul)),
                    };
                    if (medianRecord != null)
                    {
                        //Debug.Log(record.SessionID+", "+record.Time+", "+record.p1HeadPosition);
                        playbackManager.medianPerformanceFile.lines.Add(medianRecord);
                    }
                }
            }
        }
        playbackManager.performanceMaxTime = (float)(playbackManager.performanceFile.lines[playbackManager.performanceFile.lines.Count - 1].Time / 1000);
    }