mirror of
https://github.com/GTA-ASM/SanAndreasUnity
synced 2024-11-26 05:50:18 +00:00
add multiple iterations when waiting for jobs to finish
This commit is contained in:
parent
0b3fa3a436
commit
205820733b
1 changed files with 31 additions and 16 deletions
|
@ -297,6 +297,7 @@ namespace SanAndreasUnity.Editor
|
|||
$"\r\nobjects processed {i}/{objectsToExport.Length}",
|
||||
i / (float)objectsToExport.Length,
|
||||
nextNextIndex / (float)objectsToExport.Length,
|
||||
4,
|
||||
isCanceledRef))
|
||||
yield return item;
|
||||
|
||||
|
@ -347,35 +348,49 @@ namespace SanAndreasUnity.Editor
|
|||
EditorUtility.DisplayDialog("", $"Finished ! \r\n\r\n{displayText}", "Ok");
|
||||
}
|
||||
|
||||
private static IEnumerable WaitForCompletionOfLoadingJobs(string textSuffix, float startPerc, float endPerc, Ref<bool> isCanceledRef)
|
||||
private static IEnumerable WaitForCompletionOfLoadingJobs(
|
||||
string textSuffix,
|
||||
float startPerc,
|
||||
float endPerc,
|
||||
int numIterations,
|
||||
Ref<bool> isCanceledRef)
|
||||
{
|
||||
if (numIterations < 1)
|
||||
throw new ArgumentOutOfRangeException(nameof(numIterations));
|
||||
|
||||
isCanceledRef.value = false;
|
||||
|
||||
float diffPerc = endPerc - startPerc;
|
||||
|
||||
long initialNumPendingJobs = LoadingThread.Singleton.GetNumPendingJobs();
|
||||
|
||||
// TODO: this should be removed
|
||||
yield return null; // this must be done, otherwise LoadingThread does not start processing any job
|
||||
|
||||
long numPendingJobs;
|
||||
for (int i = 0; i < numIterations; i++)
|
||||
{
|
||||
long initialNumPendingJobs = LoadingThread.Singleton.GetNumPendingJobs();
|
||||
long numPendingJobs = initialNumPendingJobs;
|
||||
|
||||
do
|
||||
{
|
||||
LoadingThread.Singleton.UpdateJobs();
|
||||
|
||||
numPendingJobs = LoadingThread.Singleton.GetNumPendingJobs();
|
||||
long numJobsProcessed = initialNumPendingJobs - numPendingJobs;
|
||||
|
||||
float currentPerc = startPerc + diffPerc * (numJobsProcessed / (float)initialNumPendingJobs);
|
||||
float currentPerc = startPerc + diffPerc * (0 == initialNumPendingJobs ? 0f : numJobsProcessed / (float)initialNumPendingJobs);
|
||||
if (EditorUtility.DisplayCancelableProgressBar("", $"Waiting for async jobs to finish ({numJobsProcessed}/{initialNumPendingJobs})...{textSuffix}", currentPerc))
|
||||
{
|
||||
isCanceledRef.value = true;
|
||||
yield break;
|
||||
}
|
||||
|
||||
System.Threading.Thread.Sleep(10); // don't interact with background thread too often, and also reduce CPU usage
|
||||
LoadingThread.Singleton.UpdateJobs();
|
||||
|
||||
//System.Threading.Thread.Sleep(10); // don't interact with background thread too often, and also reduce CPU usage
|
||||
yield return null;
|
||||
|
||||
numPendingJobs = LoadingThread.Singleton.GetNumPendingJobs();
|
||||
initialNumPendingJobs = Math.Max(initialNumPendingJobs, numPendingJobs);
|
||||
|
||||
} while (numPendingJobs > 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue