dotnet core jank

This commit is contained in:
Mike 2020-11-02 20:02:03 -08:00
parent c3e9e7cf80
commit 5317c2745d
5 changed files with 140 additions and 76 deletions

24
.vscode/launch.json vendored
View File

@ -4,7 +4,23 @@
"version": "0.2.0", "version": "0.2.0",
"configurations": [ "configurations": [
{
"name": "Launch (dotnet)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "Build (Debug)",
"program": "${workspaceFolder}/project_name/bin/Debug/project_name.dll",
"args": [],
"cwd": "${workspaceFolder}/project_name",
"console": "internalConsole",
"stopAtEntry": false,
"internalConsoleOptions": "openOnSessionStart",
"osx":{
"env": {
"DYLD_LIBRARY_PATH": "${workspaceFolder}/project_name/bin/Debug/osx/"
}
}
},
{ {
"name": "Launch (Mac)", "name": "Launch (Mac)",
"type": "mono", "type": "mono",
@ -18,7 +34,7 @@
} }
} }
}, },
{ {
"name": "Launch Without Building (Mac)", "name": "Launch Without Building (Mac)",
"type": "mono", "type": "mono",
@ -40,7 +56,7 @@
"cwd": "${workspaceFolder}/project_name", "cwd": "${workspaceFolder}/project_name",
"preLaunchTask": "Build (Debug)" "preLaunchTask": "Build (Debug)"
}, },
{ {
"name": "Launch Without Building (Windows)", "name": "Launch Without Building (Windows)",
"type": "clr", "type": "clr",
@ -57,4 +73,4 @@
"port": 55555 "port": 55555
} }
] ]
} }

27
.vscode/tasks.json vendored
View File

@ -1,6 +1,19 @@
{ {
"version": "2.0.0", "version": "2.0.0",
"tasks": [ "tasks": [
{
"label": "dotnet Build and Run (Debug)",
"type": "shell",
"group": "build",
"osx":{
"command": "dotnet ${workspaceFolder}/project_name/bin/Debug/project_name.dll",
"env": {
"DYLD_LIBRARY_PATH": "${workspaceFolder}/project_name/bin/Debug/osx/"
},
},
"dependsOn": "Build (Debug)",
"problemMatcher": "$msCompile"
},
{ {
"label": "Restore Project", "label": "Restore Project",
"type": "shell", "type": "shell",
@ -8,7 +21,7 @@
"group": "build", "group": "build",
"problemMatcher": "$msCompile" "problemMatcher": "$msCompile"
}, },
{ {
// this does a bunch of stuff: // this does a bunch of stuff:
// - update submodules to lastest (fetch latest Nez version) // - update submodules to lastest (fetch latest Nez version)
@ -117,7 +130,7 @@
}, },
"problemMatcher": "$msCompile" "problemMatcher": "$msCompile"
}, },
{ {
"label": "Build Content", "label": "Build Content",
"type": "shell", "type": "shell",
@ -136,8 +149,8 @@
"osx": { "osx": {
"command": "mono /Applications/Pipeline.app/Contents/MonoBundle/MGCB.exe /@:Content.mgcb -r", "command": "mono /Applications/Pipeline.app/Contents/MonoBundle/MGCB.exe /@:Content.mgcb -r",
}, },
"windows": { "windows": {
"command":"C:/Program Files (x86)/MSBuild/MonoGame/v3.0/Tools/MGCB.exe", "command":"C:/Program Files (x86)/MSBuild/MonoGame/v3.0/Tools/MGCB.exe",
"args": [ "args": [
"/@:Content.mgcb", "/@:Content.mgcb",
"-r" "-r"
@ -161,7 +174,7 @@
}, },
"problemMatcher": "$msCompile" "problemMatcher": "$msCompile"
}, },
{ {
"label": "Process T4 Templates", "label": "Process T4 Templates",
"type": "shell", "type": "shell",
@ -170,9 +183,9 @@
}, },
"windows": { "windows": {
"command": "powershell", "command": "powershell",
"args": [ "args": [
"-File", "-File",
"${workspaceFolder}/.vscode/processT4Templates.ps1" "${workspaceFolder}/.vscode/processT4Templates.ps1"
] ]
}, },
"group": "build", "group": "build",

View File

@ -1,32 +1,35 @@
using System;
using System.Reflection;
using System.Runtime.InteropServices;
using Nez; using Nez;
using Nez.ImGuiTools; using Nez.ImGuiTools;
namespace project_name namespace project_name
{ {
class Game1 : Core class Game1 : Core
{ {
public Game1() : base() public Game1() : base()
{ {
// uncomment this line for scaled pixel art games // uncomment this line for scaled pixel art games
// System.Environment.SetEnvironmentVariable("FNA_OPENGL_BACKBUFFER_SCALE_NEAREST", "1"); // System.Environment.SetEnvironmentVariable("FNA_OPENGL_BACKBUFFER_SCALE_NEAREST", "1");
} }
override protected void Initialize() override protected void Initialize()
{ {
base.Initialize(); base.Initialize();
Scene = new DefaultScene(); Scene = new DefaultScene();
#if DEBUG #if DEBUG
System.Diagnostics.Debug.Listeners.Add(new System.Diagnostics.TextWriterTraceListener(System.Console.Out)); // System.Diagnostics.Debug.Listeners.Add(new System.Diagnostics.TextWriterTraceListener(System.Console.Out));
// optionally render Nez in an ImGui window // optionally render Nez in an ImGui window
var imGuiManager = new ImGuiManager(); var imGuiManager = new ImGuiManager();
Core.RegisterGlobalManager(imGuiManager); Core.RegisterGlobalManager(imGuiManager);
// optionally load up ImGui DLL if not using the above setup so that its command gets loaded in the DebugConsole // optionally load up ImGui DLL if not using the above setup so that its command gets loaded in the DebugConsole
//System.Reflection.Assembly.Load("Nez.ImGui") //System.Reflection.Assembly.Load("Nez.ImGui")
#endif #endif
} }
} }
} }

View File

@ -1,51 +1,82 @@
using System; using System;
using System.IO; using System.IO;
using System.Reflection;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using Microsoft.Xna.Framework;
namespace project_name namespace project_name
{ {
class Program class Program
{ {
[DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)] [DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)] [return: MarshalAs(UnmanagedType.Bool)]
static extern bool SetDefaultDllDirectories(int directoryFlags); static extern bool SetDefaultDllDirectories(int directoryFlags);
[DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)] [DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
static extern void AddDllDirectory(string lpPathName); static extern void AddDllDirectory(string lpPathName);
[DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)] [DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)] [return: MarshalAs(UnmanagedType.Bool)]
static extern bool SetDllDirectory(string lpPathName); static extern bool SetDllDirectory(string lpPathName);
const int LOAD_LIBRARY_SEARCH_DEFAULT_DIRS = 0x00001000; const int LOAD_LIBRARY_SEARCH_DEFAULT_DIRS = 0x00001000;
public static void Main(string[] args) public static void Main(string[] args)
{ {
if (Environment.OSVersion.Platform == PlatformID.Win32NT) NativeLibrary.SetDllImportResolver(typeof(Microsoft.Xna.Framework.Color).Assembly, ImportResolver);
if (Environment.OSVersion.Platform == PlatformID.Win32NT)
{
try
{
SetDefaultDllDirectories(LOAD_LIBRARY_SEARCH_DEFAULT_DIRS);
AddDllDirectory(Path.Combine(
AppDomain.CurrentDomain.BaseDirectory,
Environment.Is64BitProcess ? "x64" : "x86"
));
}
catch
{
// Pre-Windows 7, KB2533623
SetDllDirectory(Path.Combine(
AppDomain.CurrentDomain.BaseDirectory,
Environment.Is64BitProcess ? "x64" : "x86"
));
}
}
using (Game1 game = new Game1())
{
game.Run();
}
}
private static IntPtr ImportResolver(string libraryName, Assembly assembly, DllImportSearchPath? searchPath)
{
IntPtr libHandle = IntPtr.Zero;
if (libraryName == "FNA3D")
{
if (Environment.OSVersion.Platform == PlatformID.Win32NT)
NativeLibrary.TryLoad("bin/Debug/x64/FNA3D.dll", assembly, DllImportSearchPath.System32, out libHandle);
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
NativeLibrary.TryLoad("bin/Debug/osx/libFNA3D.0.dylib", assembly, DllImportSearchPath.System32, out libHandle);
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
NativeLibrary.TryLoad("bin/Debug/lib64/libFNA3D.so.0", assembly, DllImportSearchPath.System32, out libHandle);
}
else if (libraryName == "SDL2")
{
if (Environment.OSVersion.Platform == PlatformID.Win32NT)
NativeLibrary.TryLoad("bin/Debug/x64/SDL2.dll", assembly, DllImportSearchPath.System32, out libHandle);
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
NativeLibrary.TryLoad("bin/Debug/osx/libSDL2-2.0.0.dylib", assembly, DllImportSearchPath.System32, out libHandle);
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
NativeLibrary.TryLoad("bin/Debug/lib64/libSDL2-2.0.0.so.0", assembly, DllImportSearchPath.System32, out libHandle);
}
else
{ {
try Console.WriteLine($"----- no case for library load: {libraryName} ---------");
{
SetDefaultDllDirectories(LOAD_LIBRARY_SEARCH_DEFAULT_DIRS);
AddDllDirectory(Path.Combine(
AppDomain.CurrentDomain.BaseDirectory,
Environment.Is64BitProcess ? "x64" : "x86"
));
}
catch
{
// Pre-Windows 7, KB2533623
SetDllDirectory(Path.Combine(
AppDomain.CurrentDomain.BaseDirectory,
Environment.Is64BitProcess ? "x64" : "x86"
));
}
} }
Console.WriteLine($"----- no case for library load: {libHandle} ---------");
using (Game1 game = new Game1()) return libHandle;
{ }
game.Run(); }
} }
}
}
}

View File

@ -2,7 +2,7 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<TargetFramework>net471</TargetFramework> <TargetFramework>netcoreapp3.1</TargetFramework>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath> <AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<PlatformTarget>AnyCPU</PlatformTarget> <PlatformTarget>AnyCPU</PlatformTarget>
<AssemblyName>project_name</AssemblyName> <AssemblyName>project_name</AssemblyName>
@ -10,16 +10,16 @@
<AllowUnsafeBlocks>True</AllowUnsafeBlocks> <AllowUnsafeBlocks>True</AllowUnsafeBlocks>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo> <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
</PropertyGroup> </PropertyGroup>
<!-- Reference FNA, Nez, ImGui and Persistence projects. Optionally add a Farseer reference here and in the .sln file --> <!-- Reference FNA, Nez, ImGui and Persistence projects. Optionally add a Farseer reference here and in the .sln file -->
<ItemGroup> <ItemGroup>
<ProjectReference Include="../FNA/FNA.csproj"/> <ProjectReference Include="../FNA/FNA.Core.csproj"/>
<ProjectReference Include="../Nez/Nez.Portable/Nez.FNA.csproj"/> <ProjectReference Include="../Nez/Nez.Portable/Nez.FNA.Standard.csproj"/>
<ProjectReference Include="../Nez/Nez.Persistence/Nez.FNA.Persistence.csproj" /> <ProjectReference Include="../Nez/Nez.Persistence/Nez.FNA.Persistence.csproj" />
<ProjectReference Include="../Nez/Nez.ImGui/Nez.FNA.ImGui.csproj"/> <ProjectReference Include="../Nez/Nez.ImGui/Nez.FNA.ImGui.csproj"/>
<!-- <ProjectReference Include="../Nez/Nez.FarseerPhysics/Nez.FNA.FarseerPhysics.csproj" /> --> <!-- <ProjectReference Include="../Nez/Nez.FarseerPhysics/Nez.FNA.FarseerPhysics.csproj" /> -->
</ItemGroup> </ItemGroup>
<!-- Includes Nez default effects and textures --> <!-- Includes Nez default effects and textures -->
<ItemGroup> <ItemGroup>
<Content Include="../Nez/DefaultContent/FNAEffects/**/*.fxb"> <Content Include="../Nez/DefaultContent/FNAEffects/**/*.fxb">
@ -31,14 +31,14 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </Content>
</ItemGroup> </ItemGroup>
<!-- Include the Content directory (except for .fx files, since we use .fxb at runtime) --> <!-- Include the Content directory (except for .fx files, since we use .fxb at runtime) -->
<ItemGroup> <ItemGroup>
<Content Include="Content/**/*.*" Exclude="**/*.fx; Content/Content-Goes-Here.txt"> <Content Include="Content/**/*.*" Exclude="**/*.fx; Content/Content-Goes-Here.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </Content>
</ItemGroup> </ItemGroup>
<!-- Include the CompiledContent bin (MGCB output). Copy it to the Content folder in the build. --> <!-- Include the CompiledContent bin (MGCB output). Copy it to the Content folder in the build. -->
<ItemGroup> <ItemGroup>
<Content Include="CompiledContent/bin/DesktopGL/**/*.xnb"> <Content Include="CompiledContent/bin/DesktopGL/**/*.xnb">
@ -50,20 +50,21 @@
<None Remove="CompiledContent\bin\**"/> <None Remove="CompiledContent\bin\**"/>
<None Remove="CompiledContent\.*"/> <None Remove="CompiledContent\.*"/>
</ItemGroup> </ItemGroup>
<!-- MonoGames content pipeline needs this defined --> <!-- optional: MonoGame's content pipeline needs this defined
<ItemGroup> <ItemGroup>
<MonoGameContentReference Include="CompiledContent\Content.mgcb"/> <MonoGameContentReference Include="CompiledContent\Content.mgcb"/>
</ItemGroup> </ItemGroup>
<Import Project="../MonoGameContent.targets"/> <Import Project="../MonoGameContent.targets"/>
-->
<PropertyGroup> <PropertyGroup>
<IsOSX Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::OSX)))' == 'true'">true</IsOSX> <IsOSX Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::OSX)))' == 'true'">true</IsOSX>
<IsLinux Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Linux)))' == 'true'">true</IsLinux> <IsLinux Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Linux)))' == 'true'">true</IsLinux>
</PropertyGroup> </PropertyGroup>
<!-- Copy fnalib directories to output --> <!-- Copy fnalib directories to output -->
<ItemGroup> <ItemGroup>
<Content Include="..\fnalibs\x86\**\*.*" Visible="false" Condition="'$(OS)' == 'Windows_NT' AND '$(Platform)' != 'x64'"> <Content Include="..\fnalibs\x86\**\*.*" Visible="false" Condition="'$(OS)' == 'Windows_NT' AND '$(Platform)' != 'x64'">