C
C#3mo ago
mynarco

Optimize Search Algorithm to find Most dense part in rhythm game map.

Hello, so i am struggling with a logic problem, i am writing a 3d rhythm game where notes approach at you(a rewrite for this game https://www.youtube.com/watch?v=t40kkLAAvtk) I need to be able to calculate the MAX amount of notes that will be rendered at a time so i can just create a statically sized array for instances to render to optimize now the 2 things i am working with are an approach time, hitwindow, and each notes time to get the max lifetime of a note i just need to add approach time to hitwindow so now i have a notes lifetime and each notes specific time into the song so i have written out a solution, now i need to optimize it, there is absolutely NO room for error as this is determining the amount of memory to allocate for notes
public int CalculateMaxInstanceCount() {
float lifetime = Global.Settings.Note.ApproachTime + NoteObject.HitWindow;
int max = 0;
for(int i = 0; i < OrderedNotes.Length; i++) {
int count = 0;
for(int j = i; j < OrderedNotes.Length; j++) {
if(OrderedNotes[j].Time > OrderedNotes[i].Time + lifetime) break;
count++;
}
if(count > max) max = count;
}
return max;
}
public int CalculateMaxInstanceCount() {
float lifetime = Global.Settings.Note.ApproachTime + NoteObject.HitWindow;
int max = 0;
for(int i = 0; i < OrderedNotes.Length; i++) {
int count = 0;
for(int j = i; j < OrderedNotes.Length; j++) {
if(OrderedNotes[j].Time > OrderedNotes[i].Time + lifetime) break;
count++;
}
if(count > max) max = count;
}
return max;
}
azer
YouTube
Sunhiausa - Yellow Supernova - (95.548%, NP) (First)
done last stream, sorry for taking so long to upload! i've been playing osu! a lot recently and earlier today got a 112pp play in just 11 days of playing! :) Rhythia Settings: --------------------------- Please note that I do regularly change my settings when I feel like I need a change. If I am streaming and you happen to notice that I am usin...
2 Replies
MutableString
MutableString3mo ago
is resizing this array once or twice that much of an issue (it's not like the rest of the program will never allocate any memory anyway)? i would consider the standard algorithm of starting from n items (say n=8) and doubling it when it's not big enough
mynarco
mynarco3mo ago
i guess that's fair thanks
Want results from more Discord servers?
Add your server