Example #1
0
        /// <summary>
        /// Update all spongy visualizations.
        /// </summary>
        private void UpdateSpongy()
        {
            Debug.Assert(manager != null, "This should not be called without a valid manager");
            AnchorManager anchorManager = manager.AnchorManager as AnchorManager;

            Debug.Assert(anchorManager != null, "This should not be called without a valid AnchorManager");

            CheckSpongyRoot(manager.AdjustmentFrame);

            var spongyCurrent = anchorManager.SpongyAnchors;

            spongyCurrent.Sort((x, y) => x.anchorId.CompareTo(y.anchorId));

            SpongyVisualCreator spongyCreator = new SpongyVisualCreator(Prefab_SpongyAnchorViz, spongyWorldViz);

            ResourceMirror.Sync(
                spongyCurrent,
                spongyResources,
                (item, res) => item.anchorId.CompareTo(res.id),
                spongyCreator.CreateSpongyVisual,
                (x, y) => { },
                spongyCreator.DestroySpongyVisual);

            SetSupportRelevances();
        }
        /// <summary>
        /// Update all frozen visualizations.
        /// </summary>
        private void UpdateFrozen()
        {
            Debug.Assert(manager != null, "This should not be called without a valid manager");
            var plugin = manager.Plugin;

            AnchorFragmentPose[] frozenItems = plugin.GetFrozenAnchors();
            Array.Sort(frozenItems, (x, y) => x.anchorId.CompareTo(y.anchorId));

            UpdateFragmentVisuals();

            /// The "frozen" coordinates here are ignoring the rest of the transform up the camera tree.
            Pose globalFromLocked = manager.ApplyAdjustment ? manager.FrozenFromLocked : manager.SpongyFromLocked;

            /// Apply the vertical displacement through the globalFromLocked transform.
            globalFromLocked.position = new Vector3(globalFromLocked.position.x, globalFromLocked.position.y + verticalDisplacement, globalFromLocked.position.z);

            var frozenCreator = new FrozenAnchorVisualCreator(Prefab_FrozenAnchorViz, frozenFragmentVizs, globalFromLocked);

            ResourceMirror.Sync(
                frozenItems,
                frozenResources,
                (item, res) => item.anchorId.CompareTo(res.id),
                frozenCreator.CreateFrozenVisual,
                frozenCreator.UpdateFrozenVisual,
                frozenCreator.DestroyFrozenVisual);

            // Connect frozen anchors with corresponding spongy anchors with a line.
            DisplacementCreator displacementCreator = new DisplacementCreator();

            SyncDisplacements(displacementCreator,
                              frozenResources,
                              spongyResources,
                              displacementResources);

            var edgeItems = plugin.GetFrozenEdges();

            for (int i = 0; i < edgeItems.Length; ++i)
            {
                edgeItems[i] = RegularizeEdge(edgeItems[i]);
            }
            Array.Sort(edgeItems, anchorEdgeComparer);

            var frozenEdgeCreator = new FrozenEdgeVisualCreator(this, frozenResources);

            ResourceMirror.Sync(
                edgeItems,
                edgeResources,
                (x, y) => CompareAnchorEdges(x, y.id),
                frozenEdgeCreator.CreateFrozenEdge,
                (x, y) => { },
                frozenEdgeCreator.DestroyFrozenEdge);
        }
        public void CreateFailTest()
        {
            List <AnchorId> anchorIds = new List <AnchorId>();

            for (int i = (int)AnchorId.FirstValid; i < 10; ++i)
            {
                anchorIds.Add((AnchorId)i);
            }

            List <AnchorVisTest> resources = new List <AnchorVisTest>();

            AnchorIdOddOnlyCreator creator = new AnchorIdOddOnlyCreator();

            ResourceMirror.Sync(anchorIds, resources,
                                (x, y) => x.CompareTo(y.id),
                                creator.Create,
                                creator.Update,
                                creator.Destroy);

            Assert.IsTrue(resources.Count == (anchorIds.Count + 1) / 2);
            for (int i = 0; i < resources.Count; ++i)
            {
                Assert.IsTrue(1 == (((int)resources[i].id) & 1));
            }

            ResourceMirror.Sync(resources, anchorIds,
                                /* Compare */ (x, y) => x.id.CompareTo(y),
                                /* Create  */ (AnchorVisTest x, out AnchorId y) => { y = x.id; return(true); },
                                /* Update  */ (x, y) => { },
                                /* Destroy */ (x) => { }
                                );

            Assert.IsTrue(resources.Count == anchorIds.Count);
            for (int i = 0; i < resources.Count; ++i)
            {
                Assert.AreEqual(anchorIds[i], resources[i].id);
            }
        }
        public void AnchorListSyncTest()
        {
            UnityEngine.Debug.Log("Enter Sync Test");

            List <IdPair <AnchorId, AnchorVisTest> > existing = new List <IdPair <AnchorId, AnchorVisTest> >();

            for (int i = 2; i < 6; ++i)
            {
                existing.Add(AnchorIdVisTestCreator.Make(i));
            }
            existing.Sort(IdPair <AnchorId, AnchorVisTest> .CompareById);

            List <IdPair <AnchorId, AnchorDummy> > current = new List <IdPair <AnchorId, AnchorDummy> >();

            for (int i = 1; i < 7; ++i)
            {
                current.Add(new IdPair <AnchorId, AnchorDummy>()
                {
                    id = (AnchorId)i, target = AnchorDummy.Create(i)
                });
            }
            current.Sort(IdPair <AnchorId, AnchorDummy> .CompareById);

            /// Initial state is:
            ///   current == [1..7]
            ///   existing == [2..6]
            /// Expected is to add 1 and 7 to existing.
            ResourceMirror.Sync <IdPair <AnchorId, AnchorDummy>, IdPair <AnchorId, AnchorVisTest> >(
                current,
                existing,
                (item, res) => item.id.CompareTo(res.id),
                AnchorIdVisTestCreator.Create,
                AnchorIdVisTestCreator.Update,
                x => { Debug.LogError("Not expecting to be deleting here, only adding."); }
                );
            CheckSynced(existing, current);

            current.RemoveAt(current.Count / 2);

            /// Lists are the same, except one has been removed from current.
            /// Expect a single matching resource removed from existing.
            ResourceMirror.CompareToResource <IdPair <AnchorId, AnchorDummy>, IdPair <AnchorId, AnchorVisTest> > comparisonById = (item, res) => item.id.CompareTo(res.id);
            ResourceMirror.Sync <IdPair <AnchorId, AnchorDummy>, IdPair <AnchorId, AnchorVisTest> >(
                current,
                existing,
                comparisonById,
                (IdPair <AnchorId, AnchorDummy> x, out IdPair <AnchorId, AnchorVisTest> y) => { Debug.LogError("Not expecting to be creating resources here, only deleting."); y = new IdPair <AnchorId, AnchorVisTest>(); return(false); },
                AnchorIdVisTestCreator.Update,
                AnchorIdVisTestCreator.Destroy
                );
            CheckSynced(existing, current);

            current.RemoveAt(0);
            current.RemoveAt(current.Count - 1);

            ResourceMirror.Sync(
                current,
                existing,
                comparisonById, // reused from above
                AnchorIdVisTestCreator.Create,
                AnchorIdVisTestCreator.Update,
                AnchorIdVisTestCreator.Destroy
                );
            CheckSynced(existing, current);

            current.Clear();
            ResourceMirror.Sync(
                current,
                existing,
                comparisonById,
                AnchorIdVisTestCreator.Create,
                AnchorIdVisTestCreator.Update,
                AnchorIdVisTestCreator.Destroy
                );
            CheckSynced(existing, current);
        }
        public void EdgeListSyncTest()
        {
            UnityEngine.Debug.Log("Enter Sync Edge");

            List <IdPair <AnchorEdge, AnchorEdgeVisTest> > existing = new List <IdPair <AnchorEdge, AnchorEdgeVisTest> >();

            List <AnchorEdge> current = new List <AnchorEdge>();

            for (int i = 1; i < 7; ++i)
            {
                current.Add(
                    RegularizeEdge(new AnchorEdge()
                {
                    anchorId1 = (AnchorId)i,
                    anchorId2 = (AnchorId)(i + 1)
                }
                                   ));
            }
            current.Sort(CompareEdges);

            ResourceMirror.Sync <AnchorEdge, IdPair <AnchorEdge, AnchorEdgeVisTest> >(
                current,
                existing,
                (item, res) => CompareEdges(item, res.id),
                AnchorEdgeVisTestPair.Create,
                AnchorEdgeVisTestPair.Update,
                AnchorEdgeVisTestPair.Destroy
                );
            CheckSynced(existing, current);

            current.RemoveAt(current.Count / 2);

            ResourceMirror.Sync(
                current,
                existing,
                (item, res) => CompareEdges(item, res.id),
                AnchorEdgeVisTestPair.Create,
                AnchorEdgeVisTestPair.Update,
                AnchorEdgeVisTestPair.Destroy
                );
            CheckSynced(existing, current);

            current.Add(
                RegularizeEdge(new AnchorEdge()
            {
                anchorId1 = (AnchorId)100,
                anchorId2 = (AnchorId)(100 + 1)
            }
                               ));
            current.RemoveAt(current.Count / 2);

            ResourceMirror.Sync(
                current,
                existing,
                (item, res) => CompareEdges(item, res.id),
                AnchorEdgeVisTestPair.Create,
                AnchorEdgeVisTestPair.Update,
                AnchorEdgeVisTestPair.Destroy
                );
            CheckSynced(existing, current);

            current.Clear();

            ResourceMirror.Sync(
                current,
                existing,
                (item, res) => CompareEdges(item, res.id),
                AnchorEdgeVisTestPair.Create,
                AnchorEdgeVisTestPair.Update,
                AnchorEdgeVisTestPair.Destroy
                );
            CheckSynced(existing, current);
        }