// Copyright (c) Microsoft Corporation. 
// Licensed under the MIT license.

#include "SimplygonTestsHelper.h"

#include "HierarchicalLODUtilitiesModule.h"
#include "HierarchicalLODProxyProcessor.h"
#include "HAL/ThreadManager.h"

DEFINE_LOG_CATEGORY_STATIC(LogSimplygonTestsHelper, All, All);

bool SimplygonTestsHelper::WaitForHLODProcessor(const double Timeout)
{
    FHierarchicalLODUtilitiesModule& Module = FModuleManager::LoadModuleChecked<FHierarchicalLODUtilitiesModule>("HierarchicalLODUtilities");
    FHierarchicalLODProxyProcessor* Processor = Module.GetProxyProcessor();

    double StartTime = FPlatformTime::Seconds();
    double Duration = 0.0;

    while (Processor->IsProxyGenerationRunning())
    {
        Duration = FPlatformTime::Seconds() - StartTime;
        if ( Duration >= Timeout)
			return false;

        FTicker::GetCoreTicker().Tick(FApp::GetDeltaTime());
        FThreadManager::Get().Tick();
        FTaskGraphInterface::Get().ProcessThreadUntilIdle(ENamedThreads::GameThread);
        FPlatformProcess::Sleep(0.1f);
    }

	return true;
}