Пример #1
0
void PhysicsObject::SetVelocity(const Vector3 &vel)
{
	assert(IsDynamic());
	Actor->setLinearVelocity(Vector3_NxVec3(vel));
}
Пример #2
0
void PhysicsObject::SetPosition(const Vector3 &pos)
{
	assert(IsDynamic());
	Actor->setGlobalPosition(Vector3_NxVec3(pos));
}
Пример #3
0
void PhysicsObject::SetOrientation(const Matrix &o)
{
	assert(IsDynamic());
	Actor->setGlobalOrientation(Matrix_NxMat33(o));
}
Пример #4
0
FString FAIDataProviderValue::ToString() const
{
	return IsDynamic() ? DataBinding->ToString(DataField) : ValueToString();
}
Пример #5
0
void CEditableObject::Save(IWriter& F)
{
	F.open_chunk	(EOBJ_CHUNK_VERSION);
	F.w_u16			(EOBJ_CURRENT_VERSION);
	F.close_chunk	();

	F.open_chunk	(EOBJ_CHUNK_CLASSSCRIPT);
	F.w_stringZ		(m_ClassScript);
	F.close_chunk	();

	F.open_chunk	(EOBJ_CHUNK_LODS);
	F.w_stringZ		(m_LODs);
	F.close_chunk	();

    F.w_chunk		(EOBJ_CHUNK_FLAGS,&m_Flags.flags,sizeof(m_Flags.flags));

//    Log("1: ",F.tell());
    // meshes
    F.open_chunk	(EOBJ_CHUNK_EDITMESHES);
    int count = 0;
    for(EditMeshIt m = m_Meshes.begin();m!=m_Meshes.end();m++){
        F.open_chunk(count); count++;
        (*m)->SaveMesh(F);
        F.close_chunk();
    }
    F.close_chunk	();
//    Log("2: ",F.tell());
    // surfaces
    F.open_chunk	(EOBJ_CHUNK_SURFACES3);
    F.w_u32		(m_Surfaces.size());
    for (SurfaceIt sf_it=m_Surfaces.begin(); sf_it!=m_Surfaces.end(); sf_it++){
        F.w_stringZ	((*sf_it)->_Name			());
        F.w_stringZ	((*sf_it)->_ShaderName		());
        F.w_stringZ	((*sf_it)->_ShaderXRLCName	());
        F.w_stringZ	((*sf_it)->_GameMtlName		());
		F.w_stringZ	((*sf_it)->_Texture			());
		F.w_stringZ	((*sf_it)->_VMap			());
        F.w_u32	((*sf_it)->m_Flags.get		());
        F.w_u32	((*sf_it)->_FVF				());
        F.w_u32	(1);
    }
    F.close_chunk	();
//    Log("3: ",F.tell());

    // bones
    if (!m_Bones.empty()){
	    F.open_chunk	(EOBJ_CHUNK_BONES2);
	    for (BoneIt b_it=m_Bones.begin(); b_it!=m_Bones.end(); b_it++){
        	F.open_chunk	(b_it-m_Bones.begin());
        	(*b_it)->Save	(F);
	    	F.close_chunk	();
        }
    	F.close_chunk	();
    }
//    Log("4: ",F.tell());

    // skeleton motions
    if (!m_SMotions.empty()){
        F.open_chunk	(EOBJ_CHUNK_SMOTIONS);
        F.w_u32			(m_SMotions.size());
        for (SMotionIt s_it=m_SMotions.begin(); s_it!=m_SMotions.end(); s_it++) (*s_it)->Save(F);
        F.close_chunk	();
    }
    // skeleton motions refs
    if (m_SMotionRefs.size()){
        F.open_chunk	(EOBJ_CHUNK_SMOTIONS2);
        F.w_stringZ		(m_SMotionRefs);
        F.close_chunk	();
    }
//    Log("5: ",F.tell());

    // bone parts
    if (!m_BoneParts.empty()){
        F.open_chunk	(EOBJ_CHUNK_BONEPARTS2);
        F.w_u32			(m_BoneParts.size());
        for (BPIt bp_it=m_BoneParts.begin(); bp_it!=m_BoneParts.end(); bp_it++){
            F.w_stringZ	(bp_it->alias);
            F.w_u32		(bp_it->bones.size());
            for (RStringVecIt s_it=bp_it->bones.begin(); s_it!=bp_it->bones.end(); s_it++)
	            F.w_stringZ(s_it->c_str());
        }
        F.close_chunk	();
    }
//    Log("6: ",F.tell());

    if (IsDynamic()){
		F.open_chunk	(EOBJ_CHUNK_ACTORTRANSFORM);
        F.w_fvector3		(a_vPosition);
        F.w_fvector3		(a_vRotate);
		F.close_chunk	();
    }
//    Log("7: ",F.tell());

    F.open_chunk		(EOBJ_CHUNK_DESC);
    F.w_stringZ			(m_CreateName.c_str());
    F.w					(&m_CreateTime,sizeof(m_CreateTime));
    F.w_stringZ			(m_ModifName.c_str());
    F.w					(&m_ModifTime,sizeof(m_ModifTime));
    F.close_chunk		();

    // set modif desc
	SetVersionToCurrent	(FALSE, TRUE);

	bOnModified		= false;
}
Пример #6
0
bool FCollection::CheckinCollection(FText& OutError)
{
	if ( !ensure(SourceFilename.Len()) )
	{
		OutError = LOCTEXT("Error_Internal", "There was an internal error.");
		return false;
	}

	ISourceControlProvider& SourceControlProvider = ISourceControlModule::Get().GetProvider();
	if ( !ISourceControlModule::Get().IsEnabled() )
	{
		OutError = LOCTEXT("Error_SCCDisabled", "Source control is not enabled. Enable source control in the preferences menu.");
		return false;
	}

	if ( !SourceControlProvider.IsAvailable() )
	{
		OutError = LOCTEXT("Error_SCCNotAvailable", "Source control is currently not available. Check your connection and try again.");
		return false;
	}

	FString AbsoluteFilename = FPaths::ConvertRelativePathToFull(SourceFilename);
	FSourceControlStatePtr SourceControlState = SourceControlProvider.GetState(AbsoluteFilename, EStateCacheUsage::ForceUpdate);

	if ( SourceControlState.IsValid() && !(SourceControlState->IsCheckedOut() || SourceControlState->IsAdded()) )
	{
		OutError = LOCTEXT("Error_SCCNotCheckedOut", "Collection not checked out or open for add.");
		return false;
	}

	// Form an appropriate summary for the changelist
	const FText CollectionNameText = FText::FromName( CollectionName );
	FText ChangelistDesc = FText::Format( LOCTEXT("CollectionGenericModifiedDesc", "Modified collection: {0}"), CollectionNameText );
	if ( SourceControlState.IsValid() && SourceControlState->IsAdded() )
	{
		ChangelistDesc = FText::Format( LOCTEXT("CollectionAddedNewDesc", "Added collection"), CollectionNameText);
	}
	else if ( IsDynamic() )
	{
		// @todo collection Change description for dynamic collections
	}
	else
	{
		// Gather differences from disk
		TArray<FName> AssetsAdded;
		TArray<FName> AssetsRemoved;
		GetDifferencesFromDisk(AssetsAdded, AssetsRemoved);

		// Clear description
		ChangelistDesc = FText::GetEmpty();

		// Report added files
		FFormatNamedArguments Args;
		Args.Add( TEXT("AssetAdded"), AssetsAdded.Num() > 0 ? FText::FromName( AssetsAdded[0] ) : NSLOCTEXT( "Core", "None", "None" ) );
		Args.Add( TEXT("NumberAdded"), FText::AsNumber( FMath::Max( AssetsAdded.Num() - 1, 0 ) ));
		Args.Add( TEXT("CollectionName"), CollectionNameText );

		if ( AssetsRemoved.Num() == 0 )
		{
			if (AssetsAdded.Num() == 1)
			{
				ChangelistDesc = FText::Format( LOCTEXT("CollectionAddedSingleDesc", "Added {AssetAdded} to collection: {CollectionName}"), Args );
			}
			else if (AssetsAdded.Num() > 1)
			{
				ChangelistDesc = FText::Format( LOCTEXT("CollectionAddedMultipleDesc", "Added {AssetAdded} and {NumberAdded} other(s) to collection: {CollectionName}"), Args );
			}
		}
		else
		{
			Args.Add( TEXT("AssetRemoved"), FText::FromName( AssetsRemoved[0] ) );
			Args.Add( TEXT("NumberRemoved"), FText::AsNumber( AssetsRemoved.Num() - 1 ) );

			if ( AssetsAdded.Num() == 1 )
			{
				if ( AssetsRemoved.Num() == 1 )
				{
					ChangelistDesc = FText::Format( LOCTEXT("CollectionRemovedSingle_AddedSingleDesc", "Added {AssetAdded} to collection: {CollectionName} : Removed {AssetRemoved} from collection: {CollectionName}"), Args );
				}
				else if (AssetsRemoved.Num() > 1)
				{
					ChangelistDesc = FText::Format( LOCTEXT("CollectionRemovedMultiple_AddedSingleDesc", "Added {AssetAdded} to collection: {CollectionName} : Removed {AssetRemoved} and {NumberRemoved} other(s) from collection: {CollectionName}"), Args );
				}
			}
			else if (AssetsAdded.Num() > 1)
			{
				if ( AssetsRemoved.Num() == 1 )
				{
					ChangelistDesc = FText::Format( LOCTEXT("CollectionRemovedSingle_AddedMultpleDesc", "Added {AssetAdded} and {NumberAdded} other(s) to collection: {CollectionName} : Removed {AssetRemoved} from collection: {CollectionName}"), Args );
				}
				else if (AssetsRemoved.Num() > 1)
				{
					ChangelistDesc = FText::Format( LOCTEXT("CollectionRemovedMultiple_AddedMultpleDesc", "Added {AssetAdded} and {NumberAdded} other(s) to collection: {CollectionName} : Removed {AssetRemoved} and {NumberRemoved} other(s) from collection: {CollectionName}"), Args );
				}
			}
			else
			{
				if ( AssetsRemoved.Num() == 1 )
				{
					ChangelistDesc = FText::Format( LOCTEXT("CollectionRemovedSingleDesc", "Removed {AssetRemoved} from collection: {CollectionName}"), Args );
				}
				else if (AssetsRemoved.Num() > 1)
				{
					ChangelistDesc = FText::Format( LOCTEXT("CollectionRemovedMultipleDesc", "Removed {AssetRemoved} and {NumberRemoved} other(s) from collection: {CollectionName}"), Args );
				}
			}
		}
	}

	if ( ChangelistDesc.IsEmpty() )
	{
		// No files were added or removed
		FFormatNamedArguments Args;
		Args.Add( TEXT("CollectionName"), CollectionNameText );
		ChangelistDesc = FText::Format( LOCTEXT("CollectionNotModifiedDesc", "Collection not modified: {CollectionName}"), Args );
	}

	// Finally check in the file
	TSharedRef<FCheckIn, ESPMode::ThreadSafe> CheckInOperation = ISourceControlOperation::Create<FCheckIn>();
	CheckInOperation->SetDescription( ChangelistDesc.ToString() );
	if ( SourceControlProvider.Execute( CheckInOperation, AbsoluteFilename ) )
	{
		return true;
	}
	else 
	{
		OutError = LOCTEXT("Error_SCCCheckIn", "Failed to check in collection.");
		return false;
	}
}
Пример #7
0
bool FCollection::LoadFromFile(const FString& InFilename, bool InUseSCC)
{
	Clear();

	FString FullFileContentsString;
	if ( !FFileHelper::LoadFileToString(FullFileContentsString, *InFilename) )
	{
		return false;
	}

	// Initialize the FCollection and set up the collection name
	bUseSCC = InUseSCC;
	SourceFilename = InFilename;
	CollectionName = FName(*FPaths::GetBaseFilename(InFilename));
		
	// Normalize line endings and parse into array
	TArray<FString> FileContents;
	FullFileContentsString.ReplaceInline(TEXT("\r"), TEXT(""));
	FullFileContentsString.ParseIntoArray(&FileContents, TEXT("\n"), /*bCullEmpty=*/false);

	if ( FileContents.Num() == 0 )
	{
		// Empty file, assume static collection with no items
		return true;
	}

	// Load the header from the contents array
	TMap<FString,FString> HeaderPairs;
	while ( FileContents.Num() )
	{
		// Pop the 0th element from the contents array and read it
		const FString Line = FileContents[0].Trim().TrimTrailing();
		FileContents.RemoveAt(0);

		if (Line.Len() == 0)
		{
			// Empty line. Done reading headers.
			break;
		}

		FString Key;
		FString Value;
		if ( Line.Split(TEXT(":"), &Key, &Value) )
		{
			HeaderPairs.Add(Key, Value);
		}
	}

	// Now process the header pairs to prepare and validate this collection
	if ( !LoadHeaderPairs(HeaderPairs) )
	{
		// Bad header
		return false;
	}

	// Now load the content if the header load was successful
	if ( IsDynamic() )
	{
		// @todo collection Load dynamic collections
	}
	else
	{
		// Static collection, a flat list of asset paths
		for (int32 LineIdx = 0; LineIdx < FileContents.Num(); ++LineIdx)
		{
			const FString Line = FileContents[LineIdx].Trim().TrimTrailing();

			if ( Line.Len() )
			{
				AddAssetToCollection(FName(*Line));
			}
		}

		DiskAssetList = AssetList;
	}

	return true;
}
Пример #8
0
bool FCollection::Save(FText& OutError)
{
	if ( !ensure(SourceFilename.Len()) )
	{
		OutError = LOCTEXT("Error_Internal", "There was an internal error.");
		return false;
	}

	// Store the start time for profiling reasons
	double SaveStartTime = FPlatformTime::Seconds();

	// Keep track of save progress to update the slow task dialog
	const int32 SaveProgressDenominator = 3;
	int32 SaveProgressNumerator = 0;


	GWarn->BeginSlowTask( FText::Format( LOCTEXT("SavingCollection", "Saving Collection {0}"), FText::FromName( CollectionName ) ), true);
	GWarn->UpdateProgress(SaveProgressNumerator++, SaveProgressDenominator);

	if ( bUseSCC )
	{
		// Checkout the file
		if ( !CheckoutCollection(OutError) )
		{
			UE_LOG(LogCollectionManager, Error, TEXT("Failed to check out a collection file: %s"), *CollectionName.ToString());
			GWarn->EndSlowTask();
			return false;
		}
	}

	GWarn->UpdateProgress(SaveProgressNumerator++, SaveProgressDenominator);

	// Generate a string with the file contents
	FString FileOutput;

	// Start with the header
	TMap<FString,FString> HeaderPairs;
	GenerateHeaderPairs(HeaderPairs);
	for (TMap<FString,FString>::TConstIterator HeaderIt(HeaderPairs); HeaderIt; ++HeaderIt)
	{
		FileOutput += HeaderIt.Key() + TEXT(":") + HeaderIt.Value() + LINE_TERMINATOR;
	}
	FileOutput += LINE_TERMINATOR;

	// Now for the content
	if ( IsDynamic() )
	{
		// @todo Dynamic collections
	}
	else
	{
		// Static collection. Save a flat list of all assets in the collection.
		for (int32 AssetIdx = 0; AssetIdx < AssetList.Num(); ++AssetIdx)
		{
			FileOutput += AssetList[AssetIdx].ToString() + LINE_TERMINATOR;
		}
	}

	// Attempt to save the file
	bool bSaveSuccessful = false;
	if ( ensure(FileOutput.Len()) )
	{
		// We have some output, write it to file
		if ( FFileHelper::SaveStringToFile(FileOutput, *SourceFilename) )
		{
			bSaveSuccessful = true;
		}
		else
		{
			OutError = LOCTEXT("Error_WriteFailed", "Failed to write to collection file.");
			UE_LOG(LogCollectionManager, Error, TEXT("%s %s"), *OutError.ToString(), *CollectionName.ToString());
		}
	}
	else
	{
		OutError = LOCTEXT("Error_Internal", "There was an internal error.");
	}

	GWarn->UpdateProgress(SaveProgressNumerator++, SaveProgressDenominator);

	if ( bSaveSuccessful )
	{
		if ( bUseSCC )
		{
			// Check in the file if the save was successful
			if ( bSaveSuccessful )
			{
				if ( !CheckinCollection(OutError) )
				{
					UE_LOG(LogCollectionManager, Error, TEXT("Failed to check in a collection successfully saving: %s"), *CollectionName.ToString());
					bSaveSuccessful = false;
				}
			}
		
			// If the save was not successful or the checkin failed, revert
			if ( !bSaveSuccessful )
			{
				FText Unused;
				if ( !RevertCollection(Unused) )
				{
					// The revert failed... file will be left on disk as it was saved.
					// DiskAssetList will still hold the version of the file when this collection was last loaded or saved successfully so nothing will be out of sync.
					// If the user closes the editor before successfully saving, this file may not be exactly what was seen at the time the editor closed.
					UE_LOG(LogCollectionManager, Warning, TEXT("Failed to revert a checked out collection after failing to save or checkin: %s"), *CollectionName.ToString());
				}
			}
		}
	}

	GWarn->UpdateProgress(SaveProgressNumerator++, SaveProgressDenominator);

	if ( bSaveSuccessful )
	{
		DiskAssetList = AssetList;
	}

	GWarn->EndSlowTask();

	UE_LOG(LogCollectionManager, Verbose, TEXT("Saved collection %s in %0.6f seconds"), *CollectionName.ToString(), FPlatformTime::Seconds() - SaveStartTime);

	return bSaveSuccessful;
}