diff --git a/source/PlayState.hx b/source/PlayState.hx index 2539f71..639ced5 100644 --- a/source/PlayState.hx +++ b/source/PlayState.hx @@ -1717,20 +1717,22 @@ class PlayState extends MusicBeatState #end - if (currentFrames == FlxG.save.data.fpsCap) + // reverse iterate to remove oldest notes first and not invalidate the iteration + // stop iteration as soon as a note is not removed + // all notes should be kept in the correct order and this is optimal, safe to do every frame/update { - for(i in 0...notesHitArray.length) + var balls = notesHitArray.length-1; + while (balls >= 0) { - var cock:Date = notesHitArray[i]; - if (cock != null) - if (cock.getTime() + 2000 < Date.now().getTime()) - notesHitArray.remove(cock); + var cock:Date = notesHitArray[balls]; + if (cock != null && cock.getTime() + 1000 < Date.now().getTime()) + notesHitArray.remove(cock); + else + balls = 0; + balls--; } - nps = Math.floor(notesHitArray.length / 2); - currentFrames = 0; + nps = notesHitArray.length; } - else - currentFrames++; if (FlxG.keys.justPressed.NINE) { @@ -3046,8 +3048,10 @@ class PlayState extends MusicBeatState note.rating = Ratings.CalculateRating(noteDiff); + // add newest note to front of notesHitArray + // the oldest notes are at the end and are removed first if (!note.isSustainNote) - notesHitArray.push(Date.now()); + notesHitArray.unshift(Date.now()); if (!resetMashViolation && mashViolations >= 1) mashViolations--;