Exemple #1
0
        void AddVertices(BlockID block, int face)
        {
            int      i             = TerrainAtlas1D.Get1DIndex(BlockInfo.GetTextureLoc(block, face));
            bool     isLava        = IsBlockLiquid(block);
            bool     isTranslucent = BlockInfo.Draw[block] == DrawType.Translucent;
            DrawInfo part;

            //DrawInfo part = BlockInfo.Draw[block] == DrawType.Translucent ? translucentParts[i] : normalParts[i];
            if (isLava && !isTranslucent)
            {
                part = liquidParts[i];
            }
            else
            {
                part = isTranslucent ? translucentParts[i] : normalParts[i];
            }
                        #if ALPHA
            if (block == Block.Fence)
            {
                part.vCount[face] += 4 * 9;
            }
            else
            {
                part.vCount[face] += 4;
            }
                        #else
            part.vCount[face] += 4;
                        #endif
        }
Exemple #2
0
        public void Dispose()
        {
            MapRenderer.Dispose();
            TerrainAtlas.Dispose();
            TerrainAtlas1D.Dispose();
            ModelCache.Dispose();
            Entities.Dispose();
            WorldEvents.OnNewMap       -= OnNewMapCore;
            WorldEvents.OnNewMapLoaded -= OnNewMapLoadedCore;
            Events.TextureChanged      -= TextureChangedCore;

            for (int i = 0; i < Components.Count; i++)
            {
                Components[i].Dispose();
            }

            Graphics.DeleteIb(ref defaultIb);
            Drawer2D.DisposeInstance();
            Graphics.DeleteTexture(ref CloudsTex);
            Graphics.Dispose();
            if (lastAtlas != null)
            {
                lastAtlas.Dispose();
            }

            if (Options.OptionsChanged.Count == 0)
            {
                return;
            }
            Options.Load();
            Options.Save();
        }
Exemple #3
0
 void LoadAtlas(Bitmap bmp)
 {
     TerrainAtlas1D.Dispose();
     TerrainAtlas.Dispose();
     TerrainAtlas.UpdateState(BlockInfo, bmp);
     TerrainAtlas1D.UpdateState(TerrainAtlas);
 }
        void SpriteXQuad(BlockID block, bool firstPart)
        {
            int        texLoc = BlockInfo.GetTextureLoc(block, Side.Right);
            TextureRec rec    = TerrainAtlas1D.GetTexRec(texLoc, 1, out texIndex);

            if (lastTexIndex != texIndex)
            {
                Flush();
            }

            VertexP3fT2fC4b v = default(VertexP3fT2fC4b);

            v.Colour = colNormal;

            if (BlockInfo.Tinted[block])
            {
                v.Colour = Utils.Tint(v.Colour, BlockInfo.FogColour[block]);
            }

            float z1 = firstPart ? 0.5f : -0.1f, z2 = firstPart ? 1.1f : 0.5f;

            rec.U1 = firstPart ? 0.0f : 0.5f; rec.U2 = (firstPart ? 0.5f : 1.0f) * (15.99f / 16f);
            float minY = scale * (1 - 0 * 2) + pos.Y, maxY = scale * (1 - 1.1f * 2) + pos.Y;
            float minZ = scale * (1 - z1 * 2) + pos.Z, maxZ = scale * (1 - z2 * 2) + pos.Z;

            v.X = pos.X;
            v.Y = minY; v.Z = minZ; v.U = rec.U2; v.V = rec.V2; vertices[index++] = v;
            v.Y = maxY;                           v.V = rec.V1; vertices[index++] = v;
            v.Z = maxZ; v.U = rec.U1;               vertices[index++] = v;
            v.Y = minY;                           v.V = rec.V2; vertices[index++] = v;
        }
Exemple #5
0
        void AddSpriteVertices(BlockID block)
        {
            int      i    = TerrainAtlas1D.Get1DIndex(BlockInfo.GetTextureLoc(block, Side.Left));
            DrawInfo part = normalParts[i];

            part.spriteCount += 4 * 4;
        }
        void PreStretchTiles(int x1, int y1, int z1)
        {
            invVerElementSize  = game.TerrainAtlas1D.invElementSize;
            elementsPerAtlas1D = game.TerrainAtlas1D.elementsPerAtlas1D;
            arraysCount        = game.TerrainAtlas1D.TexIds.Length;
            atlas = game.TerrainAtlas1D;

            if (drawInfoNormal == null)
            {
                drawInfoNormal      = new DrawInfo[arraysCount];
                drawInfoTranslucent = new DrawInfo[arraysCount];
                for (int i = 0; i < drawInfoNormal.Length; i++)
                {
                    drawInfoNormal[i]      = new DrawInfo();
                    drawInfoTranslucent[i] = new DrawInfo();
                }
            }
            else
            {
                for (int i = 0; i < drawInfoNormal.Length; i++)
                {
                    drawInfoNormal[i].ResetState();
                    drawInfoTranslucent[i].ResetState();
                }
            }
        }
Exemple #7
0
        protected virtual void PreStretchTiles(int x1, int y1, int z1)
        {
            atlas              = game.TerrainAtlas1D;
            invVerElementSize  = atlas.invElementSize;
            elementsPerAtlas1D = atlas.elementsPerAtlas1D;
            arraysCount        = atlas.TexIds.Length;

            if (normalParts == null)
            {
                normalParts      = new DrawInfo[arraysCount];
                translucentParts = new DrawInfo[arraysCount];
                for (int i = 0; i < normalParts.Length; i++)
                {
                    normalParts[i]      = new DrawInfo();
                    translucentParts[i] = new DrawInfo();
                }
            }
            else
            {
                for (int i = 0; i < normalParts.Length; i++)
                {
                    normalParts[i].ResetState();
                    translucentParts[i].ResetState();
                }
            }
        }
Exemple #8
0
        void AddVertices(BlockID block, int face)
        {
            int      i    = TerrainAtlas1D.Get1DIndex(BlockInfo.GetTextureLoc(block, face));
            DrawInfo part = BlockInfo.Draw[block] == DrawType.Translucent ? translucentParts[i] : normalParts[i];

            part.vCount[face] += 4;
        }
        void LoadAtlas(Bitmap bmp)
        {
            TerrainAtlas1D.Dispose();
            TerrainAtlas2D.Dispose();

            TerrainAtlas2D.UpdateState(bmp);
            TerrainAtlas1D.UpdateState();
        }
Exemple #10
0
        public static void Draw(Game game, byte block, float size, float x, float y)
        {
            info       = game.BlockInfo;
            cache      = game.ModelCache;
            atlas      = game.TerrainAtlas1D;
            minBB      = info.MinBB[block];
            maxBB      = info.MaxBB[block];
            fullBright = info.FullBright[block];
            if (info.IsSprite[block])
            {
                minBB = Vector3.Zero; maxBB = Vector3.One;
            }
            if (info.IsAir[block])
            {
                return;
            }
            index = 0;
            api   = game.Graphics;

            // isometric coords size: cosY * -scale - sinY * scale
            // we need to divide by (2 * cosY), as the calling function expects size to be in pixels.
            scale = size / (2 * cosY);
            // screen to isometric coords (cos(-x) = cos(x), sin(-x) = -sin(x))
            pos.X = x; pos.Y = y; pos.Z = 0;
            pos   = Utils.RotateY(Utils.RotateX(pos, cosX, -sinX), cosY, -sinY);

            if (info.IsSprite[block])
            {
                SpriteXQuad(block, TileSide.Right, false);
                SpriteZQuad(block, TileSide.Back, false);

                SpriteZQuad(block, TileSide.Back, true);
                SpriteXQuad(block, TileSide.Right, true);
            }
            else
            {
                XQuad(block, Make(maxBB.X), TileSide.Left);
                ZQuad(block, Make(minBB.Z), TileSide.Back);
                YQuad(block, Make(maxBB.Y), TileSide.Top);
            }

            if (index == 0)
            {
                return;
            }
            if (atlas.TexIds[texIndex] != lastTexId)
            {
                lastTexId = atlas.TexIds[texIndex];
                api.BindTexture(lastTexId);
            }
            for (int i = 0; i < index; i++)
            {
                TransformVertex(ref cache.vertices[i]);
            }
            api.UpdateDynamicIndexedVb(DrawMode.Triangles, cache.vb, cache.vertices, index, index * 6 / 4);
        }
Exemple #11
0
        void LoadAtlas(Bitmap bmp, Stream data)
        {
            TerrainAtlas1D.Dispose();
            TerrainAtlas.Dispose();
            if (lastAtlas != null)
            {
                lastAtlas.Dispose();
            }

            TerrainAtlas.UpdateState(BlockInfo, bmp);
            TerrainAtlas1D.UpdateState(TerrainAtlas);
            lastAtlas = data;
        }
        public void DrawBatch(BlockID block, float size, float x, float y)
        {
            BlockInfo info = game.BlockInfo;

            atlas = game.TerrainAtlas1D;
            drawer.elementsPerAtlas1D = atlas.elementsPerAtlas1D;
            drawer.invVerElementSize  = atlas.invElementSize;

            bright = info.FullBright[block];
            if (info.Draw[block] == DrawType.Gas)
            {
                return;
            }

            // isometric coords size: cosY * -scale - sinY * scale
            // we need to divide by (2 * cosY), as the calling function expects size to be in pixels.
            scale = size / (2 * cosY);
            // screen to isometric coords (cos(-x) = cos(x), sin(-x) = -sin(x))
            pos.X = x; pos.Y = y; pos.Z = 0;
            Utils.RotateX(ref pos.Y, ref pos.Z, cosX, -sinX);
            Utils.RotateY(ref pos.X, ref pos.Z, cosY, -sinY);

            // See comment in IGraphicsApi.Draw2DTexture()
            pos.X -= 0.5f; pos.Y -= 0.5f;

            if (info.Draw[block] == DrawType.Sprite)
            {
                SpriteXQuad(block, true);
                SpriteZQuad(block, true);

                SpriteZQuad(block, false);
                SpriteXQuad(block, false);
            }
            else
            {
                drawer.minBB = info.MinBB[block]; drawer.minBB.Y = 1 - drawer.minBB.Y;
                drawer.maxBB = info.MaxBB[block]; drawer.maxBB.Y = 1 - drawer.maxBB.Y;

                Vector3 min = info.MinBB[block], max = info.MaxBB[block];
                drawer.x1 = scale * (1 - min.X * 2) + pos.X; drawer.x2 = scale * (1 - max.X * 2) + pos.X;
                drawer.y1 = scale * (1 - min.Y * 2) + pos.Y; drawer.y2 = scale * (1 - max.Y * 2) + pos.Y;
                drawer.z1 = scale * (1 - min.Z * 2) + pos.Z; drawer.z2 = scale * (1 - max.Z * 2) + pos.Z;

                drawer.Tinted     = info.Tinted[block];
                drawer.TintColour = info.FogColour[block];

                drawer.Right(1, bright ? colNormal : colXSide, GetTex(block, Side.Right), vertices, ref index);
                drawer.Front(1, bright ? colNormal : colZSide, GetTex(block, Side.Front), vertices, ref index);
                drawer.Top(1, colNormal, GetTex(block, Side.Top), vertices, ref index);
            }
        }
Exemple #13
0
        public override void Dispose()
        {
            MapRenderer.Dispose();
            MapBordersRenderer.Dispose();
            EnvRenderer.Dispose();
            WeatherRenderer.Dispose();
            SetNewScreen(null);
            fpsScreen.Dispose();
            SelectionManager.Dispose();
            TerrainAtlas.Dispose();
            TerrainAtlas1D.Dispose();
            ModelCache.Dispose();
            Picking.Dispose();
            ParticleManager.Dispose();
            Players.Dispose();
            AsyncDownloader.Dispose();
            AudioPlayer.Dispose();
            AxisLinesRenderer.Dispose();

            Chat.Dispose();
            if (activeScreen != null)
            {
                activeScreen.Dispose();
            }
            Graphics.DeleteIb(defaultIb);
            Graphics.Dispose();
            Drawer2D.DisposeInstance();
            Animations.Dispose();
            Graphics.DeleteTexture(ref CloudsTexId);
            Graphics.DeleteTexture(ref RainTexId);
            Graphics.DeleteTexture(ref SnowTexId);
            Graphics.DeleteTexture(ref GuiTexId);
            Graphics.DeleteTexture(ref GuiClassicTexId);

            if (Options.HasChanged)
            {
                Options.Save();
            }
            base.Dispose();
        }
Exemple #14
0
        public void Dispose()
        {
            MapRenderer.Dispose();
            SetNewScreen(null);
            fpsScreen.Dispose();
            TerrainAtlas.Dispose();
            TerrainAtlas1D.Dispose();
            ModelCache.Dispose();
            Entities.Dispose();
            WorldEvents.OnNewMap       -= OnNewMapCore;
            WorldEvents.OnNewMapLoaded -= OnNewMapLoadedCore;

            foreach (IGameComponent comp in Components)
            {
                comp.Dispose();
            }

            if (activeScreen != null)
            {
                activeScreen.Dispose();
            }
            Graphics.DeleteIb(defaultIb);
            Drawer2D.DisposeInstance();
            Graphics.DeleteTexture(ref CloudsTex);
            Graphics.DeleteTexture(ref GuiTex);
            Graphics.DeleteTexture(ref GuiClassicTex);
            Graphics.DeleteTexture(ref IconsTex);
            Graphics.Dispose();

            foreach (WarningScreen screen in WarningOverlays)
            {
                screen.Dispose();
            }

            if (Options.HasChanged)
            {
                Options.Load();
                Options.Save();
            }
        }
        public void DrawBatch(byte block, float size, float x, float y)
        {
            BlockInfo info = game.BlockInfo;

            atlas      = game.TerrainAtlas1D;
            minBB      = info.MinBB[block];
            maxBB      = info.MaxBB[block];
            fullBright = info.FullBright[block];
            if (info.IsSprite[block])
            {
                minBB = Vector3.Zero; maxBB = Vector3.One;
            }
            if (info.IsAir[block])
            {
                return;
            }

            // isometric coords size: cosY * -scale - sinY * scale
            // we need to divide by (2 * cosY), as the calling function expects size to be in pixels.
            scale = size / (2 * cosY);
            // screen to isometric coords (cos(-x) = cos(x), sin(-x) = -sin(x))
            pos.X = x; pos.Y = y; pos.Z = 0;
            Utils.RotateX(ref pos.Y, ref pos.Z, cosX, -sinX);
            Utils.RotateY(ref pos.X, ref pos.Z, cosY, -sinY);

            if (info.IsSprite[block])
            {
                SpriteXQuad(block, Side.Right, false);
                SpriteZQuad(block, Side.Back, false);

                SpriteZQuad(block, Side.Back, true);
                SpriteXQuad(block, Side.Right, true);
            }
            else
            {
                XQuad(block, maxBB.X, Side.Left);
                ZQuad(block, minBB.Z, Side.Back);
                YQuad(block, maxBB.Y, Side.Top);
            }
        }
        void DrawBackground()
        {
            VertexPos3fTex2fCol4b[] vertices = game.ModelCache.vertices;
            int        index = 0, atlasIndex = 0;
            int        drawnY = 0, height = game.Height;
            FastColour col = new FastColour(64, 64, 64);

            int            texLoc = game.BlockInfo.GetTextureLoc((byte)Block.Dirt, TileSide.Top);
            TerrainAtlas1D atlas  = game.TerrainAtlas1D;
            TextureRec     tex = atlas.GetTexRec(texLoc, 1, out atlasIndex);

            tex.U2 = (float)game.Width / 64;
            bool bound = false;

            while (drawnY < height)
            {
                float x1 = 0, x2 = game.Width;
                float y1 = drawnY, y2 = drawnY + 64;
                                #if USE_DX
                // NOTE: see "https://msdn.microsoft.com/en-us/library/windows/desktop/bb219690(v=vs.85).aspx",
                // i.e. the msdn article called "Directly Mapping Texels to Pixels (Direct3D 9)" for why we have to do this.
                x1 -= 0.5f; x2 -= 0.5f;
                y1 -= 0.5f; y2 -= 0.5f;
                                #endif

                vertices[index++] = new VertexPos3fTex2fCol4b(x1, y1, 0, tex.U1, tex.V1, col);
                vertices[index++] = new VertexPos3fTex2fCol4b(x2, y1, 0, tex.U2, tex.V1, col);
                vertices[index++] = new VertexPos3fTex2fCol4b(x2, y2, 0, tex.U2, tex.V2, col);
                vertices[index++] = new VertexPos3fTex2fCol4b(x1, y2, 0, tex.U1, tex.V2, col);
                if (index >= vertices.Length)
                {
                    DrawBackgroundVertices(ref index, atlasIndex, ref bound);
                }
                drawnY += 64;
            }
            DrawBackgroundVertices(ref index, atlasIndex, ref bound);
        }
        void PreStretchTiles( int x1, int y1, int z1 )
        {
            invVerElementSize = game.TerrainAtlas1D.invElementSize;
            arraysCount = game.TerrainAtlas1D.TexIds.Length;
            atlas = game.TerrainAtlas1D;

            if( drawInfoNormal == null ) {
                drawInfoNormal = new DrawInfo[arraysCount];
                drawInfoTranslucent = new DrawInfo[arraysCount];
                for( int i = 0; i < drawInfoNormal.Length; i++ ) {
                    drawInfoNormal[i] = new DrawInfo();
                    drawInfoTranslucent[i] = new DrawInfo();
                }
            } else {
                for( int i = 0; i < drawInfoNormal.Length; i++ ) {
                    drawInfoNormal[i].ResetState();
                    drawInfoTranslucent[i].ResetState();
                }
            }
        }
Exemple #18
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;

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

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

            if (Options.GetBool(OptionsKey.SurvivalMode, false))
            {
                Mode = new SurvivalGameMode();
            }
            else
            {
                Mode = new CreativeGameMode();
            }
            Components.Add(Mode);

            Input           = new InputHandler(this);
            defaultIb       = Graphics.MakeDefaultIb();
            ParticleManager = new ParticleManager(); Components.Add(ParticleManager);
            TabList         = new TabList(); Components.Add(TabList);
            LoadOptions();
            LoadGuiOptions();
            Chat = new Chat(); Components.Add(Chat);

            WorldEvents.OnNewMap       += OnNewMapCore;
            WorldEvents.OnNewMapLoaded += OnNewMapLoadedCore;
            Events.TextureChanged      += TextureChangedCore;

            BlockInfo.Init();
            ModelCache = new ModelCache(this);
            ModelCache.InitCache();
            AsyncDownloader = new AsyncDownloader(Drawer2D); Components.Add(AsyncDownloader);
            Lighting        = new BasicLighting(); Components.Add(Lighting);

            Drawer2D.UseBitmappedChat = ClassicMode || !Options.GetBool(OptionsKey.UseChatFont, false);
            Drawer2D.BlackTextShadows = Options.GetBool(OptionsKey.BlackText, false);
            Graphics.Mipmaps          = Options.GetBool(OptionsKey.Mipmaps, false);

            TerrainAtlas1D = new TerrainAtlas1D(this);
            TerrainAtlas   = new TerrainAtlas2D(this);
            Animations     = new Animations(); Components.Add(Animations);
            Inventory      = new Inventory(); Components.Add(Inventory);

            BlockInfo.SetDefaultPerms();
            World       = new World(this);
            LocalPlayer = new LocalPlayer(this); Components.Add(LocalPlayer);
            Entities.List[EntityList.SelfID] = 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;

            Cameras.Add(new FirstPersonCamera(this));
            Cameras.Add(new ThirdPersonCamera(this, false));
            Cameras.Add(new ThirdPersonCamera(this, true));
            Camera = Cameras[0];
            UpdateProjection();

            Gui               = new GuiInterface(this); Components.Add(Gui);
            CommandList       = new CommandList(); Components.Add(CommandList);
            SelectionManager  = new SelectionManager(); Components.Add(SelectionManager);
            WeatherRenderer   = new WeatherRenderer(); Components.Add(WeatherRenderer);
            HeldBlockRenderer = new HeldBlockRenderer(); Components.Add(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           = new PickedPosRenderer(); Components.Add(Picking);
            AudioPlayer       = new AudioPlayer(); Components.Add(AudioPlayer);
            AxisLinesRenderer = new AxisLinesRenderer(); Components.Add(AxisLinesRenderer);
            SkyboxRenderer    = new SkyboxRenderer(); Components.Add(SkyboxRenderer);

            plugins = new PluginLoader(this);
            List <string> nonLoaded = plugins.LoadAll();

            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();

            if (nonLoaded != null)
            {
                for (int i = 0; i < nonLoaded.Count; i++)
                {
                    plugins.MakeWarning(this, nonLoaded[i]);
                }
            }

            window.LoadIcon();
            string connectString = "Connecting to " + IPAddress + ":" + Port + "..";
            if (Graphics.WarnIfNecessary(Chat))
            {
                MapBordersRenderer.UseLegacyMode(true);
                EnvRenderer.UseLegacyMode(true);
            }
            Gui.SetNewScreen(new LoadingMapScreen(this, connectString, ""));
            Server.Connect(IPAddress, Port);
        }
Exemple #19
0
        protected override void OnLoad(EventArgs e)
        {
                        #if !USE_DX
            Graphics = new OpenGLApi();
                        #else
            Graphics = new Direct3D9Api(this);
                        #endif
            Graphics.MakeGraphicsInfo();
            Players = new EntityList(this);

            Options.Load();
            AcceptedUrls.Load(); DeniedUrls.Load();
            ViewDistance     = Options.GetInt(OptionsKey.ViewDist, 16, 4096, 512);
            UserViewDistance = ViewDistance;
            CameraClipping   = Options.GetBool(OptionsKey.CameraClipping, true);
            InputHandler     = new InputHandler(this);
            Chat             = new ChatLog(this);
            ParticleManager  = new ParticleManager(this);
            HudScale         = Options.GetFloat(OptionsKey.HudScale, 0.25f, 5f, 1f);
            ChatScale        = Options.GetFloat(OptionsKey.ChatScale, 0.35f, 5f, 1f);
            defaultIb        = Graphics.MakeDefaultIb();
            MouseSensitivity = Options.GetInt(OptionsKey.Sensitivity, 1, 100, 30);
            UseClassicGui    = Options.GetBool(OptionsKey.UseClassicGui, false);
            BlockInfo        = new BlockInfo();
            BlockInfo.Init();
            ChatLines     = Options.GetInt(OptionsKey.ChatLines, 1, 30, 12);
            ClickableChat = Options.GetBool(OptionsKey.ClickableChat, true);
            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 PickingRenderer(this);
            AudioPlayer       = new AudioPlayer(this);
            LiquidsBreakable  = Options.GetBool(OptionsKey.LiquidsBreakable, 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 #20
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();
            Entities = new EntityList(this);
            AcceptedUrls.Load();
            DeniedUrls.Load();
            ETags.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;

            BlockInfo = new BlockInfo();
            BlockInfo.Init();
            ModelCache = new ModelCache(this);
            ModelCache.InitCache();
            AsyncDownloader           = AddComponent(new AsyncDownloader());
            Drawer2D                  = new GdiPlusDrawer2D(Graphics);
            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.SetDefaultBlockPermissions(Inventory.CanPlace, Inventory.CanDelete);
            World              = new World(this);
            LocalPlayer        = AddComponent(new LocalPlayer(this));
            Entities[255]      = LocalPlayer;
            width              = Width;
            height             = Height;
            MapRenderer        = new MapRenderer(this);
            MapBordersRenderer = AddComponent(new MapBordersRenderer());
            EnvRenderer        = AddComponent(new StandardEnvRenderer());
            if (IPAddress == null)
            {
                Network = new Singleplayer.SinglePlayerServer(this);
            }
            else
            {
                Network = new Network.NetworkProcessor(this);
            }
            Graphics.LostContextFunction = Network.Tick;

            firstPersonCam        = new FirstPersonCamera(this);
            thirdPersonCam        = new ThirdPersonCamera(this);
            forwardThirdPersonCam = new ForwardThirdPersonCamera(this);
            Camera = firstPersonCam;
            UpdateProjection();
            CommandManager    = AddComponent(new CommandManager());
            SelectionManager  = AddComponent(new SelectionManager());
            WeatherRenderer   = AddComponent(new WeatherRenderer());
            BlockHandRenderer = AddComponent(new BlockHandRenderer());

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

            foreach (IGameComponent comp in Components)
            {
                comp.Init(this);
            }
            ExtractInitialTexturePack();
            foreach (IGameComponent comp in Components)
            {
                comp.Ready(this);
            }

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