示例#1
0
 /// <summary>
 /// Called when the window is loading, only to be used by the startup process.
 /// </summary>
 void Window_Load(object sender, EventArgs e)
 {
     SysConsole.Output(OutputType.INIT, "Window generated!");
     DPIScale = Window.Width / CVars.r_width.ValueF;
     SysConsole.Output(OutputType.INIT, "DPIScale is " + DPIScale + "!");
     SysConsole.Output(OutputType.INIT, "Loading base textures...");
     PreInitRendering();
     Textures = new TextureEngine();
     Textures.InitTextureSystem(this);
     ItemFrame = Textures.GetTexture("ui/hud/item_frame");
     SysConsole.Output(OutputType.INIT, "Loading shaders...");
     Shaders = new ShaderEngine();
     GLVendor = GL.GetString(StringName.Vendor);
     CVars.s_glvendor.Value = GLVendor;
     GLVersion = GL.GetString(StringName.Version);
     CVars.s_glversion.Value = GLVersion;
     GLRenderer = GL.GetString(StringName.Renderer);
     CVars.s_glrenderer.Value = GLRenderer;
     SysConsole.Output(OutputType.INIT, "Vendor: " + GLVendor + ", GLVersion: " + GLVersion + ", Renderer: " + GLRenderer);
     if (GLVendor.ToLowerFast().Contains("intel"))
     {
         SysConsole.Output(OutputType.INIT, "Disabling good graphics (Appears to be Intel: '" + GLVendor + "')");
         Shaders.MCM_GOOD_GRAPHICS = false;
     }
     Shaders.InitShaderSystem(this);
     View3D.CheckError("Load - Shaders");
     SysConsole.Output(OutputType.INIT, "Loading rendering helper...");
     Rendering = new Renderer(Textures, Shaders);
     Rendering.Init();
     SysConsole.Output(OutputType.INIT, "Preparing load screen...");
     Texture load_screen = Textures.GetTexture("ui/menus/loadscreen");
     load_screen.Bind();
     Shaders.ColorMultShader.Bind();
     Establish2D();
     Rendering.RenderRectangle(0, 0, Window.Width, Window.Height);
     Window.SwapBuffers();
     SysConsole.Output(OutputType.INIT, "Loading block textures...");
     TBlock = new TextureBlock();
     TBlock.Generate(this, CVars, Textures);
     View3D.CheckError("Load - Textures");
     SysConsole.Output(OutputType.INIT, "Loading fonts...");
     Fonts = new GLFontEngine(Shaders);
     Fonts.Init(this);
     FontSets = new FontSetEngine(Fonts);
     FontSets.Init(this);
     View3D.CheckError("Load - Fonts");
     SysConsole.Output(OutputType.INIT, "Loading animation engine...");
     Animations = new AnimationEngine();
     SysConsole.Output(OutputType.INIT, "Loading model engine...");
     Models = new ModelEngine();
     Models.Init(Animations, this);
     SysConsole.Output(OutputType.INIT, "Loading general graphics settings...");
     CVars.r_vsync.OnChanged += onVsyncChanged;
     onVsyncChanged(CVars.r_vsync, null);
     CVars.r_cloudshadows.OnChanged += onCloudShadowChanged;
     View3D.CheckError("Load - General Graphics");
     SysConsole.Output(OutputType.INIT, "Loading UI engine...");
     UIConsole.InitConsole(); // TODO: make this non-static
     InitChatSystem();
     View3D.CheckError("Load - UI");
     SysConsole.Output(OutputType.INIT, "Preparing rendering engine...");
     InitRendering();
     View3D.CheckError("Load - Rendering");
     SysConsole.Output(OutputType.INIT, "Loading particle effect engine...");
     Particles = new ParticleHelper(this) { Engine = new ParticleEngine(this) };
     SysConsole.Output(OutputType.INIT, "Preparing mouse, keyboard, and gamepad handlers...");
     KeyHandler.Init();
     GamePadHandler.Init();
     View3D.CheckError("Load - Keyboard/mouse");
     SysConsole.Output(OutputType.INIT, "Building the sound system...");
     Sounds = new SoundEngine();
     Sounds.Init(this, CVars);
     View3D.CheckError("Load - Sound");
     SysConsole.Output(OutputType.INIT, "Building game world...");
     BuildWorld();
     View3D.CheckError("Load - World");
     SysConsole.Output(OutputType.INIT, "Preparing networking...");
     Network = new NetworkBase(this);
     RegisterDefaultEntityTypes();
     View3D.CheckError("Load - Net");
     SysConsole.Output(OutputType.INIT, "Playing background music...");
     BackgroundMusic();
     CVars.a_musicvolume.OnChanged += onMusicVolumeChanged;
     CVars.a_musicpitch.OnChanged += onMusicPitchChanged;
     CVars.a_music.OnChanged += onMusicChanged;
     CVars.a_echovolume.OnChanged += OnEchoVolumeChanged;
     OnEchoVolumeChanged(null, null);
     SysConsole.Output(OutputType.INIT, "Setting up screens...");
     TheMainMenuScreen = new MainMenuScreen(this);
     TheGameScreen = new GameScreen(this);
     TheSingleplayerMenuScreen = new SingleplayerMenuScreen(this);
     SysConsole.Output(OutputType.INIT, "Preparing inventory...");
     InitInventory();
     SysConsole.Output(OutputType.INIT, "Showing main menu...");
     ShowMainMenu();
     SysConsole.Output(OutputType.INIT, "Trying to grab RawGamePad...");
     try
     {
         RawGamePad = new XInput();
     }
     catch (Exception ex)
     {
         SysConsole.Output(OutputType.INIT, "Failed to grab RawGamePad: " + ex.Message);
     }
     View3D.CheckError("Load - Final");
     SysConsole.Output(OutputType.INIT, "Ready and looping!");
 }
示例#2
0
        /// <summary>
        /// Called when the window is loading, only to be used by the startup process.
        /// </summary>
        void Window_Load(object sender, EventArgs e)
        {
            SysConsole.Output(OutputType.CLIENTINIT, "Window generated!");
            DPIScale = Window.Width / CVars.r_width.ValueF;
            SysConsole.Output(OutputType.CLIENTINIT, "DPIScale is " + DPIScale + "!");
            SysConsole.Output(OutputType.CLIENTINIT, "Setting up a game engine backend placeholder...");
            FakeEngine();
            SysConsole.Output(OutputType.CLIENTINIT, "Loading base textures...");
            PreInitRendering();
            Textures = new TextureEngine();
            Textures.InitTextureSystem(Files);
            ItemFrame        = Textures.GetTexture("ui/hud/item_frame");
            CWindow.Textures = Textures;
            SysConsole.Output(OutputType.CLIENTINIT, "Loading shaders...");
            Shaders    = new ShaderEngine();
            GLVendor   = GL.GetString(StringName.Vendor);
            GLVersion  = GL.GetString(StringName.Version);
            GLRenderer = GL.GetString(StringName.Renderer);
            SysConsole.Output(OutputType.CLIENTINIT, "Vendor: " + GLVendor + ", GLVersion: " + GLVersion + ", Renderer: " + GLRenderer);
            if (GLVendor.ToLowerFast().Contains("intel"))
            {
                SysConsole.Output(OutputType.CLIENTINIT, "Disabling good graphics (Appears to be Intel: '" + GLVendor + "')");
                Shaders.MCM_GOOD_GRAPHICS = false;
            }
            Shaders.InitShaderSystem();
            CWindow.Shaders = Shaders;
            Engine.GetShaders();
            GraphicsUtil.CheckError("Load - Shaders");
            SysConsole.Output(OutputType.CLIENTINIT, "Loading animation engine...");
            Animations         = new AnimationEngine();
            CWindow.Animations = Animations;
            SysConsole.Output(OutputType.CLIENTINIT, "Loading model engine...");
            Models = new ModelEngine();
            Models.Init(Animations, CWindow);
            LODHelp        = new ModelLODHelper(this);
            CWindow.Models = Models;
            SysConsole.Output(OutputType.CLIENTINIT, "Loading rendering helper...");
            Rendering = new Renderer(Textures, Shaders, Models);
            Rendering.Init();
            CWindow.Rendering3D = Rendering;
            CWindow.Rendering2D = new Renderer2D(Textures, Shaders);
            CWindow.Rendering2D.Init();
            SysConsole.Output(OutputType.CLIENTINIT, "Preparing load screen...");
            load_screen = Textures.GetTexture("ui/menus/loadscreen");
            Establish2D();
            SWLoading.Start();
            PassLoadScreen();
            SysConsole.Output(OutputType.CLIENTINIT, "Loading block textures...");
            TBlock = new TextureBlock();
            TBlock.Generate(this, CVars, Textures, false);
            GraphicsUtil.CheckError("Load - Textures");
            SysConsole.Output(OutputType.CLIENTINIT, "Loading fonts...");
            Fonts = new GLFontEngine(Shaders);
            Fonts.Init(Files);
            FontSets = new FontSetEngine(Fonts);
            FontSets.Init((subdat) => Languages.GetText(Files, subdat), () => Ortho, () => GlobalTickTimeLocal);
            GraphicsUtil.CheckError("Load - Fonts");
            PassLoadScreen();
            CWindow.FontSets = FontSets;
            CWindow.GLFonts  = Fonts;
            SysConsole.Output(OutputType.CLIENTINIT, "Loading general graphics settings...");
            CVars.r_vsync.OnChanged += OnVsyncChanged;
            OnVsyncChanged(CVars.r_vsync, EventArgs.Empty);
            CVars.r_cloudshadows.OnChanged += OnCloudShadowChanged;
            CVars.r_transpll.OnChanged     += OnLLChanged;
            OnLLChanged(CVars.r_transpll, EventArgs.Empty);
            GraphicsUtil.CheckError("Load - General Graphics");
            SysConsole.Output(OutputType.CLIENTINIT, "Loading UI engine...");
            UIConsole.InitConsole(); // TODO: make this non-static
            InitChatSystem();
            PassLoadScreen();
            GraphicsUtil.CheckError("Load - UI");
            SysConsole.Output(OutputType.CLIENTINIT, "Preparing rendering engine...");
            InitRendering();
            GraphicsUtil.CheckError("Load - Rendering");
            SysConsole.Output(OutputType.CLIENTINIT, "Loading particle effect engine...");
            Particles = new ParticleHelper(this)
            {
                Engine = new ParticleEngine(this)
            };
            SysConsole.Output(OutputType.CLIENTINIT, "Preparing mouse and keyboard handlers...");
            KeyHandler.Init();
            Gamepad = new GamePadHandler();
            Gamepad.Init(this);
            PassLoadScreen();
            GraphicsUtil.CheckError("Load - Keyboard/mouse");
            SysConsole.Output(OutputType.CLIENTINIT, "Building the sound system...");
            Sounds.Init(Engine);
            GraphicsUtil.CheckError("Load - Sound");
            SysConsole.Output(OutputType.CLIENTINIT, "Building game world...");
            BuildWorld();
            PassLoadScreen();
            GraphicsUtil.CheckError("Load - World");
            SysConsole.Output(OutputType.CLIENTINIT, "Preparing networking...");
            Network = new NetworkBase(this);
            RegisterDefaultEntityTypes();
            GraphicsUtil.CheckError("Load - Net");
            PassLoadScreen();
            SysConsole.Output(OutputType.CLIENTINIT, "Loading Voxel computer...");
            try
            {
                VoxelComputer = new VoxelComputeEngine();
                VoxelComputer.Init(this);
            }
            catch (Exception ex)
            {
                SysConsole.Output(ex);
            }
            PassLoadScreen();
            SysConsole.Output(OutputType.CLIENTINIT, "Playing background music...");
            BackgroundMusic();
            CVars.a_musicvolume.OnChanged += OnMusicVolumeChanged;
            CVars.a_musicpitch.OnChanged  += OnMusicPitchChanged;
            CVars.a_music.OnChanged       += OnMusicChanged;
            CVars.a_echovolume.OnChanged  += OnEchoVolumeChanged;
            OnEchoVolumeChanged(null, null);
            PassLoadScreen();
            SysConsole.Output(OutputType.CLIENTINIT, "Setting up screens...");
            TheMainMenuScreen         = new MainMenuScreen(this);
            TheGameScreen             = new GameScreen(this);
            TheSingleplayerMenuScreen = new SingleplayerMenuScreen(this);
            TheLoadScreen             = new LoadScreen(this);
            CScreen = TheMainMenuScreen;
            SysConsole.Output(OutputType.CLIENTINIT, "Trying to grab RawGamePad...");
            try
            {
                RawGamePad = new XInput();
            }
            catch (Exception ex)
            {
                SysConsole.Output(OutputType.CLIENTINIT, "Failed to grab RawGamePad: " + ex.Message);
            }
            SysConsole.Output(OutputType.CLIENTINIT, "Preparing inventory...");
            InitInventory();
            PassLoadScreen();
            SysConsole.Output(OutputType.CLIENTINIT, "Requesting a menu server...");
            LocalServer?.ShutDown();
            LocalServer = new Server(28009)
            {
                IsMenu = true
            };                                                 // TODO: Grab first free port?
            Object locky = new Object();
            bool   ready = false;

            Schedule.StartAsyncTask(() =>
            {
                LocalServer.StartUp("menu", () =>
                {
                    lock (locky)
                    {
                        ready = true;
                    }
                });
            });
            while (true)
            {
                lock (locky)
                {
                    if (ready)
                    {
                        break;
                    }
                }
                PassLoadScreen();
                Thread.Sleep(50);
            }
            SysConsole.Output(OutputType.CLIENTINIT, "Connecting to a menu server...");
            Network.LastConnectionFailed = false;
            Network.Connect("localhost", "28009", true, null); // TODO: Grab accurate local IP?
            Stopwatch sw = new Stopwatch();

            sw.Start();
            bool annc = false;

            while (true)
            {
                if (Network.LastConnectionFailed)
                {
                    SysConsole.Output(OutputType.CLIENTINIT, "Failed to connect to menu server! Failing!");
                    Window.Close();
                    return;
                }
                if (Network.IsAlive)
                {
                    break;
                }
                sw.Stop();
                long ms = sw.ElapsedMilliseconds;
                sw.Start();
                if (ms > 10000 && !annc)
                {
                    annc = true;
                    SysConsole.Output(OutputType.WARNING, "Taking weirdly long, did something fail?!");
                }
                if (ms > 20000)
                {
                    SysConsole.Output(OutputType.CLIENTINIT, "Timed out while trying to connect to menu server! Failing!");
                    Window.Close();
                    return;
                }
                PassLoadScreen();
                Thread.Sleep(50);
            }
            SysConsole.Output(OutputType.CLIENTINIT, "Showing main menu...");
            ShowMainMenu();
            GraphicsUtil.CheckError("Load - Final");
            SysConsole.Output(OutputType.CLIENTINIT, "Ready and looping!");
        }