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/TrueCraft.Client/Handlers/ChunkHandlers.cs b/TrueCraft.Client/Handlers/ChunkHandlers.cs index 6698c5ba..ede145a7 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/HighlightModule.cs b/TrueCraft.Client/Modules/HighlightModule.cs index 879809be..62c0599a 100644 --- a/TrueCraft.Client/Modules/HighlightModule.cs +++ b/TrueCraft.Client/Modules/HighlightModule.cs @@ -53,7 +53,7 @@ static HighlightModule() }; RasterizerState = new RasterizerState { - DepthBias = -3, + DepthBias = -3 / (float) ((1 << 24) - 1), SlopeScaleDepthBias = -3 }; } 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/Rendering/TextureMapper.cs b/TrueCraft.Client/Rendering/TextureMapper.cs index f6bf7089..3c662253 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,15 +28,15 @@ 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/moon.png", new PngReader().Read(File.OpenRead("Content/moon.png"), graphicsDevice)); - Defaults.Add("terrain/sun.png", new PngReader().Read(File.OpenRead("Content/sun.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"))); + Defaults.Add("terrain/moon.png", Texture2D.FromStream(graphicsDevice, File.OpenRead("Content/moon.png"))); + Defaults.Add("terrain/sun.png", Texture2D.FromStream(graphicsDevice, File.OpenRead("Content/sun.png"))); } /// @@ -112,7 +111,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/TrueCraft.Client.csproj b/TrueCraft.Client/TrueCraft.Client.csproj index f24c6f01..627655c8 100644 --- a/TrueCraft.Client/TrueCraft.Client.csproj +++ b/TrueCraft.Client/TrueCraft.Client.csproj @@ -1,6 +1,5 @@  - Debug AnyCPU @@ -74,14 +73,8 @@ - - ..\packages\MonoGame.Framework.DesktopGL.3.5.1.1679\lib\net40\MonoGame.Framework.dll - - ..\packages\MonoGame.Framework.DesktopGL.3.5.1.1679\lib\net40\NVorbis.dll - - - ..\packages\MonoGame.Framework.DesktopGL.3.5.1.1679\lib\net40\OpenTK.dll + ..\packages\NVorbis.0.8.4.0\lib\NVorbis.dll @@ -167,6 +160,10 @@ {FA4BE9A3-DBF0-4380-BA2B-FFAA71C4706D} TrueCraft.Core + + {35253CE1-C864-4CD3-8249-4D1319748E8F} + FNA + @@ -376,10 +373,6 @@ PreserveNewest - - OpenTK.dll.config - PreserveNewest - PreserveNewest diff --git a/TrueCraft.Client/TrueCraftGame.cs b/TrueCraft.Client/TrueCraftGame.cs index 3445638e..9a62368c 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; @@ -82,6 +81,8 @@ 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.PreparingDeviceSettings += PrepareDeviceSettings; Graphics.ApplyChanges(); Window.ClientSizeChanged += Window_ClientSizeChanged; Client = client; @@ -102,6 +103,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) @@ -122,6 +128,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; + Camera = new Camera(GraphicsDevice.Viewport.AspectRatio, 70.0f, 0.1f, 1000.0f); UpdateCamera(); @@ -192,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) @@ -334,7 +348,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)); } @@ -413,7 +427,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(); diff --git a/TrueCraft.Client/packages.config b/TrueCraft.Client/packages.config index a21946de..667ada70 100644 --- a/TrueCraft.Client/packages.config +++ b/TrueCraft.Client/packages.config @@ -1,5 +1,4 @@  - \ No newline at end of file diff --git a/TrueCraft.Core/Paths.cs b/TrueCraft.Core/Paths.cs index e655362f..39adbca8 100644 --- a/TrueCraft.Core/Paths.cs +++ b/TrueCraft.Core/Paths.cs @@ -9,32 +9,51 @@ public static string Base { get { - var xdg_config_home = Environment.GetEnvironmentVariable("XDG_CONFIG_HOME"); - string config = null; - if (xdg_config_home != null) + string result; + if (RuntimeInfo.IsWindows) { - config = Path.Combine(xdg_config_home, "truecraft"); - if (Directory.Exists(config)) - return config; + result = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); } - 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 if (RuntimeInfo.IsMacOSX) { - Directory.CreateDirectory(config); - return config; + result = Environment.GetEnvironmentVariable("HOME"); + if (String.IsNullOrEmpty(result)) + { + result = "./"; // Oh well. + } + else + { + result += "/Library/Application Support/"; + } } - Directory.CreateDirectory(appdata); - return appdata; + else if (RuntimeInfo.IsLinux) + { + // 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/"; + } + } + } + else + { + System.Console.WriteLine("Unrecognized platform. Fall back to CWD."); + result = Environment.CurrentDirectory; + } + result = Path.Combine(result, "truecraft"); + if (!Directory.Exists(result)) + { + Directory.CreateDirectory(result); + } + return result; } } diff --git a/TrueCraft.sln b/TrueCraft.sln index 9d3f441c..b1ebc5f0 100644 --- a/TrueCraft.sln +++ b/TrueCraft.sln @@ -21,6 +21,7 @@ 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}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TrueCraft.API.Test", "TrueCraft.Core.Test\TrueCraft.API.Test\TrueCraft.API.Test.csproj", "{90712322-5904-4BCE-8606-C662706B8EAE}" EndProject Global @@ -30,6 +31,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/externals/FNA b/externals/FNA new file mode 160000 index 00000000..10d33723 --- /dev/null +++ b/externals/FNA @@ -0,0 +1 @@ +Subproject commit 10d33723174364beae4c74ab43b1d8bd6e614f9e diff --git a/lib/OpenTK.dll.config b/lib/OpenTK.dll.config deleted file mode 100644 index 3f888ccf..00000000 --- a/lib/OpenTK.dll.config +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - 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