Optimized note math
This commit is contained in:
@@ -581,6 +581,10 @@ class CoolUtil
|
||||
return r;
|
||||
}
|
||||
|
||||
public static inline function quantize(Value:Float, Quant:Float) {
|
||||
return Math.fround(Value * Quant) / Quant;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a SoundFrontEnd's music to a FlxSound.
|
||||
* Example: `FlxG.sound.setMusic(music);`
|
||||
|
||||
@@ -83,6 +83,14 @@ class Note extends FlxSprite
|
||||
@:dox(hide) public var __strumCameras:Array<FlxCamera> = null;
|
||||
@:dox(hide) public var __strum:Strum = null;
|
||||
@:dox(hide) public var __noteAngle:Float = 0;
|
||||
@:dox(hide) public var __scrollSpeed(default, set):Float = 0;
|
||||
@:dox(hide) public var __length:Float = 0;
|
||||
|
||||
@:dox(hide) private inline function set___scrollSpeed(v:Float) {
|
||||
if(__scrollSpeed != v)
|
||||
__length = 0.45 * CoolUtil.quantize(v, 100);
|
||||
return __scrollSpeed = v;
|
||||
}
|
||||
|
||||
private function get_noteType() {
|
||||
if (PlayState.instance == null) return null;
|
||||
@@ -251,13 +259,11 @@ class Note extends FlxSprite
|
||||
public var latePressWindow:Float = 1;
|
||||
|
||||
public function updateSustain(strum:Strum) {
|
||||
var scrollSpeed = strum.getScrollSpeed(this);
|
||||
|
||||
if (nextSustain != null && lastScrollSpeed != scrollSpeed) {
|
||||
if (nextSustain != null && lastScrollSpeed != __scrollSpeed) {
|
||||
// is long sustain
|
||||
lastScrollSpeed = scrollSpeed;
|
||||
lastScrollSpeed = __scrollSpeed;
|
||||
|
||||
scale.y = (sustainLength * (0.45 * FlxMath.roundDecimal(scrollSpeed, 2))) / frameHeight;
|
||||
scale.y = (sustainLength * __length) / frameHeight;
|
||||
updateHitbox();
|
||||
if (useAntialiasingFix) {
|
||||
// dumbass antialiasing
|
||||
@@ -266,7 +272,7 @@ class Note extends FlxSprite
|
||||
}
|
||||
|
||||
if (!wasGoodHit) return;
|
||||
var t = FlxMath.bound((Conductor.songPosition - strumTime) / (height / (0.45 * FlxMath.roundDecimal(scrollSpeed, 2))), 0, 1);
|
||||
var t = FlxMath.bound((Conductor.songPosition - strumTime) / (height) * __length, 0, 1);
|
||||
var swagRect = this.clipRect == null ? new FlxRect() : this.clipRect;
|
||||
swagRect.x = 0;
|
||||
swagRect.y = t * frameHeight;
|
||||
|
||||
@@ -1095,7 +1095,7 @@ class PlayState extends MusicBeatState
|
||||
|
||||
@:privateAccess {
|
||||
accFormat.format.color = curRating.color;
|
||||
accuracyTxt.text = 'Accuracy:${accuracy < 0 ? "-%" : '${FlxMath.roundDecimal(accuracy * 100, 2)}%'} - ${curRating.rating}';
|
||||
accuracyTxt.text = 'Accuracy:${accuracy < 0 ? "-%" : '${CoolUtil.quantize(accuracy * 100, 100)}%'} - ${curRating.rating}';
|
||||
|
||||
accuracyTxt._formatRanges[0].range.start = accuracyTxt.text.length - curRating.rating.length;
|
||||
accuracyTxt._formatRanges[0].range.end = accuracyTxt.text.length;
|
||||
|
||||
@@ -88,6 +88,7 @@ class Strum extends FlxSprite {
|
||||
daNote.__strum = this;
|
||||
daNote.scrollFactor.set(scrollFactor.x, scrollFactor.y);
|
||||
daNote.__noteAngle = getNotesAngle(daNote);
|
||||
daNote.__scrollSpeed = getScrollSpeed(daNote);
|
||||
daNote.angle = daNote.isSustainNote ? daNote.__noteAngle : angle;
|
||||
|
||||
updateNotePos(daNote);
|
||||
@@ -95,10 +96,10 @@ class Strum extends FlxSprite {
|
||||
|
||||
private inline function updateNotePos(daNote:Note) {
|
||||
if (daNote.strumRelativePos) {
|
||||
daNote.setPosition((this.width - daNote.width) / 2, (daNote.strumTime - Conductor.songPosition) * (0.45 * FlxMath.roundDecimal(getScrollSpeed(daNote), 2)));
|
||||
daNote.setPosition((this.width - daNote.width) / 2, (daNote.strumTime - Conductor.songPosition) * daNote.__length);
|
||||
if (daNote.isSustainNote) daNote.y += N_WIDTHDIV2;
|
||||
} else {
|
||||
var offset = FlxPoint.get(0, (Conductor.songPosition - daNote.strumTime) * (0.45 * FlxMath.roundDecimal(getScrollSpeed(daNote), 2)));
|
||||
var offset = FlxPoint.get(0, (Conductor.songPosition - daNote.strumTime) * daNote.__length);
|
||||
var realOffset = FlxPoint.get(0, 0);
|
||||
|
||||
if (daNote.isSustainNote) offset.y -= N_WIDTHDIV2;
|
||||
|
||||
Reference in New Issue
Block a user