© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•2y ago•
3 replies
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;
    }
YouTubeazer
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...
Sunhiausa - Yellow Supernova - (95.548%, NP) (First)
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Find file duplicates | Optimize
C#CC# / help
4y ago
✅ String search by user text input algorithm
C#CC# / help
3y ago
Hi there, this is part of an algorithm for the game: connect 4
C#CC# / help
3y ago