int RenderBeatLines(TimeSignature ts, TimeSignature.BeatInfo beatInfo, GameObject[] lineObjectPool, int poolPosStart, uint startRange, uint endRange, uint nextTSTick) { int poolPos = poolPosStart; uint currentTick = ts.tick + beatInfo.tickOffset; int repetitions = 0; uint fullCycleLength = beatInfo.tickGap * (uint)beatInfo.repetitions + beatInfo.repetitionCycleOffset; uint distanceFromStartRange = startRange >= currentTick ? startRange - currentTick : 0; currentTick += fullCycleLength * (distanceFromStartRange / fullCycleLength); // Skip closer to where our viewport currently is, wastes cpu cycles otherwise while (currentTick < nextTSTick && currentTick <= endRange) { if (currentTick >= startRange) { SetBeatLinePosition(currentTick, lineObjectPool, ref poolPos); } currentTick += beatInfo.tickGap; if (++repetitions >= beatInfo.repetitions) { currentTick += beatInfo.repetitionCycleOffset; repetitions -= beatInfo.repetitions; } } return(poolPos - poolPosStart); }
public static uint TickToSnappedTick(uint tick, int step, Song song) { float resolution = song.resolution; var timeSignatures = song.timeSignatures; int tsIndex = SongObjectHelper.FindClosestPositionRoundedDown(tick, timeSignatures); TimeSignature ts = timeSignatures[tsIndex]; uint? endRange = tsIndex < (timeSignatures.Count - 1) ? (uint?)timeSignatures[tsIndex + 1].tick : null; TimeSignature.MeasureInfo measureInfo = ts.GetMeasureInfo(); TimeSignature.BeatInfo measureLineInfo = measureInfo.measureLine; TimeSignature.BeatInfo beatLineInfo = measureInfo.beatLine; uint tickOffsetFromTs = tick - ts.tick; int measuresFromTsToSnap = (int)((float)tickOffsetFromTs / measureLineInfo.tickGap); uint lastMeasureTick = ts.tick + (uint)(measuresFromTsToSnap * measureLineInfo.tickGap); float realBeatStep = step / 4.0f; float tickGap = beatLineInfo.tickGap / realBeatStep * ts.denominator / 4.0f; uint tickOffsetFromLastMeasure = tick - lastMeasureTick; int beatsFromLastMeasureToSnap = Mathf.RoundToInt((float)tickOffsetFromLastMeasure / tickGap); uint snappedTick = lastMeasureTick + (uint)(beatsFromLastMeasureToSnap * tickGap); if (endRange.HasValue) { return(snappedTick < endRange.Value ? snappedTick : endRange.Value); } else { return(snappedTick); } // Old algorithm // Snap position based on step //float factor = Song.FULL_STEP / (float)step * resolution / Song.STANDARD_BEAT_RESOLUTION; //float divisor = tick / factor; //float lowerBound = (int)divisor * factor; //float remainder = divisor - (int)divisor; // //if (remainder > 0.5f) // tick = (uint)Mathf.Round(lowerBound + factor); //else // tick = (uint)Mathf.Round(lowerBound); // //return tick; }