initial commit

main
cosmonaut 2020-08-03 17:55:59 -07:00
commit 5b12720f77
17 changed files with 1181 additions and 0 deletions

353
.gitignore vendored Normal file
View File

@ -0,0 +1,353 @@
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
##
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
fnalibs/
# User-specific files
*.rsuser
*.suo
*.user
*.userosscache
*.sln.docstates
# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
# Mono auto generated files
mono_crash.*
# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
[Aa][Rr][Mm]/
[Aa][Rr][Mm]64/
bld/
[Bb]in/
[Oo]bj/
[Ll]og/
[Ll]ogs/
# Visual Studio 2015/2017 cache/options directory
.vs/
# Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/
# Visual Studio 2017 auto generated files
Generated\ Files/
# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
# NUnit
*.VisualState.xml
TestResult.xml
nunit-*.xml
# Build Results of an ATL Project
[Dd]ebugPS/
[Rr]eleasePS/
dlldata.c
# Benchmark Results
BenchmarkDotNet.Artifacts/
# .NET Core
project.lock.json
project.fragment.lock.json
artifacts/
# StyleCop
StyleCopReport.xml
# Files built by Visual Studio
*_i.c
*_p.c
*_h.h
*.ilk
*.meta
*.obj
*.iobj
*.pch
*.pdb
*.ipdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*_wpftmp.csproj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.svclog
*.scc
# Chutzpah Test files
_Chutzpah*
# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opendb
*.opensdf
*.sdf
*.cachefile
*.VC.db
*.VC.VC.opendb
# Visual Studio profiler
*.psess
*.vsp
*.vspx
*.sap
# Visual Studio Trace Files
*.e2e
# TFS 2012 Local Workspace
$tf/
# Guidance Automation Toolkit
*.gpState
# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user
# TeamCity is a build add-in
_TeamCity*
# DotCover is a Code Coverage Tool
*.dotCover
# AxoCover is a Code Coverage Tool
.axoCover/*
!.axoCover/settings.json
# Coverlet is a free, cross platform Code Coverage Tool
coverage*[.json, .xml, .info]
# Visual Studio code coverage results
*.coverage
*.coveragexml
# NCrunch
_NCrunch_*
.*crunch*.local.xml
nCrunchTemp_*
# MightyMoose
*.mm.*
AutoTest.Net/
# Web workbench (sass)
.sass-cache/
# Installshield output folder
[Ee]xpress/
# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html
# Click-Once directory
publish/
# Publish Web Output
*.[Pp]ublish.xml
*.azurePubxml
# Note: Comment the next line if you want to checkin your web deploy settings,
# but database connection strings (with potential passwords) will be unencrypted
*.pubxml
*.publishproj
# Microsoft Azure Web App publish settings. Comment the next line if you want to
# checkin your Azure Web App publish settings, but sensitive information contained
# in these scripts will be unencrypted
PublishScripts/
# NuGet Packages
*.nupkg
# NuGet Symbol Packages
*.snupkg
# The packages folder can be ignored because of Package Restore
**/[Pp]ackages/*
# except build/, which is used as an MSBuild target.
!**/[Pp]ackages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/[Pp]ackages/repositories.config
# NuGet v3's project.json files produces more ignorable files
*.nuget.props
*.nuget.targets
# Microsoft Azure Build Output
csx/
*.build.csdef
# Microsoft Azure Emulator
ecf/
rcf/
# Windows Store app package directories and files
AppPackages/
BundleArtifacts/
Package.StoreAssociation.xml
_pkginfo.txt
*.appx
*.appxbundle
*.appxupload
# Visual Studio cache files
# files ending in .cache can be ignored
*.[Cc]ache
# but keep track of directories ending in .cache
!?*.[Cc]ache/
# Others
ClientBin/
~$*
*~
*.dbmdl
*.dbproj.schemaview
*.jfm
*.pfx
*.publishsettings
orleans.codegen.cs
# Including strong name files can present a security risk
# (https://github.com/github/gitignore/pull/2483#issue-259490424)
#*.snk
# Since there are multiple workflows, uncomment next line to ignore bower_components
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
#bower_components/
# RIA/Silverlight projects
Generated_Code/
# Backup & report files from converting an old project file
# to a newer Visual Studio version. Backup files are not needed,
# because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm
ServiceFabricBackup/
*.rptproj.bak
# SQL Server files
*.mdf
*.ldf
*.ndf
# Business Intelligence projects
*.rdl.data
*.bim.layout
*.bim_*.settings
*.rptproj.rsuser
*- [Bb]ackup.rdl
*- [Bb]ackup ([0-9]).rdl
*- [Bb]ackup ([0-9][0-9]).rdl
# Microsoft Fakes
FakesAssemblies/
# GhostDoc plugin setting file
*.GhostDoc.xml
# Node.js Tools for Visual Studio
.ntvs_analysis.dat
node_modules/
# Visual Studio 6 build log
*.plg
# Visual Studio 6 workspace options file
*.opt
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
*.vbw
# Visual Studio LightSwitch build output
**/*.HTMLClient/GeneratedArtifacts
**/*.DesktopClient/GeneratedArtifacts
**/*.DesktopClient/ModelManifest.xml
**/*.Server/GeneratedArtifacts
**/*.Server/ModelManifest.xml
_Pvt_Extensions
# Paket dependency manager
.paket/paket.exe
paket-files/
# FAKE - F# Make
.fake/
# CodeRush personal settings
.cr/personal
# Python Tools for Visual Studio (PTVS)
__pycache__/
*.pyc
# Cake - Uncomment if you are using it
# tools/**
# !tools/packages.config
# Tabs Studio
*.tss
# Telerik's JustMock configuration file
*.jmconfig
# BizTalk build output
*.btp.cs
*.btm.cs
*.odx.cs
*.xsd.cs
# OpenCover UI analysis results
OpenCover/
# Azure Stream Analytics local run output
ASALocalRun/
# MSBuild Binary and Structured Log
*.binlog
# NVidia Nsight GPU debugger configuration file
*.nvuser
# MFractors (Xamarin productivity tool) working folder
.mfractor/
# Local History for Visual Studio
.localhistory/
# BeatPulse healthcheck temp database
healthchecksdb
# Backup folder for Package Reference Convert tool in Visual Studio 2017
MigrationBackup/
# Ionide (cross platform F# VS Code tools) working folder
.ionide/

6
.gitmodules vendored Normal file
View File

@ -0,0 +1,6 @@
[submodule "FNA"]
path = FNA
url = https://github.com/FNA-XNA/FNA.git
[submodule "Smuggler"]
path = Smuggler
url = https://gitea.moonside.games/MoonsideGames/Smuggler.git

20
.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,20 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Attach to Core Debugger",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "Build: Core Debug",
"program": "${workspaceFolder}/PreShaderTest/bin/Debug/netcoreapp3.1/PreShaderTest.dll",
"args": [],
"env": {
"LD_LIBRARY_PATH": "${workspaceFolder}/PreShaderTest/bin/Debug/netcoreapp3.1/lib64",
"DYLD_LIBRARY_PATH": "${workspaceFolder}/PreShaderTest/bin/Debug/netcoreapp3.1/osx"
},
"cwd": "${workspaceFolder}",
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen"
}
]
}

224
.vscode/tasks.json vendored Normal file
View File

@ -0,0 +1,224 @@
{
"version": "2.0.0",
"options": {
"cwd": "${workspaceRoot}"
},
"windows": {
"options": {
"shell": {
"executable": "cmd.exe",
"args": [
"/d",
"/c"
]
}
}
},
"presentation": {
"reveal": "always",
"focus": true,
"panel": "shared"
},
"tasks": [
{
"label": "Build: Framework Release",
"command": "msbuild",
"args": [
"-restore:True",
"${workspaceFolder}/PreShaderTest.Framework.sln",
"-p:Configuration=Release"
],
"type": "shell",
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": "$msCompile"
},
{
"label": "Run: Framework Release",
"command": "mono",
"args": [
"PreShaderTest.exe"
],
"options": {
"env": {
"LD_LIBRARY_PATH": "./lib64",
"DYLD_LIBRARY_PATH": "./osx"
},
"cwd": "${workspaceFolder}/PreShaderTest/bin/Release/net461"
},
"type": "process",
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": []
},
{
"label": "Build & Run: Framework Release",
"dependsOn": [
"Build: Framework Release",
"Run: Framework Release"
],
"dependsOrder": "sequence",
"type": "shell",
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": []
},
{
"label": "Build: Framework Debug",
"command": "msbuild",
"args": [
"-restore:True",
"${workspaceFolder}/PreShaderTest.Framework.sln",
"-p:Configuration=Debug"
],
"type": "shell",
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": []
},
{
"label": "Run: Framework Debug",
"command": "mono",
"args": [
"PreShaderTest.exe"
],
"options": {
"env": {
"LD_LIBRARY_PATH": "./lib64",
"DYLD_LIBRARY_PATH": "./osx"
},
"cwd": "${workspaceFolder}/PreShaderTest/bin/Debug/net461"
},
"type": "process",
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": []
},
{
"label": "Build & Run: Framework Debug",
"dependsOn": [
"Build: Framework Debug",
"Run: Framework Debug"
],
"dependsOrder": "sequence",
"type": "shell",
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": []
},
{
"label": "Build & Run: Core Debug",
"type": "shell",
"dependsOrder": "sequence",
"dependsOn": [
"Build: Core Debug",
"Run: Core Debug"
],
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": []
},
{
"label": "Build: Core Debug",
"command": "dotnet",
"args": [
"build",
"./PreShaderTest.Core.sln",
"-f",
"netcoreapp3.1"
],
"type": "shell",
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": []
},
{
"label": "Run: Core Debug",
"command": "dotnet",
"args": [
"./PreShaderTest.dll"
],
"options": {
"env": {
"LD_LIBRARY_PATH": "./lib64",
"DYLD_LIBRARY_PATH": "./osx"
},
"cwd": "${workspaceFolder}/PreShaderTest/bin/Debug/netcoreapp3.1"
},
"type": "process",
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": []
},
{
"label": "Build: Core Release",
"command": "dotnet",
"args": [
"build",
"./PreShaderTest.Core.sln",
"--configuration",
"Release",
"-f",
"netcoreapp3.1"
],
"type": "shell",
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": []
},
{
"label": "Run: Core Release",
"command": "dotnet",
"args": [
"./PreShaderTest.dll"
],
"options": {
"env": {
"LD_LIBRARY_PATH": "./lib64",
"DYLD_LIBRARY_PATH": "./osx"
},
"cwd": "${workspaceFolder}/PreShaderTest/bin/Release/netcoreapp3.1"
},
"type": "process",
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": []
},
{
"label": "Build & Run: Core Release",
"dependsOrder": "sequence",
"dependsOn": [
"Build: Core Release",
"Run: Core Release"
],
"type": "shell",
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": []
}
]
}

1
FNA Submodule

@ -0,0 +1 @@
Subproject commit 65eac75144771ba2d5b0e8df6628b3f3ce5ea261

6
FNA.Settings.props Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<DefineConstants>$(DefineConstants)</DefineConstants>
</PropertyGroup>
</Project>

34
PreShaderTest.Core.sln Normal file
View File

@ -0,0 +1,34 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26124.0
MinimumVisualStudioVersion = 15.0.26124.0
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PreShaderTest.Core", "PreShaderTest\PreShaderTest.Core.csproj", "{4589302C-174A-4173-9654-CAA6CA1B5220}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{4589302C-174A-4173-9654-CAA6CA1B5220}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4589302C-174A-4173-9654-CAA6CA1B5220}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4589302C-174A-4173-9654-CAA6CA1B5220}.Debug|x64.ActiveCfg = Debug|Any CPU
{4589302C-174A-4173-9654-CAA6CA1B5220}.Debug|x64.Build.0 = Debug|Any CPU
{4589302C-174A-4173-9654-CAA6CA1B5220}.Debug|x86.ActiveCfg = Debug|Any CPU
{4589302C-174A-4173-9654-CAA6CA1B5220}.Debug|x86.Build.0 = Debug|Any CPU
{4589302C-174A-4173-9654-CAA6CA1B5220}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4589302C-174A-4173-9654-CAA6CA1B5220}.Release|Any CPU.Build.0 = Release|Any CPU
{4589302C-174A-4173-9654-CAA6CA1B5220}.Release|x64.ActiveCfg = Release|Any CPU
{4589302C-174A-4173-9654-CAA6CA1B5220}.Release|x64.Build.0 = Release|Any CPU
{4589302C-174A-4173-9654-CAA6CA1B5220}.Release|x86.ActiveCfg = Release|Any CPU
{4589302C-174A-4173-9654-CAA6CA1B5220}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,34 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26124.0
MinimumVisualStudioVersion = 15.0.26124.0
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FNATemplate.Framework", "PreShaderTest\PreShaderTest.Framework.csproj", "{9ED076FA-32C3-4F1E-BB90-549B3A2FA46F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{9ED076FA-32C3-4F1E-BB90-549B3A2FA46F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9ED076FA-32C3-4F1E-BB90-549B3A2FA46F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9ED076FA-32C3-4F1E-BB90-549B3A2FA46F}.Debug|x64.ActiveCfg = Debug|Any CPU
{9ED076FA-32C3-4F1E-BB90-549B3A2FA46F}.Debug|x64.Build.0 = Debug|Any CPU
{9ED076FA-32C3-4F1E-BB90-549B3A2FA46F}.Debug|x86.ActiveCfg = Debug|Any CPU
{9ED076FA-32C3-4F1E-BB90-549B3A2FA46F}.Debug|x86.Build.0 = Debug|Any CPU
{9ED076FA-32C3-4F1E-BB90-549B3A2FA46F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9ED076FA-32C3-4F1E-BB90-549B3A2FA46F}.Release|Any CPU.Build.0 = Release|Any CPU
{9ED076FA-32C3-4F1E-BB90-549B3A2FA46F}.Release|x64.ActiveCfg = Release|Any CPU
{9ED076FA-32C3-4F1E-BB90-549B3A2FA46F}.Release|x64.Build.0 = Release|Any CPU
{9ED076FA-32C3-4F1E-BB90-549B3A2FA46F}.Release|x86.ActiveCfg = Release|Any CPU
{9ED076FA-32C3-4F1E-BB90-549B3A2FA46F}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal

View File

@ -0,0 +1 @@
Insert your content files here (sprites, sound, etc)

259
PreShaderTest/DllMap.cs Normal file
View File

@ -0,0 +1,259 @@
// only works in .NET Core. disable in .NET framework
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Xml.Linq;
public static class DllMap
{
[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)]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool SetDllDirectory(string lpPathName);
const int LOAD_LIBRARY_SEARCH_DEFAULT_DIRS = 0x00001000;
public static Dictionary<string, string> MapDictionary;
public static string OS;
public static string CPU;
public static bool Optimise;
public static void Initialise(bool optimise = true)
{
Optimise = optimise;
// Our executabe needs to know how to find the native libraries
// For Windows, we can set this to be x86 or x64 directory at runtime (below)
// For Linux we need to move our native libraries to 'netcoredeps' which is set by .net core
// For OSX we need to set an environment variable (DYLD_LIBRARY_PATH) outside of the process by a script
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"
));
}
}
// .NET Core also doesn't use DllImport but we can replicate this using NativeLibrary as per below
// Uses FNA.dll.config to dictate what the name of the native library is per platform and architecture
var fnaAssembly = Assembly.GetAssembly(typeof(Microsoft.Xna.Framework.Graphics.ColorWriteChannels));
DllMap.Register(fnaAssembly);
}
// Register a call-back for native library resolution.
public static void Register(Assembly assembly)
{
NativeLibrary.SetDllImportResolver(assembly, MapAndLoad);
// Do setup so that MapLibraryName is faster than reading the XML each time
// 1) Get platform & cpu
OS = GetCurrentPlatform().ToString().ToLowerInvariant();
CPU = GetCurrentRuntimeArchitecture().ToString().ToLowerInvariant();
// 2) Setup MapDictionary
// For Windows use hardcoded values
// Why? This is our development platform and we wanted the fastest start time possible (eliminates XML Load)
if (OS == "windows" && Optimise)
{
MapDictionary = new Dictionary<string, string>();
MapDictionary.Add("SDL2", "SDL2.dll");
MapDictionary.Add("SDL_image", "SDL_image.dll");
MapDictionary.Add("FAudio", "FAudio.dll");
}
else
{
// For every other platform use XML file
// Read in config XML and only store details we're interested in within MapDictionary
string xmlPath = Path.Combine(Path.GetDirectoryName(assembly.Location),
Path.GetFileNameWithoutExtension(assembly.Location) + ".dll.config");
if (!File.Exists(xmlPath))
{
Console.WriteLine($"=== Cannot find XML: " + xmlPath);
return;
}
XElement root = XElement.Load(xmlPath);
MapDictionary = new Dictionary<string, string>();
ParseXml(root, true); // Direct match on OS & CPU first
ParseXml(root, false); // Loose match on CPU second (won't allow duplicates)
}
}
private static void ParseXml(XElement root, bool matchCPU)
{
foreach (var el in root.Elements("dllmap"))
{
// Ignore entries for other OSs
if (el.Attribute("os").ToString().IndexOf(OS) < 0)
continue;
// Ignore entries for other CPUs
if (matchCPU)
{
if (el.Attribute("cpu") == null)
continue;
if (el.Attribute("cpu").ToString().IndexOf(CPU) < 0)
continue;
}
else
{
if (el.Attribute("cpu") != null && el.Attribute("cpu").ToString().IndexOf(CPU) < 0)
continue;
}
string oldLib = el.Attribute("dll").Value;
string newLib = el.Attribute("target").Value;
if (string.IsNullOrWhiteSpace(oldLib) || string.IsNullOrWhiteSpace(newLib))
continue;
// Don't allow duplicates
if (MapDictionary.ContainsKey(oldLib))
continue;
MapDictionary.Add(oldLib, newLib);
}
}
// The callback: which loads the mapped libray in place of the original
private static IntPtr MapAndLoad(string libraryName, Assembly assembly, DllImportSearchPath? dllImportSearchPath)
{
string mappedName = null;
mappedName = MapLibraryName(assembly.Location, libraryName, out mappedName) ? mappedName : libraryName;
return NativeLibrary.Load(mappedName, assembly, dllImportSearchPath);
}
// Parse the assembly.xml file, and map the old name to the new name of a library.
private static bool MapLibraryName(string assemblyLocation, string originalLibName, out string mappedLibName)
{
if (MapDictionary.TryGetValue(originalLibName, out mappedLibName))
return true;
else
return false;
}
// Below pinched from Mono.DllMap project: https://github.com/Firwood-Software/AdvancedDLSupport/tree/1b7394211a655b2f77649ce3b610a3161215cbdc/Mono.DllMap
public static DllMapOS GetCurrentPlatform()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
return DllMapOS.Linux;
}
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
return DllMapOS.Windows;
}
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
return DllMapOS.OSX;
}
var operatingDesc = RuntimeInformation.OSDescription.ToUpperInvariant();
foreach (var system in Enum.GetValues(typeof(DllMapOS)).Cast<DllMapOS>()
.Except(new[] { DllMapOS.Linux, DllMapOS.Windows, DllMapOS.OSX }))
{
if (operatingDesc.Contains(system.ToString().ToUpperInvariant()))
{
return system;
}
}
throw new PlatformNotSupportedException($"Couldn't detect platform: {RuntimeInformation.OSDescription}");
}
public static DllMapArchitecture GetCurrentRuntimeArchitecture()
{
switch (RuntimeInformation.ProcessArchitecture)
{
case Architecture.Arm:
{
return DllMapArchitecture.ARM;
}
case Architecture.X64:
{
return DllMapArchitecture.x86_64;
}
case Architecture.X86:
{
return DllMapArchitecture.x86;
}
}
typeof(object).Module.GetPEKind(out _, out var machine);
switch (machine)
{
case ImageFileMachine.I386:
{
return DllMapArchitecture.x86;
}
case ImageFileMachine.AMD64:
{
return DllMapArchitecture.x86_64;
}
case ImageFileMachine.ARM:
{
return DllMapArchitecture.ARM;
}
case ImageFileMachine.IA64:
{
return DllMapArchitecture.IA64;
}
}
throw new PlatformNotSupportedException("Couldn't detect the current architecture.");
}
public enum DllMapOS
{
Linux = 1 << 0,
OSX = 1 << 1,
Solaris = 1 << 2,
FreeBSD = 1 << 3,
OpenBSD = 1 << 4,
NetBSD = 1 << 5,
Windows = 1 << 6,
AIX = 1 << 7,
HPUX = 1 << 8
}
public enum DllMapArchitecture
{
x86 = 1 << 0,
x86_64 = 1 << 1,
SPARC = 1 << 2,
PPC = 1 << 3,
S390 = 1 << 4,
S390X = 1 << 5,
ARM = 1 << 6,
ARMV8 = 1 << 7,
MIPS = 1 << 8,
Alpha = 1 << 9,
HPPA = 1 << 10,
IA64 = 1 << 11
}
}

View File

@ -0,0 +1,30 @@
<Project>
<PropertyGroup>
<BaseIntermediateOutputPath>obj\$(MSBuildPreShaderTest)</BaseIntermediateOutputPath>
</PropertyGroup>
<Import Sdk="Microsoft.NET.Sdk" Project="Sdk.props" />
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetName>PreShaderTest</TargetName>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<GenerateTargetFrameworkAttribute>false</GenerateTargetFrameworkAttribute>
<LangVersion>8.0</LangVersion>
<StartupObject>PreShaderTest.Program</StartupObject>
<AssemblyName>PreShaderTest</AssemblyName>
<RootNamespace>PreShaderTest</RootNamespace>
<TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>
<RuntimeIdentifiers>win-x64;osx-x64;linux-x64</RuntimeIdentifiers>
<ApplicationIcon/>
</PropertyGroup>
<ItemGroup>
<Content Include="Content\**\*.*">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\FNA\FNA.Core.csproj"/>
</ItemGroup>
<Import Project="..\build\CopyFNALibs.targets"/>
<Import Sdk="Microsoft.NET.Sdk" Project="Sdk.targets" />
</Project>

View File

@ -0,0 +1,34 @@
<Project>
<PropertyGroup>
<BaseIntermediateOutputPath>obj\$(MSBuildPreShaderTest)</BaseIntermediateOutputPath>
</PropertyGroup>
<Import Sdk="Microsoft.NET.Sdk" Project="Sdk.props" />
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net461</TargetFramework>
<TargetName>PreShaderTest</TargetName>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<GenerateTargetFrameworkAttribute>false</GenerateTargetFrameworkAttribute>
<LangVersion>8.0</LangVersion>
<StartupObject>PreShaderTest.Program</StartupObject>
<AssemblyName>PreShaderTest</AssemblyName>
<RootNamespace>PreShaderTest</RootNamespace>
<TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>
<RuntimeIdentifiers>win-x64;osx-x64;linux-x64</RuntimeIdentifiers>
<ApplicationIcon/>
</PropertyGroup>
<PropertyGroup>
<DefaultItemExcludes>$(DefaultItemExcludes);DllMap.cs</DefaultItemExcludes>
</PropertyGroup>
<ItemGroup>
<Content Include="Content\**\*.*">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\FNA\FNA.csproj"/>
<ProjectReference Include="..\Smuggler\Smuggler.csproj" />
</ItemGroup>
<Import Project="..\build\CopyFNALibs.targets"/>
<Import Sdk="Microsoft.NET.Sdk" Project="Sdk.targets" />
</Project>

View File

@ -0,0 +1,70 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
namespace PreShaderTest
{
class PreShaderTestGame : Game
{
GraphicsDeviceManager graphics;
VertexBuffer vertexBuffer;
Effect pbrEffect;
public PreShaderTestGame()
{
graphics = new GraphicsDeviceManager(this);
graphics.PreferredBackBufferWidth = 1280;
graphics.PreferredBackBufferHeight = 720;
graphics.PreferMultiSampling = true;
Content.RootDirectory = "Content";
Window.AllowUserResizing = true;
IsMouseVisible = true;
}
protected override void LoadContent()
{
vertexBuffer = new VertexBuffer(GraphicsDevice, typeof(VertexPositionNormalTexture), 1, BufferUsage.None);
vertexBuffer.SetData(new VertexPositionNormalTexture[] {
new VertexPositionNormalTexture(
new Vector3(0, 1, 1),
new Vector3(0, 1, 1),
new Vector2(0, 1)
)
});
pbrEffect = new Smuggler.PBREffect(GraphicsDevice);
}
protected override void UnloadContent()
{
base.UnloadContent();
}
protected override void Update(GameTime gameTime)
{
//
// Insert your game update logic here.
//
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
//
// Replace this with your own drawing code.
//
GraphicsDevice.Clear(Color.CornflowerBlue);
pbrEffect.Techniques[0].Passes[0].Apply();
GraphicsDevice.SetVertexBuffer(vertexBuffer);
GraphicsDevice.DrawPrimitives(PrimitiveType.PointListEXT, 0, 1);
base.Draw(gameTime);
}
}
}

47
PreShaderTest/Program.cs Normal file
View File

@ -0,0 +1,47 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;
namespace PreShaderTest
{
class Program
{
[DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool SetDllDirectory(string lpPathName);
static void Main(string[] args)
{
#if NETCOREAPP
DllMap.Initialise(false);
#endif
// https://github.com/FNA-XNA/FNA/wiki/4:-FNA-and-Windows-API#64-bit-support
if (Environment.OSVersion.Platform == PlatformID.Win32NT)
{
SetDllDirectory(Path.Combine(
AppDomain.CurrentDomain.BaseDirectory,
Environment.Is64BitProcess ? "x64" : "x86"
));
}
// https://github.com/FNA-XNA/FNA/wiki/7:-FNA-Environment-Variables#fna_graphics_enable_highdpi
// NOTE: from documentation:
// Lastly, when packaging for macOS, be sure this is in your app bundle's Info.plist:
// <key>NSHighResolutionCapable</key>
// <string>True</string>
Environment.SetEnvironmentVariable("FNA_GRAPHICS_ENABLE_HIGHDPI", "1");
using (PreShaderTestGame game = new PreShaderTestGame())
{
bool isHighDPI = Environment.GetEnvironmentVariable("FNA_GRAPHICS_ENABLE_HIGHDPI") == "1";
if (isHighDPI)
Debug.WriteLine("HiDPI Enabled");
game.Run();
}
}
}
}

38
README.md Normal file
View File

@ -0,0 +1,38 @@
# FNA-VSCode-Template
Template and build tasks for developing a cross-platform multi-target .NET Framework and .NET Core FNA project in VSCode.
## Features
- Includes project boilerplate code
- Build tasks for both .NET Framework and .NET Core side by side
- Press F5 to build and debug in-editor with Core Debugger
## Requirements
- [Git](https://git-scm.com/)
- [Git for Windows](https://gitforwindows.org/) if on Windows
- [Visual Studio Code](https://code.visualstudio.com/)
- [VSCode C# Extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode.csharp)
- [.NET Core SDK](https://dotnet.microsoft.com/download/dotnet-core)
- [.NET Framework SDK](https://dotnet.microsoft.com/download/visual-studio-sdks) or [Mono](https://www.mono-project.com/)
## Installation
- Make sure you have Git Bash from Git for Windows if you are on Windows
- Download this repository
- Run `install.sh`
- Move the newly created project directory wherever you want
## Usage
- Open the project directory in VSCode
- Press Ctrl-Shift-B to open the build tasks menu
- `Framework` tasks use .NET Framework or Mono to build and run
- `Core` tasks use .NET Core to build and run
- Press F5 to build and debug with Core Debugger
## Acknowledgments
Thanks to Andrew Russell and Caleb Cornett's FNA templates for a starting point for this template.

1
Smuggler Submodule

@ -0,0 +1 @@
Subproject commit 9aabffa8d76ffe36eec0a71410ee19f7a6cbea02

23
build/CopyFNALibs.targets Normal file
View File

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Content Include="..\fnalibs\x86\**\*.*" Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Windows)))' == 'true' AND '$(Platform)' != 'x64'">
<Link>%(RecursiveDir)%(Filename)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="..\fnalibs\x64\**\*.*" Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Windows)))' == 'true' AND '$(Platform)' != 'x86'">
<Link>%(RecursiveDir)%(Filename)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="..\fnalibs\osx\**\*.*" Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::OSX)))' == 'true'" >
<Link>osx\%(RecursiveDir)%(Filename)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="..\fnalibs\lib64\**\*.*" Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Linux)))' == 'true'" >
<Link>lib64\%(RecursiveDir)%(Filename)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
</Project>