Ejemplo n.º 1
0
        public void Dispose()
        {
            ChunkUpdater.Dispose();
            Atlas2D.Dispose();
            Atlas1D.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();
            }

            Drawer2D.DisposeInstance();
            Graphics.Dispose();
            // TODO: is this needed
            //window.Dispose();

            if (!Options.HasChanged())
            {
                return;
            }
            Options.Load();
            Options.Save();
        }
Ejemplo n.º 2
0
        void Render3D(double delta, float t)
        {
            if (SkyboxRenderer.ShouldRender)
            {
                SkyboxRenderer.Render(delta);
            }
            AxisLinesRenderer.Render(delta);
            Entities.RenderModels(Graphics, delta, t);
            Entities.RenderNames(Graphics, delta);

            ParticleManager.Render(delta, t);
            Camera.GetPickedBlock(SelectedPos);             // TODO: only pick when necessary
            EnvRenderer.Render(delta);
            ChunkUpdater.Update(delta);
            MapRenderer.RenderNormal(delta);
            MapBordersRenderer.RenderSides(delta);

            Entities.DrawShadows();
            if (SelectedPos.Valid && !HideGui)
            {
                Picking.Update(SelectedPos);
                Picking.Render(delta);
            }

            // Render water over translucent blocks when underwater for proper alpha blending
            Vector3 pos = LocalPlayer.Position;

            if (CurrentCameraPos.Y < World.Env.EdgeHeight &&
                (pos.X < 0 || pos.Z < 0 || pos.X > World.Width || pos.Z > World.Length))
            {
                MapRenderer.RenderTranslucent(delta);
                MapBordersRenderer.RenderEdges(delta);
            }
            else
            {
                MapBordersRenderer.RenderEdges(delta);
                MapRenderer.RenderTranslucent(delta);
            }

            // Need to render again over top of translucent block, as the selection outline
            // is drawn without writing to the depth buffer
            if (SelectedPos.Valid && !HideGui && BlockInfo.Draw[SelectedPos.Block] == DrawType.Translucent)
            {
                Picking.Render(delta);
            }

            SelectionManager.Render(delta);
            Entities.RenderHoveredNames(Graphics, delta);

            bool left   = IsMousePressed(MouseButton.Left);
            bool middle = IsMousePressed(MouseButton.Middle);
            bool right  = IsMousePressed(MouseButton.Right);

            Input.PickBlocks(true, left, middle, right);
            if (!HideGui)
            {
                HeldBlockRenderer.Render(delta);
            }
        }
Ejemplo n.º 3
0
        public static IEnumerator SetVoxelOn(Vector3Int vec, byte value, Volume volume)
        {
            yield return(null);

            volume.Voxel[vec.x, vec.y, vec.z] = value;
            ChunkUpdater.UpdateVoxel(vec.x, vec.y, vec.z, volume);
            //Debug.Log(vec);
        }
Ejemplo n.º 4
0
        void OnLowVRAMDetected()
        {
            if (UserViewDistance <= 16)
            {
                throw new OutOfMemoryException("Out of video memory!");
            }
            UserViewDistance /= 2;
            UserViewDistance  = Math.Max(16, UserViewDistance);

            ChunkUpdater.Refresh();
            SetViewDistance(UserViewDistance);
            Chat.Add("&cOut of VRAM! Halving view distance..");
        }
Ejemplo n.º 5
0
        public static IEnumerator SetCubeIn(byte value, Volume volume)
        {
            yield return(null);

            vec1 = GetVectorIn();

            int xMin = vec0.x < vec1.x ? vec0.x : vec1.x;
            int xMax = vec0.x > vec1.x ? vec0.x : vec1.x;
            int yMin = vec0.y < vec1.y ? vec0.y : vec1.y;
            int yMax = vec0.y > vec1.y ? vec0.y : vec1.y;
            int zMin = vec0.z < vec1.z ? vec0.z : vec1.z;
            int zMax = vec0.z > vec1.z ? vec0.z : vec1.z;

            int cxMin = xMin / ChunkSize.X;
            int cxMax = xMax / ChunkSize.X;
            int czMin = zMin / ChunkSize.Z;
            int czMax = zMax / ChunkSize.Z;

            for (int x = xMin; x < xMax + 1; x++)
            {
                for (int y = yMin; y < yMax + 1; y++)
                {
                    for (int z = zMin; z < zMax + 1; z++)
                    {
                        volume.Voxel[x, y, z] = value;
                    }
                }
            }

            if (cxMax - cxMin == 0 && czMax - czMin == 0)
            {
                ChunkUpdater.UpdateChunk(cxMin, czMin, volume);
            }
            else
            {
                for (int x = cxMin; x < cxMax + 1; x++)
                {
                    for (int z = czMin; z < czMax + 1; z++)
                    {
                        ChunkUpdater.UpdateChunk(x, z, volume);
                    }
                }
            }
        }
Ejemplo n.º 6
0
        public IEnumerator Update()
        {
            if (Width < 17 && Depth < 17)
            {
                yield return(null);

                ChunkUpdater.UpdateChunk(0, 0, this);
            }
            else
            {
                for (int x = 0; x < ChunkSize.X; x++)
                {
                    for (int z = 0; z < ChunkSize.Z; z++)
                    {
                        yield return(null);

                        ChunkUpdater.UpdateChunk(x, z, this);
                    }
                }
            }
        }
Ejemplo n.º 7
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.ExtraInfo = 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);

            Events.OnNewMap        += OnNewMapCore;
            Events.OnNewMapLoaded  += OnNewMapLoadedCore;
            Events.TextureChanged  += TextureChangedCore;
            Events.LowVRAMDetected += OnLowVRAMDetected;

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

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

            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();
        }
Ejemplo n.º 8
0
        public static IEnumerator SetLineOn(byte value, Volume volume)
        {
            yield return(null);

            vec1 = GetVectorOn();

            int x0 = vec0.x;
            int x1 = vec1.x;
            int y0 = vec0.y;
            int y1 = vec1.y;
            int z0 = vec0.z;
            int z1 = vec1.z;

            if (vec0 != vec1)
            {
                bool steepXY = Mathf.Abs(y1 - y0) > Mathf.Abs(x1 - x0);
                if (steepXY)
                {
                    Swap(ref x0, ref y0);
                    Swap(ref x1, ref y1);
                }
                bool steepXZ = Mathf.Abs(z1 - z0) > Mathf.Abs(x1 - x0);
                if (steepXZ)
                {
                    Swap(ref x0, ref z0);
                    Swap(ref x1, ref z1);
                }

                int deltaX = Mathf.FloorToInt(Mathf.Abs(x1 - x0));
                int deltaY = Mathf.FloorToInt(Mathf.Abs(y1 - y0));
                int deltaZ = Mathf.FloorToInt(Mathf.Abs(z1 - z0));

                int errorXY = deltaX / 2, errorXZ = deltaX / 2;

                int stepX = x0 > x1 ? -1 : 1;
                int stepY = y0 > y1 ? -1 : 1;
                int stepZ = z0 > z1 ? -1 : 1;

                int y = y0, z = z0;
                int xCopy, yCopy, zCopy;
                int prevX = 0;
                int prevY = 0;
                int prevZ = 0;

                for (int x = x0; stepX > 0 ? x != x1 + 1 : x != x1 - 1; x += stepX)
                {
                    xCopy = x;
                    yCopy = y;
                    zCopy = z;

                    if (steepXZ)
                    {
                        Swap(ref xCopy, ref zCopy);
                    }
                    if (steepXY)
                    {
                        Swap(ref xCopy, ref yCopy);
                    }

                    yield return(new WaitForSeconds(0.1f));

                    SetVoxelAt(new Vector3Int(xCopy, yCopy, zCopy), value, volume);

                    errorXY -= deltaY;
                    errorXZ -= deltaZ;

                    if (errorXY < 0)
                    {
                        y       += stepY;
                        errorXY += deltaX;
                    }

                    if (errorXZ < 0)
                    {
                        z       += stepZ;
                        errorXZ += deltaX;
                    }

                    if (x != x0)
                    {
                        if (prevX != xCopy && prevY != yCopy && prevZ == zCopy)
                        {
                            yield return(new WaitForSeconds(0.1f));

                            SetVoxelAt(new Vector3Int(prevX, yCopy, zCopy), value, volume);
                        }
                        else if (prevX != xCopy && prevY == yCopy && prevZ != zCopy)
                        {
                            yield return(new WaitForSeconds(0.1f));

                            SetVoxelAt(new Vector3Int(prevX, yCopy, zCopy), value, volume);
                        }
                        else if (prevX == xCopy && prevY != yCopy && prevZ != zCopy)
                        {
                            yield return(new WaitForSeconds(0.1f));

                            SetVoxelAt(new Vector3Int(xCopy, yCopy, prevZ), value, volume);
                        }
                        else if (prevX != xCopy && prevY != yCopy && prevZ != zCopy)
                        {
                            yield return(new WaitForSeconds(0.1f));

                            SetVoxelAt(new Vector3Int(prevX, yCopy, zCopy), value, volume);
                            yield return(new WaitForSeconds(0.1f));

                            SetVoxelAt(new Vector3Int(prevX, yCopy, prevZ), value, volume);
                        }
                    }
                    prevX = xCopy;
                    prevY = yCopy;
                    prevZ = zCopy;
                }
            }
            else
            {
                volume.Voxel[x0, y0, z0] = value;
                ChunkUpdater.UpdateVoxel(x0, y0, z0, volume);
            }
        }
Ejemplo n.º 9
0
 public static void SetVoxelAt(Vector3Int vec, byte value, Volume volume)
 {
     volume.Voxel[vec.x, vec.y, vec.z] = value;
     ChunkUpdater.UpdateVoxel(vec.x, vec.y, vec.z, volume);
 }