Skip to content
This repository has been archived by the owner on Jan 26, 2025. It is now read-only.

Commit

Permalink
stop using dynamic for note and event sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
MaybeMaru committed Apr 11, 2024
1 parent 6aef31e commit 1052fe7
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 40 deletions.
7 changes: 4 additions & 3 deletions source/flixel/graphics/tile/FlxDrawQuadsItem.hx
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,11 @@ class FlxDrawQuadsItem extends FlxDrawBaseItem<FlxDrawQuadsItem>
return;

if (shader == null)
{
shader = graphics.shader;

if (shader == null)
return;
if (shader == null)
return;
}

shader.bitmap.input = graphics.bitmap;
shader.alpha.value = alphas;
Expand Down
4 changes: 2 additions & 2 deletions source/funkin/objects/NotesGroup.hx
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,8 @@ class NotesGroup extends Group

scrollSpeed = songSpeed;

unspawnNotes.sort(CoolUtil.sortByStrumTime);
events.sort(CoolUtil.sortByStrumTime);
unspawnNotes.sort((a:BasicNote, b:BasicNote) -> return FlxSort.byValues(FlxSort.ASCENDING, a.strumTime, b.strumTime));
events.sort((a:Event, b:Event) -> return FlxSort.byValues(FlxSort.ASCENDING, a.strumTime, b.strumTime));

curSpawnNote = unspawnNotes[0];
curCheckEvent = events[0];
Expand Down
53 changes: 29 additions & 24 deletions source/funkin/util/CoolUtil.hx
Original file line number Diff line number Diff line change
Expand Up @@ -279,18 +279,15 @@ class CoolUtil {
FlxG.sound.music = null;
}

public static inline var baseLerp = 1 / 60;
inline public static function getLerp(ratio:Float):Float {
return FlxG.elapsed / baseLerp * ratio;
return FlxG.elapsed / (1 / 60) * ratio;
}

inline public static function coolLerp(a:Float, b:Float, ratio:Float):Float {
inline public static function lerp(a:Float, b:Float, ratio:Float):Float {
return FlxMath.lerp(a, b, getLerp(ratio));
}

public static inline function sortByStrumTime(a:Dynamic, b:Dynamic) {
return FlxSort.byValues(FlxSort.ASCENDING, a.strumTime, b.strumTime);
}
inline public static function coolLerp(a:Float, b:Float, r:Float):Float return lerp(a, b, r);

public static function sortAlphabetically(a:String, b:String):Int {
a = a.toUpperCase();
Expand Down Expand Up @@ -332,11 +329,17 @@ class CoolUtil {
return classFolders.join(formatDir ? '/' : '.');
}

inline public static function formatInt(text:Dynamic, zeroLength:Int = 5):String {
var result:String = Std.string(text);
inline public static function formatInt(value:Dynamic, zeroLength:Int = 5):String
{
var result:String = Std.string(value);
var lengthDiff:Int = zeroLength - result.length;
if (lengthDiff <= 0) return result;
for (i in 0...lengthDiff) result = '0$result';

if (lengthDiff <= 0)
return result;

for (i in 0...lengthDiff)
result = '0$result';

return result;
}

Expand All @@ -357,14 +360,14 @@ class CoolUtil {
}

inline public static function cacheImage(image:FlxGraphicAsset, ?library:String, ?camera:FlxCamera):FlxGraphicAsset {
if (image == null) return null;

if (image is String)
image = Paths.image(image, library);

if ((camera != null) && (image is FlxGraphic))
camera.startQuadBatch(image, false, false, null, false, null);

if (image != null)
{
if (image is String)
image = Paths.image(image, library);
if (camera != null) if (image is FlxGraphic)
camera.startQuadBatch(image, false, false, null, false, null);
}
return image;
}

Expand All @@ -387,24 +390,26 @@ class CoolUtil {
var i = 0;
var l = judgeOffsets.length;
while (i < l) {
if (checkDiff(noteDiff, judgeOffsets[i]))
return returnJudgements[i];
if (checkDiff(noteDiff, judgeOffsets.unsafeGet(i)))
return returnJudgements.unsafeGet(i);
i++;
}
return "sick";
}

inline public static function checkDiff(noteDiff:Float, safeOffset:Int):Bool {
var safeZoneOffset = Conductor.safeZoneOffset;
var millisecondDiff = getMillisecondDiff(safeOffset);
return (noteDiff > safeZoneOffset * millisecondDiff || noteDiff < safeZoneOffset * -millisecondDiff);
return (
(noteDiff > (Conductor.safeZoneOffset * millisecondDiff)) ||
(noteDiff < (Conductor.safeZoneOffset * -millisecondDiff))
);
}

inline public static function getMillisecondDiff(milliseconds:Int):Float {
return (milliseconds * Conductor.safeZoneOffsetMult);
}

inline public static function getNoteDiff(daNote:Note):Float {
return Math.abs(daNote.strumTime - Conductor.songPosition);
inline public static function getNoteDiff(note:Note):Float {
return Math.abs(note.strumTime - Conductor.songPosition);
}
}
17 changes: 9 additions & 8 deletions source/funkin/util/Paths.hx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ class Paths
public static function set_currentLevel(value:String)
return currentLevel = value.toLowerCase();

public static function getPath(file:String, type:AssetType, ?library:String, allMods:Bool = false, mods:Bool = true, ?level:String):String {
public static function getPath(file:String, type:AssetType, ?library:String, allMods:Bool = false, mods:Bool = true, ?level:String):String
{
final hasLevel = currentLevel.length > 0;

#if MODS_ALLOWED
Expand Down Expand Up @@ -272,17 +273,17 @@ class Paths
return frames;

var lodScale = parent.lodScale;
for (frame in frames.frames) {
frames.frames.fastForEach((frame, i) -> {
var rect = frame.frame;
rect.x /= lodScale;
rect.y /= lodScale;
rect.width /= lodScale;
rect.height /= lodScale;

rect.x = rect.x / lodScale;
rect.y = rect.y / lodScale;
rect.width = rect.width / lodScale;
rect.height = rect.height / lodScale;
var offset = frame.offset;
offset.x /= lodScale;
offset.y /= lodScale;
}
});

parent.parsedChildren = true;

Expand Down
7 changes: 4 additions & 3 deletions source/funkin/util/song/WeekSetup.hx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ typedef WeekData = {
var name:String;
}

class WeekSetup {
class WeekSetup
{
public static var weekList:Array<WeekData> = [];
public static var vanillaWeekList:Array<WeekData> = [];
public static var weekMap:Map<String, WeekData> = [];
Expand Down Expand Up @@ -209,12 +210,12 @@ class WeekSetup {
loadScreen.init(Stage.getJson(song.stage), song.players, song.song);

// Pre-clear cache to make sure the loading screen stuff doesnt get disposed
loadScreen.onStart = function () {
loadScreen.onStart = () -> {
PlayState.clearCache = false;
CoolUtil.clearCache();
}

loadScreen.onComplete = function () {
loadScreen.onComplete = () -> {
Paths.currentLevel = PlayState.storyWeek;
CoolUtil.switchState(instance, true, skipTrans);
}
Expand Down

0 comments on commit 1052fe7

Please sign in to comment.