Exemple #1
0
        internal void RenderFrame(double delta)
        {
            frameTimer.Reset();
            frameTimer.Start();

            Graphics.BeginFrame(this);
            Graphics.BindIb(defaultIb);
            accumulator += delta;
            Vertices     = 0;
            if (!Focused && !ScreenLockedInput)
            {
                SetNewScreen(new PauseScreen(this));
            }

            CheckScheduledTasks(delta);
            float t = (float)(ticksAccumulator / ticksPeriod);

            LocalPlayer.SetInterpPosition(t);

            Graphics.Clear();
            Graphics.SetMatrixMode(MatrixType.Modelview);
            Matrix4 modelView = Camera.GetView(delta);

            View = modelView;
            Graphics.LoadMatrix(ref modelView);
            Culling.CalcFrustumEquations(ref Projection, ref modelView);

            bool visible = activeScreen == null || !activeScreen.BlocksWorld;

            if (Map.IsNotLoaded)
            {
                visible = false;
            }
            if (visible)
            {
                AxisLinesRenderer.Render(delta);
                Players.RenderModels(Graphics, delta, t);
                Players.RenderNames(Graphics, delta, t);
                CurrentCameraPos = Camera.GetCameraPos(LocalPlayer.EyePosition);

                ParticleManager.Render(delta, t);
                Camera.GetPickedBlock(SelectedPos);                   // TODO: only pick when necessary
                EnvRenderer.Render(delta);
                if (SelectedPos.Valid && !HideGui)
                {
                    Picking.Render(delta, SelectedPos);
                }
                MapRenderer.Render(delta);
                SelectionManager.Render(delta);
                Players.RenderHoveredNames(Graphics, delta, t);

                bool left   = IsMousePressed(MouseButton.Left);
                bool middle = IsMousePressed(MouseButton.Middle);
                bool right  = IsMousePressed(MouseButton.Right);
                InputHandler.PickBlocks(true, left, middle, right);
                if (!HideGui)
                {
                    BlockHandRenderer.Render(delta, t);
                }
            }
            else
            {
                SelectedPos.SetAsInvalid();
            }

            Graphics.Mode2D(Width, Height, EnvRenderer is StandardEnvRenderer);
            fpsScreen.Render(delta);
            if (activeScreen == null || !activeScreen.HidesHud && !activeScreen.RenderHudAfter)
            {
                hudScreen.Render(delta);
            }
            if (activeScreen != null)
            {
                activeScreen.Render(delta);
            }
            if (activeScreen != null && !activeScreen.HidesHud && activeScreen.RenderHudAfter)
            {
                hudScreen.Render(delta);
            }
            Graphics.Mode3D(EnvRenderer is StandardEnvRenderer);

            if (screenshotRequested)
            {
                TakeScreenshot();
            }
            Graphics.EndFrame(this);
            LimitFPS();
        }
Exemple #2
0
        internal void OnLoad()
        {
            Mouse    = window.Mouse;
            Keyboard = window.Keyboard;
                        #if !USE_DX
            Graphics = new OpenGLApi();
                        #else
            Graphics = new Direct3D9Api(this);
                        #endif
            Graphics.MakeGraphicsInfo();

            Options.Load();
            Players = new EntityList(this);
            AcceptedUrls.Load(); DeniedUrls.Load();
            ViewDistance     = Options.GetInt(OptionsKey.ViewDist, 16, 4096, 512);
            UserViewDistance = ViewDistance;
            CameraClipping   = Options.GetBool(OptionsKey.CameraClipping, true);
            InputHandler     = new InputHandler(this);
            defaultIb        = Graphics.MakeDefaultIb();
            ParticleManager  = new ParticleManager(this);
            MouseSensitivity = Options.GetInt(OptionsKey.Sensitivity, 1, 100, 30);
            LoadGui();

            UseClassicGui       = Options.GetBool(OptionsKey.UseClassicGui, true);
            UseClassicTabList   = Options.GetBool(OptionsKey.UseClassicTabList, false);
            UseClassicOptions   = Options.GetBool(OptionsKey.UseClassicOptions, false);
            AllowCustomBlocks   = Options.GetBool(OptionsKey.AllowCustomBlocks, true);
            PureClassicMode     = Options.GetBool("mode-classic", false);
            UseCPE              = Options.GetBool(OptionsKey.UseCPE, true);
            AllowServerTextures = Options.GetBool(OptionsKey.AllowServerTextures, true);

            BlockInfo = new BlockInfo();
            BlockInfo.Init();
            ChatLines     = Options.GetInt(OptionsKey.ChatLines, 1, 30, 12);
            ClickableChat = Options.GetBool(OptionsKey.ClickableChat, false);
            ModelCache    = new ModelCache(this);
            ModelCache.InitCache();
            AsyncDownloader           = new AsyncDownloader(skinServer);
            Drawer2D                  = new GdiPlusDrawer2D(Graphics);
            Drawer2D.UseBitmappedChat = !Options.GetBool(OptionsKey.ArialChatFont, false);
            ViewBobbing               = Options.GetBool(OptionsKey.ViewBobbing, false);
            ShowBlockInHand           = Options.GetBool(OptionsKey.ShowBlockInHand, true);
            InvertMouse               = Options.GetBool(OptionsKey.InvertMouse, false);
            SimpleArmsAnim            = Options.GetBool(OptionsKey.SimpleArmsAnim, false);

            TerrainAtlas1D = new TerrainAtlas1D(Graphics);
            TerrainAtlas   = new TerrainAtlas2D(Graphics, Drawer2D);
            Animations     = new Animations(this);
            defTexturePack = Options.Get(OptionsKey.DefaultTexturePack) ?? "default.zip";
            TexturePackExtractor extractor = new TexturePackExtractor();
            extractor.Extract("default.zip", this);
            // in case the user's default texture pack doesn't have all required textures
            if (defTexturePack != "default.zip")
            {
                extractor.Extract(DefaultTexturePack, this);
            }
            Inventory = new Inventory(this);

            BlockInfo.SetDefaultBlockPermissions(Inventory.CanPlace, Inventory.CanDelete);
            Map                = new Map(this);
            LocalPlayer        = new LocalPlayer(this);
            Players[255]       = LocalPlayer;
            width              = Width;
            height             = Height;
            MapRenderer        = new MapRenderer(this);
            MapBordersRenderer = new MapBordersRenderer(this);
            EnvRenderer        = new StandardEnvRenderer(this);
            if (IPAddress == null)
            {
                Network = new Singleplayer.SinglePlayerServer(this);
            }
            else
            {
                Network = new NetworkProcessor(this);
            }
            Graphics.LostContextFunction = Network.Tick;

            firstPersonCam        = new FirstPersonCamera(this);
            thirdPersonCam        = new ThirdPersonCamera(this);
            forwardThirdPersonCam = new ForwardThirdPersonCamera(this);
            Camera          = firstPersonCam;
            FieldOfView     = Options.GetInt(OptionsKey.FieldOfView, 1, 150, 70);
            ZoomFieldOfView = FieldOfView;
            UpdateProjection();
            CommandManager = new CommandManager();
            CommandManager.Init(this);
            SelectionManager = new SelectionManager(this);
            WeatherRenderer  = new WeatherRenderer(this);
            WeatherRenderer.Init();
            BlockHandRenderer = new BlockHandRenderer(this);
            BlockHandRenderer.Init();

            FpsLimitMethod method = Options.GetEnum(OptionsKey.FpsLimit, FpsLimitMethod.LimitVSync);
            SetFpsLimitMethod(method);
            Graphics.DepthTest = true;
            Graphics.DepthTestFunc(CompareFunc.LessEqual);
            //Graphics.DepthWrite = true;
            Graphics.AlphaBlendFunc(BlendFunc.SourceAlpha, BlendFunc.InvSourceAlpha);
            Graphics.AlphaTestFunc(CompareFunc.Greater, 0.5f);
            fpsScreen = new FpsScreen(this);
            fpsScreen.Init();
            hudScreen = new HudScreen(this);
            hudScreen.Init();
            Culling = new FrustumCulling();
            EnvRenderer.Init();
            MapBordersRenderer.Init();
            Picking           = new PickedPosRenderer(this);
            AudioPlayer       = new AudioPlayer(this);
            ModifiableLiquids = Options.GetBool(OptionsKey.ModifiableLiquids, false);
            AxisLinesRenderer = new AxisLinesRenderer(this);

            LoadIcon();
            string connectString = "Connecting to " + IPAddress + ":" + Port + "..";
            Graphics.WarnIfNecessary(Chat);
            SetNewScreen(new LoadingMapScreen(this, connectString, "Waiting for handshake"));
            Network.Connect(IPAddress, Port);
        }
Exemple #3
0
        internal void OnLoad()
        {
            Mouse    = window.Mouse;
            Keyboard = window.Keyboard;
                        #if ANDROID
            Graphics = new OpenGLESApi();
                        #elif !USE_DX
            Graphics = new OpenGLApi();
                        #else
            Graphics = new Direct3D9Api(this);
                        #endif
            Graphics.MakeApiInfo();
            ErrorHandler.AdditionalInfo = Graphics.ApiInfo;

            Options.Load();
            Entities = new EntityList(this);
            AcceptedUrls.Load();
            DeniedUrls.Load();
            ETags.Load();
            LastModified.Load();

            InputHandler    = new InputHandler(this);
            defaultIb       = Graphics.MakeDefaultIb();
            ParticleManager = AddComponent(new ParticleManager());
            TabList         = AddComponent(new TabList());
            LoadOptions();
            LoadGuiOptions();
            Chat = AddComponent(new Chat());
            WorldEvents.OnNewMap       += OnNewMapCore;
            WorldEvents.OnNewMapLoaded += OnNewMapLoadedCore;
            Events.TextureChanged      += TextureChangedCore;

            BlockInfo = new BlockInfo();
            BlockInfo.Init();
            ModelCache = new ModelCache(this);
            ModelCache.InitCache();
            AsyncDownloader = AddComponent(new AsyncDownloader());

                        #if ANDROID
            Drawer2D = new CanvasDrawer2D(Graphics);
                        #else
            Drawer2D = new GdiPlusDrawer2D(Graphics);
                        #endif

            Drawer2D.UseBitmappedChat = ClassicMode || !Options.GetBool(OptionsKey.ArialChatFont, false);
            Drawer2D.BlackTextShadows = Options.GetBool(OptionsKey.BlackTextShadows, false);

            TerrainAtlas1D = new TerrainAtlas1D(Graphics);
            TerrainAtlas   = new TerrainAtlas2D(Graphics, Drawer2D);
            Animations     = AddComponent(new Animations());
            Inventory      = AddComponent(new Inventory());

            BlockInfo.SetDefaultBlockPerms(Inventory.CanPlace, Inventory.CanDelete);
            World         = new World(this);
            LocalPlayer   = AddComponent(new LocalPlayer(this));
            Entities[255] = LocalPlayer;
            Width         = window.Width; Height = window.Height;

            MapRenderer = new MapRenderer(this);
            string renType = Options.Get(OptionsKey.RenderType) ?? "normal";
            if (!SetRenderType(renType))
            {
                SetRenderType("normal");
            }

            if (IPAddress == null)
            {
                Server = new Singleplayer.SinglePlayerServer(this);
            }
            else
            {
                Server = new Network.NetworkProcessor(this);
            }
            Graphics.LostContextFunction = Server.Tick;

            firstPersonCam        = new FirstPersonCamera(this);
            thirdPersonCam        = new ThirdPersonCamera(this, false);
            forwardThirdPersonCam = new ThirdPersonCamera(this, true);
            Camera = firstPersonCam;
            UpdateProjection();

            Gui               = AddComponent(new GuiInterface(this));
            CommandList       = AddComponent(new CommandList());
            SelectionManager  = AddComponent(new SelectionManager());
            WeatherRenderer   = AddComponent(new WeatherRenderer());
            HeldBlockRenderer = AddComponent(new HeldBlockRenderer());

            Graphics.DepthTest = true;
            Graphics.DepthTestFunc(CompareFunc.LessEqual);
            //Graphics.DepthWrite = true;
            Graphics.AlphaBlendFunc(BlendFunc.SourceAlpha, BlendFunc.InvSourceAlpha);
            Graphics.AlphaTestFunc(CompareFunc.Greater, 0.5f);
            Culling           = new FrustumCulling();
            Picking           = AddComponent(new PickedPosRenderer());
            AudioPlayer       = AddComponent(new AudioPlayer());
            AxisLinesRenderer = AddComponent(new AxisLinesRenderer());
            SkyboxRenderer    = AddComponent(new SkyboxRenderer());

            for (int i = 0; i < Components.Count; i++)
            {
                Components[i].Init(this);
            }
            ExtractInitialTexturePack();
            for (int i = 0; i < Components.Count; i++)
            {
                Components[i].Ready(this);
            }
            InitScheduledTasks();

            window.LoadIcon();
            string connectString = "Connecting to " + IPAddress + ":" + Port + "..";
            if (Graphics.WarnIfNecessary(Chat))
            {
                MapBordersRenderer.UseLegacyMode(true);
                EnvRenderer.UseLegacyMode(true);
            }
            Gui.SetNewScreen(new LoadingMapScreen(this, connectString, "Waiting for handshake"));
            Server.Connect(IPAddress, Port);
        }