public bool ChangeTerrainAtlas(Bitmap atlas) { if (!ValidateBitmap("terrain.png", atlas)) { return(false); } if (atlas.Height < atlas.Width) { Chat.Add("&cUnable to use terrain.png from the texture pack."); Chat.Add("&c Its height is less than its width."); return(false); } if (Graphics.LostContext) { return(false); } Atlas1D.Dispose(); Atlas2D.Dispose(); Atlas2D.UpdateState(atlas); Atlas1D.UpdateState(); Events.RaiseTerrainAtlasChanged(); return(true); }
public bool ValidateBitmap(string file, Bitmap bmp) { if (bmp == null) { Chat.Add("&cError loading " + file + " from the texture pack."); return(false); } int maxWidth = Graphics.MaxTexWidth, maxHeight = Graphics.MaxTexHeight; if (bmp.Width > maxWidth || bmp.Height > maxHeight) { Chat.Add("&cUnable to use " + file + " from the texture pack."); Chat.Add("&c Its size is (" + bmp.Width + "," + bmp.Height + "), your GPU supports (" + maxWidth + "," + maxHeight + ") at most."); return(false); } if (!Utils.IsPowerOf2(bmp.Width) || !Utils.IsPowerOf2(bmp.Height)) { Chat.Add("&cUnable to use " + file + " from the texture pack."); Chat.Add("&c Its size is (" + bmp.Width + "," + bmp.Height + "), which is not power of two dimensions."); return(false); } return(true); }
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.."); }
public bool ChangeTerrainAtlas(Bitmap atlas) { bool pow2 = Utils.IsPowerOf2(atlas.Width) && Utils.IsPowerOf2(atlas.Height); if (!pow2 || atlas.Width != atlas.Height) { Chat.Add("&cCurrent texture pack has an invalid terrain.png"); Chat.Add("&cWidth and length must be the same, and also powers of two."); return(false); } LoadAtlas(atlas); Events.RaiseTerrainAtlasChanged(); return(true); }
void TakeScreenshot() { Utils.EnsureDirectory("screenshots"); string timestamp = Utils.LocalNow().ToString("dd-MM-yyyy-HH-mm-ss"); string file = "screenshot_" + timestamp + ".png"; string path = PathIO.Combine("screenshots", file); using (Stream fs = Platform.FileCreate(path)) { Graphics.TakeScreenshot(fs, Width, Height); } screenshotRequested = false; Chat.Add("&eTaken screenshot as: " + file); }
void TakeScreenshot() { string path = PathIO.Combine(Program.AppDirectory, "screenshots"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } string timestamp = DateTime.Now.ToString("dd-MM-yyyy-HH-mm-ss"); string file = "screenshot_" + timestamp + ".png"; path = PathIO.Combine(path, file); Graphics.TakeScreenshot(path, Width, Height); Chat.Add("&eTaken screenshot as: " + file); screenshotRequested = false; }
public bool ChangeItemAtlas(Bitmap atlas) { if (!ValidateBitmap("items.png", atlas)) { return(false); } if (atlas.Width != atlas.Height) { Chat.Add("&cUnable to use items.png from the texture pack."); Chat.Add("&c Its width is not the same as its height."); return(false); } if (Graphics.LostContext) { return(false); } LoadItemAtlas(atlas); Events.RaiseItemAtlasChanged(); return(true); }
/// <summary> Reads a bitmap from the stream (converting it to 32 bits per pixel if necessary), /// and updates the native texture for it. </summary> public bool UpdateTexture(ref int texId, string file, byte[] data, bool setSkinType) { MemoryStream stream = new MemoryStream(data); int maxSize = Graphics.MaxTextureDimensions; using (Bitmap bmp = Platform.ReadBmp(stream)) { if (bmp.Width > maxSize || bmp.Height > maxSize) { Chat.Add("&cUnable to use " + file + " from the texture pack."); Chat.Add("&c Its size is (" + bmp.Width + "," + bmp.Height + "), your GPU supports (" + maxSize + "," + maxSize + ") at most."); return(false); } Graphics.DeleteTexture(ref texId); if (setSkinType) { DefaultPlayerSkinType = Utils.GetSkinType(bmp); if (DefaultPlayerSkinType == SkinType.Invalid) { throw new NotSupportedException("char.png has invalid dimensions"); } } if (!Platform.Is32Bpp(bmp)) { using (Bitmap bmp32 = Drawer2D.ConvertTo32Bpp(bmp)) texId = Graphics.CreateTexture(bmp32, true); } else { texId = Graphics.CreateTexture(bmp, true); } return(true); } }