Exemple #1
0
 public static void Destroy(PositionedInstance instance)
 {
     if (MouseHandler.IsSelectedNode(instance.SceneNode))
     {
         MouseHandler.ClearSelectedNode();
     }
     if (MouseHandler.IsAlreadyHovered(instance.SceneNode))
     {
         MouseHandler.ClearHovered();
     }
     SceneNodeStore.RemoveSceneNode(instance.SceneNode);
     instance.SceneNode.RemoveAllChildren();
     _renderer.Scene.DestroySceneNode(instance.SceneNode);
 }
Exemple #2
0
        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();
                        }
                    });
                });
            });
        }