public void LateUpdate() { Utils.FakeNews = false; if (CurrentRole == RDSRT_Role.Receiver) { // if there are input records in the first place... if (inputRecords.Count > 0 && currentRecordIndex < inputRecords.Count) { // if we should play this record... if (currentRecordIndex < inputRecords.Count && Utils.ShouldWePlayThisInputRecordNow(inputRecords[currentRecordIndex], SongLastFrame)) { InputRecord currentRecord = inputRecords[currentRecordIndex]; // set the fake news Utils.FakeNewsValue = currentRecord.time + scrConductor.instance.startOfSong; Debug.Log(String.Format("[FakeNews] The time is {0}, instead of {1}. frame {2}", Utils.FakeNewsValue - scrConductor.instance.startOfSong, Utils.CurrentTimePassed(), Time.frameCount)); Utils.FakeNews = true; // play the record Utils.PlayInputRecord(currentRecord); Debug.Log(String.Format( "[InputRecord] Playing {0} InputRecord {1} at time {2}, OT {3}, error {4}, DT {5}, frame {6}", currentRecord.player == 1 ? "P2" : "P1", currentRecord.inputs, Utils.CurrentTimePassed(), currentRecord.time, Math.Abs(Utils.CurrentTimePassed() - currentRecord.time), Time.deltaTime, Utils.DeltaTimeNoScale )); currentRecordIndex++; } } SongLastFrame = Utils.GetCurrentSongName(); } }
public static bool ShouldWePlayThisInputRecordNow(InputRecord record, string songLastFrame) { string songThisFrame = GetCurrentSongName(); // Case: the song in the frame we're currently in isn't the song that the record states! if (songThisFrame != record.song) { // there's two different scenarios here: // Case 1: the previous frame's song is different from this frame. this means the song change occured // at some point between this frame and the previous frame, so the hit can only ever be less than one deltaTime // away from our current position. therefore, we should just hit it now. if (songLastFrame != songThisFrame) { return(true); } // OTHERWISE: the previous frame's song is the same as this one, so only the record has changed songs // but we're still in the previous song, it's just the user didn't do any input until the song change. return(false); } // Otherwise, we're in the same song as the record, so we can rely on the time values. // realistically, the different songs case shouldn't occur too often - i don't think there's many levels that have // gameplay-important segmenets next to a song change. else { // Something like: hit the beat if it's close to us, or if we've already past it if (record.time < (CurrentTimePassed() + DeltaTimeNoScale)) { return(true); } return(false); } }
public static void PlayInputRecord(InputRecord record) { RDInput.PlayerEmu keyToPress = ((record.inputs >> 1 & 1) == 1) ? RDInput.PlayerEmu.Up : RDInput.PlayerEmu.Down; // player 1 if (record.player == 0) { RDInput.SetP1Emu(keyToPress); } // player 2 else { RDInput.SetP2Emu(keyToPress); } }
public static List <InputRecord> loadInputRecordsFromFile() { List <InputRecord> final = new List <InputRecord>(); string line; // Read the file and load in input events line-by-line. System.IO.StreamReader file = new System.IO.StreamReader(RECORD_FILE); while ((line = file.ReadLine()) != null) { string[] tokens = line.Split(','); InputRecord newRecord = new InputRecord( tokens[0], Double.Parse(tokens[1]), int.Parse(tokens[2]), int.Parse(tokens[3]) ); final.Add(newRecord); } file.Close(); return(final); }