void FEditorModeTools::JumpToBookmark( uint32 InIndex, bool bShouldRestoreLevelVisibility, FEditorViewportClient* InViewportClient )
{
	UWorld* World = InViewportClient->GetWorld();
	if ( World )
	{
		AWorldSettings* WorldSettings = World->GetWorldSettings();

		// Can only jump to a pre-existing bookmark
		if ( WorldSettings && InIndex < AWorldSettings::MAX_BOOKMARK_NUMBER && WorldSettings->BookMarks[ InIndex ] )
		{
			const UBookMark* CurBookMark = WorldSettings->BookMarks[ InIndex ];
			check(CurBookMark);

			// Set all level editing cameras to this bookmark
			for( int32 v = 0 ; v < GEditor->LevelViewportClients.Num() ; v++ )
			{
				GEditor->LevelViewportClients[v]->SetViewLocation( CurBookMark->Location );
				if( !GEditor->LevelViewportClients[v]->IsOrtho() )
				{
					GEditor->LevelViewportClients[v]->SetViewRotation( CurBookMark->Rotation );
				}
				GEditor->LevelViewportClients[v]->Invalidate();
			}
		}
	}
}
void FPhATEdPreviewViewportClient::Tick(float DeltaSeconds)
{
	FEditorViewportClient::Tick(DeltaSeconds);

	UWorld* World = SharedData->PreviewScene.GetWorld();

	if (SharedData->bRunningSimulation)
	{
		// check if PIE disabled the realtime viewport and quit sim if so
		if (!bIsRealtime)
		{
			SharedData->ToggleSimulation();
			
			Invalidate();
		}

		AWorldSettings* Setting = World->GetWorldSettings();
		Setting->WorldGravityZ = SharedData->bNoGravitySimulation ? 0.0f : UPhysicsSettings::Get()->DefaultGravityZ*SharedData->EditorSimOptions->GravScale;
		Setting->bWorldGravitySet = true;

		// We back up the transforms array now
		SharedData->EditorSkelComp->AnimationSpaceBases = SharedData->EditorSkelComp->GetComponentSpaceTransforms();
		SharedData->EditorSkelComp->SetPhysicsBlendWeight(SharedData->EditorSimOptions->PhysicsBlend);
		SharedData->EditorSkelComp->bUpdateJointsFromAnimation = SharedData->EditorSimOptions->bUpdateJointsFromAnimation;
		SharedData->EditorSkelComp->PhysicsTransformUpdateMode = SharedData->EditorSimOptions->PhysicsUpdateMode;


		static FPhysicalAnimationData EmptyProfile;

		SharedData->PhysicalAnimationComponent->ApplyPhysicalAnimationProfileBelow(NAME_None, SharedData->PhysicsAsset->CurrentPhysicalAnimationProfileName, /*Include Self=*/true, /*Clear Not Found=*/true);
		
	}

	World->Tick(LEVELTICK_All, DeltaSeconds * SharedData->EditorSimOptions->TimeDilation);
}
void UWorldComposition::UpdateStreamingState()
{
	UWorld* PlayWorld = GetWorld();
	check(PlayWorld);

	// Commandlets and Dedicated server does not use distance based streaming and just loads everything
	if (IsRunningCommandlet() || PlayWorld->GetNetMode() == NM_DedicatedServer)
	{
		UpdateStreamingState(FVector::ZeroVector);
		return;
	}
	
	int32 NumPlayers = GEngine->GetNumGamePlayers(PlayWorld);
	if (NumPlayers == 0)
	{
		return;
	}

	// calculate centroid location using local players views
	bool bCinematic = false;
	FVector CentroidLocation = FVector::ZeroVector;
	TArray<FVector, TInlineAllocator<16>> Locations;
		
	for (int32 PlayerIndex = 0; PlayerIndex < NumPlayers; ++PlayerIndex)
	{
		ULocalPlayer* Player = GEngine->GetGamePlayer(PlayWorld, PlayerIndex);
		if (Player && Player->PlayerController)
		{
			FVector ViewLocation;
			FRotator ViewRotation;
			Player->PlayerController->GetPlayerViewPoint(ViewLocation, ViewRotation);
			Locations.Add(ViewLocation);
			CentroidLocation+= ViewLocation;
			bCinematic|= Player->PlayerController->bCinematicMode;
		}
	}

	// In case there is no valid views don't bother updating level streaming state
	if (Locations.Num())
	{
		CentroidLocation/= Locations.Num();
		if (PlayWorld->GetWorldSettings()->bEnableWorldOriginRebasing)
		{
			EvaluateWorldOriginLocation(CentroidLocation);
		}
		
		if (bCinematic)
		{
			UpdateStreamingStateCinematic(Locations.GetData(), Locations.Num());
		}
		else
		{
			UpdateStreamingState(Locations.GetData(), Locations.Num());
		}
	}
}
bool FEditorModeTools::CheckBookmark( uint32 InIndex, FEditorViewportClient* InViewportClient )
{
	UWorld* World = InViewportClient->GetWorld();
	if ( World )
	{
		AWorldSettings* WorldSettings = World->GetWorldSettings();
		if ( WorldSettings && InIndex < AWorldSettings::MAX_BOOKMARK_NUMBER && WorldSettings->BookMarks[ InIndex ] )
		{
			return ( WorldSettings->BookMarks[ InIndex ] ? true : false );
		}
	}

	return false;
}
/**
 * Clears a bookmark
 */
void FEditorModeTools::ClearBookmark( uint32 InIndex, FEditorViewportClient* InViewportClient )
{
	UWorld* World = InViewportClient->GetWorld();
	if( World )
	{
		AWorldSettings* pWorldSettings = World->GetWorldSettings();

		// Verify the index is valid for the bookmark
		if ( pWorldSettings && InIndex < AWorldSettings::MAX_BOOKMARK_NUMBER )
		{
			pWorldSettings->BookMarks[ InIndex ] = NULL;
		}
	}
}
float UAirBlueprintLib::GetWorldToMetersScale(const AActor* context)
{
    float w2m = 100.f;
    UWorld* w = context->GetWorld();
    if (w != nullptr)
    {
        AWorldSettings* ws = w->GetWorldSettings();
        if (ws != nullptr)
        {
            w2m = ws->WorldToMeters;
        }
    }
    return w2m;
}
void UOSVRInputComponent::InitializeComponent()
{
	Super::InitializeComponent();

	WorldToMetersScale = 100.f;
	UWorld* w = GetWorld();
	if (w != nullptr)
	{
		AWorldSettings* ws = w->GetWorldSettings();
		if (ws != nullptr)
		{
			WorldToMetersScale = ws->WorldToMeters;
		}
	}

	auto InterfaceCollection = IOSVR::Get().GetEntryPoint()->GetInterfaceCollection();

	OSVRInterfaceCollection::RegistrationToken RegToken =
		InterfaceCollection->RegisterOnStateChangedCallback(
			[=](OSVRInterface* Interface, uint32 State)
			{
		/*
		FTransform Pose;
		if (((State & OSVRInterface::POSE_STATE_AVAILABLE) > 0) && Interface->GetPose(Pose, false))
		{
			Pose.ScaleTranslation(WorldToMetersScale);
			OnPoseChanged.Broadcast(Interface->GetName(), Pose);
		}
		*/

		FVector Position;
		if (((State & OSVRInterface::POSITION_STATE_AVAILABLE) > 0) && Interface->GetPosition(Position, false))
			OnPositionChanged.Broadcast(Interface->GetName(), Position * WorldToMetersScale);

		FQuat Orientation;
		if (((State & OSVRInterface::ORIENTATION_STATE_AVAILABLE) > 0) && Interface->GetOrientation(Orientation, false))
			OnOrientationChanged.Broadcast(Interface->GetName(), Orientation.Rotator());

		float Analog;
		if (((State & OSVRInterface::ANALOG_STATE_AVAILABLE) > 0) && Interface->GetAnalogState(Analog, false))
			OnAnalogValueChanged.Broadcast(Interface->GetName(), Analog);

		uint8 Button;
		if (((State & OSVRInterface::BUTTON_STATE_AVAILABLE) > 0) && Interface->GetButtonState(Button, false))
			OnButtonStateChanged.Broadcast(Interface->GetName(), EButtonState::Type(Button));
			});

	RegistrationToken = RegToken.Token;
}
void FHierarchicalLODOutlinerModule::OnHLODLevelsArrayChangedEvent()
{
	UWorld* CurrentWorld = nullptr;
	
	// Get the correct UWorld instance
	for (const FWorldContext& Context : GEngine->GetWorldContexts())
	{
		if (Context.WorldType == EWorldType::PIE)
		{
			CurrentWorld = Context.World();
			break;
		}
		else if (Context.WorldType == EWorldType::Editor)
		{
			CurrentWorld = Context.World();
		}
	}

	AWorldSettings* WorldSettings = (CurrentWorld) ? CurrentWorld->GetWorldSettings() : nullptr;

	if (WorldSettings)
	{
		TArray<FHierarchicalSimplification>& HierarchicalLODSetup = WorldSettings->HierarchicalLODSetup;
		int32 NumHLODLevels = WorldSettings->NumHLODLevels;

		if (HierarchicalLODSetup.Num() > 1 && HierarchicalLODSetup.Num() > NumHLODLevels)
		{
			// HLOD level was added, use previous level settings to "guess" new settings
			FHierarchicalSimplification& NewLevelSetup = HierarchicalLODSetup.Last();
			const FHierarchicalSimplification& OldLastLevelSetup = HierarchicalLODSetup[HierarchicalLODSetup.Num() - 2];

			NewLevelSetup.bSimplifyMesh = OldLastLevelSetup.bSimplifyMesh;
			NewLevelSetup.MergeSetting = OldLastLevelSetup.MergeSetting;
			NewLevelSetup.ProxySetting = OldLastLevelSetup.ProxySetting;

			NewLevelSetup.DesiredBoundRadius = OldLastLevelSetup.DesiredBoundRadius * 2.5f;
			NewLevelSetup.DesiredFillingPercentage = FMath::Max(OldLastLevelSetup.DesiredFillingPercentage * 0.75f, 1.0f);
			NewLevelSetup.TransitionScreenSize = OldLastLevelSetup.TransitionScreenSize * 0.75f;
			NewLevelSetup.MinNumberOfActorsToBuild = OldLastLevelSetup.MinNumberOfActorsToBuild;
		}
		else if (HierarchicalLODSetup.Num() < NumHLODLevels)
		{
			// HLOD Level was removed, now remove all LODActors for this level
			FHierarchicalLODUtilities::DeleteLODActorsInHLODLevel(CurrentWorld, NumHLODLevels - 1);
		}
	}
}
void FEditorModeTools::SetBookmark( uint32 InIndex, FEditorViewportClient* InViewportClient )
{
	UWorld* World = InViewportClient->GetWorld();
	if ( World )
	{
		AWorldSettings* WorldSettings = World->GetWorldSettings();

		// Verify the index is valid for the bookmark
		if ( WorldSettings && InIndex < AWorldSettings::MAX_BOOKMARK_NUMBER )
		{
			// If the index doesn't already have a bookmark in place, create a new one
			if ( !WorldSettings->BookMarks[ InIndex ] )
			{
				WorldSettings->BookMarks[ InIndex ] = ConstructObject<UBookMark>( UBookMark::StaticClass(), WorldSettings );
			}

			UBookMark* CurBookMark = WorldSettings->BookMarks[ InIndex ];
			check(CurBookMark);
			check(InViewportClient);

			// Use the rotation from the first perspective viewport can find.
			FRotator Rotation(0,0,0);
			if( !InViewportClient->IsOrtho() )
			{
				Rotation = InViewportClient->GetViewRotation();
			}

			CurBookMark->Location = InViewportClient->GetViewLocation();
			CurBookMark->Rotation = Rotation;

			// Keep a record of which levels were hidden so that we can restore these with the bookmark
			CurBookMark->HiddenLevels.Empty();
			for ( int32 LevelIndex = 0 ; LevelIndex < World->StreamingLevels.Num() ; ++LevelIndex )
			{
				ULevelStreaming* StreamingLevel = World->StreamingLevels[LevelIndex];
				if ( StreamingLevel )
				{
					if( !StreamingLevel->bShouldBeVisibleInEditor )
					{
						CurBookMark->HiddenLevels.Add( StreamingLevel->GetFullName() );
					}
				}
			}
		}
	}
}
AActor* AGameModeBase::FindPlayerStart_Implementation(AController* Player, const FString& IncomingName)
{
	UWorld* World = GetWorld();

	// If incoming start is specified, then just use it
	if (!IncomingName.IsEmpty())
	{
		const FName IncomingPlayerStartTag = FName(*IncomingName);
		for (TActorIterator<APlayerStart> It(World); It; ++It)
		{
			APlayerStart* Start = *It;
			if (Start && Start->PlayerStartTag == IncomingPlayerStartTag)
			{
				return Start;
			}
		}
	}

	// Always pick StartSpot at start of match
	if (ShouldSpawnAtStartSpot(Player))
	{
		if (AActor* PlayerStartSpot = Player->StartSpot.Get())
		{
			return PlayerStartSpot;
		}
		else
		{
			UE_LOG(LogGameMode, Error, TEXT("Error - ShouldSpawnAtStartSpot returned true but the Player StartSpot was null."));
		}
	}

	AActor* BestStart = ChoosePlayerStart(Player);
	if (BestStart == nullptr)
	{
		// No player start found
		UE_LOG(LogGameMode, Log, TEXT("Warning - PATHS NOT DEFINED or NO PLAYERSTART with positive rating"));

		// This is a bit odd, but there was a complex chunk of code that in the end always resulted in this, so we may as well just 
		// short cut it down to this.  Basically we are saying spawn at 0,0,0 if we didn't find a proper player start
		BestStart = World->GetWorldSettings();
	}

	return BestStart;
}
Beispiel #11
0
void AKillZVolume::ActorEnteredVolume(AActor* Other)
{
	Super::ActorEnteredVolume(Other);
	
	if ( Other )
	{
		const UDamageType* DamageType = GetDefault<UDamageType>();

		UWorld* World = GetWorld();
		if ( World )
		{
			AWorldSettings* WorldSettings = World->GetWorldSettings( true );
			if ( WorldSettings && WorldSettings->KillZDamageType )
			{
				DamageType = WorldSettings->KillZDamageType->GetDefaultObject<UDamageType>();
			}
		}

		Other->FellOutOfWorld(*DamageType);
	}
}
Beispiel #12
0
void AWorldSettings::CheckForErrors()
{
	Super::CheckForErrors();

	UWorld* World = GetWorld();
	if ( World->GetWorldSettings() != this )
	{
		FMessageLog("MapCheck").Warning()
			->AddToken(FUObjectToken::Create(this))
			->AddToken(FTextToken::Create(LOCTEXT( "MapCheck_Message_DuplicateLevelInfo", "Duplicate level info" ) ))
			->AddToken(FMapErrorToken::Create(FMapErrors::DuplicateLevelInfo));
	}

	if( World->NumLightingUnbuiltObjects > 0 )
	{
		FMessageLog("MapCheck").Error()
			->AddToken(FUObjectToken::Create(this))
			->AddToken(FTextToken::Create(LOCTEXT( "MapCheck_Message_RebuildLighting", "Maps need lighting rebuilt" ) ))
			->AddToken(FMapErrorToken::Create(FMapErrors::RebuildLighting));
	}
}
Beispiel #13
0
UWorld* NUTNet::CreateUnitTestWorld(bool bHookTick/*=true*/)
{
	UWorld* ReturnVal = NULL;

	// Unfortunately, this hack is needed, to avoid a crash when running as commandlet
	// NOTE: Sometimes, depending upon build settings, PRIVATE_GIsRunningCommandlet is a define instead of a global
#ifndef PRIVATE_GIsRunningCommandlet
	bool bIsCommandlet = PRIVATE_GIsRunningCommandlet;

	PRIVATE_GIsRunningCommandlet = false;
#endif

	ReturnVal = UWorld::CreateWorld(EWorldType::None, false);

#ifndef PRIVATE_GIsRunningCommandlet
	PRIVATE_GIsRunningCommandlet = bIsCommandlet;
#endif


	if (ReturnVal != NULL)
	{
		UnitTestWorlds.Add(ReturnVal);

		// Hook the new worlds 'tick' event, so that we can capture logging
		if (bHookTick)
		{
			FWorldTickHook* TickHook = new FWorldTickHook(ReturnVal);

			ActiveTickHooks.Add(TickHook);

			TickHook->Init();
		}


		// Hack-mark the world as having begun play (when it has not)
		ReturnVal->bBegunPlay = true;

		// Hack-mark the world as having initialized actors (to allow RPC hooks)
		ReturnVal->bActorsInitialized = true;

		// Enable pause, using the PlayerController of the primary world (unless we're in the editor)
		if (!GIsEditor)
		{
			AWorldSettings* CurSettings = ReturnVal->GetWorldSettings();

			if (CurSettings != NULL)
			{
				ULocalPlayer* PrimLocPlayer = GEngine->GetFirstGamePlayer(NUTUtil::GetPrimaryWorld());
				APlayerController* PrimPC = (PrimLocPlayer != NULL ? PrimLocPlayer->PlayerController : NULL);
				APlayerState* PrimState = (PrimPC != NULL ? PrimPC->PlayerState : NULL);

				if (PrimState != NULL)
				{
					CurSettings->Pauser = PrimState;
				}
			}
		}

		// Create a blank world context, to prevent crashes
		FWorldContext& CurContext = GEngine->CreateNewWorldContext(EWorldType::None);
		CurContext.SetCurrentWorld(ReturnVal);
	}

	return ReturnVal;
}
void AGameModeBase::ReplicateStreamingStatus(APlayerController* PC)
{
	UWorld* MyWorld = GetWorld();

	if (MyWorld->GetWorldSettings()->bUseClientSideLevelStreamingVolumes)
	{
		// Client will itself decide what to stream
		return;
	}

	// Don't do this for local players or players after the first on a splitscreen client
	if (Cast<ULocalPlayer>(PC->Player) == nullptr && Cast<UChildConnection>(PC->Player) == nullptr)
	{
		// If we've loaded levels via CommitMapChange() that aren't normally in the StreamingLevels array, tell the client about that
		if (MyWorld->CommittedPersistentLevelName != NAME_None)
		{
			PC->ClientPrepareMapChange(MyWorld->CommittedPersistentLevelName, true, true);
			// Tell the client to commit the level immediately
			PC->ClientCommitMapChange();
		}

		if (MyWorld->StreamingLevels.Num() > 0)
		{
			// Tell the player controller the current streaming level status
			for (int32 LevelIndex = 0; LevelIndex < MyWorld->StreamingLevels.Num(); LevelIndex++)
			{
				ULevelStreaming* TheLevel = MyWorld->StreamingLevels[LevelIndex];

				if (TheLevel != nullptr)
				{
					const ULevel* LoadedLevel = TheLevel->GetLoadedLevel();

					UE_LOG(LogGameMode, Log, TEXT("levelStatus: %s %i %i %i %s %i"),
						*TheLevel->GetWorldAssetPackageName(),
						TheLevel->bShouldBeVisible,
						LoadedLevel && LoadedLevel->bIsVisible,
						TheLevel->bShouldBeLoaded,
						*GetNameSafe(LoadedLevel),
						TheLevel->bHasLoadRequestPending);

					PC->ClientUpdateLevelStreamingStatus(
						TheLevel->GetWorldAssetPackageFName(),
						TheLevel->bShouldBeLoaded,
						TheLevel->bShouldBeVisible,
						TheLevel->bShouldBlockOnLoad,
						TheLevel->LevelLODIndex);
				}
			}
			PC->ClientFlushLevelStreaming();
		}

		// If we're preparing to load different levels using PrepareMapChange() inform the client about that now
		if (MyWorld->PreparingLevelNames.Num() > 0)
		{
			for (int32 LevelIndex = 0; LevelIndex < MyWorld->PreparingLevelNames.Num(); LevelIndex++)
			{
				PC->ClientPrepareMapChange(MyWorld->PreparingLevelNames[LevelIndex], LevelIndex == 0, LevelIndex == MyWorld->PreparingLevelNames.Num() - 1);
			}
			// DO NOT commit these changes yet - we'll send that when we're done preparing them
		}
	}
}