示例#1
0
        protected override void OnLoad( EventArgs e )
        {
            #if !USE_DX
            Graphics = new OpenGLApi();
            #else
            Graphics = new Direct3D9Api( this );
            #endif
            Graphics.MakeGraphicsInfo();

            Options.Load();
            ViewDistance = Options.GetInt( OptionsKey.ViewDist, 16, 4096, 512 );
            InputHandler = new InputHandler( this );
            Chat = new ChatLog( this );
            Chat.FontSize = Options.GetInt( OptionsKey.FontSize, 6, 30, 12 );
            defaultIb = Graphics.MakeDefaultIb();
            MouseSensitivity = Options.GetInt( OptionsKey.Sensitivity, 1, 100, 30 );
            BlockInfo = new BlockInfo();
            BlockInfo.Init();
            ChatLines = Options.GetInt( OptionsKey.ChatLines, 1, 30, 12 );
            ModelCache = new ModelCache( this );
            ModelCache.InitCache();
            AsyncDownloader = new AsyncDownloader( skinServer );
            Drawer2D = new GdiPlusDrawer2D( Graphics );
            Drawer2D.UseBitmappedChat = !Options.GetBool( OptionsKey.ArialChatFont, false );

            TerrainAtlas1D = new TerrainAtlas1D( Graphics );
            TerrainAtlas = new TerrainAtlas2D( Graphics, Drawer2D );
            Animations = new Animations( this );
            TexturePackExtractor extractor = new TexturePackExtractor();
            extractor.Extract( defaultTexPack, this );
            Inventory = new Inventory( this );

            BlockInfo.SetDefaultBlockPermissions( Inventory.CanPlace, Inventory.CanDelete );
            Map = new Map( this );
            LocalPlayer = new LocalPlayer( this );
            LocalPlayer.SpeedMultiplier = Options.GetInt( OptionsKey.Speed, 1, 50, 10 );
            Players[255] = LocalPlayer;
            width = Width;
            height = Height;
            MapRenderer = new MapRenderer( this );
            MapEnvRenderer = new MapEnvRenderer( 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;
            CommandManager = new CommandManager();
            CommandManager.Init( this );
            SelectionManager = new SelectionManager( this );
            ParticleManager = new ParticleManager( this );
            WeatherRenderer = new WeatherRenderer( this );
            WeatherRenderer.Init();

            bool vsync = Options.GetBool( OptionsKey.VSync, true );
            Graphics.SetVSync( this, vsync );
            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();
            Culling = new FrustumCulling();
            EnvRenderer.Init();
            MapEnvRenderer.Init();
            Picking = new PickingRenderer( this );

            string connectString = "Connecting to " + IPAddress + ":" + Port +  "..";
            Graphics.WarnIfNecessary( Chat );
            SetNewScreen( new LoadingMapScreen( this, connectString, "Reticulating splines" ) );
            Network.Connect( IPAddress, Port );
        }
示例#2
0
        protected override void OnLoad( EventArgs e )
        {
            #if !USE_DX
            Graphics = new OpenGLApi();
            #else
            Graphics = new Direct3D9Api( this );
            #endif
            try {
                Options.Load();
            } catch( IOException ) {
                Utils.LogWarning( "Unable to load options.txt" );
            }
            ViewDistance = Options.GetInt( "viewdist", 16, 8192, 512 );
            Keys = new KeyMap();
            InputHandler = new InputHandler( this );
            Chat = new ChatLog( this );
            Drawer2D = new GdiPlusDrawer2D( Graphics );
            defaultIb = Graphics.MakeDefaultIb();

            ModelCache = new ModelCache( this );
            ModelCache.InitCache();
            AsyncDownloader = new AsyncDownloader( skinServer );
            Graphics.PrintGraphicsInfo();
            TerrainAtlas1D = new TerrainAtlas1D( Graphics );
            TerrainAtlas = new TerrainAtlas2D( Graphics, Drawer2D );
            Animations = new Animations( this );
            TexturePackExtractor extractor = new TexturePackExtractor();
            extractor.Extract( defaultTexPack, this );
            Inventory = new Inventory( this );

            BlockInfo = new BlockInfo();
            BlockInfo.Init();
            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 );
            MapEnvRenderer = new MapEnvRenderer( 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 );
            Camera = firstPersonCam;
            CommandManager = new CommandManager();
            CommandManager.Init( this );
            SelectionManager = new SelectionManager( this );
            ParticleManager = new ParticleManager( this );
            WeatherRenderer = new WeatherRenderer( this );
            WeatherRenderer.Init();

            Graphics.SetVSync( this, true );
            Graphics.DepthTest = true;
            Graphics.DepthTestFunc( CompareFunc.LessEqual );
            //Graphics.DepthWrite = true;
            Graphics.AlphaBlendFunc( BlendFunc.SourceAlpha, BlendFunc.InvSourceAlpha );
            Graphics.AlphaTestFunc( CompareFunc.Greater, 0.5f );
            Title = Utils.AppName;
            fpsScreen = new FpsScreen( this );
            fpsScreen.Init();
            Culling = new FrustumCulling();
            EnvRenderer.Init();
            MapEnvRenderer.Init();
            Picking = new PickingRenderer( this );

            string connectString = "Connecting to " + IPAddress + ":" + Port +  "..";
            SetNewScreen( new LoadingMapScreen( this, connectString, "Reticulating splines" ) );
            Network.Connect( IPAddress, Port );
        }
示例#3
0
        public void PickBlocks(bool cooldown, bool left, bool middle, bool right)
        {
            DateTime now   = DateTime.UtcNow;
            double   delta = (now - lastClick).TotalMilliseconds;

            if (cooldown && delta < 250)
            {
                return;                                      // 4 times per second
            }
            lastClick = now;
            Inventory inv = game.Inventory;

            if (game.Server.UsingPlayerClick && !game.Gui.ActiveScreen.HandlesAllInput)
            {
                input.pickingId = -1;
                input.ButtonStateChanged(MouseButton.Left, left);
                input.ButtonStateChanged(MouseButton.Right, right);
                input.ButtonStateChanged(MouseButton.Middle, middle);
            }

            if (game.Gui.ActiveScreen.HandlesAllInput || inv.Selected == Block.Invalid)
            {
                return;
            }

            if (left)
            {
                if (game.Mode.PickingLeft())
                {
                    return;
                }
                Vector3I pos = game.SelectedPos.BlockPos;
                if (!game.SelectedPos.Valid || !game.World.IsValidPos(pos))
                {
                    return;
                }

                BlockID old = game.World.GetBlock(pos);
                if (BlockInfo.Draw[old] == DrawType.Gas || !BlockInfo.CanDelete[old])
                {
                    return;
                }
                game.Mode.PickLeft(old);
            }
            else if (right)
            {
                if (game.Mode.PickingRight())
                {
                    return;
                }
                Vector3I pos = game.SelectedPos.TranslatedPos;
                if (!game.SelectedPos.Valid || !game.World.IsValidPos(pos))
                {
                    return;
                }

                BlockID old   = game.World.GetBlock(pos);
                BlockID block = inv.Selected;
                if (game.AutoRotate)
                {
                    block = AutoRotate.RotateBlock(game, block);
                }

                if (game.CanPick(old) || !BlockInfo.CanPlace[block])
                {
                    return;
                }
                if (!PickingHandler.CheckIsFree(game, block))
                {
                    return;
                }
                game.Mode.PickRight(old, block);
            }
            else if (middle)
            {
                Vector3I pos = game.SelectedPos.BlockPos;
                if (!game.SelectedPos.Valid || !game.World.IsValidPos(pos))
                {
                    return;
                }

                BlockID old = game.World.GetBlock(pos);
                game.Mode.PickMiddle(old);
            }
        }