From 1661aba041846934bc43506bfa2eb8705babe9ca Mon Sep 17 00:00:00 2001 From: Ethan Lee Date: Tue, 2 Feb 2016 12:52:05 -0500 Subject: [PATCH 01/23] Sloppy but functional FNA port --- TrueCraft.Client/Handlers/ChunkHandlers.cs | 2 +- TrueCraft.Client/Modules/HUDModule.cs | 12 ++++---- TrueCraft.Client/Modules/WindowModule.cs | 27 +++++++++-------- TrueCraft.Client/OpenTK.dll.config | 25 --------------- TrueCraft.Client/Program.cs | 32 -------------------- TrueCraft.Client/Rendering/TextureMapper.cs | 17 +++++------ TrueCraft.Client/Tao.Sdl.dll.config | 29 ------------------ TrueCraft.Client/TrueCraft.Client.csproj | 14 +++------ TrueCraft.Client/TrueCraftGame.cs | 4 +-- TrueCraft.Client/packages.config | 3 -- TrueCraft.Launcher/TrueCraft.Launcher.csproj | 9 ------ TrueCraft.sln | 8 +++++ targets/Client.targets | 22 -------------- 13 files changed, 43 insertions(+), 161 deletions(-) delete mode 100644 TrueCraft.Client/OpenTK.dll.config delete mode 100644 TrueCraft.Client/Tao.Sdl.dll.config delete mode 100644 targets/Client.targets diff --git a/TrueCraft.Client/Handlers/ChunkHandlers.cs b/TrueCraft.Client/Handlers/ChunkHandlers.cs index 16dd9cd9..4f26aea7 100644 --- a/TrueCraft.Client/Handlers/ChunkHandlers.cs +++ b/TrueCraft.Client/Handlers/ChunkHandlers.cs @@ -3,9 +3,9 @@ using TrueCraft.Core.Networking.Packets; using TrueCraft.API; using TrueCraft.Core.World; -using MonoGame.Utilities; using TrueCraft.Client.Events; using TrueCraft.API.World; +using Ionic.Zlib; namespace TrueCraft.Client.Handlers { diff --git a/TrueCraft.Client/Modules/HUDModule.cs b/TrueCraft.Client/Modules/HUDModule.cs index ec4c7a1f..a6fd6e15 100644 --- a/TrueCraft.Client/Modules/HUDModule.cs +++ b/TrueCraft.Client/Modules/HUDModule.cs @@ -33,7 +33,7 @@ public void Update(GameTime gameTime) public void Draw(GameTime gameTime) { - SpriteBatch.Begin(samplerState: SamplerState.PointClamp, blendState: BlendState.NonPremultiplied); + SpriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, SamplerState.PointClamp, DepthStencilState.None, RasterizerState.CullCounterClockwise); SpriteBatch.Draw(Icons, new Vector2( Game.GraphicsDevice.Viewport.Width / 2 - (8 * Game.ScaleFactor * 2), @@ -50,7 +50,7 @@ public void Draw(GameTime gameTime) DrawHotbarBlockSprites(gameTime); // Once more, with feeling - SpriteBatch.Begin(samplerState: SamplerState.PointClamp, blendState: BlendState.NonPremultiplied); + SpriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, SamplerState.PointClamp, DepthStencilState.None, RasterizerState.CullCounterClockwise); DrawHotbarSlotCounts(gameTime); SpriteBatch.End(); } @@ -125,7 +125,7 @@ private void DrawLife(GameTime gameTime) private void DrawHotbarItemSprites(GameTime gameTime) { - var scale = new Point((int)(16 * Game.ScaleFactor * 2)); + var scale = new Point((int)(16 * Game.ScaleFactor * 2), (int)(16 * Game.ScaleFactor * 2)); var origin = new Point((int)(Game.GraphicsDevice.Viewport.Width / 2 - Scale(HotbarBackgroundRect.Width / 2)), (int)(Game.GraphicsDevice.Viewport.Height - Scale(HotbarBackgroundRect.Height + 5))); origin.X += (int)Scale(3); @@ -139,7 +139,7 @@ private void DrawHotbarItemSprites(GameTime gameTime) if (provider.GetIconTexture((byte)item.Metadata) == null) continue; var position = origin + new Point((int)Scale(i * 20), 0); - var rect = new Rectangle(position, scale); + var rect = new Rectangle(position.X, position.Y, scale.X, scale.Y); IconRenderer.RenderItemIcon(SpriteBatch, Items, provider, (byte)item.Metadata, rect, Color.White); // TODO: Fuck, metadata was supposed to be a short } @@ -147,7 +147,7 @@ private void DrawHotbarItemSprites(GameTime gameTime) private void DrawHotbarBlockSprites(GameTime gameTime) { - var scale = new Point((int)(16 * Game.ScaleFactor * 2)); + var scale = new Point((int)(16 * Game.ScaleFactor * 2), (int)(16 * Game.ScaleFactor * 2)); var origin = new Point((int)(Game.GraphicsDevice.Viewport.Width / 2 - Scale(HotbarBackgroundRect.Width / 2)), (int)(Game.GraphicsDevice.Viewport.Height - Scale(HotbarBackgroundRect.Height + 5))); origin.X += (int)Scale(3); @@ -161,7 +161,7 @@ private void DrawHotbarBlockSprites(GameTime gameTime) if (provider == null || provider.GetIconTexture((byte)item.Metadata) != null) continue; var position = origin + new Point((int)Scale(i * 20), 0); - var rect = new Rectangle(position, scale); + var rect = new Rectangle(position.X, position.Y, scale.X, scale.Y); IconRenderer.RenderBlockIcon(Game, provider, (byte)item.Metadata, rect); } } diff --git a/TrueCraft.Client/Modules/WindowModule.cs b/TrueCraft.Client/Modules/WindowModule.cs index af7dcef7..4c6e2574 100644 --- a/TrueCraft.Client/Modules/WindowModule.cs +++ b/TrueCraft.Client/Modules/WindowModule.cs @@ -57,14 +57,14 @@ public void Draw(GameTime gameTime) SelectedSlot = -999; IItemProvider provider = null; - var scale = new Point((int)(16 * Game.ScaleFactor * 2)); - var mouse = Mouse.GetState().Position.ToVector2().ToPoint() - - new Point((int)(8 * Game.ScaleFactor * 2)); - var rect = new Rectangle(mouse, scale); + var scale = new Point((int)(16 * Game.ScaleFactor * 2), (int)(16 * Game.ScaleFactor * 2)); + MouseState state = Mouse.GetState(); + var mouse = new Point(state.X - (int)(8 * Game.ScaleFactor * 2), state.Y - (int)(8 * Game.ScaleFactor * 2)); + var rect = new Rectangle(mouse.X, mouse.Y, scale.X, scale.Y); if (!HeldItem.Empty) provider = Game.ItemRepository.GetItemProvider(HeldItem.ID); - SpriteBatch.Begin(samplerState: SamplerState.PointClamp, blendState: BlendState.NonPremultiplied); + SpriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, SamplerState.PointClamp, DepthStencilState.None, RasterizerState.CullCounterClockwise); SpriteBatch.Draw(Game.White1x1, new Rectangle(0, 0, Game.GraphicsDevice.Viewport.Width, Game.GraphicsDevice.Viewport.Height), new Color(Color.Black, 180)); switch (Game.Client.CurrentWindow.Type) @@ -109,7 +109,7 @@ public void Draw(GameTime gameTime) IconRenderer.RenderBlockIcon(Game, provider as IBlockProvider, (byte)HeldItem.Metadata, rect); } } - SpriteBatch.Begin(samplerState: SamplerState.PointClamp, blendState: BlendState.NonPremultiplied); + SpriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, SamplerState.PointClamp, DepthStencilState.None, RasterizerState.CullCounterClockwise); switch (Game.Client.CurrentWindow.Type) { case -1: @@ -137,10 +137,10 @@ public void Draw(GameTime gameTime) { var p = Game.ItemRepository.GetItemProvider(item.ID); var size = Font.MeasureText(p.DisplayName); - mouse = Mouse.GetState().Position.ToVector2().ToPoint(); - mouse += new Point(10, 10); - SpriteBatch.Draw(Game.White1x1, new Rectangle(mouse, - new Point(size.X + 10, size.Y + 15)), + mouse.X = state.X + 10; + mouse.Y = state.Y + 10; + SpriteBatch.Draw(Game.White1x1, new Rectangle(mouse.X, mouse.Y, + size.X + 10, size.Y + 15), new Color(Color.Black, 200)); Font.DrawText(SpriteBatch, mouse.X + 5, mouse.Y, p.DisplayName); } @@ -225,8 +225,9 @@ private void DrawCraftingWindow(RenderStage stage) private void DrawWindowArea(IWindowArea area, int _x, int _y, Rectangle frame, RenderStage stage) { - var mouse = Mouse.GetState().Position.ToVector2(); - var scale = new Point((int)(16 * Game.ScaleFactor * 2)); + MouseState state = Mouse.GetState(); + var mouse = new Point(state.X, state.Y); + var scale = new Point((int)(16 * Game.ScaleFactor * 2), (int)(16 * Game.ScaleFactor * 2)); var origin = new Point((int)( Game.GraphicsDevice.Viewport.Width / 2 - Scale(frame.Width / 2) + Scale(_x)), (int)(Game.GraphicsDevice.Viewport.Height / 2 - Scale(frame.Height / 2) + Scale(_y))); @@ -260,7 +261,7 @@ private void DrawWindowArea(IWindowArea area, int _x, int _y, Rectangle frame, R } } var position = origin + new Point(x, y); - var rect = new Rectangle(position, scale); + var rect = new Rectangle(position.X, position.Y, scale.X, scale.Y); if (stage == RenderStage.Sprites && rect.Contains(mouse)) { SelectedSlot = (short)(area.StartIndex + i); diff --git a/TrueCraft.Client/OpenTK.dll.config b/TrueCraft.Client/OpenTK.dll.config deleted file mode 100644 index 3f888ccf..00000000 --- a/TrueCraft.Client/OpenTK.dll.config +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/TrueCraft.Client/Program.cs b/TrueCraft.Client/Program.cs index eae1a0f5..711228fc 100644 --- a/TrueCraft.Client/Program.cs +++ b/TrueCraft.Client/Program.cs @@ -13,38 +13,6 @@ public static class Program { [STAThread] public static void Main(string[] args) - { - AppDomain.CurrentDomain.AssemblyResolve += AppDomain_CurrentDomain_AssemblyResolve; - - // We need to run this in another method to avoid referencing MonoGame before registering - // our AssemblyResolve handler - Main_Thread(args); - } - - static Assembly AppDomain_CurrentDomain_AssemblyResolve (object sender, ResolveEventArgs args) - { - var assemblyName = new AssemblyName(args.Name); - if (assemblyName.Name != "MonoGame.Framework") - return null; - if (RuntimeInfo.IsLinux) - return Assembly.LoadFile("MonoGame.Framework.Linux.dll"); - if (RuntimeInfo.IsWindows) - { - // MS.NET needs the absolute path to an assembly to load it. - var fileInfo = new FileInfo("MonoGame.Framework.Windows.dll"); - return Assembly.LoadFile(fileInfo.FullName); - } - if (RuntimeInfo.IsMacOSX) - { - var fileInfo = new FileInfo("MonoGame.Framework.MacOS.dll"); - return Assembly.LoadFile(fileInfo.FullName); - } - return null; - } - - // We need to spawn the main thread manually so we can register the assembly resolver - // and manage apartment state ourselves. - private static void Main_Thread(string[] args) { UserSettings.Local = new UserSettings(); UserSettings.Local.Load(); diff --git a/TrueCraft.Client/Rendering/TextureMapper.cs b/TrueCraft.Client/Rendering/TextureMapper.cs index 0d2020a1..a40859e9 100644 --- a/TrueCraft.Client/Rendering/TextureMapper.cs +++ b/TrueCraft.Client/Rendering/TextureMapper.cs @@ -6,7 +6,6 @@ using Microsoft.Xna.Framework.Graphics; using TrueCraft.Core; using Ionic.Zip; -using MonoGame.Utilities.Png; namespace TrueCraft.Client.Rendering { @@ -29,13 +28,13 @@ public static void LoadDefaults(GraphicsDevice graphicsDevice) { Defaults.Clear(); - Defaults.Add("terrain.png", new PngReader().Read(File.OpenRead("Content/terrain.png"), graphicsDevice)); - Defaults.Add("gui/items.png", new PngReader().Read(File.OpenRead("Content/items.png"), graphicsDevice)); - Defaults.Add("gui/gui.png", new PngReader().Read(File.OpenRead("Content/gui.png"), graphicsDevice)); - Defaults.Add("gui/icons.png", new PngReader().Read(File.OpenRead("Content/icons.png"), graphicsDevice)); - Defaults.Add("gui/crafting.png", new PngReader().Read(File.OpenRead("Content/crafting.png"), graphicsDevice)); - Defaults.Add("gui/furnace.png", new PngReader().Read(File.OpenRead("Content/furnace.png"), graphicsDevice)); - Defaults.Add("gui/inventory.png", new PngReader().Read(File.OpenRead("Content/inventory.png"), graphicsDevice)); + Defaults.Add("terrain.png", Texture2D.FromStream(graphicsDevice, File.OpenRead("Content/terrain.png"))); + Defaults.Add("gui/items.png", Texture2D.FromStream(graphicsDevice, File.OpenRead("Content/items.png"))); + Defaults.Add("gui/gui.png", Texture2D.FromStream(graphicsDevice, File.OpenRead("Content/gui.png"))); + Defaults.Add("gui/icons.png", Texture2D.FromStream(graphicsDevice, File.OpenRead("Content/icons.png"))); + Defaults.Add("gui/crafting.png", Texture2D.FromStream(graphicsDevice, File.OpenRead("Content/crafting.png"))); + Defaults.Add("gui/furnace.png", Texture2D.FromStream(graphicsDevice, File.OpenRead("Content/furnace.png"))); + Defaults.Add("gui/inventory.png", Texture2D.FromStream(graphicsDevice, File.OpenRead("Content/inventory.png"))); } /// @@ -110,7 +109,7 @@ public void AddTexturePack(TexturePack texturePack) { CopyStream(stream, ms); ms.Seek(0, SeekOrigin.Begin); - AddTexture(key, new PngReader().Read(ms, Device)); + AddTexture(key, Texture2D.FromStream(Device, ms)); } } catch (Exception ex) { Console.WriteLine("Exception occured while loading {0} from texture pack:\n\n{1}", key, ex); } diff --git a/TrueCraft.Client/Tao.Sdl.dll.config b/TrueCraft.Client/Tao.Sdl.dll.config deleted file mode 100644 index ec83f1e9..00000000 --- a/TrueCraft.Client/Tao.Sdl.dll.config +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/TrueCraft.Client/TrueCraft.Client.csproj b/TrueCraft.Client/TrueCraft.Client.csproj index c37e97dd..860b2287 100644 --- a/TrueCraft.Client/TrueCraft.Client.csproj +++ b/TrueCraft.Client/TrueCraft.Client.csproj @@ -1,6 +1,5 @@  - Debug AnyCPU @@ -74,9 +73,6 @@ - - ..\packages\MonoGame.Framework.Linux.3.4.0.459\lib\net40\MonoGame.Framework.dll - ..\packages\NVorbis.0.8.4.0\lib\NVorbis.dll @@ -163,6 +159,10 @@ {FA4BE9A3-DBF0-4380-BA2B-FFAA71C4706D} TrueCraft.Core + + {35253CE1-C864-4CD3-8249-4D1319748E8F} + FNA + @@ -218,13 +218,7 @@ PreserveNewest - - PreserveNewest - - - PreserveNewest - PreserveNewest diff --git a/TrueCraft.Client/TrueCraftGame.cs b/TrueCraft.Client/TrueCraftGame.cs index d1259de7..b1cc344c 100644 --- a/TrueCraft.Client/TrueCraftGame.cs +++ b/TrueCraft.Client/TrueCraftGame.cs @@ -7,7 +7,6 @@ using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; -using MonoGame.Utilities.Png; using TrueCraft.API; using TrueCraft.API.Logic; using TrueCraft.API.World; @@ -81,6 +80,7 @@ public TrueCraftGame(MultiplayerClient client, IPEndPoint endPoint) Graphics.IsFullScreen = UserSettings.Local.IsFullscreen; Graphics.PreferredBackBufferWidth = UserSettings.Local.WindowResolution.Width; Graphics.PreferredBackBufferHeight = UserSettings.Local.WindowResolution.Height; + Graphics.GraphicsProfile = GraphicsProfile.HiDef; Graphics.ApplyChanges(); Window.ClientSizeChanged += Window_ClientSizeChanged; Client = client; @@ -331,7 +331,7 @@ public void TakeScreenshot() if (!Directory.Exists(Path.GetDirectoryName(path))) Directory.CreateDirectory(Path.GetDirectoryName(path)); using (var stream = File.OpenWrite(path)) - new PngWriter().Write(RenderTarget, stream); + RenderTarget.SaveAsPng(stream, RenderTarget.Width, RenderTarget.Height); ChatModule.AddMessage("Screenshot saved to " + Path.GetFileName(path)); } diff --git a/TrueCraft.Client/packages.config b/TrueCraft.Client/packages.config index 8fa2b4e9..146f2656 100644 --- a/TrueCraft.Client/packages.config +++ b/TrueCraft.Client/packages.config @@ -1,7 +1,4 @@  - - - \ No newline at end of file diff --git a/TrueCraft.Launcher/TrueCraft.Launcher.csproj b/TrueCraft.Launcher/TrueCraft.Launcher.csproj index f46e0367..27fb2c91 100644 --- a/TrueCraft.Launcher/TrueCraft.Launcher.csproj +++ b/TrueCraft.Launcher/TrueCraft.Launcher.csproj @@ -107,15 +107,6 @@ - - rm $(TargetDir)/MonoGame.Framework.dll && cp $(SolutionDir)/packages/MonoGame.Framework.Linux.3.4.0.459/lib/net40/MonoGame.Framework.dll $(TargetDir)/MonoGame.Framework.Linux.dll && cp $(SolutionDir)/packages/MonoGame.Framework.WindowsGL.3.4.0.459/lib/net40/MonoGame.Framework.dll $(TargetDir)/MonoGame.Framework.Windows.dll && cp $(SolutionDir)/packages/MonoGame.Framework.MacOS.3.4.0.459/lib/net40/MonoGame.Framework.dll $(TargetDir)/MonoGame.Framework.MacOS.dll - - - del $(TargetDir)MonoGame.Framework.dll -copy $(SolutionDir)packages\MonoGame.Framework.Linux.3.4.0.459\lib\net40\MonoGame.Framework.dll $(TargetDir)MonoGame.Framework.Linux.dll -copy $(SolutionDir)packages\MonoGame.Framework.WindowsGL.3.4.0.459\lib\net40\MonoGame.Framework.dll $(TargetDir)MonoGame.Framework.Windows.dll -copy $(SolutionDir)packages\MonoGame.Framework.MacOS.3.4.0.459\lib\net40\MonoGame.Framework.dll $(TargetDir)MonoGame.Framework.MacOS.dll - true bin\Optimized Debug diff --git a/TrueCraft.sln b/TrueCraft.sln index f48ebd5d..824422d8 100644 --- a/TrueCraft.sln +++ b/TrueCraft.sln @@ -21,6 +21,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TrueCraft.Core.Test", "True EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TrueCraft.Profiling", "TrueCraft.Profiling\TrueCraft.Profiling.csproj", "{BCA0E139-CF47-43B3-9DC9-D4611C0A2AAD}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FNA", "externals\FNA\FNA.csproj", "{35253CE1-C864-4CD3-8249-4D1319748E8F}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -28,6 +30,12 @@ Global Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution + {35253CE1-C864-4CD3-8249-4D1319748E8F}.Debug|Any CPU.ActiveCfg = Debug|x86 + {35253CE1-C864-4CD3-8249-4D1319748E8F}.Debug|Any CPU.Build.0 = Debug|x86 + {35253CE1-C864-4CD3-8249-4D1319748E8F}.Optimized Debug|Any CPU.ActiveCfg = Debug|x86 + {35253CE1-C864-4CD3-8249-4D1319748E8F}.Optimized Debug|Any CPU.Build.0 = Debug|x86 + {35253CE1-C864-4CD3-8249-4D1319748E8F}.Release|Any CPU.ActiveCfg = Release|x86 + {35253CE1-C864-4CD3-8249-4D1319748E8F}.Release|Any CPU.Build.0 = Release|x86 {4488498D-976D-4DA3-BF72-109531AF0488}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {4488498D-976D-4DA3-BF72-109531AF0488}.Debug|Any CPU.Build.0 = Debug|Any CPU {4488498D-976D-4DA3-BF72-109531AF0488}.Optimized Debug|Any CPU.ActiveCfg = Debug|Any CPU diff --git a/targets/Client.targets b/targets/Client.targets deleted file mode 100644 index 39119fdc..00000000 --- a/targets/Client.targets +++ /dev/null @@ -1,22 +0,0 @@ - - - - - ..\packages\MonoGame.Framework.Linux.3.4.0.459\lib\net40\MonoGame.Framework.dll - - - ..\packages\MonoGame.Framework.Linux.3.4.0.459\lib\net40\OpenTK.dll - - - ..\packages\MonoGame.Framework.Linux.3.4.0.459\lib\net40\Tao.Sdl.dll - - - - - ..\packages\MonoGame.Framework.WindowsGL.3.4.0.459\lib\net40\MonoGame.Framework.dll - - - ..\packages\MonoGame.Framework.WindowsGL.3.4.0.459\lib\net40\OpenTK.dll - - - \ No newline at end of file From a96b7b9b0090a18c430d3cfaf60845a41b8c0e5c Mon Sep 17 00:00:00 2001 From: Ethan Lee Date: Tue, 2 Feb 2016 13:27:34 -0500 Subject: [PATCH 02/23] Add FNA submodule, checked out 16.02.02 --- .gitmodules | 3 +++ externals/FNA | 1 + 2 files changed, 4 insertions(+) create mode 160000 externals/FNA diff --git a/.gitmodules b/.gitmodules index 2b758bc4..6c041cd9 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "externals/fNbt"] path = externals/fNbt url = https://github.com/SirCmpwn/fNbt.git +[submodule "externals/FNA"] + path = externals/FNA + url = https://github.com/FNA-XNA/FNA.git diff --git a/externals/FNA b/externals/FNA new file mode 160000 index 00000000..0f2d4f50 --- /dev/null +++ b/externals/FNA @@ -0,0 +1 @@ +Subproject commit 0f2d4f50f9a46eda5c1277634cba49670b36e969 From 3eafa3a94a8a8e846da834a92c71f0cfd5feb939 Mon Sep 17 00:00:00 2001 From: Ethan Lee Date: Tue, 2 Feb 2016 14:22:43 -0500 Subject: [PATCH 03/23] Set ScaleFactor on startup --- TrueCraft.Client/TrueCraftGame.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/TrueCraft.Client/TrueCraftGame.cs b/TrueCraft.Client/TrueCraftGame.cs index b1cc344c..a882eecd 100644 --- a/TrueCraft.Client/TrueCraftGame.cs +++ b/TrueCraft.Client/TrueCraftGame.cs @@ -121,6 +121,13 @@ protected override void Initialize() base.Initialize(); // (calls LoadContent) + if (GraphicsDevice.Viewport.Width < 640 || GraphicsDevice.Viewport.Height < 480) + ScaleFactor = 0.5f; + else if (GraphicsDevice.Viewport.Width < 978 || GraphicsDevice.Viewport.Height < 720) + ScaleFactor = 1.0f; + else + ScaleFactor = 1.5f; + White1x1 = new Texture2D(GraphicsDevice, 1, 1); White1x1.SetData(new[] { Color.White }); From 8e7164977452d016500366b0b422c7893187765d Mon Sep 17 00:00:00 2001 From: Ethan Lee Date: Tue, 2 Feb 2016 14:31:55 -0500 Subject: [PATCH 04/23] DepthBias accuracy fix --- TrueCraft.Client/Modules/HighlightModule.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TrueCraft.Client/Modules/HighlightModule.cs b/TrueCraft.Client/Modules/HighlightModule.cs index 3062a4b1..661917a9 100644 --- a/TrueCraft.Client/Modules/HighlightModule.cs +++ b/TrueCraft.Client/Modules/HighlightModule.cs @@ -52,7 +52,7 @@ static HighlightModule() }; RasterizerState = new RasterizerState { - DepthBias = -3, + DepthBias = -3 / (float) ((1 << 24) - 1), SlopeScaleDepthBias = -3 }; } From 0e66c1421c302f221ce122db9d248499f15b0bea Mon Sep 17 00:00:00 2001 From: Ethan Lee Date: Tue, 2 Feb 2016 15:51:32 -0500 Subject: [PATCH 05/23] Fix and optimize target sets/clears --- TrueCraft.Client/TrueCraftGame.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/TrueCraft.Client/TrueCraftGame.cs b/TrueCraft.Client/TrueCraftGame.cs index a882eecd..0e164be2 100644 --- a/TrueCraft.Client/TrueCraftGame.cs +++ b/TrueCraft.Client/TrueCraftGame.cs @@ -81,6 +81,7 @@ public TrueCraftGame(MultiplayerClient client, IPEndPoint endPoint) Graphics.PreferredBackBufferWidth = UserSettings.Local.WindowResolution.Width; Graphics.PreferredBackBufferHeight = UserSettings.Local.WindowResolution.Height; Graphics.GraphicsProfile = GraphicsProfile.HiDef; + Graphics.PreparingDeviceSettings += PrepareDeviceSettings; Graphics.ApplyChanges(); Window.ClientSizeChanged += Window_ClientSizeChanged; Client = client; @@ -101,6 +102,11 @@ public TrueCraftGame(MultiplayerClient client, IPEndPoint endPoint) Components.Add(GamePadComponent); } + void PrepareDeviceSettings(object sender, PreparingDeviceSettingsEventArgs e) + { + e.GraphicsDeviceInformation.PresentationParameters.RenderTargetUsage = RenderTargetUsage.PreserveContents; + } + void Window_ClientSizeChanged(object sender, EventArgs e) { if (GraphicsDevice.Viewport.Width < 640 || GraphicsDevice.Viewport.Height < 480) @@ -418,7 +424,7 @@ protected override void Draw(GameTime gameTime) GraphicsDevice.SetRenderTarget(null); - SpriteBatch.Begin(); + SpriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Opaque); SpriteBatch.Draw(RenderTarget, Vector2.Zero, Color.White); SpriteBatch.End(); From 687fbdbde6822c49e31ed9bdbca8c98b3549709e Mon Sep 17 00:00:00 2001 From: Ethan Lee Date: Tue, 2 Feb 2016 21:56:44 -0500 Subject: [PATCH 06/23] Improve OS Paths --- TrueCraft.Core/Paths.cs | 83 ++++++++++++++++++++++++++++++----------- 1 file changed, 61 insertions(+), 22 deletions(-) diff --git a/TrueCraft.Core/Paths.cs b/TrueCraft.Core/Paths.cs index e655362f..ffb8530d 100644 --- a/TrueCraft.Core/Paths.cs +++ b/TrueCraft.Core/Paths.cs @@ -9,32 +9,71 @@ public static string Base { get { - var xdg_config_home = Environment.GetEnvironmentVariable("XDG_CONFIG_HOME"); - string config = null; - if (xdg_config_home != null) + string os; + // FIXME: SDL_GetPlatform() is nicer! -flibit + if (Environment.OSVersion.Platform == PlatformID.Win32NT) { - config = Path.Combine(xdg_config_home, "truecraft"); - if (Directory.Exists(config)) - return config; + os = "Windows"; } - var appdata = Path.Combine( - Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), - "truecraft"); - if (Directory.Exists(appdata)) - return appdata; - var userprofile = Path.Combine( - Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), - ".truecraft"); - if (Directory.Exists(userprofile)) - return userprofile; - // At this point, there's no existing data to choose from, so use the best option - if (config != null) + else { - Directory.CreateDirectory(config); - return config; + if (Environment.CurrentDirectory.StartsWith("/Users/")) + { + os = "Mac OS X"; + } + else // FIXME: Assumption! -flibit + { + os = "Linux"; + } } - Directory.CreateDirectory(appdata); - return appdata; + string result; + if (os.Equals("Windows")) + { + result = Path.Combine( + Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), + "truecraft" + ); + } + else if (os.Equals("Mac OS X")) + { + result = Environment.GetEnvironmentVariable("HOME"); + if (String.IsNullOrEmpty(result)) + { + result = "./"; // Oh well. + } + else + { + result += "/Library/Application Support/truecraft"; + } + result = Path.Combine(result, "truecraft"); + } + else if (os.Equals("Linux")) + { + // Assuming a non-OSX Unix platform will follow the XDG. Which it should. + result = Environment.GetEnvironmentVariable("XDG_CONFIG_HOME"); + if (String.IsNullOrEmpty(result)) + { + result = Environment.GetEnvironmentVariable("HOME"); + if (String.IsNullOrEmpty(result)) + { + result = "./"; // Oh well. + } + else + { + result += "/.config/"; + } + } + result = Path.Combine(result, "truecraft"); + } + else + { + throw new NotSupportedException("Unhandled SDL2 platform!"); + } + if (!Directory.Exists(result)) + { + Directory.CreateDirectory(result); + } + return result; } } From 768b7e89b3648543f22a7d5f80749702dc8fbe41 Mon Sep 17 00:00:00 2001 From: Ethan Lee Date: Tue, 2 Feb 2016 22:17:56 -0500 Subject: [PATCH 07/23] Just add the game folder name at the end... --- TrueCraft.Core/Paths.cs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/TrueCraft.Core/Paths.cs b/TrueCraft.Core/Paths.cs index ffb8530d..b9110930 100644 --- a/TrueCraft.Core/Paths.cs +++ b/TrueCraft.Core/Paths.cs @@ -29,10 +29,7 @@ public static string Base string result; if (os.Equals("Windows")) { - result = Path.Combine( - Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), - "truecraft" - ); + result = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); } else if (os.Equals("Mac OS X")) { @@ -45,7 +42,6 @@ public static string Base { result += "/Library/Application Support/truecraft"; } - result = Path.Combine(result, "truecraft"); } else if (os.Equals("Linux")) { @@ -63,12 +59,12 @@ public static string Base result += "/.config/"; } } - result = Path.Combine(result, "truecraft"); } else { throw new NotSupportedException("Unhandled SDL2 platform!"); } + result = Path.Combine(result, "truecraft"); if (!Directory.Exists(result)) { Directory.CreateDirectory(result); From 46c56b5f858a946c8fbec8344b436d7b8000959e Mon Sep 17 00:00:00 2001 From: Ethan Lee Date: Tue, 2 Feb 2016 22:55:17 -0500 Subject: [PATCH 08/23] Turns out Drew already got this... welp --- TrueCraft.Core/Paths.cs | 25 ++++--------------------- 1 file changed, 4 insertions(+), 21 deletions(-) diff --git a/TrueCraft.Core/Paths.cs b/TrueCraft.Core/Paths.cs index b9110930..afa20601 100644 --- a/TrueCraft.Core/Paths.cs +++ b/TrueCraft.Core/Paths.cs @@ -9,29 +9,12 @@ public static string Base { get { - string os; - // FIXME: SDL_GetPlatform() is nicer! -flibit - if (Environment.OSVersion.Platform == PlatformID.Win32NT) - { - os = "Windows"; - } - else - { - if (Environment.CurrentDirectory.StartsWith("/Users/")) - { - os = "Mac OS X"; - } - else // FIXME: Assumption! -flibit - { - os = "Linux"; - } - } string result; - if (os.Equals("Windows")) + if (RuntimeInfo.IsWindows) { result = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); } - else if (os.Equals("Mac OS X")) + else if (RuntimeInfo.IsMacOSX) { result = Environment.GetEnvironmentVariable("HOME"); if (String.IsNullOrEmpty(result)) @@ -43,7 +26,7 @@ public static string Base result += "/Library/Application Support/truecraft"; } } - else if (os.Equals("Linux")) + else if (RuntimeInfo.IsLinux) { // Assuming a non-OSX Unix platform will follow the XDG. Which it should. result = Environment.GetEnvironmentVariable("XDG_CONFIG_HOME"); @@ -62,7 +45,7 @@ public static string Base } else { - throw new NotSupportedException("Unhandled SDL2 platform!"); + throw new NotSupportedException("Unhandled RuntimeInfo platform!"); } result = Path.Combine(result, "truecraft"); if (!Directory.Exists(result)) From 7476b76a9badd1f92baf43d9e485f321dbf26608 Mon Sep 17 00:00:00 2001 From: Ethan Lee Date: Wed, 3 Feb 2016 09:14:20 -0500 Subject: [PATCH 09/23] CWD fallback --- TrueCraft.Core/Paths.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/TrueCraft.Core/Paths.cs b/TrueCraft.Core/Paths.cs index afa20601..b7aa1fee 100644 --- a/TrueCraft.Core/Paths.cs +++ b/TrueCraft.Core/Paths.cs @@ -45,7 +45,8 @@ public static string Base } else { - throw new NotSupportedException("Unhandled RuntimeInfo platform!"); + System.Console.WriteLine("Unrecognized platform. Fall back to CWD."); + result = Environment.CurrentDirectory; } result = Path.Combine(result, "truecraft"); if (!Directory.Exists(result)) From 3b74b1a41638505058b06564b200ef360e8d45d4 Mon Sep 17 00:00:00 2001 From: Ethan Lee Date: Wed, 3 Feb 2016 09:26:38 -0500 Subject: [PATCH 10/23] Kind of obvious, right? --- TrueCraft.Core/Paths.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TrueCraft.Core/Paths.cs b/TrueCraft.Core/Paths.cs index b7aa1fee..39adbca8 100644 --- a/TrueCraft.Core/Paths.cs +++ b/TrueCraft.Core/Paths.cs @@ -23,7 +23,7 @@ public static string Base } else { - result += "/Library/Application Support/truecraft"; + result += "/Library/Application Support/"; } } else if (RuntimeInfo.IsLinux) From a14c5fdf7f439939f377d793038da86c936b366d Mon Sep 17 00:00:00 2001 From: Ethan Lee Date: Thu, 4 Feb 2016 16:15:32 -0500 Subject: [PATCH 11/23] FNA update --- externals/FNA | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/externals/FNA b/externals/FNA index 0f2d4f50..6d2d2abe 160000 --- a/externals/FNA +++ b/externals/FNA @@ -1 +1 @@ -Subproject commit 0f2d4f50f9a46eda5c1277634cba49670b36e969 +Subproject commit 6d2d2abe6dc0827c726548641a236d22b25ec726 From 2c23bae29a8fdacb0261777388e1950148198e3d Mon Sep 17 00:00:00 2001 From: Ethan Lee Date: Tue, 9 Feb 2016 01:25:40 -0500 Subject: [PATCH 12/23] FNA update --- externals/FNA | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/externals/FNA b/externals/FNA index 6d2d2abe..67ffd37f 160000 --- a/externals/FNA +++ b/externals/FNA @@ -1 +1 @@ -Subproject commit 6d2d2abe6dc0827c726548641a236d22b25ec726 +Subproject commit 67ffd37fda09c56f8936fa83202be2471e4549f0 From a7c3acee5217f75137d372e0aa992924684c2951 Mon Sep 17 00:00:00 2001 From: Ethan Lee Date: Fri, 1 Apr 2016 11:34:47 -0400 Subject: [PATCH 13/23] FNA update --- externals/FNA | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/externals/FNA b/externals/FNA index 67ffd37f..525bdfe6 160000 --- a/externals/FNA +++ b/externals/FNA @@ -1 +1 @@ -Subproject commit 67ffd37fda09c56f8936fa83202be2471e4549f0 +Subproject commit 525bdfe61e053b0a7edba4f5bc9cedbd222c161d From 1fb6cda8857c23461ac01110d9055bac641b16ec Mon Sep 17 00:00:00 2001 From: Ethan Lee Date: Fri, 1 Apr 2016 11:41:04 -0400 Subject: [PATCH 14/23] Oops, NuGet --- TrueCraft.Client/packages.config | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/TrueCraft.Client/packages.config b/TrueCraft.Client/packages.config index 54823896..667ada70 100644 --- a/TrueCraft.Client/packages.config +++ b/TrueCraft.Client/packages.config @@ -1,5 +1,4 @@  - - + \ No newline at end of file From 836c0482a2fae19de4fe386b005fbf052fb30739 Mon Sep 17 00:00:00 2001 From: Ethan Lee Date: Fri, 1 Apr 2016 11:49:08 -0400 Subject: [PATCH 15/23] Package fixes... --- TrueCraft.Client/TrueCraft.Client.csproj | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/TrueCraft.Client/TrueCraft.Client.csproj b/TrueCraft.Client/TrueCraft.Client.csproj index 26911f98..cedc9c17 100644 --- a/TrueCraft.Client/TrueCraft.Client.csproj +++ b/TrueCraft.Client/TrueCraft.Client.csproj @@ -73,14 +73,8 @@ - - ..\packages\MonoGame.Framework.DesktopGL.3.5.0.1678\lib\net40\MonoGame.Framework.dll - - ..\packages\MonoGame.Framework.DesktopGL.3.5.0.1678\lib\net40\NVorbis.dll - - - ..\packages\MonoGame.Framework.DesktopGL.3.5.0.1678\lib\net40\OpenTK.dll + ..\packages\NVorbis.0.8.4.0\lib\NVorbis.dll @@ -378,10 +372,6 @@ PreserveNewest - - OpenTK.dll.config - PreserveNewest - From d72a090465293afea7a4889406eb8a5eab82c1e7 Mon Sep 17 00:00:00 2001 From: Ethan Lee Date: Sat, 23 Apr 2016 16:38:56 -0400 Subject: [PATCH 16/23] FNA update --- externals/FNA | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/externals/FNA b/externals/FNA index 525bdfe6..2adf4192 160000 --- a/externals/FNA +++ b/externals/FNA @@ -1 +1 @@ -Subproject commit 525bdfe61e053b0a7edba4f5bc9cedbd222c161d +Subproject commit 2adf4192363478a2189b89eaea0c9d1ce10a1e1b From 9ad079a83ec395d07dc0895202d0594e17bccd1f Mon Sep 17 00:00:00 2001 From: Ethan Lee Date: Sat, 23 Apr 2016 16:53:53 -0400 Subject: [PATCH 17/23] SkyModule clears the target now! --- TrueCraft.Client/TrueCraftGame.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/TrueCraft.Client/TrueCraftGame.cs b/TrueCraft.Client/TrueCraftGame.cs index 7cfe5596..9a62368c 100644 --- a/TrueCraft.Client/TrueCraftGame.cs +++ b/TrueCraft.Client/TrueCraftGame.cs @@ -205,7 +205,8 @@ public void Invoke(Action action) private void CreateRenderTarget() { RenderTarget = new RenderTarget2D(GraphicsDevice, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height, - false, GraphicsDevice.PresentationParameters.BackBufferFormat, DepthFormat.Depth24); + false, GraphicsDevice.PresentationParameters.BackBufferFormat, DepthFormat.Depth24, + 0, RenderTargetUsage.PreserveContents); } void HandleClientPropertyChanged(object sender, PropertyChangedEventArgs e) From c5bdad096e68b12ffd6ceaae51576f8c4bb64b4f Mon Sep 17 00:00:00 2001 From: Ethan Lee Date: Fri, 6 May 2016 12:02:43 -0400 Subject: [PATCH 18/23] FNA update --- externals/FNA | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/externals/FNA b/externals/FNA index 2adf4192..86e4a6a4 160000 --- a/externals/FNA +++ b/externals/FNA @@ -1 +1 @@ -Subproject commit 2adf4192363478a2189b89eaea0c9d1ce10a1e1b +Subproject commit 86e4a6a48a3daed3add4d7b90731be9cadd5ec72 From 10bf719f00ed60605dbd1a047e6dd4bc8d0b21a2 Mon Sep 17 00:00:00 2001 From: Ethan Lee Date: Wed, 1 Jun 2016 10:01:48 -0400 Subject: [PATCH 19/23] FNA 16.06 --- externals/FNA | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/externals/FNA b/externals/FNA index 86e4a6a4..400f688e 160000 --- a/externals/FNA +++ b/externals/FNA @@ -1 +1 @@ -Subproject commit 86e4a6a48a3daed3add4d7b90731be9cadd5ec72 +Subproject commit 400f688ee8fe4474626c062972295279233daf47 From 3b3aa51a99ed14684f52645715f95b4b1bbae28a Mon Sep 17 00:00:00 2001 From: Ethan Lee Date: Mon, 4 Jul 2016 11:42:25 -0400 Subject: [PATCH 20/23] FNA 16.07 --- externals/FNA | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/externals/FNA b/externals/FNA index 400f688e..aea78b1c 160000 --- a/externals/FNA +++ b/externals/FNA @@ -1 +1 @@ -Subproject commit 400f688ee8fe4474626c062972295279233daf47 +Subproject commit aea78b1c5e787dcd49d7ba6bd7f2dc0af5ad0105 From d1b23ea06bab84109f65d68d36b32fa86cfbb9da Mon Sep 17 00:00:00 2001 From: Ethan Lee Date: Thu, 8 Jun 2017 10:54:47 -0400 Subject: [PATCH 21/23] FNA update --- externals/FNA | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/externals/FNA b/externals/FNA index aea78b1c..c255a533 160000 --- a/externals/FNA +++ b/externals/FNA @@ -1 +1 @@ -Subproject commit aea78b1c5e787dcd49d7ba6bd7f2dc0af5ad0105 +Subproject commit c255a5338c4f18091021f80edc1f0eebee47e75c From e6c645b237b9c8395cfc9fa8aa4934875793a3e4 Mon Sep 17 00:00:00 2001 From: Ethan Lee Date: Tue, 25 Jul 2017 10:32:26 -0400 Subject: [PATCH 22/23] FNA update --- externals/FNA | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/externals/FNA b/externals/FNA index c255a533..6e5111ec 160000 --- a/externals/FNA +++ b/externals/FNA @@ -1 +1 @@ -Subproject commit c255a5338c4f18091021f80edc1f0eebee47e75c +Subproject commit 6e5111ec02573e95cb8b0e2591f091c4b89c49dd From d1dadf24f7453a2183ab95505b145d271a26ba46 Mon Sep 17 00:00:00 2001 From: Ethan Lee Date: Thu, 26 Oct 2017 15:16:52 -0400 Subject: [PATCH 23/23] FNA update --- externals/FNA | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/externals/FNA b/externals/FNA index 6e5111ec..10d33723 160000 --- a/externals/FNA +++ b/externals/FNA @@ -1 +1 @@ -Subproject commit 6e5111ec02573e95cb8b0e2591f091c4b89c49dd +Subproject commit 10d33723174364beae4c74ab43b1d8bd6e614f9e