Skip to content

Commit

Permalink
Fixed main thread being blocked on initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
davi3684dk committed Aug 18, 2022
1 parent 797988c commit 6434080
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 20 deletions.
15 changes: 4 additions & 11 deletions TaohSongSuggest/Managers/SongSuggestManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ static async void UpdateProgessNew()

public static void Init()
{
Task.Run(async () =>
Task.Run(() =>
{
try
{
Expand All @@ -51,14 +51,7 @@ public static void Init()
lastSuggestionsPath = configDir
};
await IPA.Utilities.Async.UnityMainThreadTaskScheduler.Factory.StartNew(async() =>
{
var userinf = await BS_Utils.Gameplay.GetUserInfo.GetUserAsync();
toolBox = new SongSuggest(fps, userinf.platformUserId);
});
toolBox = new SongSuggest(fps, "-1");
}
catch (Exception e)
{
Expand Down Expand Up @@ -115,7 +108,7 @@ public static void SuggestSongs(bool p_ignoreNonImprovable = false)
toolBox.songSuggest.songSuggestCompletion = 1;
Task.Delay(100);
//Task.Delay(100);
await IPA.Utilities.Async.UnityMainThreadTaskScheduler.Factory.StartNew(() =>
{
Expand Down Expand Up @@ -186,7 +179,7 @@ public static void Oldest100ActivePlayer()
toolBox.GenerateOldestSongs(settings);
Task.Delay(200);
//Task.Delay(200);
IPA.Utilities.Async.UnityMainThreadTaskScheduler.Factory.StartNew(() =>
{
Expand Down
4 changes: 2 additions & 2 deletions TaohSongSuggest/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.5.18")]
[assembly: AssemblyFileVersion("1.5.18")]
[assembly: AssemblyVersion("1.5.19")]
[assembly: AssemblyFileVersion("1.5.19")]
20 changes: 16 additions & 4 deletions TaohSongSuggest/SongSuggest/Actions/OldestSongs.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
using PlaylistNS;
using SongSuggestNS;
using Settings;
using System.Linq;
using System.Collections.Generic;
using System;

namespace Actions
{
Expand All @@ -17,13 +20,22 @@ public OldestSongs(SongSuggest songSuggest)

public void Oldest100ActivePlayer(OldestSongSettings settings)
{
songSuggest.RefreshActivePlayer();
//Create empty playlist, and reset output window.
playlist = new Playlist(settings.playlistSettings) {songSuggest = songSuggest};

//Add up to 100 oldest song to playlist
//Add up to 100 oldest song to playlist that has not been banned, and is within given parameters.
songSuggest.status = "Finding 100 Oldest";
playlist.AddSongs(songSuggest.activePlayer.GetOldest(100, settings.ignoreAccuracyEqualAbove, settings.ignorePlayedDays));
List<String> oldestSongs = songSuggest.activePlayer.scores
.Where(c => c.Value.accuracy < settings.ignoreAccuracyEqualAbove) //Ignore high Acc
.Where(c => c.Value.timeSet < DateTime.UtcNow.AddDays(-settings.ignorePlayedDays)) //Ignore newest plays
.OrderBy(c => c.Value.timeSet) //Sort list by oldest
.Select(c => c.Value.songID) //Get the ID of the songs
.Except(songSuggest.songBanning.GetPermaBannedIDs()) //Remove PermaBanned songs
.Take(100) //Get up to 100 songs
.ToList();

//Lets get them into the playlist.
playlist.AddSongs(oldestSongs);

//Generate and save a playlist with the selected songs in the playlist.
songSuggest.status = "Generating Playlist";
Expand Down
9 changes: 7 additions & 2 deletions TaohSongSuggest/SongSuggest/DataHandling/SongSuggest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ public SongSuggest(FilePathSettings filePathSettings, String userID)
public void GenerateSongSuggestions(SongSuggestSettings settings)
{
//Refresh Player Data
activePlayerID = settings.scoreSaberID;
RefreshActivePlayer();

//Create the Song Suggestion (so once the creation has been made additional information can be kept and loaded from it.
Expand All @@ -121,7 +122,7 @@ public void GenerateSongSuggestions(SongSuggestSettings settings)

//Requires a RankedSongsSuggest has been performed, then it evaluates the linked songs without updating the user via new settings.
//**Consider checks for updates of user, and that RankedSongsSuggest has already been performed**
public void Recalculate (SongSuggestSettings settings)
public void Recalculate(SongSuggestSettings settings)
{
songSuggest.settings = settings;
songSuggest.Recalculate();
Expand All @@ -134,6 +135,10 @@ public void ClearSongSuggestions()

public void GenerateOldestSongs(OldestSongSettings settings)
{
//Refresh Player Data
activePlayerID = settings.scoreSaberID;
RefreshActivePlayer();

oldestSongs = new OldestSongs(this);
oldestSongs.Oldest100ActivePlayer(settings);
status = "Ready";
Expand Down Expand Up @@ -166,7 +171,7 @@ public String GetSongRankingCount()
//Clear all Banned Songs
public void ClearBan()
{
songBanning = new SongBanning()
songBanning = new SongBanning()
{
songSuggest = this
};
Expand Down
2 changes: 1 addition & 1 deletion TaohSongSuggest/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"id": "SmartSongSuggest",
"name": "SmartSongSuggest",
"author": "HypersonicSharkz & Taoh",
"version": "1.5.18",
"version": "1.5.19",
"description": "Can make and update a playlist with ranked song suggestions, based on played and liked songs. Option to ban songs temporary or permanent. Can also make a playlist based on oldest ranked scores.",
"gameVersion": "1.21.0",
"dependsOn": {
Expand Down

0 comments on commit 6434080

Please sign in to comment.