Skip to content

Commit

Permalink
Add public API to specify console variables for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
slonopotamus committed Aug 5, 2024
1 parent 401cd76 commit ff6832a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
15 changes: 10 additions & 5 deletions Source/UEST/Private/ScopedGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ static int32 NumScopedGames = 0;

static TUniquePtr<FCVarsGuard> CVarsGuard;

FScopedGameInstance::FScopedGameInstance(TSubclassOf<UGameInstance> GameInstanceClass, const bool bGarbageCollectOnDestroy)
FScopedGameInstance::FScopedGameInstance(TSubclassOf<UGameInstance> GameInstanceClass, const bool bGarbageCollectOnDestroy, const TMap<FString, FString>& CVars)
: GameInstanceClass{MoveTemp(GameInstanceClass)}
, LastInstanceId{0}
, bGarbageCollectOnDestroy{bGarbageCollectOnDestroy}
Expand All @@ -65,9 +65,10 @@ FScopedGameInstance::FScopedGameInstance(TSubclassOf<UGameInstance> GameInstance
{
CVarsGuard = MakeUnique<FCVarsGuard>();

// Client runs DNS lookup in separate thread without any way to wait for it (except sleeping real time)
// So just disable it for now because we know that we connect via IP address
CVarsGuard->ConsoleVariableGuards.Emplace(IConsoleManager::Get().FindConsoleVariable(TEXT("net.IpConnectionDisableResolution")),TEXT("1"));
for (const auto& CVar : CVars)
{
CVarsGuard->ConsoleVariableGuards.Emplace(IConsoleManager::Get().FindConsoleVariable(*CVar.Key), *CVar.Value);
}
}

++NumScopedGames;
Expand Down Expand Up @@ -405,9 +406,13 @@ FScopedGame::FScopedGame()
{
GameInstanceClass = UGameInstance::StaticClass();
}

// Client runs DNS lookup in separate thread without any way to wait for it (except sleeping real time)
// So just disable it for now because we know that we connect via IP address
CVars.Add(TEXT("net.IpConnectionDisableResolution"), TEXT("1"));
}

FScopedGameInstance FScopedGame::Create() const
{
return FScopedGameInstance{GameInstanceClass, bGarbageCollectOnDestroy};
return FScopedGameInstance{GameInstanceClass, bGarbageCollectOnDestroy, CVars};
}
9 changes: 8 additions & 1 deletion Source/UEST/Public/ScopedGame.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class FScopedGameInstance : FNoncopyable
public:
static constexpr auto DefaultStepSeconds = 0.1f;

explicit FScopedGameInstance(TSubclassOf<UGameInstance> GameInstanceClass, bool bGarbageCollectOnDestroy);
explicit FScopedGameInstance(TSubclassOf<UGameInstance> GameInstanceClass, const bool bGarbageCollectOnDestroy, const TMap<FString, FString>& CVars);

FScopedGameInstance(FScopedGameInstance&& Other);

Expand Down Expand Up @@ -59,6 +59,7 @@ class FScopedGame
{
TSubclassOf<UGameInstance> GameInstanceClass;
bool bGarbageCollectOnDestroy = true;
TMap<FString, FString> CVars;

public:
FScopedGame();
Expand All @@ -69,6 +70,12 @@ class FScopedGame
return *this;
}

FScopedGame& WithConsoleVariable(FString Name, FString Value)
{
CVars.Add(MoveTemp(Name), MoveTemp(Value));
return *this;
}

FScopedGame& WithGarbageCollectOnDestroy(const bool bInGarbageCollectOnDestroy)
{
bGarbageCollectOnDestroy = bInGarbageCollectOnDestroy;
Expand Down

0 comments on commit ff6832a

Please sign in to comment.