Skip to content
This repository has been archived by the owner on Nov 19, 2018. It is now read-only.

[WIP] TrueCraft FNA #228

Open
wants to merge 30 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
1661aba
Sloppy but functional FNA port
flibitijibibo Feb 2, 2016
a96b7b9
Add FNA submodule, checked out 16.02.02
flibitijibibo Feb 2, 2016
3eafa3a
Set ScaleFactor on startup
flibitijibibo Feb 2, 2016
8e71649
DepthBias accuracy fix
flibitijibibo Feb 2, 2016
0e66c14
Fix and optimize target sets/clears
flibitijibibo Feb 2, 2016
687fbdb
Improve OS Paths
flibitijibibo Feb 3, 2016
768b7e8
Just add the game folder name at the end...
flibitijibibo Feb 3, 2016
46c56b5
Turns out Drew already got this... welp
flibitijibibo Feb 3, 2016
7476b76
CWD fallback
flibitijibibo Feb 3, 2016
3b74b1a
Kind of obvious, right?
flibitijibibo Feb 3, 2016
a14c5fd
FNA update
flibitijibibo Feb 4, 2016
2c23bae
FNA update
flibitijibibo Feb 9, 2016
a7c3ace
FNA update
flibitijibibo Apr 1, 2016
2574793
Merge back from master
flibitijibibo Apr 1, 2016
1fb6cda
Oops, NuGet
flibitijibibo Apr 1, 2016
836c048
Package fixes...
flibitijibibo Apr 1, 2016
539d734
Merge back from upstream
flibitijibibo Apr 23, 2016
d72a090
FNA update
flibitijibibo Apr 23, 2016
9ad079a
SkyModule clears the target now!
flibitijibibo Apr 23, 2016
ec02023
Merge git://github.com/SirCmpwn/TrueCraft
flibitijibibo May 6, 2016
c5bdad0
FNA update
flibitijibibo May 6, 2016
10bf719
FNA 16.06
flibitijibibo Jun 1, 2016
3b3aa51
FNA 16.07
flibitijibibo Jul 4, 2016
b637bdc
Merge back from upstream
flibitijibibo Jun 8, 2017
d1b23ea
FNA update
flibitijibibo Jun 8, 2017
f4c5b3a
Merge git://github.com/SirCmpwn/TrueCraft
flibitijibibo Jul 25, 2017
e6c645b
FNA update
flibitijibibo Jul 25, 2017
d1dadf2
FNA update
flibitijibibo Oct 26, 2017
15cb428
Merge https://github.com/SirCmpwn/TrueCraft
flibitijibibo Oct 27, 2017
374dd4d
Merge git://github.com/ddevault/TrueCraft
flibitijibibo Feb 13, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion TrueCraft.Client/Handlers/ChunkHandlers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
12 changes: 6 additions & 6 deletions TrueCraft.Client/Modules/HUDModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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();
}
Expand Down Expand Up @@ -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);
Expand All @@ -139,15 +139,15 @@ 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
}
}

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);
Expand All @@ -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);
}
}
Expand Down
2 changes: 1 addition & 1 deletion TrueCraft.Client/Modules/HighlightModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ static HighlightModule()
};
RasterizerState = new RasterizerState
{
DepthBias = -3,
DepthBias = -3 / (float) ((1 << 24) - 1),
SlopeScaleDepthBias = -3
};
}
Expand Down
27 changes: 14 additions & 13 deletions TrueCraft.Client/Modules/WindowModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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)));
Expand Down Expand Up @@ -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);
Expand Down
21 changes: 10 additions & 11 deletions TrueCraft.Client/Rendering/TextureMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using Microsoft.Xna.Framework.Graphics;
using TrueCraft.Core;
using Ionic.Zip;
using MonoGame.Utilities.Png;

namespace TrueCraft.Client.Rendering
{
Expand All @@ -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")));
}

/// <summary>
Expand Down Expand Up @@ -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); }
Expand Down
17 changes: 5 additions & 12 deletions TrueCraft.Client/TrueCraft.Client.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\targets\Client.targets" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
Expand Down Expand Up @@ -74,14 +73,8 @@
</Reference>
<Reference Include="System" />
<Reference Include="System.Xml" />
<Reference Include="MonoGame.Framework">
<HintPath>..\packages\MonoGame.Framework.DesktopGL.3.5.1.1679\lib\net40\MonoGame.Framework.dll</HintPath>
</Reference>
<Reference Include="NVorbis">
<HintPath>..\packages\MonoGame.Framework.DesktopGL.3.5.1.1679\lib\net40\NVorbis.dll</HintPath>
</Reference>
<Reference Include="OpenTK">
<HintPath>..\packages\MonoGame.Framework.DesktopGL.3.5.1.1679\lib\net40\OpenTK.dll</HintPath>
<HintPath>..\packages\NVorbis.0.8.4.0\lib\NVorbis.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
Expand Down Expand Up @@ -167,6 +160,10 @@
<Project>{FA4BE9A3-DBF0-4380-BA2B-FFAA71C4706D}</Project>
<Name>TrueCraft.Core</Name>
</ProjectReference>
<ProjectReference Include="..\externals\FNA\FNA.csproj">
<Project>{35253CE1-C864-4CD3-8249-4D1319748E8F}</Project>
<Name>FNA</Name>
</ProjectReference>
</ItemGroup>
<ProjectExtensions>
<MonoDevelop>
Expand Down Expand Up @@ -376,10 +373,6 @@
<Content Include="Content\inventory.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<None Include="..\lib\OpenTK.dll.config">
<Link>OpenTK.dll.config</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Content\moon.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down
22 changes: 18 additions & 4 deletions TrueCraft.Client/TrueCraftGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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)
Expand All @@ -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();

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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));
}

Expand Down Expand Up @@ -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();

Expand Down
1 change: 0 additions & 1 deletion TrueCraft.Client/packages.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="MonoGame.Framework.DesktopGL" version="3.5.1.1679" targetFramework="net45" />
<package id="NVorbis" version="0.8.4.0" targetFramework="net45" />
</packages>
63 changes: 41 additions & 22 deletions TrueCraft.Core/Paths.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down
Loading