Exemplo n.º 1
16
void UAIPerceptionSystem::Tick(float DeltaSeconds)
{
	SCOPE_CYCLE_COUNTER(STAT_AI_PerceptionSys);

	// if no new stimuli
	// and it's not time to remove stimuli from "know events"

	UWorld* World = GEngine->GetWorldFromContextObject(GetOuter());
	check(World);

	if (World->bPlayersOnly == false)
	{
		// cache it
		CurrentTime = World->GetTimeSeconds();

		bool bNeedsUpdate = false;

		if (bStimuliSourcesRefreshRequired == true)
		{
			// this is a bit naive, but we don't get notifications from the engine which Actor ended play, 
			// we just know one did. Let's just refresh the map removing all no-longer-valid instances
			// @todo: we should be just calling senses directly here to unregister specific source
			// but at this point source actor is invalid already so we can't really pin and use it
			// this will go away once OnEndPlay broadcast passes in its instigator
			FPerceptionChannelWhitelist SensesToUpdate;
			for (auto It = RegisteredStimuliSources.CreateIterator(); It; ++It)
			{
				if (It->Value.SourceActor.IsValid() == false)
				{
					SensesToUpdate.MergeFilterIn(It->Value.RelevantSenses);
					It.RemoveCurrent();
				}
			}

			for (FPerceptionChannelWhitelist::FConstIterator It(SensesToUpdate); It && Senses.IsValidIndex(*It); ++It)
			{
				if (Senses[*It] != nullptr)
				{
					Senses[*It]->CleanseInvalidSources();
				}
			}

			bStimuliSourcesRefreshRequired = false;
		}
		
		if (SourcesToRegister.Num() > 0)
		{
			PerformSourceRegistration();
		}

		{
			UAISense** SenseInstance = Senses.GetData();
			for (int32 SenseID = 0; SenseID < Senses.Num(); ++SenseID, ++SenseInstance)
			{
				bNeedsUpdate |= *SenseInstance != nullptr && (*SenseInstance)->ProgressTime(DeltaSeconds);
			}
		}

		if (bNeedsUpdate)
		{
			// first update cached location of all listener, and remove invalid listeners
			for (AIPerception::FListenerMap::TIterator ListenerIt(ListenerContainer); ListenerIt; ++ListenerIt)
			{
				if (ListenerIt->Value.Listener.IsValid())
				{
					ListenerIt->Value.CacheLocation();
				}
				else
				{
					OnListenerRemoved(ListenerIt->Value);
					ListenerIt.RemoveCurrent();
				}
			}

			UAISense** SenseInstance = Senses.GetData();
			for (int32 SenseID = 0; SenseID < Senses.Num(); ++SenseID, ++SenseInstance)
			{
				if (*SenseInstance != nullptr)
				{
					(*SenseInstance)->Tick();
				}
			}
		}

		/** no point in soring in no new stimuli was processed */
		bool bStimuliDelivered = DeliverDelayedStimuli(bNeedsUpdate ? RequiresSorting : NoNeedToSort);

		if (bNeedsUpdate || bStimuliDelivered || bSomeListenersNeedUpdateDueToStimuliAging)
		{
			for (AIPerception::FListenerMap::TIterator ListenerIt(ListenerContainer); ListenerIt; ++ListenerIt)
			{
				check(ListenerIt->Value.Listener.IsValid())
				if (ListenerIt->Value.HasAnyNewStimuli())
				{
					ListenerIt->Value.ProcessStimuli();
				}
			}

			bSomeListenersNeedUpdateDueToStimuliAging = false;
		}
	}
Exemplo n.º 2
0
// removes the first occurance of pzMatch from the list
// or every occurance if bRemoveAllOccurances = 1
// if bMatchCase = 1 only ExAcT Case Matches are removed
// returns number of items removed.
__int64 GStringList::Remove(const char *pzMatch, int bMatchCase, int bRemoveAllOccurances)
{
	GString *p = (GString *)First();
	__int64 nItemsRemoved = 0;
	while(p)
	{
		if (bMatchCase)
		{
			if (p->Compare(pzMatch) == 0)
			{
				nItemsRemoved++;
				RemoveCurrent();
				delete p;
				if (!bRemoveAllOccurances)
					break;
			}
		}
		else
		{
			if (p->CompareNoCase(pzMatch) == 0)
			{
				nItemsRemoved++;
				RemoveCurrent();
				delete p;
				if (!bRemoveAllOccurances)
					break;
			}
		}
		p = (GString *)Next();
	}
	return nItemsRemoved;
}
Exemplo n.º 3
0
void FVertexSnappingImpl::DrawSnappingHelpers(const FSceneView* View,FPrimitiveDrawInterface* PDI)
{
	if( ActorVertsToDraw.IsValid() )
	{
		float PointSize = View->IsPerspectiveProjection() ? 4.0f : 5.0f;
		DrawSnapVertices( ActorVertsToDraw.Get(), PointSize, PDI );
	}

	for( auto It = ActorVertsToFade.CreateIterator(); It; ++It )
	{
		TWeakObjectPtr<AActor> Actor = It.Key();
		double FadeStart = It.Value();

		if( Actor.IsValid() )
		{
			float PointSize = View->IsPerspectiveProjection() ? 4.0f : 5.0f;

			if( FApp::GetCurrentTime()-FadeStart <= VertexSnappingConstants::FadeTime )
			{
				PointSize = FMath::Lerp( PointSize, 0.0f, (FApp::GetCurrentTime()-FadeStart)/VertexSnappingConstants::FadeTime );

				DrawSnapVertices( Actor.Get(), PointSize, PDI );
			}
		}
	
		if( !Actor.IsValid() || FApp::GetCurrentTime()-FadeStart > VertexSnappingConstants::FadeTime )
		{
			It.RemoveCurrent();
		}
	}
}
Exemplo n.º 4
0
void FComponentAssetBrokerage::UnregisterBroker(TSharedPtr<IComponentAssetBroker> Broker)
{
	UClass* AssetClass = Broker->GetSupportedAssetClass();

	if (TArray< TSharedPtr<IComponentAssetBroker> >* pBrokerList = AssetToBrokerMap.Find(AssetClass))
	{
		pBrokerList->Remove(Broker);
	}

	if (FComponentClassList* pTypesForClass = AssetToComponentClassMap.Find(AssetClass))
	{
		for (auto ComponentTypeIt = ComponentToBrokerMap.CreateIterator(); ComponentTypeIt; ++ComponentTypeIt)
		{
			TSubclassOf<UActorComponent> ComponentClass = ComponentTypeIt.Key();

			if (ComponentTypeIt.Value() == Broker)
			{
				ComponentTypeIt.RemoveCurrent();
				pTypesForClass->Remove(ComponentClass);
			}
		}

		if (pTypesForClass->Num() == 0)
		{
			AssetToComponentClassMap.Remove(AssetClass);
		}
	}
}
Exemplo n.º 5
0
void UActorComponent::ConsolidatedPostEditChange(const FPropertyChangedEvent& PropertyChangedEvent)
{
	FComponentReregisterContext* ReregisterContext = nullptr;
	if(EditReregisterContexts.RemoveAndCopyValue(this, ReregisterContext))
	{
		delete ReregisterContext;

		AActor* MyOwner = GetOwner();
		if ( MyOwner && !MyOwner->IsTemplate() && PropertyChangedEvent.ChangeType != EPropertyChangeType::Interactive )
		{
			MyOwner->RerunConstructionScripts();
		}
	}
	else
	{
		// This means there are likely some stale elements left in there now, strip them out
		for (auto It(EditReregisterContexts.CreateIterator()); It; ++It)
		{
			if (!It.Key().IsValid())
			{
				It.RemoveCurrent();
			}
		}
	}

	// The component or its outer could be pending kill when calling PostEditChange when applying a transaction.
	// Don't do do a full recreate in this situation, and instead simply detach.
	if( IsPendingKill() )
	{
		// @todo UE4 james should this call UnregisterComponent instead to remove itself from the RegisteredComponents array on the owner?
		ExecuteUnregisterEvents();
		World = NULL;
	}
}
void FActorFolders::Housekeeping()
{
	for (auto It = TemporaryWorldFolders.CreateIterator(); It; ++It)
	{
		if (!It.Key().Get())
		{
			It.RemoveCurrent();
		}
	}
}
Exemplo n.º 7
0
void GList::Remove(void *Data)
{
	void *p = First();
	while(p)
	{
		if (p == Data)
		{
			RemoveCurrent();
			break;
		}
		p = Next();
	}
}
Exemplo n.º 8
0
void UPackageMap::CleanPackageMap()
{
	for ( auto It = Cache->ObjectLookup.CreateIterator(); It; ++It )
	{
		if ( !It.Value().Object.IsValid() )
		{
			UE_LOG( LogNetPackageMap, Log, TEXT( "Cleaning reference to NetGUID: <%s> (ObjectLookup)" ), *It.Key().ToString() );
			It.RemoveCurrent();
			continue;
		}

		// Make sure the path matches (which can change during seamless travel)
		It.Value().FullPath = It.Value().Object->GetPathName();
	}

	for ( auto It = Cache->NetGUIDLookup.CreateIterator(); It; ++It )
	{
		if ( !It.Key().IsValid() )
		{
			UE_LOG( LogNetPackageMap, Log, TEXT( "Cleaning reference to NetGUID: <%s> (NetGUIDLookup)" ), *It.Value().ToString() );
			It.RemoveCurrent();
		}
	}

	// Sanity check
	for ( auto It = Cache->ObjectLookup.CreateIterator(); It; ++It )
	{
		check( It.Value().Object.IsValid() );
		checkf( Cache->NetGUIDLookup.FindRef( It.Value().Object ) == It.Key(), TEXT("Failed to validate ObjectLookup map in UPackageMap. Object '%s' was not in the NetGUIDLookup map with with value '%s'."), *It.Value().Object.Get()->GetPathName(), *It.Key().ToString());
	}

	for ( auto It = Cache->NetGUIDLookup.CreateIterator(); It; ++It )
	{
		check( It.Key().IsValid() );
		checkf( Cache->ObjectLookup.FindRef( It.Value() ).Object == It.Key(), TEXT("Failed to validate NetGUIDLookup map in UPackageMap. GUID '%s' was not in the ObjectLookup map with with object '%s'."), *It.Value().ToString(), *It.Key().Get()->GetPathName());
	}
}
void FUMGSequencerObjectBindingManager::UnbindPossessableObjects( const FGuid& PossessableGuid )
{
	for( auto It = PreviewObjectToGuidMap.CreateIterator(); It; ++It )
	{
		if( It.Value() == PossessableGuid )
		{
			It.RemoveCurrent();
		}
	}

	UWidgetBlueprint* WidgetBlueprint = WidgetBlueprintEditor.GetWidgetBlueprintObj();

	WidgetAnimation->AnimationBindings.RemoveAll( [&]( const FWidgetAnimationBinding& Binding ) { return Binding.AnimationGuid == PossessableGuid; } );

}
Exemplo n.º 10
0
void FPredictionKeyDelegates::CatchUpTo(FPredictionKey::KeyType Key)
{
	for (auto MapIt = Get().DelegateMap.CreateIterator(); MapIt; ++MapIt)
	{
		if (MapIt.Key() <= Key)
		{		
			for (auto Delegate : MapIt.Value().CaughtUpDelegates)
			{
				Delegate.ExecuteIfBound();
			}
			
			MapIt.RemoveCurrent();
		}
	}
}
void UGameplayCueManager::EndGameplayCuesFor(AActor* TargetActor)
{
	for (auto It = NotifyMapActor.CreateIterator(); It; ++It)
	{
		FGCNotifyActorKey& Key = It.Key();
		if (Key.TargetActor == TargetActor)
		{
			AGameplayCueNotify_Actor* InstancedCue = It.Value().Get();
			if (InstancedCue)
			{
				InstancedCue->OnOwnerDestroyed(TargetActor);
			}
			It.RemoveCurrent();
		}
	}
}
Exemplo n.º 12
0
void ServerContextManager::UnRegisterThreadContext(ServerThreadContext* threadContext)
{
    AutoCriticalSection autoCS(&cs);
    threadContexts.Remove(threadContext);
    auto iter = scriptContexts.GetIteratorWithRemovalSupport();
    while (iter.IsValid())
    {
        ServerScriptContext* scriptContext = iter.Current().Key();
        if (scriptContext->GetThreadContext() == threadContext)
        {   
            scriptContext->Close();
            iter.RemoveCurrent();
        }
        iter.MoveNext();
    }
}
Exemplo n.º 13
0
void FGAEffectModifier::RemoveOutgoingBonusOfType(EGAAttributeMod ModType)
{
	for (auto aIt = OutgoingModifiers.CreateIterator(); aIt; ++aIt)
	{
		for (auto It = aIt->Value.CreateIterator(); It; ++It)
		{
			if (It->AttributeMod == ModType)
			{
				aIt->Value.RemoveAt(It.GetIndex());
				if (aIt->Value.Num() <= 0)
				{
					aIt.RemoveCurrent();
				}
			}
		}
	}
	CalculateIncomingBonus();
}
Exemplo n.º 14
0
void UAutoReimportManager::Tick( float DeltaTime ) 
{
	ReimportTime += DeltaTime;

	//we wait this amount of time after a modification to re-import, this is because some tools save the file multiple times
	const double DeltaSinceModified = 1.0;

	//last modification must have been prior to this time
	const double CanImportTime = ReimportTime - DeltaSinceModified;

	//Reimport files that have been modified
	for (auto It(ModifiedFiles.CreateIterator());It;++It)
	{
		if(It.Value() < CanImportTime)
		{
			if(ReimportDelegates* Reimporters = ExtensionToReimporter.Find(FPaths::GetExtension(It.Key())))
			{
				OnFileModified(*Reimporters, It.Key());
			}
			It.RemoveCurrent();
		}
	}
}
Exemplo n.º 15
0
bool FProfilerClientManager::HandleMessagesTicker( float DeltaTime )
{
#if STATS
	for (auto It = Connections.CreateIterator(); It; ++It)
	{
		FServiceConnection& Connection = It.Value();

		while (Connection.PendingMessages.Contains(Connection.CurrentFrame+1))
		{
			TArray<uint8>& Data = *Connection.PendingMessages.Find(Connection.CurrentFrame+1);
			Connection.CurrentFrame++;

			// pass the data to the visualization code
			FArrayReader Reader(true);
			Reader.Append(Data);

			int64 Size = Reader.TotalSize();
			FStatsReadStream& Stream = Connection.Stream;

			// read in the data and post if we reach a 
			{
				SCOPE_CYCLE_COUNTER(STAT_PC_ReadStatMessages);
				while(Reader.Tell() < Size)
				{
					// read the message
					FStatMessage Message(Stream.ReadMessage(Reader));

					if (Message.NameAndInfo.GetField<EStatOperation>() == EStatOperation::AdvanceFrameEventGameThread)
					{
						Connection.AddCollectedStatMessages( Message );
					}

					new (Connection.Messages) FStatMessage(Message);
				}
			}

			// create an old format data frame from the data
			Connection.GenerateProfilerDataFrame();

			// Fire a meta data update message
			if (Connection.CurrentData.MetaDataUpdated)
			{
				ProfilerMetaDataUpdatedDelegate.Broadcast(Connection.InstanceId);
			}

			// send the data out
			ProfilerDataDelegate.Broadcast(Connection.InstanceId, Connection.CurrentData,0.0f);

			Connection.PendingMessages.Remove(Connection.CurrentFrame);
		}
	}

	// Remove any active transfer that timed out.
	for( auto It = ActiveTransfers.CreateIterator(); It; ++It )
	{
		FReceivedFileInfo& ReceivedFileInfo = It.Value();
		const FString& Filename = It.Key();

		if( ReceivedFileInfo.IsTimedOut() )
		{
			UE_LOG(LogProfile, Log, TEXT( "File service-client timed out, aborted: %s" ), *Filename );
			FailedTransfer.Add( Filename );

			delete ReceivedFileInfo.FileWriter;
			ReceivedFileInfo.FileWriter = nullptr;

			IFileManager::Get().Delete( *ReceivedFileInfo.DestFilepath );
			ProfilerFileTransferDelegate.Broadcast( Filename, -1, -1 );
			It.RemoveCurrent();	
		}
	}
#endif

	return true;
}
void FHTML5TargetPlatform::RefreshHTML5Setup()
{
	FString Temp;
	if (!FHTML5TargetPlatform::IsSdkInstalled(true, Temp))
	{
		// nothing to do.
		return;
	}

	// update available devices
	TArray<FString> DeviceMaps;
	GConfig->GetArray( TEXT("/Script/HTML5PlatformEditor.HTML5SDKSettings"), TEXT("DeviceMap"), DeviceMaps, GEngineIni );
	if ( ! DeviceMaps.Num() )
	{
		// trash can: nukes everything
		// default list will be repopulated
		FScopeLock Lock( &DevicesCriticalSection );
		for (auto Iter = Devices.CreateIterator(); Iter; ++Iter)
		{
			FHTML5TargetDevicePtr Device = Iter->Value;
			Iter.RemoveCurrent();
			DeviceLostEvent.Broadcast(Device.ToSharedRef());
		}
		DefaultDeviceName.Empty();
	}
	else
	{
		// add or update
		for (auto It : DeviceMaps)
		{
			FString DeviceName = "";
			FString DevicePath = "";
			if( FParse::Value( *It, TEXT( "DeviceName=" ), DeviceName ) &&
				FParse::Value( *It, TEXT( "DevicePath=(FilePath=" ), DevicePath ) )
			{
				if (FPlatformFileManager::Get().GetPlatformFile().FileExists(*DevicePath) ||
				    FPlatformFileManager::Get().GetPlatformFile().DirectoryExists(*DevicePath))
				{
					FScopeLock Lock( &DevicesCriticalSection );
					DeviceName = TEXT("user: "******"existing" - so can "update" it
						DeviceLostEvent.Broadcast(Device.ToSharedRef());
					}

					Device = MakeShareable( new FHTML5TargetDevice( *this, DeviceName, DevicePath ) );
					DeviceDiscoveredEvent.Broadcast( Device.ToSharedRef() );
					if ( DefaultDeviceName.IsEmpty() )
					{
						DefaultDeviceName = DeviceName;
					}
				}
			}
		}
	}

	struct FBrowserLocation
	{
		FString Name;
		FString Path;
	} PossibleLocations[] =
	{
#if PLATFORM_WINDOWS
		{ TEXT("Nightly(64bit)"), TEXT("C:/Program Files/Nightly/firefox.exe") },
		{ TEXT("Nightly"),        TEXT("C:/Program Files (x86)/Nightly/firefox.exe") },
		{ TEXT("Firefox(64bit)"), TEXT("C:/Program Files/Mozilla Firefox/firefox.exe") },
		{ TEXT("Firefox"),        TEXT("C:/Program Files (x86)/Mozilla Firefox/firefox.exe") },
		{ TEXT("Chrome"),         TEXT("C:/Program Files (x86)/Google/Chrome/Application/chrome.exe") },
#elif PLATFORM_MAC
		{ TEXT("Safari"),  TEXT("/Applications/Safari.app") },
		{ TEXT("Firefox"), TEXT("/Applications/Firefox.app") },
		{ TEXT("Chrome"),  TEXT("/Applications/Google Chrome.app") },
#elif PLATFORM_LINUX
		{ TEXT("Firefox"), TEXT("/usr/bin/firefox") },
#else
		{ TEXT("Firefox"), TEXT("") },
#endif
	};

	// Add default devices..
	for (const auto& Loc : PossibleLocations)
	{
		if (FPlatformFileManager::Get().GetPlatformFile().FileExists(*Loc.Path) || FPlatformFileManager::Get().GetPlatformFile().DirectoryExists(*Loc.Path))
		{
			FScopeLock Lock( &DevicesCriticalSection );

			FHTML5TargetDevicePtr& Device = Devices.FindOrAdd( *Loc.Name );

			if( !Device.IsValid() )
			{
				Device = MakeShareable( new FHTML5TargetDevice( *this, *Loc.Name, *Loc.Path ) );
				DeviceDiscoveredEvent.Broadcast(Device.ToSharedRef());
			}
		}
	}
}
Exemplo n.º 17
0
void UActorComponent::PostEditUndo()
{
	// Objects marked pending kill don't call PostEditChange() from UObject::PostEditUndo(),
	// so they can leave an EditReregisterContexts entry around if they are deleted by an undo action.
	if( IsPendingKill() )
	{
		// The reregister context won't bother attaching components that are 'pending kill'. 
		FComponentReregisterContext* ReregisterContext = nullptr;
		if (EditReregisterContexts.RemoveAndCopyValue(this, ReregisterContext))
		{
			delete ReregisterContext;
		}
		else
		{
			// This means there are likely some stale elements left in there now, strip them out
			for (auto It(EditReregisterContexts.CreateIterator()); It; ++It)
			{
				if (!It.Key().IsValid())
				{
					It.RemoveCurrent();
				}
			}
		}
	}
	else
	{
		bIsBeingDestroyed = false;

		Owner = GetTypedOuter<AActor>();
		bCanUseCachedOwner = true;

		// Let the component be properly registered, after it was restored.
		if (Owner)
		{
			Owner->AddOwnedComponent(this);
		}

		TArray<UObject*> Children;
		GetObjectsWithOuter(this, Children);

		for (UObject* Child : Children)
		{
			if (UActorComponent* ChildComponent = Cast<UActorComponent>(Child))
			{
				if (ChildComponent->Owner)
				{
					ChildComponent->Owner->RemoveOwnedComponent(ChildComponent);
				}
				ChildComponent->Owner = Owner;
				if (Owner)
				{
					Owner->AddOwnedComponent(ChildComponent);
				}
			}
		}

		if (GetWorld())
		{
			GetWorld()->UpdateActorComponentEndOfFrameUpdateState(this);
		}
	}
	Super::PostEditUndo();
}
void AReplayPlayer::UpdateActors() {

	FActorSpawnParameters spawnParameters;
	spawnParameters.bNoCollisionFail = true;
	spawnParameters.Owner = this;
	spawnParameters.Instigator = NULL;
	spawnParameters.bDeferConstruction = false;

	for (auto Iter = Vehicles.CreateIterator(); Iter; ++Iter) {
		EVehicleData* VehicleData = &(Iter.Value());
		EVehicleDataPoint* Current = &(VehicleData->Current);
		EVehicleDataPoint* Next = &(VehicleData->Next);
		uint32 UniqueId = Iter.Key();

		// Important Note. There might be multiple vehicles with the same unique id, but not
		// at the same time! Therefore, if a new vehicle is spawned with this id, without
		// the old being deleted (could happen if spooling), we need to destroy the old
		// actor.
		if (Current->New && VehicleData->Vehicle) {
			VehicleData->Vehicle->Destroy();
			VehicleData->Vehicle = NULL;
		}
		Current->New = false;

		if (!Current->Exists) {
			AMockingVehicle* Vehicle = VehicleData->Vehicle;
			if (UniqueId == LookAtUniqueId) {
				LookAtActor = NULL;
			}
			if (Vehicle) {
				if (!Vehicle->Destroy()) {
					continue;
				}

			}
			VehicleData->Vehicle = NULL;
			if (!VehicleData->Next.Exists) {
				Iter.RemoveCurrent();
			}

			continue;
		}

		float dt = Time - Current->LastUpdateTime;
		float TillNext;
		if (Current->LastUpdateTime == Next->LastUpdateTime) {
			TillNext = 0;
		}
		else {
			TillNext = (Time - Current->LastUpdateTime) / (Next->LastUpdateTime - Current->LastUpdateTime);
		}
		FVector ChangeLocation = Next->Location - Current->Location;
		FVector TimeCorrectedLocation = Current->Location + ChangeLocation * TillNext;

		FRotator ChangeRotation = (Next->Rotation - Current->Rotation).GetNormalized();
		FRotator TimeCorrectedRotation = (Current->Rotation + ChangeRotation * TillNext).GetNormalized();

		float ChangeSuspensionOffset = Next->SuspensionOffset - Current->SuspensionOffset;
		float TimeCorrectedSuspensionOffset = Current->SuspensionOffset + ChangeSuspensionOffset * TillNext;

		if (VehicleData->Vehicle) {
			VehicleData->Vehicle->SetActorLocation(TimeCorrectedLocation);
			VehicleData->Vehicle->SetActorRotation(TimeCorrectedRotation);
			VehicleData->Vehicle->BehaviorVectors = Current->BehaviorVectors;
			float WheelSpeed = -1.0f * FMath::RadiansToDegrees(Current->WheelRotationSpeed);
			VehicleData->Vehicle->WheelRotationAngle = Current->WheelRotationAngle + WheelSpeed * dt;

			VehicleData->Vehicle->WheelSteerAngle = Current->WheelSteerAngle;
			VehicleData->Vehicle->SuspensionOffset = TimeCorrectedSuspensionOffset;

			if (Current->FlockingState != VehicleData->Vehicle->GetFlockingState()) {
				VehicleData->Vehicle->SetFlockingState(Current->FlockingState, ShowArrows);
			}

			VehicleData->Vehicle->UpdateArrows();


			// We do not want to do this before the vehicle has been created, therefore we do it the first time
			// it arrives here
			if (VehicleData->FirstTick) {
				if (UniqueId == VehicleCameraId) {
					SelectVehicleCamera(VehicleData->Vehicle, VehicleCameraName);
				}

				if (UniqueId == LookAtUniqueId) {
					LookAtActor = VehicleData->Vehicle;
				}
				VehicleData->FirstTick = false;
			}
		} else {
			TSubclassOf<class AMockingVehicle> Type = VehicleTypeClass[(uint8)Current->VehicleType];
			AMockingVehicle* NewVehicle = GetWorld()->SpawnActor<AMockingVehicle>(Type, TimeCorrectedLocation, Current->Rotation, spawnParameters);
			NewVehicle->ReplayUniqueId = UniqueId;
			if (VehicleTypeMaterials.Contains((uint8)Current->VehicleType)) {
				auto Materials = VehicleTypeMaterials[(uint8)Current->VehicleType];
				int32 Index = Current->ColorMaterialIndex;
				UMaterial* Material = Materials[Index];
				NewVehicle->GetMesh()->SetMaterial(2, Material);
			}

			NewVehicle->VehicleType = Current->VehicleType;
			NewVehicle->ShowArrowBehaviors = &ShowArrowBehaviors;
			NewVehicle->SetFlockingState(Current->FlockingState, ShowArrows);
			NewVehicle->BehaviorVectors = Current->BehaviorVectors;
			NewVehicle->UpdateArrows();

			VehicleData->Vehicle = NewVehicle;
			VehicleData->FirstTick = true;
		}

	}
}
Exemplo n.º 19
0
const IntBounds *IntBounds::Add(
    const Value *const baseValue,
    const int n,
    const bool baseValueInfoIsPrecise,
    const IntConstantBounds &newConstantBounds,
    JitArenaAllocator *const allocator)
{
    Assert(baseValue);
    Assert(baseValue->GetValueInfo()->IsLikelyInt());
    Assert(!baseValue->GetValueInfo()->HasIntConstantValue());

    // Determine whether the new constant upper bound was established explicitly
    bool wasConstantUpperBoundEstablishedExplicitly = false;
    ValueInfo const * const baseValueInfo = baseValue->GetValueInfo();
    const IntBounds *const baseBounds = baseValueInfo->IsIntBounded() ? baseValueInfo->AsIntBounded()->Bounds() : nullptr;
    if(baseBounds && baseBounds->WasConstantUpperBoundEstablishedExplicitly())
    {
        int baseAdjustedConstantUpperBound;
        if(!Int32Math::Add(baseBounds->ConstantUpperBound(), n, &baseAdjustedConstantUpperBound) &&
            baseAdjustedConstantUpperBound == newConstantBounds.UpperBound())
        {
            wasConstantUpperBoundEstablishedExplicitly = true;
        }
    }

    // Create the new bounds. Don't try to determine the constant bounds by offsetting the current constant bounds, as loop
    // prepasses are conservative. Use the constant bounds that are passed in.
    IntBounds *const newBounds = New(newConstantBounds, wasConstantUpperBoundEstablishedExplicitly, allocator);

    // Adjust the relative bounds by the constant. The base value info would not be precise for instance, when we're in a loop
    // and the value was created before the loop or in a previous loop iteration.
    if(n < 0 && !baseValueInfoIsPrecise)
    {
        // Don't know the number of similar decreases in value that will take place
        Assert(newBounds->constantLowerBound == IntConstMin);
    }
    else if(baseBounds)
    {
        Assert(!baseBounds->relativeLowerBounds.ContainsKey(baseValue->GetValueNumber()));
        newBounds->relativeLowerBounds.Copy(&baseBounds->relativeLowerBounds);
        if(n != 0)
        {
            for(auto it = newBounds->relativeLowerBounds.GetIteratorWithRemovalSupport(); it.IsValid(); it.MoveNext())
            {
                ValueRelativeOffset &bound = it.CurrentValueReference();
                if(!bound.Add(n))
                    it.RemoveCurrent();
            }
        }
    }
    if(n > 0 && !baseValueInfoIsPrecise)
    {
        // Don't know the number of similar increases in value that will take place, so clear the relative upper bounds
        Assert(newBounds->constantUpperBound == IntConstMax);
    }
    else if(baseBounds)
    {
        Assert(!baseBounds->relativeUpperBounds.ContainsKey(baseValue->GetValueNumber()));
        newBounds->relativeUpperBounds.Copy(&baseBounds->relativeUpperBounds);
        if(n != 0)
        {
            for(auto it = newBounds->relativeUpperBounds.GetIteratorWithRemovalSupport(); it.IsValid(); it.MoveNext())
            {
                ValueRelativeOffset &bound = it.CurrentValueReference();
                if(!bound.Add(n))
                    it.RemoveCurrent();
            }
        }
    }

    // The result is equal to (baseValue +/- n), so set that as a relative lower and upper bound
    if(baseValueInfo->HasIntConstantValue())
        return newBounds;
    const ValueRelativeOffset bound(baseValue, n, true);
    if(n >= 0 || baseValueInfoIsPrecise)
        newBounds->relativeLowerBounds.Add(bound);
    if(n <= 0 || baseValueInfoIsPrecise)
        newBounds->relativeUpperBounds.Add(bound);
    return newBounds;
}
Exemplo n.º 20
0
void FObjectReplicator::UpdateUnmappedObjects( bool & bOutHasMoreUnmapped )
{
	UObject* Object = GetObject();

	if ( Object == NULL || Object->IsPendingKill() )
	{
		bOutHasMoreUnmapped = false;
		return;
	}

	if ( Connection->State == USOCK_Closed )
	{
		UE_LOG(LogNet, Warning, TEXT("FObjectReplicator::UpdateUnmappedObjects: Connection->State == USOCK_Closed"));
		return;
	}

	checkf( RepState->RepNotifies.Num() == 0, TEXT("Failed RepState RepNotifies check. Num=%d. Object=%s"), RepState->RepNotifies.Num(), *Object->GetFullName() );
	checkf( RepNotifies.Num() == 0, TEXT("Failed replicator RepNotifies check. Num=%d. Object=%s."), RepNotifies.Num(), *Object->GetFullName() );

	bool bSomeObjectsWereMapped = false;

	// Let the rep layout update any unmapped properties
	RepLayout->UpdateUnmappedObjects( RepState, Connection->PackageMap, Object, bSomeObjectsWereMapped, bOutHasMoreUnmapped );

	// Update unmapped objects for custom properties (currently just fast tarray)
	for ( auto It = UnmappedCustomProperties.CreateIterator(); It; ++It )
	{
		const int32			Offset			= It.Key();
		UStructProperty*	StructProperty	= It.Value();
		UScriptStruct*		InnerStruct		= StructProperty->Struct;

		check( InnerStruct->StructFlags & STRUCT_NetDeltaSerializeNative );

		UScriptStruct::ICppStructOps* CppStructOps = InnerStruct->GetCppStructOps();

		check( CppStructOps );
		check( !InnerStruct->InheritedCppStructOps() );

		FNetDeltaSerializeInfo Parms;

		FNetSerializeCB NetSerializeCB( OwningChannel->Connection->Driver );

		Parms.DebugName			= StructProperty->GetName();
		Parms.Struct			= InnerStruct;
		Parms.Map				= Connection->PackageMap;
		Parms.NetSerializeCB	= &NetSerializeCB;

		Parms.bUpdateUnmappedObjects	= true;
		Parms.bCalledPreNetReceive		= bSomeObjectsWereMapped;	// RepLayout used this to flag whether PreNetReceive was called
		Parms.Object					= Object;

		// Call the custom delta serialize function to handle it
		CppStructOps->NetDeltaSerialize( Parms, (uint8*)Object + Offset );

		// Merge in results
		bSomeObjectsWereMapped	|= Parms.bOutSomeObjectsWereMapped;
		bOutHasMoreUnmapped		|= Parms.bOutHasMoreUnmapped;

		if ( Parms.bOutSomeObjectsWereMapped )
		{
			// If we mapped a property, call the rep notify
			TArray<uint8> MetaData;
			QueuePropertyRepNotify( Object, StructProperty, 0, MetaData );
		}

		// If this property no longer has unmapped objects, we can stop checking it
		if ( !Parms.bOutHasMoreUnmapped )
		{
			It.RemoveCurrent();
		}
	}

	// Call any rep notifies that need to happen when object pointers change
	// Pass in false to override the check for queued bunches. Otherwise, if the owning channel has queued bunches,
	// the RepNotifies will remain in the list and the check for 0 RepNotifies above will fail next time.
	CallRepNotifies(false);

	if ( bSomeObjectsWereMapped )
	{
		// If we mapped some objects, make sure to call PostNetReceive (some game code will need to think this was actually replicated to work)
		PostNetReceive();
	}
}