Beispiel #1
0
        private void BuildPluginManager()
        {
            mainWindow = new NativeOSWindow(startup.Title,
                                            new IntVector2(-1, -1),
                                            new IntSize2(CoreConfig.EngineConfig.HorizontalRes, CoreConfig.EngineConfig.VerticalRes));

            services.TryAddSingleton <OSWindow>(mainWindow);       //This is externally owned
            services.TryAddSingleton <NativeOSWindow>(mainWindow); //This is externally owned

            mainWindow.Closed += w =>
            {
                if (PlatformConfig.CloseMainWindowOnShutdown)
                {
                    mainWindow.close();
                }
                this.exit();
            };

            //Setup DPI
            float pixelScale = mainWindow.WindowScaling;

            switch (CoreConfig.ExtraScaling)
            {
            case UIExtraScale.Smaller:
                pixelScale -= .15f;
                break;

            case UIExtraScale.Larger:
                pixelScale += .25f;
                break;
            }

            ScaleHelper._setScaleFactor(pixelScale);

            pluginManager = new PluginManager(CoreConfig.ConfigFile, services);

            services.TryAddSingleton <SystemTimer, NativeSystemTimer>();

            services.TryAddSingleton <UpdateTimer, NativeUpdateTimer>();

            services.TryAddSingleton <InputHandler>(s =>
            {
                return(new NativeInputHandler(s.GetRequiredService <NativeOSWindow>(), CoreConfig.EnableMultitouch));
            });

            services.TryAddSingleton <EventManager>(s =>
            {
                return(new EventManager(s.GetRequiredService <InputHandler>(), Enum.GetValues(typeof(EventLayers))));
            });

            MyGUIInterface.EventLayerKey     = EventLayers.Gui;
            MyGUIInterface.CreateGuiGestures = CoreConfig.EnableMultitouch && PlatformConfig.TouchType == TouchType.Screen;

            OgreInterface.CompressedTextureSupport = CompressedTextureSupport.None;
            OgreInterface.TrackMemoryLeaks         = true;

            //Configure plugins
            pluginManager.OnConfigureDefaultWindow = delegate(out WindowInfo defaultWindow)
            {
                //Setup main window
                defaultWindow              = new WindowInfo(mainWindow, "Primary");
                defaultWindow.Fullscreen   = CoreConfig.EngineConfig.Fullscreen;
                defaultWindow.MonitorIndex = 0;

                if (CoreConfig.EngineConfig.Fullscreen)
                {
                    mainWindow.setSize(CoreConfig.EngineConfig.HorizontalRes, CoreConfig.EngineConfig.VerticalRes);
                    mainWindow.ExclusiveFullscreen = true;
                    defaultWindow.Width            = CoreConfig.EngineConfig.HorizontalRes;
                    defaultWindow.Height           = CoreConfig.EngineConfig.VerticalRes;
                }
                else
                {
                    mainWindow.Maximized = true;
                }
                mainWindow.show();
            };

            //GuiFrameworkCamerasInterface.CameraTransitionTime = MedicalConfig.CameraTransitionTime;
            //GuiFrameworkCamerasInterface.DefaultCameraButton = MedicalConfig.CameraMouseButton;
            GuiFrameworkCamerasInterface.MoveCameraEventLayer   = EventLayers.Cameras;
            GuiFrameworkCamerasInterface.SelectWindowEventLayer = EventLayers.AfterGui;
            GuiFrameworkCamerasInterface.ShortcutEventLayer     = EventLayers.AfterGui;
            GuiFrameworkCamerasInterface.TouchType = PlatformConfig.TouchType;
            GuiFrameworkCamerasInterface.PanKey    = PlatformConfig.PanKey;

            pluginManager.addPluginAssembly(typeof(OgreInterface).Assembly());
            pluginManager.addPluginAssembly(typeof(BulletInterface).Assembly());
            pluginManager.addPluginAssembly(typeof(NativePlatformPlugin).Assembly());
            pluginManager.addPluginAssembly(typeof(MyGUIInterface).Assembly());
            pluginManager.addPluginAssembly(typeof(RocketInterface).Assembly());
            pluginManager.addPluginAssembly(typeof(SoundPluginInterface).Assembly());
            pluginManager.addPluginAssembly(typeof(GuiFrameworkInterface).Assembly());
            pluginManager.addPluginAssembly(typeof(RocketWidgetInterface).Assembly());
            pluginManager.addPluginAssembly(typeof(GuiFrameworkCamerasInterface).Assembly());
            foreach (var assembly in startup.AdditionalPluginAssemblies)
            {
                pluginManager.addPluginAssembly(assembly);
            }
            pluginManager.initializePlugins();

            var scope = pluginManager.GlobalScope;

            var systemTimer  = scope.ServiceProvider.GetRequiredService <SystemTimer>();
            var mainTimer    = scope.ServiceProvider.GetRequiredService <UpdateTimer>();
            var inputHandler = this.InputHandler = scope.ServiceProvider.GetRequiredService <InputHandler>();
            var eventManager = scope.ServiceProvider.GetRequiredService <EventManager>();

            //Intialize the platform
            BulletInterface.Instance.ShapeMargin = 0.005f;

            //Setup framerate cap
            if (PlatformConfig.FpsCap.HasValue)
            {
                //Use platform cap if it is set always
                mainTimer.FramerateCap = PlatformConfig.FpsCap.Value;
            }
            else if (OgreConfig.VSync)
            {
                //Use a unlimited framerate cap if vsync is on since it will cap our
                //framerate for us. If the user has requested a higher rate use it anyway.
                mainTimer.FramerateCap = 0;
            }
            else
            {
                //Otherwise config cap
                mainTimer.FramerateCap = CoreConfig.EngineConfig.FPSCap;
            }

            mainTimer.addUpdateListener(new EventUpdateListener(eventManager));

            pluginManager.setPlatformInfo(mainTimer, eventManager);

            GuiFrameworkInterface.Instance.handleCursors(mainWindow);

            SoundConfig.initialize(CoreConfig.ConfigFile);

            GuiFrameworkInterface.Instance.handleCursors(mainWindow);
            SoundPluginInterface.Instance.setResourceWindow(mainWindow);

            var touchMouseGuiForwarder = new TouchMouseGuiForwarder(eventManager, inputHandler, systemTimer, mainWindow, EventLayers.Last);

            touchMouseGuiForwarder.ForwardTouchesAsMouse = PlatformConfig.ForwardTouchAsMouse;
            var myGuiKeyboard  = new MyGUIOnscreenKeyboardManager(touchMouseGuiForwarder);
            var rocketKeyboard = new RocketWidgetOnscreenKeyboardManager(touchMouseGuiForwarder);
        }
 public override void close()
 {
     osWindow.close();
 }