diff --git a/.vscode/launch.json b/.vscode/launch.json index b26c771..3ad1268 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -4,7 +4,23 @@ "version": "0.2.0", "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)", "type": "mono", @@ -18,7 +34,7 @@ } } }, - + { "name": "Launch Without Building (Mac)", "type": "mono", @@ -40,7 +56,7 @@ "cwd": "${workspaceFolder}/project_name", "preLaunchTask": "Build (Debug)" }, - + { "name": "Launch Without Building (Windows)", "type": "clr", @@ -57,4 +73,4 @@ "port": 55555 } ] -} \ No newline at end of file +} diff --git a/.vscode/tasks.json b/.vscode/tasks.json index a4d7ee1..e08f5ab 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -1,6 +1,19 @@ { "version": "2.0.0", "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", "type": "shell", @@ -8,7 +21,7 @@ "group": "build", "problemMatcher": "$msCompile" }, - + { // this does a bunch of stuff: // - update submodules to lastest (fetch latest Nez version) @@ -117,7 +130,7 @@ }, "problemMatcher": "$msCompile" }, - + { "label": "Build Content", "type": "shell", @@ -136,8 +149,8 @@ "osx": { "command": "mono /Applications/Pipeline.app/Contents/MonoBundle/MGCB.exe /@:Content.mgcb -r", }, - "windows": { - "command":"C:/Program Files (x86)/MSBuild/MonoGame/v3.0/Tools/MGCB.exe", + "windows": { + "command":"C:/Program Files (x86)/MSBuild/MonoGame/v3.0/Tools/MGCB.exe", "args": [ "/@:Content.mgcb", "-r" @@ -161,7 +174,7 @@ }, "problemMatcher": "$msCompile" }, - + { "label": "Process T4 Templates", "type": "shell", @@ -170,9 +183,9 @@ }, "windows": { "command": "powershell", - "args": [ + "args": [ "-File", - "${workspaceFolder}/.vscode/processT4Templates.ps1" + "${workspaceFolder}/.vscode/processT4Templates.ps1" ] }, "group": "build", diff --git a/project_name/Game1.cs b/project_name/Game1.cs index 84800cf..e869d46 100755 --- a/project_name/Game1.cs +++ b/project_name/Game1.cs @@ -1,32 +1,35 @@ +using System; +using System.Reflection; +using System.Runtime.InteropServices; using Nez; using Nez.ImGuiTools; namespace project_name { - class Game1 : Core - { - public Game1() : base() - { + class Game1 : Core + { + public Game1() : base() + { // uncomment this line for scaled pixel art games // System.Environment.SetEnvironmentVariable("FNA_OPENGL_BACKBUFFER_SCALE_NEAREST", "1"); - } + } - override protected void Initialize() - { - base.Initialize(); + override protected void Initialize() + { + base.Initialize(); - Scene = new DefaultScene(); + Scene = new DefaultScene(); #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(); Core.RegisterGlobalManager(imGuiManager); // 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") #endif - } - } + } + } } diff --git a/project_name/Program.cs b/project_name/Program.cs index 436f461..47cdc97 100644 --- a/project_name/Program.cs +++ b/project_name/Program.cs @@ -1,51 +1,82 @@ using System; using System.IO; +using System.Reflection; using System.Runtime.InteropServices; -using Microsoft.Xna.Framework; namespace project_name { - class Program - { - [DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)] - [return: MarshalAs(UnmanagedType.Bool)] - static extern bool SetDefaultDllDirectories(int directoryFlags); + class Program + { + [DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)] + [return: MarshalAs(UnmanagedType.Bool)] + static extern bool SetDefaultDllDirectories(int directoryFlags); - [DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)] - static extern void AddDllDirectory(string lpPathName); + [DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)] + static extern void AddDllDirectory(string lpPathName); - [DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)] - [return: MarshalAs(UnmanagedType.Bool)] - static extern bool SetDllDirectory(string lpPathName); + [DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)] + [return: MarshalAs(UnmanagedType.Bool)] + 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) - { - if (Environment.OSVersion.Platform == PlatformID.Win32NT) + public static void Main(string[] args) + { + 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 - { - 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: {libraryName} ---------"); } - - using (Game1 game = new Game1()) - { - game.Run(); - } - } - } -} \ No newline at end of file + Console.WriteLine($"----- no case for library load: {libHandle} ---------"); + return libHandle; + } + } +} diff --git a/project_name/project_name.csproj b/project_name/project_name.csproj index 9699cfa..8016f5f 100644 --- a/project_name/project_name.csproj +++ b/project_name/project_name.csproj @@ -2,7 +2,7 @@ Exe - net471 + netcoreapp3.1 false AnyCPU project_name @@ -10,16 +10,16 @@ True false - + - - + + - + @@ -31,14 +31,14 @@ PreserveNewest - + PreserveNewest - + @@ -50,20 +50,21 @@ - - + + + + true true - +