static void CheckAgainstFullConversion(World destinationWorld)
        {
            var dstEntityManager = destinationWorld.EntityManager;

            using (var fullConversionWorld = new World("FullConversion"))
            {
                using (var blobAssetStore = new BlobAssetStore())
                {
                    var conversionSettings = GameObjectConversionSettings.FromWorld(fullConversionWorld, blobAssetStore);
                    conversionSettings.ConversionFlags = ConversionFlags;

                    GameObjectConversionUtility.ConvertScene(SceneManager.GetActiveScene(), conversionSettings);

                    const EntityManagerDifferOptions options =
                        EntityManagerDifferOptions.IncludeForwardChangeSet |
                        EntityManagerDifferOptions.ValidateUniqueEntityGuid;

                    using (var blobAssetCache = new BlobAssetCache(Allocator.TempJob))
                    {
                        EntityDiffer.PrecomputeBlobAssetCache(fullConversionWorld.EntityManager, EntityManagerDiffer.EntityGuidQueryDesc, blobAssetCache);
                        using (var changes = EntityDiffer.GetChanges(
                                   dstEntityManager,
                                   fullConversionWorld.EntityManager,
                                   options,
                                   EntityManagerDiffer.EntityGuidQueryDesc,
                                   blobAssetCache,
                                   Allocator.TempJob
                                   ))
                        {
                            Assert.IsFalse(changes.AnyChanges, "Full conversion and incremental conversion do not match!");
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        public void Validate()
        {
            var srcEm = SourceWorld.EntityManager;
            var dstEm = DestinationWorld.EntityManager;

            using (var changes = EntityDiffer.GetChanges(srcEm, dstEm, _differOptions, Query, _srcBlobAssets, Allocator.TempJob))
            {
                EntityPatcher.ApplyChangeSet(dstEm, changes.ForwardChangeSet);
            }

            using (var changes = EntityDiffer.GetChanges(dstEm, srcEm, _differOptions, Query, _dstBlobAssets, Allocator.TempJob))
            {
                if (!changes.ForwardChangeSet.HasChanges)
                {
                    return;
                }
                // TODO: Format the entity changeset nicely and print it out
                throw new Exception("Diff is not zero!");
            }
        }
        internal void DebugIncrementalConversion()
        {
            if (!_IncrementalConversionDebug.NeedsUpdate)
            {
                return;
            }
            _IncrementalConversionDebug.NeedsUpdate = false;
            var flags = _IncrementalConversionDebug.LastConversionFlags;

            using (DebugConversionMarker.Auto())
            {
                // use this to compare the results of incremental conversion with the results of a clean conversion.
                var settings = PrepareConversion(_IncrementalConversionDebug.World, flags, _buildConfigurationGUID, _buildConfiguration);
                GameObjectConversionUtility.InitializeIncrementalConversion(_Scene, settings).Dispose();
                AddMissingData(_IncrementalConversionDebug.World, _IncrementalConversionDebug.MissingSceneQuery,
                               _IncrementalConversionDebug.MissingRenderDataQuery);
                const EntityManagerDifferOptions options =
                    EntityManagerDifferOptions.IncludeForwardChangeSet |
                    EntityManagerDifferOptions.ValidateUniqueEntityGuid |
                    EntityManagerDifferOptions.UseReferentialEquality;

                unsafe
                {
                    if (_IncrementalConversionDebug.BlobAssets.BlobAssetBatch != null)
                    {
                        _IncrementalConversionDebug.BlobAssets.Dispose();
                    }
                }

                _IncrementalConversionDebug.BlobAssets = new BlobAssetCache(Allocator.Persistent);
                EntityDiffer.PrecomputeBlobAssetCache(_ConvertedWorld.EntityManager,
                                                      EntityManagerDiffer.EntityGuidQueryDesc, _IncrementalConversionDebug.BlobAssets);

                var changes = EntityDiffer.GetChanges(
                    _IncrementalConversionDebug.World.EntityManager,
                    _ConvertedWorld.EntityManager,
                    options,
                    EntityManagerDiffer.EntityGuidQueryDesc,
                    _IncrementalConversionDebug.BlobAssets,
                    Allocator.TempJob
                    );
                using (changes)
                {
                    if (!changes.AnyChanges)
                    {
                        return;
                    }

                    var fwdChanges = changes.ForwardChangeSet;
#if !UNITY_DISABLE_MANAGED_COMPONENTS
                    {
                        // Remove all companion link object changes.
                        // Companion objects will always be different between different conversions, so this is
                        // absolutely expected.
                        // It is unlikely that a diff will ever only consist of changes to hybrid components, and even
                        // in that case pointing out that the companion link changed is not exactly helpful for the user
                        // either.
                        var managedComponents       = fwdChanges.SetManagedComponents;
                        int numCompanionLinkObjects = 0;
                        var types = fwdChanges.TypeHashes;
                        var companionLinkIndex = TypeManager.GetTypeIndex <CompanionLink>();
                        int last = managedComponents.Length - 1;
                        for (int i = last; i >= 0; i--)
                        {
                            // We need to go through the type index to correctly handle null Companion Links
                            int packedTypeIdx = managedComponents[i].Component.PackedTypeIndex;
                            var idx           = TypeManager.GetTypeIndexFromStableTypeHash(types[packedTypeIdx].StableTypeHash);
                            if (idx == companionLinkIndex)
                            {
                                managedComponents[i]     = managedComponents[last - numCompanionLinkObjects];
                                numCompanionLinkObjects += 1;
                            }
                        }

                        if (numCompanionLinkObjects > 0)
                        {
                            // throw away the companion link changes
                            Array.Resize(ref managedComponents, last + 1 - numCompanionLinkObjects);
                            fwdChanges = new EntityChangeSet(fwdChanges.CreatedEntityCount,
                                                             fwdChanges.DestroyedEntityCount, fwdChanges.Entities, fwdChanges.TypeHashes,
                                                             fwdChanges.Names, fwdChanges.AddComponents, fwdChanges.RemoveComponents,
                                                             fwdChanges.SetComponents, fwdChanges.ComponentData, fwdChanges.EntityReferenceChanges,
                                                             fwdChanges.BlobAssetReferenceChanges,
                                                             managedComponents, // <- this changes
                                                             fwdChanges.SetSharedComponents, fwdChanges.LinkedEntityGroupAdditions,
                                                             fwdChanges.LinkedEntityGroupRemovals, fwdChanges.CreatedBlobAssets,
                                                             fwdChanges.DestroyedBlobAssets, fwdChanges.BlobAssetData);
                            if (!fwdChanges.HasChanges)
                            {
                                return;
                            }
                        }
                    }
#endif
                    _RequestCleanConversion = true;
                    var sb = new StringBuilder();
                    fwdChanges.PrintSummary(sb);
                    var errorString =
                        "The result of incrementally converting changes and a clean conversion didn't match, are you missing some dependencies?\n" +
                        "This is what was added/removed/changed by the clean conversion relative to the incremental conversion:\n" +
                        sb;
                    if (LiveConversionSettings.TreatIncrementalConversionFailureAsError)
                    {
                        throw new Exception(errorString);
                    }
                    Debug.LogWarning(errorString);
                }
            }
        }