#include "WingCommandlet.h"
#include "CoreMinimal.h"
#include "WingServer.h"
#include "Containers/Ticker.h"

UWingmanCommandlet::UWingmanCommandlet()
{
	IsClient = false;
	IsEditor = true;
	IsServer = false;
	LogToConsole = true;
}

int32 UWingmanCommandlet::Main(const FString& Params)
{
	// The UWingServer editor subsystem starts the server automatically.
	// We just need to tick it, since FTickableEditorObject doesn't tick in commandlet mode.
	double LastTime = FPlatformTime::Seconds();

	while (!IsEngineExitRequested())
	{
		double CurrentTime = FPlatformTime::Seconds();
		double DeltaTime = CurrentTime - LastTime;
		LastTime = CurrentTime;
		FTSTicker::GetCoreTicker().Tick(DeltaTime);
		UWingServer::TickServer(DeltaTime);
		FPlatformProcess::Sleep(0.01f);
	}

	return 0;
}
