Esempio n. 1
0
        public void Remove(ICameraPoolCamera camera)
        {
            TaskWrapper wrapper = _cameraPointers[camera.Token];

            if (!_cameraPointers.TryGetValue(camera.Token, out wrapper))
            {
                throw new ArgumentException("This camera was never added");
            }

            // Remove from the wrapper
            wrapper.AddRemoves.Enqueue(new Tuple <object, bool>(camera, false));

            // Forget where it was
            _cameraPointers.Remove(camera.Token);
        }
Esempio n. 2
0
        public void Add(ICameraPoolCamera camera)
        {
            if (_cameraPointers.ContainsKey(camera.Token))
            {
                throw new ArgumentException("This camera has already been added");
            }

            // Find the thread with the least to do
            TaskWrapper wrapper = _tasks.
                                  OrderBy(o => o.Count).
                                  First();

            // Add to the wrapper
            wrapper.AddRemoves.Enqueue(new Tuple <object, bool>(camera, true));

            // Remember where it is
            _cameraPointers.Add(camera.Token, wrapper);
        }
Esempio n. 3
0
        public void Remove(ICameraPoolCamera camera)
        {
            TaskWrapper wrapper = _cameraPointers[camera.Token];
            if (!_cameraPointers.TryGetValue(camera.Token, out wrapper))
            {
                throw new ArgumentException("This camera was never added");
            }

            // Remove from the wrapper
            wrapper.AddRemoves.Enqueue(new Tuple<object, bool>(camera, false));

            // Forget where it was
            _cameraPointers.Remove(camera.Token);
        }
Esempio n. 4
0
            //private static void AddRemoveVisuals(TaskWrapper parent, ViewportOffline viewport)
            //{
            //    #region Removes

            //    CameraPoolVisual visual;
            //    while (parent.RemoveVisuals.TryDequeue(out visual))
            //    {
            //        viewport.Viewport.Children.Remove(viewport.Visuals[visual.Token].Item2);
            //        viewport.Visuals.Remove(visual.Token);
            //    }

            //    #endregion
            //    #region Adds

            //    while (parent.AddVisuals.TryDequeue(out visual))
            //    {
            //        //  Deserialize into an instance that is specific to this thread
            //        Model3D model;
            //        using (MemoryStream stream = new MemoryStream(visual.Model3D))
            //        {
            //            model = XamlServices.Load(stream) as Model3D;
            //        }

            //        //  Create a visual to hold it (no need to set the transform here, that will be done each frame)
            //        ModelVisual3D modelVisual = new ModelVisual3D();
            //        modelVisual.Content = model;

            //        //  Store it
            //        viewport.Viewport.Children.Add(modelVisual);
            //        viewport.Visuals.Add(visual.Token, Tuple.Create(visual, (Visual3D)modelVisual));
            //    }

            //    #endregion
            //}
            //private static void AddRemoveCameras(TaskWrapper parent, List<ICameraPoolCamera> cameras)
            //{
            //    bool hadChange = false;

            //    //  Removes
            //    ICameraPoolCamera camera;
            //    while (parent.RemoveCameras.TryDequeue(out camera))
            //    {
            //        cameras.Remove(camera);
            //        hadChange = true;
            //    }

            //    //  Adds
            //    while (parent.AddCameras.TryDequeue(out camera))
            //    {
            //        cameras.Add(camera);
            //        hadChange = true;
            //    }

            //    // Store the new count
            //    if (hadChange)
            //    {
            //        parent._count = cameras.Count;
            //    }
            //}

            private static void AddRemoveItems(TaskWrapper parent, ViewportOffline viewport, List <ICameraPoolCamera> cameras)
            {
                bool numCamerasChanged = false;

                while (parent.AddRemoves.TryDequeue(out Tuple <object, bool> item))
                {
                    if (item.Item1 is CameraPoolVisual visual)
                    {
                        if (item.Item2)
                        {
                            #region Add Visual

                            //  Deserialize into an instance that is specific to this thread
                            Model3D model;
                            using (MemoryStream stream = new MemoryStream(visual.Model3D))
                            {
                                model = XamlServices.Load(stream) as Model3D;
                            }

                            //  Create a visual to hold it (no need to set the transform here, that will be done each frame)
                            ModelVisual3D modelVisual = new ModelVisual3D();
                            modelVisual.Content = model;

                            //  Store it
                            viewport.Viewport.Children.Add(modelVisual);
                            viewport.Visuals.Add(visual.Token, Tuple.Create(visual, (Visual3D)modelVisual));

                            #endregion
                        }
                        else
                        {
                            #region Remove Visual

                            viewport.Viewport.Children.Remove(viewport.Visuals[visual.Token].Item2);
                            viewport.Visuals.Remove(visual.Token);

                            #endregion
                        }
                    }
                    else if (item.Item1 is ICameraPoolCamera)
                    {
                        ICameraPoolCamera camera = (ICameraPoolCamera)item.Item1;
                        numCamerasChanged = true;

                        if (item.Item2)
                        {
                            #region Add Camera

                            cameras.Add(camera);

                            #endregion
                        }
                        else
                        {
                            #region Remove Camera

                            cameras.Remove(camera);

                            #endregion
                        }
                    }
                    else
                    {
                        throw new ApplicationException("Unknown type of item: " + item.Item1.GetType().ToString());
                    }
                }

                // Store the new count
                if (numCamerasChanged)
                {
                    parent._count = cameras.Count;
                }
            }
Esempio n. 5
0
        public void Add(ICameraPoolCamera camera)
        {
            if (_cameraPointers.ContainsKey(camera.Token))
            {
                throw new ArgumentException("This camera has already been added");
            }

            // Find the thread with the least to do
            TaskWrapper wrapper = _tasks.
                OrderBy(o => o.Count).
                First();

            // Add to the wrapper
            wrapper.AddRemoves.Enqueue(new Tuple<object, bool>(camera, true));

            // Remember where it is
            _cameraPointers.Add(camera.Token, wrapper);
        }