Skip to content

Commit 75155d7

Browse files
committed
change PreloadedChartNote to structInit for optimization
TODO: find an way to optimize the damn section loading code and split them into functions, because it's absolute spaghetti code and I can't make any major changes right now
1 parent e53abe8 commit 75155d7

File tree

2 files changed

+57
-40
lines changed

2 files changed

+57
-40
lines changed

source/Note.hx

Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,35 +12,43 @@ typedef EventNote = {
1212
value2:String
1313
}
1414

15-
typedef PreloadedChartNote = {
16-
strumTime:Float,
17-
noteData:Int,
18-
mustPress:Bool,
19-
oppNote:Bool,
20-
noteType:String,
21-
animSuffix:String,
22-
noteskin:String,
23-
texture:String,
24-
noAnimation:Bool,
25-
noMissAnimation:Bool,
26-
gfNote:Bool,
27-
isSustainNote:Bool,
28-
isSustainEnd:Bool,
29-
sustainLength:Float,
30-
parentST:Float,
31-
parentSL:Float,
32-
hitHealth:Float,
33-
missHealth:Float,
34-
hitCausesMiss:Null<Bool>,
35-
wasHit:Bool,
36-
multSpeed:Float,
37-
multAlpha:Float,
38-
noteDensity:Float,
39-
ignoreNote:Bool,
40-
blockHit:Bool,
41-
lowPriority:Bool
15+
@:structInit class PreloadedChartNote {
16+
public var strumTime:Float = 0;
17+
public var noteData:Int = 0;
18+
public var mustPress:Bool = false;
19+
public var oppNote:Bool = false;
20+
public var noteType:String = "";
21+
public var animSuffix:String = "";
22+
public var noteskin:String = "";
23+
public var texture:String = "";
24+
public var noAnimation:Bool = false;
25+
public var noMissAnimation:Bool = false;
26+
public var gfNote:Bool = false;
27+
public var isSustainNote:Bool = false;
28+
public var isSustainEnd:Bool = false;
29+
public var sustainLength:Float = 0;
30+
public var parentST:Float = 0;
31+
public var parentSL:Float = 0;
32+
public var hitHealth:Float = 0;
33+
public var missHealth:Float = 0;
34+
public var hitCausesMiss:Null<Bool> = null;
35+
public var wasHit:Bool = false;
36+
public var multSpeed:Float = 1;
37+
public var multAlpha:Float = 1;
38+
public var noteDensity:Float = 1;
39+
public var ignoreNote:Bool = false;
40+
public var blockHit:Bool = false;
41+
public var lowPriority:Bool = false;
42+
43+
public function dispose() {
44+
// will be cleared by the GC later
45+
for (field in Reflect.fields(this)) {
46+
Reflect.setField(this, field, null);
47+
}
48+
}
4249
}
4350

51+
4452
typedef NoteSplashData = {
4553
disabled:Bool,
4654
texture:String,

source/PlayState.hx

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2550,10 +2550,10 @@ class PlayState extends MusicBeatState
25502550
{
25512551
if (SONG.needsVoices)
25522552
{
2553-
var playerVocals = Paths.voices(curSong, diff, (boyfriend.vocalsFile == null || boyfriend.vocalsFile.length < 1) ? 'Player' : boyfriend.vocalsFile);
2553+
var playerVocals = Paths.voices(curSong, diff, (boyfriend.vocalsFile == null || boyfriend.vocalsFile.length < 1) ? "Player" : boyfriend.vocalsFile);
25542554
vocals.loadEmbedded(playerVocals != null ? playerVocals : Paths.voices(curSong, diff));
25552555

2556-
var oppVocals = Paths.voices(curSong, diff, (dad.vocalsFile == null || dad.vocalsFile.length < 1) ? 'Opponent' : dad.vocalsFile);
2556+
var oppVocals = Paths.voices(curSong, diff, (dad.vocalsFile == null || dad.vocalsFile.length < 1) ? "Opponent" : dad.vocalsFile);
25572557
if(oppVocals != null) opponentVocals.loadEmbedded(oppVocals);
25582558
}
25592559
}
@@ -2624,10 +2624,19 @@ class PlayState extends MusicBeatState
26242624
var currentMultiplier:Float = 1;
26252625
var gottaHitNote:Bool = false;
26262626
var swagNote:PreloadedChartNote;
2627+
var ghostNotesCleared:Int = 0;
2628+
// TODO: Optimize and clean up this mess, maybe split into functions
2629+
// this is absolute spaghetti code
26272630
for (section in noteData) {
26282631
if (section.changeBPM) currentBPMLol = section.bpm;
26292632

2630-
for (songNotes in section.sectionNotes) {
2633+
for (i in 0...section.sectionNotes.length)
2634+
{
2635+
final songNotes:Array<Dynamic> = section.sectionNotes[i];
2636+
2637+
if (songNotes[1] == -1)
2638+
continue;
2639+
26312640
if (songNotes[0] >= startingPoint + offsetStart) {
26322641
final daStrumTime:Float = songNotes[0];
26332642
var daNoteData:Int = 0;
@@ -2694,7 +2703,7 @@ class PlayState extends MusicBeatState
26942703
multiChangeEvents[1].shift();
26952704
}
26962705

2697-
swagNote = cast {
2706+
swagNote = {
26982707
strumTime: daStrumTime,
26992708
noteData: daNoteData,
27002709
mustPress: bothSides || gottaHitNote,
@@ -2728,9 +2737,9 @@ class PlayState extends MusicBeatState
27282737
unspawnNotes.push(swagNote);
27292738

27302739
if (jackingtime > 0) {
2731-
for (i in 0...Std.int(jackingtime)) {
2732-
final jackNote:PreloadedChartNote = cast {
2733-
strumTime: swagNote.strumTime + (15000 / SONG.bpm) * (i + 1),
2740+
for (j in 0...Std.int(jackingtime)) {
2741+
final jackNote:PreloadedChartNote = {
2742+
strumTime: swagNote.strumTime + (15000 / SONG.bpm) * (j + 1),
27342743
noteData: swagNote.noteData,
27352744
mustPress: swagNote.mustPress,
27362745
oppNote: swagNote.oppNote,
@@ -2761,8 +2770,7 @@ class PlayState extends MusicBeatState
27612770
final roundSus:Int = Math.round(swagNote.sustainLength / stepCrochet);
27622771
if (roundSus > 0) {
27632772
for (susNote in 0...roundSus + 1) {
2764-
2765-
final sustainNote:PreloadedChartNote = cast {
2773+
final sustainNote:PreloadedChartNote = {
27662774
strumTime: daStrumTime + (stepCrochet * susNote),
27672775
noteData: daNoteData,
27682776
mustPress: bothSides || gottaHitNote,
@@ -2791,7 +2799,7 @@ class PlayState extends MusicBeatState
27912799
} else {
27922800
final gottaHitNote:Bool = ((songNotes[1] < 4 && !opponentChart)
27932801
|| (songNotes[1] > 3 && opponentChart) ? section.mustHitSection : !section.mustHitSection);
2794-
if ((bothSides || gottaHitNote) && !songNotes.hitCausesMiss) {
2802+
if ((bothSides || gottaHitNote) && songNotes[3] != 'Hurt Note') {
27952803
totalNotes += 1;
27962804
combo += 1;
27972805
totalNotesPlayed += 1;
@@ -2804,7 +2812,9 @@ class PlayState extends MusicBeatState
28042812
}
28052813
sectionsLoaded += 1;
28062814
notesLoadedRN += section.sectionNotes.length;
2815+
#if debug
28072816
Sys.print('\rSection $sectionsLoaded loaded! (' + notesLoadedRN + ' notes)');
2817+
#end
28082818
}
28092819

28102820
bfNoteskin = boyfriend.noteskin;
@@ -2819,7 +2829,7 @@ class PlayState extends MusicBeatState
28192829
if (ClientPrefs.enableColorShader) note.updateRGBColors();
28202830
}
28212831
}
2822-
2832+
// trace('["${SONG.song.toUpperCase()}" CHART INFO]: Ghost Notes Cleared: $ghostNotesCleared');
28232833
unspawnNotes.sort(sortByTime);
28242834
eventNotes.sort(sortByTime);
28252835
generatedMusic = true;
@@ -3974,7 +3984,7 @@ class PlayState extends MusicBeatState
39743984
{
39753985
var string1:String = (value1.length > 1 ? value1 : SONG.song);
39763986
var string2:String = (value2.length > 1 ? value2 : SONG.songCredit);
3977-
3987+
39783988
var creditsPopup:CreditsPopUp = new CreditsPopUp(FlxG.width, 200, string1, string2);
39793989
creditsPopup.camera = camHUD;
39803990
creditsPopup.scrollFactor.set();
@@ -6480,4 +6490,3 @@ class PlayState extends MusicBeatState
64806490
FlxG.autoPause = ClientPrefs.autoPause;
64816491
}
64826492
}
6483-

0 commit comments

Comments
 (0)