From 1ead9ea63b0cd5fcbea3c1669104a86e68ea2222 Mon Sep 17 00:00:00 2001 From: Kade M Date: Tue, 6 Jul 2021 14:47:56 -0700 Subject: [PATCH 1/3] fix some stuff --- source/Caching.hx | 9 ++++++--- source/Paths.hx | 3 +-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/source/Caching.hx b/source/Caching.hx index 6eb01c8..1bbdf50 100644 --- a/source/Caching.hx +++ b/source/Caching.hx @@ -37,7 +37,7 @@ class Caching extends MusicBeatState var text:FlxText; var kadeLogo:FlxSprite; - public static var bitmapData:Map; + public static var bitmapData:Map; var images = []; var music = []; @@ -50,7 +50,7 @@ class Caching extends MusicBeatState FlxG.worldBounds.set(0,0); - bitmapData = new Map(); + bitmapData = new Map(); text = new FlxText(FlxG.width / 2, FlxG.height / 2 + 300,0,"Loading..."); text.size = 34; @@ -160,7 +160,10 @@ class Caching extends MusicBeatState var replaced = i.replace(".png",""); var data:BitmapData = BitmapData.fromFile("assets/shared/images/characters/" + i); trace('id ' + replaced + ' file - assets/shared/images/characters/' + i + ' ${data.width}'); - bitmapData.set(replaced,data); + var graph = FlxGraphic.fromBitmapData(data); + graph.persist = true; + graph.destroyOnNoUse = false; + bitmapData.set(replaced,graph); done++; } diff --git a/source/Paths.hx b/source/Paths.hx index 1dfe920..166955d 100644 --- a/source/Paths.hx +++ b/source/Paths.hx @@ -137,8 +137,7 @@ class Paths inline static public function imageCached(key:String):FlxGraphic { - - var data = FlxGraphic.fromBitmapData(Caching.bitmapData.get(key)); + var data = Caching.bitmapData.get(key); trace('finding ${key} - ${data.bitmap}'); return data; } From 9ab17d4776ff20aec48ddf26e3307cb132048155 Mon Sep 17 00:00:00 2001 From: Kade M Date: Tue, 6 Jul 2021 20:41:10 -0700 Subject: [PATCH 2/3] funny calculator --- source/ChartingState.hx | 11 +- source/DiffCalc.hx | 317 ++++++++++++++++++++++++++++++++++------ source/Paths.hx | 2 +- source/ResultsScreen.hx | 2 +- 4 files changed, 279 insertions(+), 53 deletions(-) diff --git a/source/ChartingState.hx b/source/ChartingState.hx index 154ac67..a1c01d3 100644 --- a/source/ChartingState.hx +++ b/source/ChartingState.hx @@ -75,7 +75,7 @@ class ChartingState extends MusicBeatState var gridBG:FlxSprite; - var _song:SwagSong; + public static var _song:SwagSong; var typingShit:FlxInputText; /* @@ -129,7 +129,7 @@ class ChartingState extends MusicBeatState blackBorder.alpha = 0.3; - snapText = new FlxText(60,10,0,"Snap: 1/" + snap + " (Press Control to unsnap the cursor)\nAdd Notes: 1-8 (or click)\n", 14); + snapText = new FlxText(60,10,0,"Snap: 1/" + snap + " (Press Control to unsnap the cursor)\nAdd Notes: 1-8 (or click)\nDiff: 0", 14); snapText.scrollFactor.set(); gridBlackLine = new FlxSprite(gridBG.x + gridBG.width / 2).makeGraphic(2, Std.int(gridBG.height), FlxColor.BLACK); @@ -661,12 +661,14 @@ class ChartingState extends MusicBeatState var writingNotes:Bool = false; var doSnapShit:Bool = true; + + public var diff:Float = 0; override function update(elapsed:Float) { updateHeads(); - snapText.text = "Snap: 1/" + snap + " (" + (doSnapShit ? "Control to disable" : "Snap Disabled, Control to renable") + ")\nAdd Notes: 1-8 (or click)\n"; + snapText.text = "Song Diff: " + diff + "\nSnap: 1/" + snap + " (" + (doSnapShit ? "Control to disable" : "Snap Disabled, Control to renable") + ")\nAdd Notes: 1-8 (or click)"; curStep = recalculateSteps(); @@ -1260,6 +1262,9 @@ class ChartingState extends MusicBeatState curRenderedSustains.add(sustainVis); } } + + if (_song != null) + diff = DiffCalc.CalculateDiff(_song); } private function addSection(lengthInSteps:Int = 16):Void diff --git a/source/DiffCalc.hx b/source/DiffCalc.hx index a1c7a7a..4aa5c1b 100644 --- a/source/DiffCalc.hx +++ b/source/DiffCalc.hx @@ -1,3 +1,5 @@ +import openfl.system.System; +import flixel.math.FlxMath; import Song.SwagSong; class SmallNote // basically Note.hx but small as fuck @@ -14,18 +16,26 @@ class SmallNote // basically Note.hx but small as fuck class DiffCalc { - public static function CalculateDiff(song:SwagSong) + + public static var scale = 3 * 1.8; + + public static function CalculateDiff(song:SwagSong, ?accuracy:Float = .93) { + trace('calcuilafjwaf'); // cleaned notes var cleanedNotes:Array = []; + if (song.notes == null) + return 0.0; + + if (song.notes.length == 0) + return 0.0; + // find all of the notes for(i in song.notes) // sections { for (ii in i.sectionNotes) // notes { - if (ii[2] != 0) // skip helds - continue; var gottaHitNote:Bool = i.mustHitSection; if (ii[1] > 3) @@ -41,6 +51,8 @@ class DiffCalc cleanedNotes.sort((a, b) -> Std.int(a.strumTime - b.strumTime)); + + var firstNoteTime = cleanedNotes[0].strumTime; // normalize the notes @@ -57,84 +69,293 @@ class DiffCalc case 0: handOne.push(i); case 1: - handTwo.push(i); + handOne.push(i); case 2: handTwo.push(i); case 3: - handOne.push(i); + handTwo.push(i); } } + var leftHandCol:Array = []; // d 0 + var leftMHandCol:Array = []; // f 1 + var rightMHandCol:Array = []; // j 2 + var rightHandCol:Array = []; // k 3 + + for(i in 0...handOne.length - 1) + { + if (handOne[i].noteData == 0) + leftHandCol.push(handOne[i].strumTime); + else + leftMHandCol.push(handOne[i].strumTime); + } + for(i in 0...handTwo.length - 1) + { + if (handTwo[i].noteData == 3) + rightHandCol.push(handTwo[i].strumTime); + else + rightMHandCol.push(handTwo[i].strumTime); + } + // length in segments of the song var length = ((cleanedNotes[cleanedNotes.length - 1].strumTime / 1000) / 0.5); // hackey way of creating a array with a length - var segmentsOne:Array = new_Array(1,Std.int(length)); - var segmentsTwo:Array = new_Array(1,Std.int(length)); - + var segmentsOne = new haxe.ds.Vector(Math.floor(length)); + + var segmentsTwo = new haxe.ds.Vector(Math.floor(length)); + + for(i in 0...segmentsOne.length) + segmentsOne[i] = new Array(); + for(i in 0...segmentsTwo.length) + segmentsTwo[i] = new Array(); + // algo loop for(i in handOne) { - var index = Std.int(((i.strumTime / 1000))); - if (index + 1 > segmentsOne.length) + var index = Std.int((((i.strumTime * 2) / 1000))); + if (index + 1 > length) continue; - segmentsOne[index] = segmentsOne[index] + 1; + segmentsOne[index].push(i); } for(i in handTwo) { - var index = Std.int(((i.strumTime / 1000))); - if (index + 1 > segmentsTwo.length) + var index = Std.int((((i.strumTime * 2) / 1000))); + if (index + 1 > length) continue; - segmentsTwo[index] = segmentsTwo[index] + 1; + segmentsTwo[index].push(i); } - // get the average of all of the segments - var sumOne:Float = 0; - var sumTwo:Float = 0; - - - var lone = segmentsOne.length; - var ltwo = segmentsOne.length; - - for (i in segmentsOne) + // Remove 0 intervals + /*for(i in 0...segmentsOne.length) { - if (i == 0) // remove empty/breaks - { - lone--; - continue; - } - //trace(i); - sumOne += i / .5; // half it because otherwise instead of nps its just fucking notes per half second which is dumb and stupid + if (segmentsOne[i].length == 0) + segmentsOne[i] = null; } - for (i in segmentsTwo) + for(i in 0...segmentsTwo.length) { - if (i == 0) // remove empty/breaks - { - ltwo--; + if (segmentsTwo[i].length == 0) + segmentsTwo[i] = null; + }*/ + + + var hand_npsOne:Array = new Array(); + var hand_npsTwo:Array = new Array(); + + for(i in segmentsOne) + { + if (i == null) continue; - } - //trace(i); - sumTwo += i / .5; // half it because otherwise instead of nps its just fucking notes per half second which is dumb and stupid + hand_npsOne.push(i.length * scale * 1.6); + } + for(i in segmentsTwo) + { + if (i == null) + continue; + hand_npsTwo.push(i.length * scale * 1.6); } - var handOneAvg = sumOne / lone; - var handTwoAvg = sumTwo / ltwo; + var hand_diffOne:Array = new Array(); + var hand_diffTwo:Array = new Array(); - return HelperFunctions.truncateFloat(handOneAvg > handTwoAvg ? handOneAvg : handTwoAvg,2); + for(i in 0...segmentsOne.length) + { + var ve = segmentsOne[i]; + if (ve == null) + continue; + var fuckYouOne:Array = []; + var fuckYouTwo:Array = []; + for(note in ve) + { + switch(note.noteData) + { + case 0: // fingie 1 + fuckYouOne.push(note); + case 1: // fingie 2 + fuckYouTwo.push(note); + } + } + + var one = fingieCalc(fuckYouOne,leftHandCol); + var two = fingieCalc(fuckYouTwo,leftMHandCol); + + + var bigFuck = ((((one > two ? one : two) * 8) + (hand_npsOne[i] / scale) * 5) / 13) * scale; + + //trace(bigFuck + " - hand one [" + i + "]"); + + + hand_diffOne.push(bigFuck); + } + + for(i in 0...segmentsTwo.length) + { + var ve = segmentsTwo[i]; + if (ve == null) + continue; + var fuckYouOne:Array = []; + var fuckYouTwo:Array = []; + for(note in ve) + { + switch(note.noteData) + { + case 2: // fingie 1 + fuckYouOne.push(note); + case 3: // fingie 2 + fuckYouTwo.push(note); + } + } + + var one = fingieCalc(fuckYouOne,rightMHandCol); + var two = fingieCalc(fuckYouTwo,rightHandCol); + + var bigFuck = ((((one > two ? one : two) * 8) + (hand_npsTwo[i] / scale) * 5) / 13) * scale; + + hand_diffTwo.push(bigFuck); + + // trace(bigFuck + " - hand two [" + i + "]"); + } + + for (i in 0...3) + { + smoothBrain(hand_npsOne,0); + smoothBrain(hand_npsTwo,0); + + smoothBrainTwo(hand_diffOne); + smoothBrainTwo(hand_diffTwo); + } + + //trace(hand_diffOne); + //trace(hand_diffTwo); + + //trace(hand_npsOne); + //trace(hand_npsTwo); + + var point_npsOne:Array = new Array(); + var point_npsTwo:Array = new Array(); + + for(i in segmentsOne) + { + if (i == null) + continue; + point_npsOne.push(i.length); + } + for(i in segmentsTwo) + { + if (i == null) + continue; + point_npsTwo.push(i.length); + } + + var maxPoints:Float = 0; + + for(i in point_npsOne) + maxPoints += i; + for(i in point_npsTwo) + maxPoints += i; + + if (accuracy > .965) + accuracy = .965; + + return HelperFunctions.truncateFloat(chisel(accuracy,hand_diffOne,hand_diffTwo,point_npsOne,point_npsTwo,maxPoints),2); } - static public function new_Array( ArrayType:T, Length:Int ):Array { - var empty:Null = null; - var newArray:Array = new Array(); - - for ( i in 0...Length ) { - newArray.push( empty ); + public static function chisel(scoreGoal:Float,diffOne:Array,diffTwo:Array,pointsOne:Array,pointsTwo:Array,maxPoints:Float) + { + var lowerBound:Float = 0; + var upperBound:Float = 100; + + while(upperBound - lowerBound > 0.01) + { + var average:Float = (upperBound + lowerBound) / 2; + var amtOfPoints:Float = calcuate(average,diffOne,pointsOne) + calcuate(average,diffTwo,pointsTwo); + if (amtOfPoints / maxPoints < scoreGoal) + lowerBound = average; + else + upperBound = average; + + } + return upperBound; + } + + public static function calcuate(midPoint:Float,diff:Array,points:Array) + { + var output:Float = 0; + + for (i in 0...diff.length) + { + var res = diff[i]; + if (midPoint > res) + output += points[i]; + else + output += points[i] * Math.pow(midPoint / res,1.2); + } + return output; + } + + public static function findStupid(strumTime:Float, array:Array) + { + for(i in 0...array.length) + if (array[i] == strumTime) + return i; + return -1; + } + + public static function fingieCalc(floats:Array, columArray:Array):Float + { + var sum:Float = 0; + if (floats.length == 0) + return 0; + var startIndex = findStupid(floats[0].strumTime,columArray); + if (startIndex == -1) + return 0; + for(i in floats) + { + sum += columArray[startIndex + 1] - columArray[startIndex]; + startIndex++; + } + + if (sum == 0) + return 0; + + return (1375 * (floats.length)) / sum; + } + + // based arrayer + // basicily smmoth the shit + public static function smoothBrain(npsVector:Array, weirdchamp:Float) + { + var floatOne = weirdchamp; + var floatTwo = weirdchamp; + + for (i in 0...npsVector.length) + { + var result = npsVector[i]; + + var chunker = floatOne; + floatOne = floatTwo; + floatTwo = result; + + npsVector[i] = (chunker + floatOne + floatTwo) / 3; + } + } + + // Smooth the shit but less + public static function smoothBrainTwo(diffVector:Array) + { + var floatZero:Float = 0; + + for(i in 0...diffVector.length) + { + var result = diffVector[i]; + + var fuck = floatZero; + floatZero = result; + diffVector[i] = (fuck + floatZero) / 2; } - - return newArray; } } \ No newline at end of file diff --git a/source/Paths.hx b/source/Paths.hx index 166955d..d16887a 100644 --- a/source/Paths.hx +++ b/source/Paths.hx @@ -145,7 +145,7 @@ class Paths inline static public function getPackerAtlas(key:String, ?library:String, ?isCharacter:Bool = false) { if (isCharacter) - return FlxAtlasFrames.fromSpriteSheetPacker(imageCached(key), file('images/$key.txt', library)); + return FlxAtlasFrames.fromSpriteSheetPacker(imageCached(key), file('images/characters/$key.txt', library)); return FlxAtlasFrames.fromSpriteSheetPacker(image(key, library), file('images/$key.txt', library)); } } diff --git a/source/ResultsScreen.hx b/source/ResultsScreen.hx index d48a231..77d62f2 100644 --- a/source/ResultsScreen.hx +++ b/source/ResultsScreen.hx @@ -75,7 +75,7 @@ class ResultsScreen extends FlxSubState text.text = "Week Cleared!"; } - comboText = new FlxText(20,-75,0,'Judgements:\nSicks - ${PlayState.sicks}\nGoods - ${PlayState.goods}\nBads - ${PlayState.bads}\n\nCombo Breaks: ${(PlayState.isStoryMode ? PlayState.campaignMisses : PlayState.misses)}\nHighest Combo: ${PlayState.highestCombo + 1}\n\nScore: ${PlayState.instance.songScore}\nAccuracy: ${HelperFunctions.truncateFloat(PlayState.instance.accuracy,2)}%\n\n${Ratings.GenerateLetterRank(PlayState.instance.accuracy)}\n\nF1 - View replay\nF2 - Replay song + comboText = new FlxText(20,-75,0,'Judgements:\nSicks - ${PlayState.sicks}\nGoods - ${PlayState.goods}\nBads - ${PlayState.bads}\n\nCombo Breaks: ${(PlayState.isStoryMode ? PlayState.campaignMisses : PlayState.misses)}\nHighest Combo: ${PlayState.highestCombo + 1}\nScore: ${PlayState.instance.songScore}\nAccuracy: ${HelperFunctions.truncateFloat(PlayState.instance.accuracy,2)}%\n\n${Ratings.GenerateLetterRank(PlayState.instance.accuracy)}\n\nF1 - View replay\nF2 - Replay song '); comboText.size = 28; comboText.setBorderStyle(FlxTextBorderStyle.OUTLINE,FlxColor.BLACK,4,1); From d0d2adcbfea1173b73c89a6cbee01fbc62a8e5cf Mon Sep 17 00:00:00 2001 From: Kade M Date: Tue, 6 Jul 2021 20:50:23 -0700 Subject: [PATCH 3/3] smooth tune --- source/DiffCalc.hx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/DiffCalc.hx b/source/DiffCalc.hx index 4aa5c1b..5f2d240 100644 --- a/source/DiffCalc.hx +++ b/source/DiffCalc.hx @@ -220,7 +220,7 @@ class DiffCalc // trace(bigFuck + " - hand two [" + i + "]"); } - for (i in 0...3) + for (i in 0...4) { smoothBrain(hand_npsOne,0); smoothBrain(hand_npsTwo,0);