void AMobileOpenCVCharacter::TouchUpdate(const ETouchIndex::Type FingerIndex, const FVector Location)
{
	if ((TouchItem.bIsPressed == true) && ( TouchItem.FingerIndex==FingerIndex))
	{
		if (TouchItem.bIsPressed)
		{
			if (GetWorld() != nullptr)
			{
				UGameViewportClient* ViewportClient = GetWorld()->GetGameViewport();
				if (ViewportClient != nullptr)
				{
					FVector MoveDelta = Location - TouchItem.Location;
					FVector2D ScreenSize;
					ViewportClient->GetViewportSize(ScreenSize);
					FVector2D ScaledDelta = FVector2D( MoveDelta.X, MoveDelta.Y) / ScreenSize;									
					if (ScaledDelta.X != 0.0f)
					{
						TouchItem.bMoved = true;
						float Value = ScaledDelta.X * BaseTurnRate;
						AddControllerYawInput(Value);
					}
					if (ScaledDelta.Y != 0.0f)
					{
						TouchItem.bMoved = true;
						float Value = ScaledDelta.Y* BaseTurnRate;
						AddControllerPitchInput(Value);
					}
					TouchItem.Location = Location;
				}
				TouchItem.Location = Location;
			}
		}
	}
}
void FGameLiveStreaming::OnSlateWindowRenderedDuringBroadcasting( SWindow& SlateWindow, void* ViewportRHIPtr )
{
	// If we're streaming live video/audio, we'll go ahead and push new video frames here
	UGameViewportClient* GameViewportClient = GEngine->GameViewport;
	if( IsBroadcastingGame() && GameViewportClient != nullptr )
	{
		// We only care about our own Slate window
		if( GameViewportClient->GetWindow() == SlateWindow.AsShared() )
		{
			// Check to see if we're streaming live video.  If so, we'll want to push new frames to be broadcast.
			if( LiveStreamer->IsReadyForVideoFrames() )
			{
				// Check to see if there are any video frames ready to push
				BroadcastGameVideoFrame();

				// Start copying next game video frame
				const FViewportRHIRef* ViewportRHI = ( const FViewportRHIRef* )ViewportRHIPtr;
				StartCopyingNextGameVideoFrame( *ViewportRHI );
			}
		}
	}
	else
	{
		// No longer broadcasting.  The live streaming service may have been interrupted.
		StopBroadcastingGame();
	}
}
/*
* Putting my own functionality in the TouchUpdate; this way we can swipe up/down/left/right from the center
* of the screen and move the character in that direction.
*/
void ASterlingResortsCharacter::TouchUpdate(const ETouchIndex::Type FingerIndex, const FVector Location)
{
    if ((TouchItem.bIsPressed == true) && (TouchItem.FingerIndex == FingerIndex))
    {
        if (TouchItem.bIsPressed)
        {
            if (GetWorld() != nullptr)
            {
                UGameViewportClient* ViewportClient = GetWorld()->GetGameViewport();
                if (ViewportClient != nullptr)
                {
                    FVector2D ScreenSize;
                    ViewportClient->GetViewportSize(ScreenSize);
                    FVector2D ScreenCenter = ScreenSize / 2.0f;

                    FVector MoveDelta = Location - TouchItem.Location;
                    FVector2D ScaledDelta = FVector2D(MoveDelta.X, MoveDelta.Y) / ScreenSize;
                    //FVector2D ScaledDelta = FVector2D(MoveDelta.X - ScreenCenter.X, MoveDelta.Y - ScreenCenter.Y) / ScreenCenter;
                    if (ScaledDelta.X != 0.0f)
                    {
                        TouchItem.bMoved = true;
                        MoveRight(ScaledDelta.X * BaseTurnRate * -1.0f);
                    }
                    if (ScaledDelta.Y != 0.0f)
                    {
                        TouchItem.bMoved = true;
                        MoveForward(ScaledDelta.Y * BaseTurnRate * -1.0f);
                    }
                }
            }
        }
    }
}
void AFP_FirstPersonCharacter::TouchUpdate(const ETouchIndex::Type FingerIndex, const FVector Location)
{
	// If we are processing a touch event and this index matches the initial touch event process movement
	if ((TouchItem.bIsPressed == true) && (TouchItem.FingerIndex == FingerIndex))
	{
		if (GetWorld() != nullptr)
		{
			UGameViewportClient* ViewportClient = GetWorld()->GetGameViewport();
			if (ViewportClient != nullptr)
			{
				FVector MoveDelta = Location - TouchItem.Location;
				FVector2D ScreenSize;
				ViewportClient->GetViewportSize(ScreenSize);
				FVector2D ScaledDelta = FVector2D(MoveDelta.X, MoveDelta.Y) / ScreenSize;
				if (ScaledDelta.X != 0.0f)
				{
					TouchItem.bMoved = true;
					float Value = ScaledDelta.X * BaseTurnRate;
					AddControllerYawInput(Value);
				}
				if (ScaledDelta.Y != 0.0f)
				{
					TouchItem.bMoved = true;
					float Value = ScaledDelta.Y* BaseTurnRate;
					AddControllerPitchInput(Value);
				}
				TouchItem.Location = Location;
			}
			TouchItem.Location = Location;
		}
	}
}
void ATutorialGameHUD::PostInitializeComponents()
{
    Super::PostInitializeComponents();

    if (GEngine && GEngine->GameViewport)
    {
        UGameViewportClient* Viewport = GEngine->GameViewport;

        SAssignNew(GameHUD, STutorialGameHUDUI)
        .OwnerHUD(TWeakObjectPtr<ATutorialGameHUD>(this));

        Viewport->AddViewportWidgetContent(
            SNew(SWeakWidget).PossiblyNullContent(GameHUD.ToSharedRef())
        );
    }
}
Example #6
0
void ULucyFunctions::SetMouseLockedToViewport(const bool Locked)
{
	if (GEngine == nullptr)
	{
		return;
	}

	UGameViewportClient* ViewportClient = GEngine->GameViewport;
	if (ViewportClient == nullptr)
	{
		return;
	}

	TSharedPtr<SViewport> ViewportWidget = ViewportClient->GetGameViewportWidget();
	if (!ViewportWidget.IsValid())
	{
		return;
	}

	TArray<APlayerController*> LocalPlayerControllers;
	GEngine->GetAllLocalPlayerControllers(LocalPlayerControllers);

	for (APlayerController* LocalPlayerController : LocalPlayerControllers)
	{
		if (LocalPlayerController == nullptr)
		{
			continue;
		}

		ULocalPlayer* LocalPlayer = Cast<ULocalPlayer>(LocalPlayerController->Player);
		if (LocalPlayer == nullptr)
		{
			continue;
		}

		if (Locked)
		{
			LocalPlayer->GetSlateOperations().LockMouseToWidget(ViewportWidget.ToSharedRef());
		}
		else
		{
			LocalPlayer->GetSlateOperations().ReleaseMouseLock();
		}
	}
}
Example #7
0
void AECommanderPawn::Tick(float DeltaSeconds)
{
	Super::Tick(DeltaSeconds);

	// Get the game viewport and make sure it exists as there is no
	// guarantee that it does.
	UGameViewportClient* GameViewport = GEngine->GameViewport;
	if (!GameViewport)
	{
		return;
	}

	// Get the position of the mouse on the screen.
	FVector2D MousePosition;
	GameViewport->GetMousePosition(MousePosition);

	// Get the size of the screen.
	FVector2D ViewportSize;
	GameViewport->GetViewportSize(ViewportSize);

	// Make sure the game view port has focus (contains the mouse).
	if (!GameViewport->IsFocused(GameViewport->Viewport))
	{
		return;
	}

	// Check if the mouse is at the left or right side of the
	// screen and move accordingly.
	if (MousePosition.X < CameraScrollBoundary)
	{
	}
	else if ((ViewportSize.X - MousePosition.X) < CameraScrollBoundary)
	{
	}

	// Check if the mouse is at the top or bottom of the screen
	// and move accordingly.
	if (MousePosition.Y < CameraScrollBoundary)
	{
	}
	else if ((ViewportSize.Y - MousePosition.Y) < CameraScrollBoundary)
	{
	}
}
Example #8
0
void FWebMRecord::OnSlateWindowRenderedDuringCapture(SWindow& SlateWindow, void* ViewportRHIPtr)
{
	// Probably need to verify that this is the window we want, but not sure yet

	UGameViewportClient* GameViewportClient = GEngine->GameViewport;
	if (bRecording && GameViewportClient != nullptr)
	{
		if (GameViewportClient->GetWindow() == SlateWindow.AsShared())
		{
			if (VideoDeltaTimeAccum >= VideoFrameDelay)
			{
				//UE_LOG(LogUTWebM, Log, TEXT("Saving video frame %f"), VideoDeltaTimeAccum);

				SaveCurrentFrameToDisk();

				const FViewportRHIRef* ViewportRHI = (const FViewportRHIRef*)ViewportRHIPtr;
				StartCopyingNextGameFrame(*ViewportRHI);
			}
		}
	}
}
void AMainCameraSpecPawn::Tick(float DeltaSeconds) {
	Super::Tick(DeltaSeconds);

	FVector2D MousePosition;
	FVector2D ViewportSize;

	UGameViewportClient* GameViewport = GEngine->GameViewport;

	check(GameViewport);
	GameViewport->GetViewportSize(ViewportSize);

	// Check if input is detectable
	if (GameViewport->IsFocused(GameViewport->Viewport) &&
		GameViewport->GetMousePosition(MousePosition) &&
		bCanMoveCamera) {

		// Edge of screen movement
		if (MousePosition.X < CameraScrollBounds) {
			YMovement = -1.0f;
		} else if (ViewportSize.X - MousePosition.X < CameraScrollBounds) {
			YMovement = 1.0f;
		}

		if (MousePosition.Y < CameraScrollBounds) {
			XMovement = 1.0f;
		}
		else if (ViewportSize.Y - MousePosition.Y < CameraScrollBounds) {
			XMovement = -1.0f;
		}

		// movement
		MoveCameraForward(XMovement * FastMoveMultiplier * DeltaSeconds);
		MoveCameraRight(YMovement * FastMoveMultiplier * DeltaSeconds);

	}
	
}
int32 UUnitTestCommandlet::Main(const FString& Params)
{
	// @todo #JohnBLowPri: Fix StandaloneRenderer support for static builds
#if IS_MONOLITHIC
	UE_LOG(LogUnitTest, Log, TEXT("NetcodeUnitTest commandlet not currently supported in static/monolithic builds"));

#else
	GIsRequestingExit = false;

	// @todo #JohnBLowPri: Steam detection doesn't seem to work this early on, but does work further down the line;
	//				try to find a way, to detect it as early as possible

	// NetcodeUnitTest is not compatible with Steam; if Steam is running/detected, abort immediately
	// @todo #JohnBLowPri: Add support for Steam
	if (NUTNet::IsSteamNetDriverAvailable())
	{
		UE_LOG(LogUnitTest, Log, TEXT("NetcodeUnitTest does not currently support Steam. Close Steam before running."));
		GIsRequestingExit = true;
	}

	if (!GIsRequestingExit)
	{
		GIsRunning = true;

		// Hack-set the engine GameViewport, so that setting GIsClient, doesn't cause an auto-exit
		// @todo JohnB: If you later remove the GIsClient setting code below, remove this as well
		if (GEngine->GameViewport == NULL)
		{
			UGameEngine* GameEngine = Cast<UGameEngine>(GEngine);

			// GameInstace = GameEngine->GameInstance;
			UGameInstance* GameInstance = GET_PRIVATE(UGameEngine, GameEngine, GameInstance);

			if (GameEngine != NULL)
			{
				UGameViewportClient* NewViewport = NewObject<UGameViewportClient>(GameEngine);
				FWorldContext* CurContext = GameInstance->GetWorldContext();

				GameEngine->GameViewport = NewViewport;
				NewViewport->Init(*CurContext, GameInstance);

				// Set the internal FViewport, for the new game viewport, to avoid another bit of auto-exit code
				NewViewport->Viewport = new FDummyViewport(NewViewport);

				// Set the main engine world context game viewport, to match the newly created viewport, in order to prevent crashes
				CurContext->GameViewport = NewViewport;
			}
		}


		// Now, after init stages are done, enable GIsClient for netcode and such
		GIsClient = true;


		// Before running any unit tests, create a world object, which will contain the unit tests manager etc.
		//	(otherwise, when the last unit test world is cleaned up, the unit test manager stops functioning)
		UWorld* UnitTestWorld = NUTNet::CreateUnitTestWorld(false);


		const TCHAR* ParamsRef = *Params;
		FString UnitTestParam = TEXT("");
		FString UnitCmd = TEXT("UnitTest ");


		if (FParse::Value(ParamsRef, TEXT("UnitTest="), UnitTestParam))
		{
			UnitCmd += UnitTestParam;
		}
		else
		{
			UnitCmd += TEXT("all");
		}

		GEngine->Exec(UnitTestWorld, *UnitCmd);


		// NOTE: This main loop is partly based off of FileServerCommandlet
		while (GIsRunning && !GIsRequestingExit)
		{
			GEngine->UpdateTimeAndHandleMaxTickRate();
			GEngine->Tick(FApp::GetDeltaTime(), false);

			if (FSlateApplication::IsInitialized())
			{
				FSlateApplication::Get().PumpMessages();
				FSlateApplication::Get().Tick();
			}


			// Execute deferred commands
			for (int32 DeferredCommandsIndex=0; DeferredCommandsIndex<GEngine->DeferredCommands.Num(); DeferredCommandsIndex++)
			{
				GEngine->Exec(UnitTestWorld, *GEngine->DeferredCommands[DeferredCommandsIndex], *GLog);
			}

			GEngine->DeferredCommands.Empty();


			FPlatformProcess::Sleep(0);


			// When the unit tests complete, open an exit-confirmation window, and when that closes, exit the main loop
			// NOTE: This will not execute, if the last open slate window is closed (such as when clicking 'yes' to 'abort all' dialog);
			//			in that circumstance, GIsRequestingExit gets set, by the internal engine code
			if (GUnitTestManager == NULL || !GUnitTestManager->IsRunningUnitTests())
			{
				if (bConfirmedExit || FApp::IsUnattended())
				{
					// Wait until the status window is closed, if it is still open, before exiting
					if (GUnitTestManager == NULL || !GUnitTestManager->StatusWindow.IsValid())
					{
						GIsRequestingExit = true;
					}
				}
				else if (!ConfirmDialog.IsValid())
				{
					FText CompleteMsg = FText::FromString(TEXT("Unit test commandlet complete."));
					FText CompleteTitle = FText::FromString(TEXT("Unit tests complete"));

					FOnLogDialogResult DialogCallback = FOnLogDialogResult::CreateLambda(
						[&](const TSharedRef<SWindow>& DialogWindow, EAppReturnType::Type Result, bool bNoResult)
						{
							if (DialogWindow == ConfirmDialog)
							{
								bConfirmedExit = true;
							}
						});

					ConfirmDialog = OpenLogDialog_NonModal(EAppMsgType::Ok, CompleteMsg, CompleteTitle, DialogCallback);


					// If the 'abort all' dialog was open, close it now as it is redundant;
					// can't close it before opening above dialog though, otherwise no slate windows, triggers an early exit
					if (GUnitTestManager != NULL && GUnitTestManager->AbortAllDialog.IsValid())
					{
						GUnitTestManager->AbortAllDialog->RequestDestroyWindow();

						GUnitTestManager->AbortAllDialog.Reset();
					}
				}
			}
		}

		// Cleanup the unit test world
		NUTNet::MarkUnitTestWorldForCleanup(UnitTestWorld, true);


		GIsRunning = false;
	}
#endif

	return (GWarn->Errors.Num() == 0 ? 0 : 1);
}
Example #11
0
void UGameEngine::Init(IEngineLoop* InEngineLoop)
{
	DECLARE_SCOPE_CYCLE_COUNTER(TEXT("UGameEngine Init"), STAT_GameEngineStartup, STATGROUP_LoadTime);

	// Call base.
	UEngine::Init(InEngineLoop);

#if USE_NETWORK_PROFILER
	FString NetworkProfilerTag;
	if( FParse::Value(FCommandLine::Get(), TEXT("NETWORKPROFILER="), NetworkProfilerTag ) )
	{
		GNetworkProfiler.EnableTracking(true);
	}
#endif

	// Load all of the engine modules that we need at startup that are not editor-related
	UGameEngine::LoadRuntimeEngineStartupModules();

	// Load and apply user game settings
	GetGameUserSettings()->LoadSettings();
	GetGameUserSettings()->ApplyNonResolutionSettings();

	// Create game instance.  For GameEngine, this should be the only GameInstance that ever gets created.
	{
		FStringClassReference GameInstanceClassName = GetDefault<UGameMapsSettings>()->GameInstanceClass;
		UClass* GameInstanceClass = (GameInstanceClassName.IsValid() ? LoadObject<UClass>(NULL, *GameInstanceClassName.ToString()) : UGameInstance::StaticClass());
		
		GameInstance = NewObject<UGameInstance>(this, GameInstanceClass);

		GameInstance->InitializeStandalone();
	}
 
//  	// Creates the initial world context. For GameEngine, this should be the only WorldContext that ever gets created.
//  	FWorldContext& InitialWorldContext = CreateNewWorldContext(EWorldType::Game);

	// Initialize the viewport client.
	UGameViewportClient* ViewportClient = NULL;
	if(GIsClient)
	{
		ViewportClient = NewObject<UGameViewportClient>(this, GameViewportClientClass);
		ViewportClient->Init(*GameInstance->GetWorldContext(), GameInstance);
		GameViewport = ViewportClient;
		GameInstance->GetWorldContext()->GameViewport = ViewportClient;
	}

	bCheckForMovieCapture = true;

	// Attach the viewport client to a new viewport.
	if(ViewportClient)
	{
		// This must be created before any gameplay code adds widgets
		bool bWindowAlreadyExists = GameViewportWindow.IsValid();
		if (!bWindowAlreadyExists)
		{
			GameViewportWindow = CreateGameWindow();
		}

		CreateGameViewport( ViewportClient );

		if( !bWindowAlreadyExists )
		{
			SwitchGameWindowToUseGameViewport();
		}

		FString Error;
		if(ViewportClient->SetupInitialLocalPlayer(Error) == NULL)
		{
			UE_LOG(LogEngine, Fatal,TEXT("%s"),*Error);
		}

		UGameViewportClient::OnViewportCreated().Broadcast();
	}

	GameInstance->StartGameInstance();


	UE_LOG(LogInit, Display, TEXT("Game Engine Initialized.") );

	// for IsInitialized()
	bIsInitialized = true;
}
Example #12
0
void UGameEngine::Init(IEngineLoop* InEngineLoop)
{
	DECLARE_SCOPE_CYCLE_COUNTER(TEXT("UGameEngine Init"), STAT_GameEngineStartup, STATGROUP_LoadTime);

	// Call base.
	UEngine::Init(InEngineLoop);

#if USE_NETWORK_PROFILER
	FString NetworkProfilerTag;
	if( FParse::Value(FCommandLine::Get(), TEXT("NETWORKPROFILER="), NetworkProfilerTag ) )
	{
		GNetworkProfiler.EnableTracking(true);
	}
#endif

	// Load and apply user game settings
	GetGameUserSettings()->LoadSettings();
	GetGameUserSettings()->ApplySettings();

	// Creates the initial world context. For GameEngine, this should be the only WorldContext that ever gets created.
	FWorldContext &InitialWorldContext = CreateNewWorldContext(EWorldType::Game);

	// Initialize the viewport client.
	UGameViewportClient* ViewportClient = NULL;
	if(GIsClient)
	{
		ViewportClient = ConstructObject<UGameViewportClient>(GameViewportClientClass,this);
		ViewportClient->SetReferenceToWorldContext(InitialWorldContext);
		GameViewport = ViewportClient;
		InitialWorldContext.GameViewport = ViewportClient;
	}

	bCheckForMovieCapture = true;

	// Attach the viewport client to a new viewport.
	if(ViewportClient)
	{
		// This must be created before any gameplay code adds widgets
		bool bWindowAlreadyExists = GameViewportWindow.IsValid();
		if (!bWindowAlreadyExists)
		{
			GameViewportWindow = CreateGameWindow();
		}

		CreateGameViewport( ViewportClient );

		if( !bWindowAlreadyExists )
		{
			SwitchGameWindowToUseGameViewport();
		}
		FString Error;
		if(!ViewportClient->Init(Error))
		{
			UE_LOG(LogEngine, Fatal,TEXT("%s"),*Error);
		}
	}

	// Create default URL.
	// @note:  if we change how we determine the valid start up map update LaunchEngineLoop's GetStartupMap()
	FURL DefaultURL;
	DefaultURL.LoadURLConfig( TEXT("DefaultPlayer"), GGameIni );

	// Enter initial world.
	EBrowseReturnVal::Type BrowseRet = EBrowseReturnVal::Failure;
	FString Error;
	TCHAR Parm[4096]=TEXT("");
	const TCHAR* Tmp = FCommandLine::Get();

#if UE_BUILD_SHIPPING
	// In shipping don't allow an override
	Tmp = TEXT("");
#endif // UE_BUILD_SHIPPING

	const UGameMapsSettings* GameMapsSettings = GetDefault<UGameMapsSettings>();
	const FString& DefaultMap = GameMapsSettings->GetGameDefaultMap();
	if (!FParse::Token(Tmp, Parm, ARRAY_COUNT(Parm), 0) || Parm[0] == '-')
	{
		FCString::Strcpy(Parm, *(DefaultMap + GameMapsSettings->LocalMapOptions));
	}
	FURL URL( &DefaultURL, Parm, TRAVEL_Partial );
	if( URL.Valid )
	{
		BrowseRet = Browse(InitialWorldContext, URL, Error );
	}

	// If waiting for a network connection, go into the starting level.
	if (BrowseRet != EBrowseReturnVal::Success && FCString::Stricmp(Parm, *DefaultMap) != 0)
	{
		const FText Message = FText::Format( NSLOCTEXT("Engine", "MapNotFound", "The map specified on the commandline '{0}' could not be found. Would you like to load the default map instead?"), FText::FromString( URL.Map ) );

		// the map specified on the command-line couldn't be loaded.  ask the user if we should load the default map instead
		if ( FCString::Stricmp(*URL.Map, *DefaultMap) != 0 &&
			FMessageDialog::Open( EAppMsgType::OkCancel, Message ) != EAppReturnType::Ok)
		{
			// user canceled (maybe a typo while attempting to run a commandlet)
			FPlatformMisc::RequestExit( false );
			return;
		}
		else
		{
			BrowseRet = Browse(InitialWorldContext, FURL(&DefaultURL, *(DefaultMap + GameMapsSettings->LocalMapOptions), TRAVEL_Partial), Error);
		}
	}

	// Handle failure.
	if( BrowseRet != EBrowseReturnVal::Success )
	{
		UE_LOG(LogLoad, Fatal, TEXT("%s"), *FString::Printf( TEXT("Failed to enter %s: %s. Please check the log for errors."), Parm, *Error) );
	}
	UE_LOG(LogInit, Display, TEXT("Game Engine Initialized.") );

	// for IsInitialized()
	bIsInitialized = true;
}