Skip to content

Commit

Permalink
Make project build on Linux. Fix issue with HairClip shader being com…
Browse files Browse the repository at this point in the history
…piled for previous MonoGame version.
  • Loading branch information
ethanmoffat committed Feb 10, 2022
1 parent 794129b commit adc091b
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 18 deletions.
1 change: 0 additions & 1 deletion EOLib.Graphics/EOLib.Graphics.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<OutputType>Library</OutputType>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<OutputPath>..\bin\$(Configuration)\lib\</OutputPath>
Expand Down
3 changes: 2 additions & 1 deletion EndlessClient/Audio/SoundManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@
using System.Collections.Generic;
using System.IO;
using System.Threading;
#if !LINUX
using System.Windows.Media;
using System.Windows.Threading;
#endif
using Microsoft.Xna.Framework.Audio;

namespace EndlessClient.Audio
{
public enum Note
{

}

public class SoundManager : IDisposable
Expand Down
1 change: 1 addition & 0 deletions EndlessClient/Content/IShaderRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public interface IShaderProvider
public class ShaderRepository : IShaderProvider, IShaderRepository
{
public const string HairClip = "HairClip";
public const string HairClipFile = "ContentPipeline/HairClip.mgfx";

IReadOnlyDictionary<string, Effect> IShaderProvider.Shaders => (IReadOnlyDictionary<string, Effect>)Shaders;

Expand Down
File renamed without changes.
25 changes: 14 additions & 11 deletions EndlessClient/EndlessClient.csproj
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<PropertyGroup Condition="!$([MSBuild]::IsOSPlatform('Linux'))">
<TargetFramework>net6.0-windows</TargetFramework>
<OutputType>WinExe</OutputType>
<MonoGamePlatform>Windows</MonoGamePlatform>
<MonoGameContentBuilderExe>
</MonoGameContentBuilderExe>
<UseWindowsForms>true</UseWindowsForms>
<UseWPF>true</UseWPF>
<ImportWindowsDesktopTargets>true</ImportWindowsDesktopTargets>
</PropertyGroup>
<PropertyGroup Condition="$([MSBuild]::IsOSPlatform('Linux'))">
<TargetFramework>net6.0</TargetFramework>
<OutputType>Exe</OutputType>
<DefineConstants>$(DefineConstants);LINUX</DefineConstants>
<MonoGamePlatform>Linux</MonoGamePlatform>
</PropertyGroup>
<PropertyGroup>
<_ResolveReferenceDependencies>true</_ResolveReferenceDependencies>
<NoWarn>CS0649;NU1701</NoWarn>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<OutputPath>..\bin\$(Configuration)\client</OutputPath>
<UseWindowsForms>true</UseWindowsForms>
<UseWPF>true</UseWPF>
<ImportWindowsDesktopTargets>true</ImportWindowsDesktopTargets>
</PropertyGroup>
<PropertyGroup>
<ApplicationIcon>Resources\Game.ico</ApplicationIcon>
</PropertyGroup>
<PropertyGroup Condition="$([MSBuild]::IsOSPlatform('Linux'))">
<DefineConstants>$(DefineConstants);LINUX</DefineConstants>
</PropertyGroup>
<ItemGroup>
<Compile Remove="ContentPipeline\bin\**" />
<Compile Remove="ContentPipeline\obj\**" />
Expand All @@ -41,8 +44,8 @@
<ProjectReference Include="..\EOLib\EOLib.csproj" />
</ItemGroup>
<ItemGroup Condition="$([MSBuild]::IsOSPlatform('Linux'))">
<Content Include="ContentPipeline\HairClip.xnb">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Content Include="ContentPipeline\HairClip.mgfx">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
Expand Down
11 changes: 9 additions & 2 deletions EndlessClient/GameExecution/EndlessGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,20 @@ protected override void LoadContent()
_graphicsDeviceRepository.GraphicsDevice = GraphicsDevice;

if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
_shaderRepository.Shaders[ShaderRepository.HairClip] = Content.Load<Effect>(ShaderRepository.HairClip);
{
if (!File.Exists(ShaderRepository.HairClipFile))
{
throw new FileNotFoundException("Missing HairClip shader");
}

var shaderBytes = File.ReadAllBytes(ShaderRepository.HairClipFile);
_shaderRepository.Shaders[ShaderRepository.HairClip] = new Effect(GraphicsDevice, shaderBytes);
}

base.LoadContent();
}

#if DEBUG

protected override void Update(GameTime gameTime)
{
//todo: this is a debug-only mode launched with the F5 key.
Expand Down
7 changes: 6 additions & 1 deletion EndlessClient/GameExecution/GameRunnerBase.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
using System.Diagnostics;
using System.IO;
using System.Windows.Forms;
using AutomaticTypeMapper;
using EndlessClient.Initialization;
using EOLib.Config;
using EOLib.Graphics;
using EOLib.Localization;

#if !LINUX
using System.Windows.Forms;
#endif

namespace EndlessClient.GameExecution
{
public abstract class GameRunnerBase : IGameRunner
Expand Down Expand Up @@ -83,7 +86,9 @@ public virtual bool SetupDependencies()

private void ShowErrorMessage(string message, string caption)
{
#if !LINUX
MessageBox.Show(message, caption, MessageBoxButtons.OK, MessageBoxIcon.Error);
#endif
}

public virtual void RunGame()
Expand Down
8 changes: 8 additions & 0 deletions EndlessClient/GameExecution/ReleaseGameRunner.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
#if !LINUX
using System.Windows.Forms;
#endif
using AutomaticTypeMapper;

namespace EndlessClient.GameExecution
Expand All @@ -20,11 +22,13 @@ public override bool SetupDependencies()
}
catch (Exception ex)
{
#if !LINUX
MessageBox.Show(
$"Error setting up dependencies for the game! Error message is:\n\n{ex.Message}",
"Dependency setup error!",
MessageBoxButtons.OK,
MessageBoxIcon.Error);
#endif
return false;
}
}
Expand All @@ -37,10 +41,13 @@ public override void RunGame()
}
catch (Exception ex)
{
#if !LINUX
ShowExceptionDialog(ex);
#endif
}
}

#if !LINUX
private static void ShowExceptionDialog(Exception ex)
{
Application.EnableVisualStyles();
Expand Down Expand Up @@ -99,5 +106,6 @@ private static void ShowExceptionDialog(Exception ex)
exForm.Controls.Add(exLabel1);
exForm.ShowDialog();
}
#endif
}
}
6 changes: 5 additions & 1 deletion EndlessClient/Old/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
#if !LINUX
using System.Windows.Forms;
#endif
using EndlessClient.Audio;
using EndlessClient.Dialogs;
using EndlessClient.GameExecution;
Expand Down Expand Up @@ -45,7 +47,7 @@ public void ShowLostConnectionDialog()
if (_backButtonPressed) return;
EOMessageBox.Show(State == GameStates.PlayingTheGame
? DialogResourceID.CONNECTION_LOST_IN_GAME
: DialogResourceID.CONNECTION_LOST_CONNECTION);
: DialogResourceID.CONNECTION_LOST_CONNECTION);
}

public void ResetWorldElements()
Expand Down Expand Up @@ -212,9 +214,11 @@ private bool InitializeSoundManager()
}
catch (Exception ex)
{
#if !LINUX
MessageBox.Show(
string.Format("There was an error (type: {2}) initializing the sound manager: {0}\n\nCall Stack:\n {1}", ex.Message,
ex.StackTrace, ex.GetType()), "Sound Manager Error");
#endif
Exit();
return false;
}
Expand Down
1 change: 0 additions & 1 deletion EndlessClient/Rendering/CharacterProperties/HatRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using EOLib.Domain.Extensions;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System.Diagnostics;
using System.Runtime.InteropServices;

namespace EndlessClient.Rendering.CharacterProperties
Expand Down

0 comments on commit adc091b

Please sign in to comment.