UWorld* GetWorldForOnline(FName InstanceName)
{
	UWorld* World = NULL;
	if (InstanceName != FOnlineSubsystemImpl::DefaultInstanceName && InstanceName != NAME_None)
	{
		FWorldContext& WorldContext = GEngine->GetWorldContextFromHandleChecked(InstanceName);
		check(WorldContext.WorldType == EWorldType::Game || WorldContext.WorldType == EWorldType::PIE);
		World = WorldContext.World();
	}
	else
	{
		UGameEngine* GameEngine = Cast<UGameEngine>(GEngine);
		World = GameEngine ? GameEngine->GetGameWorld() : NULL;
	}

	return World;
}
Ejemplo n.º 2
0
	int UGameWindow::CreateGameWindow(HINSTANCE hInstance, LPWSTR lpCmdLine, int nCmdShow, LPWSTR lpAppName)
	{
		lstrcpynW(szTitle, lpAppName, MAX_LOADSTRING);
		lstrcpynW(szWindowClass, TEXT("MADEngine"), MAX_LOADSTRING);

		if (!UGameWindow::RegisterWindowClass(hInstance))
		{
			return FALSE;
		}

		// Perform application initialization
		if (!UGameWindow::InitInstance(hInstance, nCmdShow))
		{
			return FALSE;
		}

		// Set the working directory to the executable's location
		if (!UGameWindow::SetWorkingDirectory())
		{
			return FALSE;
		}

		// Start up engine
		UGameEngine gameEngine;
		if (!gameEngine.Init(utf8util::UTF8FromUTF16(lpCmdLine)))
		{
			return FALSE;
		}

		// Main loop
		while (UGameWindow::bContinue)
		{
			// Update the game
			gameEngine.Tick();
		}

		// Release mouse
		UGameWindow::CaptureCursor(false);

		// Shut down engine
		gameEngine.Shutdown();

		return UGameWindow::mReturnCode;
	}
// respond to requests from a companion app
static void WebServerDelegate(int32 UserIndex, const FString& Action, const FString& URL, const TMap<FString, FString>& Params, TMap<FString, FString>& Response)
{
    if (URL == TEXT("/index.html?scoreboard"))
    {
        FString ScoreboardStr = TEXT("{ \"scoreboard\" : [ ");

        // you shouldn't normally use this method to get a UWorld as it won't always be correct in a PIE context.
        // However, the PS4 companion app server will never run in the Editor.
        UGameEngine* GameEngine = CastChecked<UGameEngine>(GEngine);
        if (GameEngine)
        {
            UWorld* World = GameEngine->GetGameWorld();
            if (World)
            {
                ULocalPlayer *Player = GEngine->GetFirstGamePlayer(World);
                if (Player)
                {
                    // get the shoter game
                    AShooterGameState* const GameState = Cast<AShooterGameState>(Player->PlayerController->GetWorld()->GameState);


                    RankedPlayerMap Players;
                    GameState->GetRankedMap(0, Players);

                    bool bNeedsComma = false;
                    for (auto It = Players.CreateIterator(); It; ++It)
                    {
                        if (bNeedsComma)
                        {
                            ScoreboardStr += TEXT(" ,");
                        }
                        ScoreboardStr += FString::Printf(TEXT(" { \"n\" : \"%s\" , \"k\" : \"%d\" , \"d\" : \"%d\" }"), *It.Value()->GetShortPlayerName(), It.Value()->GetKills(), It.Value()->GetDeaths());
                        bNeedsComma = true;
                    }
                }

                ScoreboardStr += TEXT(" ] }");

                Response.Add(TEXT("Content-Type"), TEXT("text/html; charset=utf-8"));
                Response.Add(TEXT("Body"), ScoreboardStr);
            }
        }
    }
}
Ejemplo n.º 4
0
UUnitTestNetDriver* NUTNet::CreateUnitTestNetDriver(UWorld* InWorld)
{
	UUnitTestNetDriver* ReturnVal = NULL;
	UGameEngine* GameEngine = Cast<UGameEngine>(GEngine);

	if (GameEngine != NULL)
	{
		static int UnitTestNetDriverCount = 0;

		// Setup a new driver name entry
		bool bFoundDef = false;
		FName UnitDefName = TEXT("UnitTestNetDriver");

		for (int i=0; i<GameEngine->NetDriverDefinitions.Num(); i++)
		{
			if (GameEngine->NetDriverDefinitions[i].DefName == UnitDefName)
			{
				bFoundDef = true;
				break;
			}
		}

		if (!bFoundDef)
		{
			FNetDriverDefinition NewDriverEntry;

			NewDriverEntry.DefName = UnitDefName;
			NewDriverEntry.DriverClassName = *UUnitTestNetDriver::StaticClass()->GetPathName();
			NewDriverEntry.DriverClassNameFallback = *UIpNetDriver::StaticClass()->GetPathName();

			GameEngine->NetDriverDefinitions.Add(NewDriverEntry);
		}


		FName NewDriverName = *FString::Printf(TEXT("UnitTestNetDriver_%i"), UnitTestNetDriverCount++);

		// Now create a reference to the driver
		if (GameEngine->CreateNamedNetDriver(InWorld, NewDriverName, UnitDefName))
		{
			ReturnVal = Cast<UUnitTestNetDriver>(GameEngine->FindNamedNetDriver(InWorld, NewDriverName));
		}


		if (ReturnVal != NULL)
		{
			ReturnVal->SetWorld(InWorld);
			InWorld->SetNetDriver(ReturnVal);

			UE_LOG(LogUnitTest, Log, TEXT("CreateUnitTestNetDriver: Created named net driver: %s, NetDriverName: %s"),
					*ReturnVal->GetFullName(), *ReturnVal->NetDriverName.ToString());
		}
		else
		{
			UE_LOG(LogUnitTest, Log, TEXT("CreateUnitTestNetDriver: CreateNamedNetDriver failed"));
		}
	}
	else
	{
		UE_LOG(LogUnitTest, Log, TEXT("CreateUnitTestNetDriver: GameEngine is NULL"));
	}

	return ReturnVal;
}