示例#1
0
        /// <summary>
        /// Helper function to create the default window. This is the callback
        /// to the PluginManager.
        /// </summary>
        /// <param name="defaultWindow"></param>
        private void createWindow(out WindowInfo defaultWindow)
        {
            //Setup main window
            defaultWindow              = new WindowInfo(mainWindow, "Primary");
            defaultWindow.Fullscreen   = AnomalyConfig.EngineConfig.Fullscreen;
            defaultWindow.MonitorIndex = 0;

            if (AnomalyConfig.EngineConfig.Fullscreen)
            {
                mainWindow.setSize(AnomalyConfig.EngineConfig.HorizontalRes, AnomalyConfig.EngineConfig.VerticalRes);
                mainWindow.ExclusiveFullscreen = true;
            }
            else
            {
                mainWindow.Maximized = true;
            }
            mainWindow.show();
        }
示例#2
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 MedicalController(NativeOSWindow mainWindow)
        {
            //Create the log.
            logListener = new LogFileListener();
            logListener.openLogFile(MedicalConfig.LogFile);
            Log.Default.addLogListener(logListener);
            Log.ImportantInfo("Running from directory {0}", FolderFinder.ExecutableFolder);

            //Create pluginmanager
            pluginManager = new PluginManager(MedicalConfig.ConfigFile, services);

            //Configure the filesystem
            VirtualFileSystem archive = VirtualFileSystem.Instance;

            //Setup microcode cache load
            OgreInterface.MicrocodeCachePath      = Path.Combine(FolderFinder.LocalPrivateDataFolder, "ShaderCache.mcc");
            OgreInterface.AllowMicrocodeCacheLoad = MedicalConfig.LastShaderVersion == UnifiedMaterialBuilder.Version;
            OgreInterface.TrackMemoryLeaks        = MedicalConfig.TrackMemoryLeaks;
            MedicalConfig.LastShaderVersion       = UnifiedMaterialBuilder.Version;

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

            RuntimePlatformInfo.addPath(MedicalConfig.OpenGLESEmulatorPath);

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

                if (MedicalConfig.EngineConfig.Fullscreen)
                {
                    mainWindow.setSize(MedicalConfig.EngineConfig.HorizontalRes, MedicalConfig.EngineConfig.VerticalRes);
                    mainWindow.ExclusiveFullscreen = true;
                    defaultWindow.Width            = MedicalConfig.EngineConfig.HorizontalRes;
                    defaultWindow.Height           = MedicalConfig.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.Gui;
            GuiFrameworkCamerasInterface.TouchType = PlatformConfig.TouchType;
            GuiFrameworkCamerasInterface.PanKey    = PlatformConfig.PanKey;

            GuiFrameworkEditorInterface.ToolsEventLayers = EventLayers.Tools;

            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(BEPUikInterface).Assembly);
            pluginManager.addPluginAssembly(typeof(SimulationPlugin).Assembly);
            pluginManager.addPluginAssembly(typeof(GuiFrameworkInterface).Assembly);
            pluginManager.addPluginAssembly(typeof(RocketWidgetInterface).Assembly);
            pluginManager.addPluginAssembly(typeof(GuiFrameworkCamerasInterface).Assembly);
            pluginManager.addPluginAssembly(typeof(GuiFrameworkEditorInterface).Assembly);
            pluginManager.addPluginAssembly(typeof(GuiFrameworkDebuggingInterface).Assembly);
            pluginManager.initializePlugins();

            performanceMetricTimer = new NativeSystemTimer();
            PerformanceMonitor.setupEnabledState(performanceMetricTimer);

            //Intialize the platform
            BulletInterface.Instance.ShapeMargin = 0.005f;
            systemTimer = new NativeSystemTimer();

            mainTimer = new NativeUpdateTimer(systemTimer);

            if (OgreConfig.VSync && MedicalConfig.EngineConfig.FPSCap < 300)
            {
                //Use a really high 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 = 300;
            }
            else
            {
                mainTimer.FramerateCap = MedicalConfig.EngineConfig.FPSCap;
            }

            inputHandler = new NativeInputHandler(mainWindow, MedicalConfig.EnableMultitouch);
            eventManager = new EventManager(inputHandler, Enum.GetValues(typeof(EventLayers)));
            eventUpdate  = new EventUpdateListener(eventManager);
            mainTimer.addUpdateListener(eventUpdate);
            pluginManager.setPlatformInfo(mainTimer, eventManager);
            medicalUpdate = new MedicalUpdate(this);
            mainTimer.addUpdateListener(medicalUpdate);

            //Initialize controllers
            medicalScene      = new MedicalSceneController(pluginManager);
            frameClearManager = new FrameClearManager(OgreInterface.Instance.OgrePrimaryWindow.OgreRenderTarget);

            SoundConfig.initialize(MedicalConfig.ConfigFile);

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

            TouchMouseGuiForwarder = new TouchMouseGuiForwarder(eventManager, inputHandler, systemTimer, mainWindow, EventLayers.Last);
            TouchMouseGuiForwarder.ForwardTouchesAsMouse = PlatformConfig.ForwardTouchAsMouse;
            var myGuiKeyboard  = new MyGUIOnscreenKeyboardManager(TouchMouseGuiForwarder);
            var rocketKeyboard = new RocketWidgetOnscreenKeyboardManager(TouchMouseGuiForwarder);
        }