some optimisation hopefully

This commit is contained in:
Yoshman29
2023-04-21 15:52:52 +02:00
parent 565c66c800
commit d323030268
8 changed files with 25 additions and 33 deletions
+1
View File
@@ -16,6 +16,7 @@
- [ ] Metadata Editing
- [ ] Cap zoom in & out
- [ ] Step based zooming
- [ ] Use latest hxCodec
- [ ] Multiple state scripts & Multiple global scripts
- [ ] Make update.bat use libs.xml instead of hmm.json
- [ ] New Switch Mod menu
+2 -1
View File
@@ -135,10 +135,11 @@ class HScript extends Script {
private override function onCall(funcName:String, parameters:Array<Dynamic>):Dynamic {
if (interp == null) return null;
if (!interp.variables.exists(funcName)) return null;
var func = interp.variables.get(funcName);
if (func != null && Reflect.isFunction(func))
return (parameters != null && parameters.length > 0) ? Reflect.callMethod(null, func, parameters) : func();
return Reflect.callMethod(null, func, parameters);
return null;
}
@@ -62,7 +62,7 @@ class ScriptPack extends Script {
* @param event Event (will be the first parameter of the function)
* @return (modified by scripts)
*/
public function event<T:CancellableEvent>(func:String, event:T):T {
public inline function event<T:CancellableEvent>(func:String, event:T):T {
for(e in scripts) {
e.call(func, [event]);
@:privateAccess
+4 -8
View File
@@ -58,7 +58,7 @@ class Note extends FlxSprite
* Name of the splash.
*/
public var splash:String = "default";
public var strumID(get, never):Int;
private function get_strumID() {
var id = noteData % 4;
@@ -102,7 +102,7 @@ class Note extends FlxSprite
public function new(strumLine:StrumLine, noteData:ChartNote, sustain:Bool = false, sustainLength:Float = 0, sustainOffset:Float = 0)
{
super();
moves = false;
this.prevNote = strumLine.notes.members.last();
@@ -114,8 +114,8 @@ class Note extends FlxSprite
x += 50;
// MAKE SURE ITS DEFINITELY OFF SCREEN?
y -= 2000;
this.strumTime = noteData.time.getDefault(0) + sustainOffset;
this.strumTime = noteData.time.getDefault(0) + sustainOffset;
this.noteData = noteData.id.getDefault(0);
var customType = Paths.image('game/notes/${this.noteType}');
@@ -199,7 +199,7 @@ class Note extends FlxSprite
override function draw() {
@:privateAccess var oldDefaultCameras = FlxCamera._defaultCameras;
@:privateAccess if (__strumCameras != null) FlxCamera._defaultCameras = __strumCameras;
var negativeScroll = isSustainNote && nextSustain != null && lastScrollSpeed < 0;
if (negativeScroll) offset.y *= -1;
@@ -233,10 +233,6 @@ class Note extends FlxSprite
// The * 0.5 is so that it's easier to hit them too late, instead of too early
public var earlyPressWindow:Float = 0.5;
public var latePressWindow:Float = 1;
override function update(elapsed:Float)
{
super.update(elapsed);
}
public function updateSustain(strum:Strum) {
var scrollSpeed = strum.getScrollSpeed(this);
+2 -2
View File
@@ -8,12 +8,12 @@ class NoteGroup extends FlxTypedGroup<Note> {
var i:Int = 0;
var __currentlyLooping:Bool = false;
public function addNotes(notes:Array<Note>) {
public inline function addNotes(notes:Array<Note>) {
for(e in notes) add(e);
sortNotes();
}
public function sortNotes() {
public inline function sortNotes() {
sort(function(i, n1, n2) {
if (n1.strumTime == n2.strumTime)
return n1.isSustainNote ? -1 : 1;
+11 -13
View File
@@ -1054,17 +1054,16 @@ class PlayState extends MusicBeatState
scoreTxt.text = 'Score:$songScore';
missesTxt.text = '${comboBreaks ? "Combo Breaks" : "Misses"}:$misses';
var rating:ComboRating = curRating == null ? new ComboRating(0, "[N/A]", 0xFF888888) : curRating;
if (curRating == null)
curRating = new ComboRating(0, "[N/A]", 0xFF888888);
@:privateAccess {
accFormat.format.color = rating.color;
accuracyTxt.text = 'Accuracy:${accuracy < 0 ? "-%" : '${FlxMath.roundDecimal(accuracy * 100, 2)}%'} - ${rating.rating}';
accFormat.format.color = curRating.color;
accuracyTxt.text = 'Accuracy:${accuracy < 0 ? "-%" : '${FlxMath.roundDecimal(accuracy * 100, 2)}%'} - ${curRating.rating}';
accuracyTxt._formatRanges[0].range.start = accuracyTxt.text.length - rating.rating.length;
accuracyTxt._formatRanges[0].range.start = accuracyTxt.text.length - curRating.rating.length;
accuracyTxt._formatRanges[0].range.end = accuracyTxt.text.length;
}
// accuracyTxt.addFormat(accFormat, accuracyTxt.text.length - rating.rating.length, accuracyTxt.text.length);
if (controls.PAUSE && startedCountdown && canPause)
pauseGame();
@@ -1327,13 +1326,12 @@ class PlayState extends MusicBeatState
var __justReleased:Array<Bool> = [];
private function keyShit():Void
{
for(id=>p in strumLines) {
p.updateNotes();
if (p.cpu) continue;
__funcsToExec.clear();
__funcsToExec = [null, null];
__pressed.clear();
__justPressed.clear();
__justReleased.clear();
@@ -1355,27 +1353,27 @@ class PlayState extends MusicBeatState
if (c.lastAnimContext != DANCE)
c.__lockAnimThisFrame = true;
__funcsToExec.push(function(note:Note) {
__funcsToExec[0] = function(note:Note) {
if (__pressed[note.strumID] && note.isSustainNote && note.canBeHit && !note.wasGoodHit) {
goodNoteHit(p, note);
}
});
};
}
var notePerStrum = [for(_ in 0...4) null];
if (__justPressed.contains(true)) {
__funcsToExec.push(function(note:Note) {
__funcsToExec[1] = function(note:Note) {
if (__justPressed[note.strumID] && !note.isSustainNote && !note.wasGoodHit && note.canBeHit) {
if (notePerStrum[note.strumID] == null) notePerStrum[note.strumID] = note;
else if (Math.abs(notePerStrum[note.strumID].strumTime - note.strumTime) <= 2) p.deleteNote(note);
else if (note.strumTime < notePerStrum[note.strumID].strumTime) notePerStrum[note.strumID] = note;
}
});
};
}
if (__funcsToExec.length > 0) {
p.notes.forEachAlive(function(note:Note) {
for(e in __funcsToExec) e(note);
for(e in __funcsToExec) if (e != null) e(note);
});
}
+2 -2
View File
@@ -85,7 +85,7 @@ class Strum extends FlxSprite {
}
}
public function updateSustain(daNote:Note) {
public inline function updateSustain(daNote:Note) {
if (!daNote.isSustainNote) return;
daNote.updateSustain(this);
}
@@ -108,7 +108,7 @@ class Strum extends FlxSprite {
centerOrigin();
}
public function press(time:Float) {
public inline function press(time:Float) {
lastHit = time;
playAnim("confirm");
}
+2 -6
View File
@@ -118,13 +118,9 @@ class StrumLine extends FlxTypedGroup<Strum> {
var __updateNote_strum:Strum;
public function updateNote(daNote:Note) {
__updateNote_strum = members[daNote.noteData];
if (__updateNote_strum == null) return;
for(e in members) {
if (e.ID == daNote.noteData % 4) {
__updateNote_strum = e;
break; //ing bad
}
}
PlayState.instance.scripts.event("onNoteUpdate", PlayState.instance.__updateNote_event.recycle(daNote, FlxG.elapsed, __updateNote_strum));
onNoteUpdate.dispatch(PlayState.instance.__updateNote_event);
if (PlayState.instance.__updateNote_event.cancelled) return;