Example #1
0
        public override async Task Run(Command command)
        {
            if (!ActiveScene.Running)
            {
                byte[] data = ActiveScene.SerializedContext;
                data = FlexUtility.Compress(data);

                SaveFileDialog saveDialog = new SaveFileDialog();

                saveDialog.AddExtension     = true;
                saveDialog.CheckFileExists  = false;
                saveDialog.CheckPathExists  = true;
                saveDialog.ValidateNames    = true;
                saveDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                saveDialog.FileName         = "MyProject.flex";
                saveDialog.Filter           = "flex project (*.flex)|*.flex|All files (*.*)|*.*";
                saveDialog.FilterIndex      = 0;

                if (saveDialog.ShowDialog() == DialogResult.OK)
                {
                    FileInfo file = new FileInfo(saveDialog.FileName);
                    file.Directory.Create();
                    File.WriteAllBytes(saveDialog.FileName, data);
                }
            }
        }
Example #2
0
        private static void Reset()
        {
            ActiveWorld world = FlexUtility.DeserializeToObject(_savedState) as ActiveWorld;

            List <InstancePair> correspondings;
            List <Instance>     removedInstances;
            List <Instance>     newInstances;

            List <Instance> newChildren = new List <Instance>();
            List <Instance> oldChildren = new List <Instance>();

            LoadResetInstanceHelper(_context.ActiveWorld.World, world.World, newChildren, oldChildren);

            newInstances     = newChildren.Where(x => !oldChildren.Any(y => x.Equals(y))).ToList();
            removedInstances = oldChildren.Where(x => !newChildren.Any(y => x.Equals(y))).ToList();
            correspondings   = oldChildren.Join(newChildren, x => x, y => y, (x, y) =>
            {
                return(new InstancePair(x, y));
            }).ToList();

            foreach (Instance newInstance in newInstances)
            {
                newInstance.Cleanup();
            }

            foreach (Instance removedInstance in removedInstances)
            {
                /*
                 * Implement
                 */
            }

            foreach (InstancePair instancePair in correspondings)
            {
                ObjectSave save = new ObjectSave(instancePair.Old, instancePair.Current, instancePair.Current.GetType());
                save.Reset();
                try
                {
                    InstancePair oldParent = correspondings.Where(x => x.Old.equals(instancePair.Old.parent)).FirstOrDefault();
                    if (oldParent != null && oldParent.Current != null)
                    {
                        instancePair.Current.parent = oldParent.Current;
                    }
                }
                catch { }
                instancePair.Current.Reload();
            }

            ResetInstance(world.Sky, _context.ActiveWorld.Sky);
        }
Example #3
0
        private void TreeInstancesDrop(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(e.Data.GetFormats()[0]) && !ActiveScene.Running)
            {
                Instance     dragging     = e.Data.GetData(e.Data.GetFormats()[0], true) as Instance;
                TreeViewItem treeViewItem =
                    FlexUtility.FindAncestor <TreeViewItem>((DependencyObject)e.OriginalSource);

                Instance dropTarget = treeViewItem.Header as Instance;

                if (dropTarget == null || dragging == null)
                {
                    return;
                }

                dragging.parent = dropTarget;

                ActiveInstances.Items.Refresh();
            }
        }
Example #4
0
        private void TreeInstancePreviewMouseMove(object sender, MouseEventArgs e)
        {
            if (e.LeftButton == MouseButtonState.Pressed && !ActiveScene.Running)
            {
                var mousePos = e.GetPosition(null);
                var diff     = _startPoint - mousePos;

                if (Math.Abs(diff.X) > SystemParameters.MinimumHorizontalDragDistance || Math.Abs(diff.Y) > SystemParameters.MinimumVerticalDragDistance)
                {
                    TreeView     treeView     = sender as TreeView;
                    TreeViewItem treeViewItem = FlexUtility.FindAncestor <TreeViewItem>((DependencyObject)e.OriginalSource);

                    if (treeView == null || treeViewItem == null)
                    {
                        return;
                    }

                    Instance dragging = treeView.SelectedItem as Instance;

                    if (dragging == null)
                    {
                        return;
                    }

                    DataObject dragData = new DataObject(dragging);

                    try
                    {
                        DragDrop.DoDragDrop(treeViewItem, dragData, DragDropEffects.Move);
                    }
                    catch
                    {
                    }
                }
            }
        }
Example #5
0
File: Engine.cs Project: ext0/Flex
        public static void Initialize(SceneViewModel view)
        {
            _sceneNodeStore = new SceneNodeStore();
            _host           = new System.Windows.Forms.Integration.WindowsFormsHost();


            _panel          = new Panel();
            _panel.Name     = "MogrePanel";
            _panel.Location = new System.Drawing.Point(0, 0);
            _panel.Size     = new System.Drawing.Size((int)view.View.RenderWindow.Width, (int)view.View.RenderWindow.Height);
            //_panel.Resize += _panel_Resize;

            _keyboardHandler = new KeyboardHandler(_host, _panel);
            _mouseHandler    = new MouseHandler(_host, _panel);

            _host.Child = _panel;

            view.View.RenderWindow.Children.Add(_host);

            FlexUtility.SpawnThread(() =>
            {
                RunOnUIThread(() =>
                {
                    _renderer = new MogreRenderer(_panel.Handle.ToString(), (uint)_panel.Width, (uint)_panel.Height);

                    _renderer.CreateScene();

                    while (_preInitializationActions.Count != 0)
                    {
                        _preInitializationActions.Dequeue().Invoke();
                    }

                    _mouseHandler.Initialize();
                    _keyboardHandler.Initialize();

                    _initialized = true;

                    FlexUtility.SpawnThread(() =>
                    {
                        _renderThread          = Thread.CurrentThread;
                        Mogre.Timer timer      = new Mogre.Timer();
                        int attemptedFrameRate = 60;
                        bool physicsRender     = true;

                        while (true)
                        {
                            while (_renderDispatcherActionQueue.Count != 0)
                            {
                                System.Action action;
                                lock (_renderDispatcherActionQueue)
                                {
                                    action = _renderDispatcherActionQueue.Dequeue();
                                }
                                if (action != null)
                                {
                                    action.Invoke();
                                }
                            }
                            lock (_renderNextDispatcherActionQueue)
                            {
                                lock (_renderDispatcherActionQueue)
                                {
                                    while (_renderNextDispatcherActionQueue.Count != 0)
                                    {
                                        _renderDispatcherActionQueue.Enqueue(_renderNextDispatcherActionQueue.Dequeue());
                                    }
                                }
                            }
                            uint elapsed = timer.Milliseconds;
                            timer.Reset();

                            int wait = (int)((1000 / attemptedFrameRate) - elapsed);

                            if (wait > 0)
                            {
                                Thread.Sleep(wait);
                            }

                            _keyboardHandler.KeyboardTick();
                            if (physicsRender)
                            {
                                PhysicsEngine.Step();
                            }
                            physicsRender = !physicsRender;
                            Renderer.Loop();
                        }
                    });
                });
            });
        }