Skip to content

Commit

Permalink
Added a launcher class and use this to launch duality in the template (
Browse files Browse the repository at this point in the history
…#840)

#CHANGE added launcher logic to core
#CHANGE launcher is now build by the template instead of referencing a launcher nuget package
  • Loading branch information
Barsonax authored Jun 18, 2020
1 parent 9ac821b commit 12094d7
Show file tree
Hide file tree
Showing 15 changed files with 75 additions and 97 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ root = true
indent_style = tab

# Xml project files
[*.{csproj}]
[*.{csproj,json}]
indent_style = space
indent_size = 2

Expand Down
29 changes: 0 additions & 29 deletions Build/NuGetPackageSpecs/Duality.Launcher.nuspec

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,29 +1,22 @@
using System;
using System.Linq;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.IO;
using System.Drawing;

using Duality;
using Duality.Resources;
using System.Linq;
using Duality.Backend;
using Duality.Resources;

namespace Duality.Launcher
{
internal static class Program
public class DualityLauncher
{
[STAThread]
public static void Main(string[] args)
public static void Run(string[] args)
{
System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture;
System.Threading.Thread.CurrentThread.CurrentUICulture = System.Globalization.CultureInfo.InvariantCulture;

bool isDebugging = System.Diagnostics.Debugger.IsAttached || args.Contains(DualityApp.CmdArgDebug);
bool isRunFromEditor = args.Contains(DualityApp.CmdArgEditor);
bool isProfiling = args.Contains(DualityApp.CmdArgProfiling);
if (isDebugging || isRunFromEditor) ShowConsole();


// Set up console logging
Logs.AddGlobalOutput(new ConsoleLogOutput());

Expand All @@ -46,7 +39,7 @@ public static void Main(string[] args)
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

// Write initial log message before actually booting Duality
Logs.Core.Write("Running DualityLauncher with flags: {1}{0}",
Logs.Core.Write("Running DualityLauncher with flags: {1}{0}",
Environment.NewLine,
new[] { isDebugging ? "Debugging" : null, isProfiling ? "Profiling" : null, isRunFromEditor ? "RunFromEditor" : null }.NotNull().ToString(", "));

Expand All @@ -56,7 +49,7 @@ public static void Main(string[] args)
DualityApp.ExecutionContext.Game,
new DefaultAssemblyLoader(),
args);

// Open up a new window
WindowOptions options = new WindowOptions
{
Expand All @@ -77,15 +70,13 @@ public static void Main(string[] args)
// Shut down the Duality core
DualityApp.Terminate();
}

// Clean up the log file
if (logfileWriter != null)
{
Logs.RemoveGlobalOutput(logfileOutput);
logfileWriter.Flush();
logfileWriter.Close();
logfileWriter = null;
logfileOutput = null;
}
}

Expand All @@ -94,16 +85,8 @@ private static void CurrentDomain_UnhandledException(object sender, UnhandledExc
try
{
Logs.Core.WriteError(LogFormat.Exception(e.ExceptionObject as Exception));
}
}
catch (Exception) { /* Ensure we're not causing any further exception by logging... */ }
}

private static bool hasConsole = false;
public static void ShowConsole()
{
if (hasConsole) return;
SafeNativeMethods.AllocConsole();
hasConsole = true;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using Duality;

namespace Duality.Launcher
namespace Duality
{
/// <summary>
/// A <see cref="ILogOutput">Log output</see> that uses the <see cref="System.Console"/> as message destination.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29911.84
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GameLauncher", "Source\Launchers\GameLauncher\GameLauncher.csproj", "{EB32E368-2C3C-444F-9F7A-C808C03D462E}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DualityGame", "Source\Launchers\DualityGame\DualityGame.csproj", "{EB32E368-2C3C-444F-9F7A-C808C03D462E}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GameEditor", "Source\Launchers\GameEditor\GameEditor.csproj", "{E587311C-714A-4078-ADAE-EC00E8D971CB}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DualityGameCorePlugin", "Source\Plugins\DualityGameCorePlugin\DualityGameCorePlugin.csproj", "{E77740F1-234A-4B92-B1BC-43AD9EB9BA03}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Plugins", "Source\Plugins", "{F75B2813-797D-44A5-A301-331C229992C7}"
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Plugins", "Plugins", "{F75B2813-797D-44A5-A301-331C229992C7}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DualityGameEditorPlugin", "Source\Plugins\DualityGameEditorPlugin\DualityGameEditorPlugin.csproj", "{F0DCA20C-6888-4294-97C4-14C82B4DBC82}"
EndProject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,4 @@
<Copy SourceFiles="@(LibFiles)" DestinationFiles="@(LibFiles->'$(DualityFolder)\%(RecursiveDir)%(Filename)%(Extension)')" SkipUnchangedFiles="true" />
</Target>

<Target Name="CoreCompile" />
<PropertyGroup>
<SkipCopyBuildProduct>true</SkipCopyBuildProduct>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AdamsLair.Duality.Backend.DefaultOpenTK" Version="4.0.0-alpha3" />
<PackageReference Include="AdamsLair.Duality.Backend.DotNetFramework" Version="4.0.0-alpha3" />
<PackageReference Include="AdamsLair.Duality.Launcher" Version="4.0.0-alpha3" />
<PackageReference Include="AdamsLair.Duality.Plugins.Compatibility" Version="4.0.0-alpha3" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.Drawing;

namespace Duality.Launcher
namespace DualityGame
{
internal static class NativeMethods
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System;
using System.Linq;
using Duality;
using Duality.Launcher;

namespace DualityGame
{
internal static class Program
{
[STAThread]
public static void Main(string[] args)
{
bool isDebugging = System.Diagnostics.Debugger.IsAttached || args.Contains(DualityApp.CmdArgDebug);
bool isRunFromEditor = args.Contains(DualityApp.CmdArgEditor);
if (isDebugging || isRunFromEditor) ShowConsole();
DualityLauncher.Run(args);
}

private static bool hasConsole = false;
private static void ShowConsole()
{
if (hasConsole) return;
SafeNativeMethods.AllocConsole();
hasConsole = true;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"profiles": {
"Debug Game": {
"commandName": "Executable",
"executablePath": ".\\DualityLauncher.exe",
"executablePath": ".\\DualityGame.exe",
"workingDirectory": ".\\..\\..\\.."
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.Drawing;

namespace Duality.Launcher
namespace DualityGame
{
internal static class SafeNativeMethods
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<Project Sdk="Microsoft.NET.Sdk">

<ItemGroup>
<PackageReference Include="AdamsLair.Duality.Editor.Backend.DefaultOpenTK" Version="4.0.0-alpha3" />
<PackageReference Include="AdamsLair.Duality.Editor.Plugins.Base" Version="4.0.0-alpha3" />
Expand All @@ -11,12 +11,15 @@
<PackageReference Include="AdamsLair.Duality.Editor.Plugins.SceneView" Version="4.0.0-alpha3" />
<PackageReference Include="AdamsLair.Duality.Editor" Version="4.0.0-alpha3" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\Plugins\DualityGameEditorPlugin\DualityGameEditorPlugin.csproj" />
<ProjectReference Include="..\GameLauncher\GameLauncher.csproj">
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
</ProjectReference>
<ProjectReference Include="..\DualityGame\DualityGame.csproj" />
</ItemGroup>


<Target Name="CoreCompile" />
<PropertyGroup>
<SkipCopyBuildProduct>true</SkipCopyBuildProduct>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>netstandard2.0</TargetFramework>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<AssemblyName>DualityGameCorePlugin.core</AssemblyName>
<AssemblyName>DualityGameCorePlugin.core</AssemblyName>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>net472</TargetFramework>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<AssemblyName>DualityGameEditorPlugin.editor</AssemblyName>
<AssemblyName>DualityGameEditorPlugin.editor</AssemblyName>
</PropertyGroup>

<ItemGroup>
Expand Down
25 changes: 14 additions & 11 deletions Source/Launcher/DualityLauncher.csproj
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net472</TargetFramework>
<LangVersion>7.3</LangVersion>
<OutputPath>$(RootFolder)Build\Output\</OutputPath>
<Copyright>Copyright © Duality Core Team 2020</Copyright>
<RootNamespace>Duality.Launcher</RootNamespace>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<ApplicationIcon>DualityIcon.ico</ApplicationIcon>
<OutputType>Exe</OutputType>
<Version>4.0.0-alpha3</Version>
</PropertyGroup>
<PropertyGroup>
<TargetFramework>net472</TargetFramework>
<LangVersion>7.3</LangVersion>
<OutputPath>$(RootFolder)Build\Output\</OutputPath>
<Copyright>Copyright © Duality Core Team 2020</Copyright>
<RootNamespace>DualityGame</RootNamespace>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<ApplicationIcon>DualityIcon.ico</ApplicationIcon>
<OutputType>WinExe</OutputType>
<Version>4.0.0-alpha3</Version>
<Packable>false</Packable>
<AssemblyName>DualityGame</AssemblyName>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Core\Primitives\DualityPrimitives.csproj">
Expand All @@ -24,6 +26,7 @@
</ItemGroup>

<ItemGroup>
<Compile Include="..\DualityTemplates\Templates\SolutionTemplate\Source\Launchers\DualityGame\*.cs"></Compile>
<Content Include="DualityIcon.ico" />
<Content Include="DualityLogoIcon.ico" />
</ItemGroup>
Expand Down

0 comments on commit 12094d7

Please sign in to comment.