public ChunkMeshBuilder( Game game )
 {
     this.game = game;
     graphics = game.Graphics;
     info = game.BlockInfo;
     game.Events.TerrainAtlasChanged += TerrainAtlasChanged;
 }
        public static void Draw( Game game, byte block, float size, float x, float y )
        {
            info = game.BlockInfo;
            cache = game.ModelCache;
            atlas = game.TerrainAtlas;
            blockHeight = info.Height[block];
            index = 0;
            scale = size;

            // 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] ) {
                DrawXFace( block, 0f, TileSide.Right );
                DrawZFace( block, 0f, TileSide.Back );
            } else {
                DrawXFace( block, scale, TileSide.Left );
                DrawZFace( block, -scale, TileSide.Back );
                DrawYFace( block, scale * blockHeight, TileSide.Top );
            }

            for( int i = 0; i < index; i++ )
                TransformVertex( ref cache.vertices[i] );
            game.Graphics.DrawDynamicIndexedVb( DrawMode.Triangles, cache.vb,
                                               cache.vertices, index, index * 6 / 4 );
        }
Beispiel #3
0
 public Map( Game game )
 {
     this.game = game;
     info = game.BlockInfo;
     SetSunlight( DefaultSunlight );
     SetShadowlight( DefaultShadowlight );
 }
        public static void Draw( Game game, byte block, float size, float x, float y )
        {
            info = game.BlockInfo;
            cache = game.ModelCache;
            atlas = game.TerrainAtlas;
            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;

            // 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] ) {
                XQuad( block, 0f, TileSide.Right );
                ZQuad( block, 0f, TileSide.Back );
            } else {
                XQuad( block, Make( maxBB.X ), TileSide.Left );
                ZQuad( block, Make( minBB.Z ), TileSide.Back );
                YQuad( block, Make( maxBB.Y ), TileSide.Top );
            }

            for( int i = 0; i < index; i++ )
                TransformVertex( ref cache.vertices[i] );
            game.Graphics.UpdateDynamicIndexedVb( DrawMode.Triangles, cache.vb,
                                               cache.vertices, index, index * 6 / 4 );
        }
 public int CalcMaxUsedRow( TerrainAtlas2D atlas2D, BlockInfo info )
 {
     int maxVerSize = Math.Min( 4096, graphics.MaxTextureDimensions );
     int verElements = maxVerSize / atlas2D.elementSize;
     int totalElements = GetMaxUsedRow( info.textures ) * TerrainAtlas2D.ElementsPerRow;
     Utils.LogDebug( "Used atlases: " + Utils.CeilDiv( totalElements, verElements ) );
     return Utils.CeilDiv( totalElements, verElements );
 }
 public WeatherRenderer( Game game )
 {
     this.game = game;
     map = game.Map;
     graphics = game.Graphics;
     info = game.BlockInfo;
     weatherVb = graphics.CreateDynamicVb( VertexFormat.Pos3fTex2fCol4b, 12 * 9 * 9 );
 }
        /// <summary> Updates the underlying atlas bitmap, fields, and texture. </summary>
        public void UpdateState( BlockInfo info, Bitmap bmp )
        {
            if( !FastBitmap.CheckFormat( bmp.PixelFormat ) ) {
                Utils.LogDebug( "Converting terrain atlas to 32bpp image" );
                drawer.ConvertTo32Bpp( ref bmp );
            }

            AtlasBitmap = bmp;
            elementSize = bmp.Width >> 4;
            using( FastBitmap fastBmp = new FastBitmap( bmp, true, true ) )
                info.RecalculateSpriteBB( fastBmp );
        }
Beispiel #8
0
        public MapRenderer( Game game )
        {
            this.game = game;
            _1Dcount = game.TerrainAtlas1D.TexIds.Length;
            builder = new ChunkMeshBuilder( game );
            api = game.Graphics;
            elementsPerBitmap = game.TerrainAtlas1D.elementsPerBitmap;
            info = game.BlockInfo;

            game.Events.TerrainAtlasChanged += TerrainAtlasChanged;
            game.Events.OnNewMap += OnNewMap;
            game.Events.OnNewMapLoaded += OnNewMapLoaded;
            game.Events.EnvVariableChanged += EnvVariableChanged;
        }
Beispiel #9
0
 public Entity( Game game )
 {
     this.game = game;
     info = game.BlockInfo;
 }
Beispiel #10
0
 public Map(Game game)
 {
     this.game = game;
     info      = game.BlockInfo;
     ResetLight();
 }
Beispiel #11
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);
        }
        public static void ClipCameraPos(Game game, Vector3 origin, Vector3 dir, float reach, PickedPos pickedPos)
        {
            if (!game.CameraClipping)
            {
                pickedPos.SetAsInvalid();
                pickedPos.IntersectPoint = origin + dir * reach;
                return;
            }
            tracer.SetRayData(origin, dir);
            World     map          = game.World;
            BlockInfo info         = game.BlockInfo;
            float     reachSquared = reach * reach;
            int       iterations   = 0;
            Vector3I  pOrigin      = Vector3I.Floor(origin);

            while (iterations < 10000)
            {
                int     x = tracer.X, y = tracer.Y, z = tracer.Z;
                byte    block = GetBlock(map, x, y, z, pOrigin);
                Vector3 min   = new Vector3(x, y, z) + info.MinBB[block];
                Vector3 max   = new Vector3(x, y, z) + info.MaxBB[block];
                if (info.IsLiquid[block])
                {
                    min.Y -= 1.5f / 16; max.Y -= 1.5f / 16;
                }

                float dx = Math.Min(Math.Abs(origin.X - min.X), Math.Abs(origin.X - max.X));
                float dy = Math.Min(Math.Abs(origin.Y - min.Y), Math.Abs(origin.Y - max.Y));
                float dz = Math.Min(Math.Abs(origin.Z - min.Z), Math.Abs(origin.Z - max.Z));

                if (dx * dx + dy * dy + dz * dz > reachSquared)
                {
                    pickedPos.SetAsInvalid();
                    pickedPos.IntersectPoint = origin + dir * reach;
                    return;
                }

                if (info.Collide[block] == CollideType.Solid && !info.IsAir[block])
                {
                    float       t0, t1;
                    const float adjust = 0.1f;
                    if (Intersection.RayIntersectsBox(origin, dir, min, max, out t0, out t1))
                    {
                        Vector3 intersect = origin + dir * t0;
                        pickedPos.SetAsValid(x, y, z, min, max, block, intersect);

                        switch (pickedPos.BlockFace)
                        {
                        case CpeBlockFace.XMin:
                            pickedPos.IntersectPoint.X -= adjust; break;

                        case CpeBlockFace.XMax:
                            pickedPos.IntersectPoint.X += adjust; break;

                        case CpeBlockFace.YMin:
                            pickedPos.IntersectPoint.Y -= adjust; break;

                        case CpeBlockFace.YMax:
                            pickedPos.IntersectPoint.Y += adjust; break;

                        case CpeBlockFace.ZMin:
                            pickedPos.IntersectPoint.Z -= adjust; break;

                        case CpeBlockFace.ZMax:
                            pickedPos.IntersectPoint.Z += adjust; break;
                        }
                        return;
                    }
                }
                tracer.Step();
                iterations++;
            }
            throw new InvalidOperationException("did over 10000 iterations in ClipCameraPos(). " +
                                                "Something has gone wrong. (dir: " + dir + ")");
        }
Beispiel #13
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 );
        }
Beispiel #14
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 );
        }
 int GetShape(BlockInfo info, byte id)
 {
     return(info.IsSprite[id] ? 0 : (byte)(info.MaxBB[id].Y * 16));
 }
 /// <summary> Updates the underlying atlas bitmap, fields, and texture. </summary>
 public static void UpdateState(Bitmap bmp)
 {
     Atlas    = bmp;
     ElemSize = bmp.Width / TilesPerRow;
     BlockInfo.RecalculateSpriteBB();
 }
Beispiel #17
0
        internal void OnLoad()
        {
                        #if ANDROID
            Graphics = new OpenGLESApi();
                        #elif !USE_DX
            Graphics = new OpenGLApi(window);
                        #else
            Graphics = new Direct3D9Api(window);
                        #endif
            Graphics.MakeApiInfo();
            ErrorHandler.AdditionalInfo = Graphics.ApiInfo;

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

            Entities = new EntityList(this);
            TextureCache.Init();

                        #if SURVIVAL_TEST
            if (Options.GetBool(OptionsKey.SurvivalMode, false))
            {
                Mode = new SurvivalGameMode();
            }
            else
            {
                Mode = new CreativeGameMode();
            }
                        #endif

            Input           = new InputHandler(this);
            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.Allocate(256);
            BlockInfo.Init();

            ModelCache = new ModelCache(this);
            ModelCache.InitCache();
            Downloader = new AsyncDownloader(Drawer2D); Components.Add(Downloader);
            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);

            Atlas1D.game  = this;
            Atlas2D.game  = this;
            Animations    = new Animations(); Components.Add(Animations);
            Inventory     = new Inventory(); Components.Add(Inventory);
            Inventory.Map = new BlockID[BlockInfo.Count];

            BlockInfo.SetDefaultPerms();
            World       = new World(this);
            LocalPlayer = new LocalPlayer(this); Components.Add(LocalPlayer);
            Entities.List[EntityList.SelfID] = LocalPlayer;

            MapRenderer        = new MapRenderer(this);
            ChunkUpdater       = new ChunkUpdater(this);
            EnvRenderer        = new EnvRenderer(); Components.Add(EnvRenderer);
            MapBordersRenderer = new MapBordersRenderer(); Components.Add(MapBordersRenderer);

            string renType = Options.Get(OptionsKey.RenderType, "normal");
            int    flags   = CalcRenderType(renType);
            if (flags == -1)
            {
                flags = 0;
            }

            MapBordersRenderer.legacy = (flags & 1) != 0;
            EnvRenderer.legacy        = (flags & 1) != 0;
            EnvRenderer.minimal       = (flags & 2) != 0;

            if (IPAddress == null)
            {
                Server = new Singleplayer.SinglePlayerServer(this);
            }
            else
            {
                Server = new Network.NetworkProcessor(this);
            }
            Components.Add(Server);
            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);

            PluginLoader.game = this;
            List <string> nonLoaded = PluginLoader.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++)
                {
                    Overlay warning = new PluginOverlay(this, nonLoaded[i]);
                    Gui.ShowOverlay(warning, false);
                }
            }

            LoadIcon();
            string connectString = "Connecting to " + IPAddress + ":" + Port + "..";
            if (Graphics.WarnIfNecessary(Chat))
            {
                MapBordersRenderer.UseLegacyMode(true);
                EnvRenderer.UseLegacyMode(true);
            }
            Gui.SetNewScreen(new LoadingScreen(this, connectString, ""));
            Server.BeginConnect();
        }
Beispiel #18
0
 static bool IsHackBlock(BlockID b)
 {
     return(b == Block.DoubleSlab || b == Block.Bedrock ||
            b == Block.Grass || BlockInfo.IsLiquid(b));
 }
Beispiel #19
0
        public static void ClipCameraPos(Game game, Vector3 origin, Vector3 dir, float reach, PickedPos pickedPos)
        {
            if (!game.CameraClipping)
            {
                pickedPos.SetAsInvalid();
                pickedPos.IntersectPoint = origin + dir * reach;
                return;
            }
            Vector3I start = Vector3I.Floor(origin);
            int      x = start.X, y = start.Y, z = start.Z;
            Vector3I step, cellBoundary;
            Vector3  tMax, tDelta;

            CalcVectors(origin, dir, out step, out cellBoundary, out tMax, out tDelta);

            Map       map          = game.Map;
            BlockInfo info         = game.BlockInfo;
            float     reachSquared = reach * reach;
            int       iterations   = 0;

            while (iterations < 10000)
            {
                byte    block = GetBlock(map, x, y, z, origin);
                Vector3 min   = new Vector3(x, y, z) + info.MinBB[block];
                Vector3 max   = new Vector3(x, y, z) + info.MaxBB[block];

                float dx = Math.Min(Math.Abs(origin.X - min.X), Math.Abs(origin.X - max.X));
                float dy = Math.Min(Math.Abs(origin.Y - min.Y), Math.Abs(origin.Y - max.Y));
                float dz = Math.Min(Math.Abs(origin.Z - min.Z), Math.Abs(origin.Z - max.Z));

                if (dx * dx + dy * dy + dz * dz > reachSquared)
                {
                    pickedPos.SetAsInvalid();
                    pickedPos.IntersectPoint = origin + dir * reach;
                    return;
                }

                if (info.CollideType[block] == BlockCollideType.Solid && !info.IsAir[block])
                {
                    float       t0, t1;
                    const float adjust = 0.1f;
                    if (Intersection.RayIntersectsBox(origin, dir, min, max, out t0, out t1))
                    {
                        Vector3 intersect = origin + dir * t0;
                        pickedPos.SetAsValid(x, y, z, min, max, block, intersect);

                        switch (pickedPos.BlockFace)
                        {
                        case CpeBlockFace.XMin:
                            pickedPos.IntersectPoint.X -= adjust; break;

                        case CpeBlockFace.XMax:
                            pickedPos.IntersectPoint.X += adjust; break;

                        case CpeBlockFace.YMin:
                            pickedPos.IntersectPoint.Y -= adjust; break;

                        case CpeBlockFace.YMax:
                            pickedPos.IntersectPoint.Y += adjust; break;

                        case CpeBlockFace.ZMin:
                            pickedPos.IntersectPoint.Z -= adjust; break;

                        case CpeBlockFace.ZMax:
                            pickedPos.IntersectPoint.Z += adjust; break;
                        }
                        return;
                    }
                }
                Step(ref tMax, ref tDelta, ref step, ref x, ref y, ref z);
                iterations++;
            }
            throw new InvalidOperationException("did over 10000 iterations in ClipCameraPos(). " +
                                                "Something has gone wrong. (dir: " + dir + ")");
        }
Beispiel #20
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);
        }
Beispiel #21
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);
        }