Esempio n. 1
0
        private static void InternalSetup(Action <Settings> config = null)
        {
            // Initiate bootstrap.
            Debugger.Log(MessageType.Info, MessageSource.Engine, "-------------------------------");
            Debugger.Log(MessageType.Info, MessageSource.Engine, $"Executed at: {Environment.CurrentDirectory}");
            Debugger.Log(MessageType.Info, MessageSource.Engine, $"Debug Mode / Debugger Attached: {Debugger.DebugMode} / {System.Diagnostics.Debugger.IsAttached}");
            Debugger.Log(MessageType.Info, MessageSource.Engine, $"64Bit: {Environment.Is64BitProcess}");
            Debugger.Log(MessageType.Info, MessageSource.Engine, $"OS: {CurrentPlatform.OS} ({Environment.OSVersion})");
            Debugger.Log(MessageType.Info, MessageSource.Engine, $"CPU: {Environment.ProcessorCount}");

            // Run platform specific boot.
            switch (CurrentPlatform.OS)
            {
            case PlatformName.Windows:
                WindowsSetup();
                break;

            case PlatformName.Linux:
                LinuxSetup();
                break;
            }

            Debugger.Log(MessageType.Info, MessageSource.Engine, "-------------------------------");
            Debugger.Log(MessageType.Info, MessageSource.Engine, "Bootstrap complete.");

            // Apply settings and run initial setup function.
            Settings initial = new Settings();

            config?.Invoke(initial);
            Settings = initial;

            // Setup thread manager.
            GLThread.BindThread();

            // Create host if not created.
            if (Host == null)
            {
                try
                {
                    Debugger.Log(MessageType.Trace, MessageSource.Engine, "Creating host...");
                    if (CurrentPlatform.OS == PlatformName.Windows || CurrentPlatform.OS == PlatformName.Linux || CurrentPlatform.OS == PlatformName.Mac)
                    {
                        Host = new OtkWindow();
                        Debugger.Log(MessageType.Info, MessageSource.Engine, "Created OpenTK window host.");
                    }
                    else
                    {
                        throw new Exception("Unsupported platform.");
                    }
                }
                catch (Exception ex)
                {
                    Debugger.Log(MessageType.Error, MessageSource.Engine, "Could not create host. Is the system supported?");
                    Debugger.Log(MessageType.Error, MessageSource.Engine, ex.ToString());
                    throw;
                }
            }

            // Apply settings and hook.
            Host.ApplySettings(Settings);
            Host.SetHooks(LoopUpdate, LoopDraw, Resize);

            // Start creating modules.

            // Scripting engine is first to provide the other modules the ability to expose functions.
            Debugger.Log(MessageType.Trace, MessageSource.Engine, "Creating scripting engine...");
            ScriptingEngine = new ScriptingEngine();

            // Asset loader is next so other modules - especially the renderer, can access the file system.
            Debugger.Log(MessageType.Trace, MessageSource.Engine, "Creating asset loader...");
            AssetLoader = new AssetLoader();

            // The order of the next modules doesn't matter.

            Debugger.InitializeModule();

            Debugger.Log(MessageType.Trace, MessageSource.Engine, "Creating renderer...");
            Renderer = new Renderer();

            Debugger.Log(MessageType.Trace, MessageSource.Engine, "Creating sound manager...");
            SoundManager = new SoundManager();

            Debugger.Log(MessageType.Trace, MessageSource.Engine, "Creating layer manager...");
            LayerManager = new LayerManager();

            Debugger.Log(MessageType.Trace, MessageSource.Engine, "Creating input manager...");
            InputManager = new InputManager();
        }