Updated Template for new dotnet runtime

- Added Submodule 'Xml-Beef'
- Use .slnx as solution-file
- Automatically set correct path to ScriptCore in Project files
This commit is contained in:
Simon Lübeß
2025-08-09 01:13:05 +02:00
parent 52cbf9dcf4
commit ac0f4dade6
20 changed files with 243 additions and 162 deletions
+3
View File
@@ -37,3 +37,6 @@
[submodule "vendor/NetHostBeef"] [submodule "vendor/NetHostBeef"]
path = vendor/NetHostBeef path = vendor/NetHostBeef
url = https://github.com/aharabada/NetHostBeef.git url = https://github.com/aharabada/NetHostBeef.git
[submodule "GlitchyEngine/vendor/Xml-Beef"]
path = GlitchyEngine/vendor/Xml-Beef
url = https://github.com/aharabada/Xml-Beef.git
+2 -2
View File
@@ -1,7 +1,7 @@
FileVersion = 1 FileVersion = 1
Projects = {GlitchyEngine = {Path = "GlitchyEngine"}, GlitchLog = {Path = "GlitchLog"}, DirectX = {Path = "GlitchyEngine/vendor/directx/DirectX"}, LodePng = {Path = "vendor/lodepng-beef/lodepng-beef"}, FreeType = {Path = "GlitchyEngine/vendor/freetype"}, cgltf-beef = {Path = "GlitchyEngine/vendor/gltf/cgltf-beef"}, GlitchyEditor = {Path = "GlitchyEditor"}, msdfgen-beef = {Path = "GlitchyEngine/vendor/msdfgen/msdfgen-beef"}, ImGui = {Path = "GlitchyEngine/vendor/imgui/ImGui"}, ImGuiImplDX11 = {Path = "GlitchyEngine/vendor/imgui/ImGuiImplDX11"}, ImGuiImplWin32 = {Path = "GlitchyEngine/vendor/imgui/ImGuiImplWin32"}, ImGuizmo = {Path = "GlitchyEngine/vendor/imgui/ImGuizmo"}, GlitchyEngineHelper = {Path = "GlitchyEngineHelper"}, bon = {Path = "GlitchyEngine/vendor/bon"}, box2d-beef = {Path = "GlitchyEngine/vendor/box2D"}, "Beef.Linq" = {Path = "GlitchyEngine/vendor/Beef.Linq/src"}, ScriptCore = {Path = "ScriptCore"}, NetHostBeef = {Path = "GlitchyEngine/vendor/NetHostBeef/NetHostBeef"}} Projects = {GlitchyEngine = {Path = "GlitchyEngine"}, GlitchLog = {Path = "GlitchLog"}, DirectX = {Path = "GlitchyEngine/vendor/directx/DirectX"}, LodePng = {Path = "vendor/lodepng-beef/lodepng-beef"}, FreeType = {Path = "GlitchyEngine/vendor/freetype"}, cgltf-beef = {Path = "GlitchyEngine/vendor/gltf/cgltf-beef"}, GlitchyEditor = {Path = "GlitchyEditor"}, msdfgen-beef = {Path = "GlitchyEngine/vendor/msdfgen/msdfgen-beef"}, ImGui = {Path = "GlitchyEngine/vendor/imgui/ImGui"}, ImGuiImplDX11 = {Path = "GlitchyEngine/vendor/imgui/ImGuiImplDX11"}, ImGuiImplWin32 = {Path = "GlitchyEngine/vendor/imgui/ImGuiImplWin32"}, ImGuizmo = {Path = "GlitchyEngine/vendor/imgui/ImGuizmo"}, GlitchyEngineHelper = {Path = "GlitchyEngineHelper"}, bon = {Path = "GlitchyEngine/vendor/bon"}, box2d-beef = {Path = "GlitchyEngine/vendor/box2D"}, "Beef.Linq" = {Path = "GlitchyEngine/vendor/Beef.Linq/src"}, ScriptCore = {Path = "ScriptCore"}, NetHostBeef = {Path = "GlitchyEngine/vendor/NetHostBeef/NetHostBeef"}, "GlitchyEngine.Test" = {Path = "GlitchyEngine.Test"}, Xml-Beef = {Path = "GlitchyEngine/vendor/Xml-Beef"}}
Locked = ["ImGui"] Locked = ["ImGui"]
WorkspaceFolders = {GlitchyEngine = ["GlitchyEngine", "GlitchLog", "GlitchyEngineHelper", "ScriptCore"], "GlitchyEngine/Dependencies" = ["cgltf-beef", "DirectX", "FreeType", "ImGui", "ImGuiImplDX11", "ImGuiImplWin32", "ImGuizmo", "LodePng", "msdfgen-beef", "bon", "box2d-beef", "Beef.Linq", "NetHostBeef"], Beef = ["Beefy2D", "corlib", "MiniZ"]} WorkspaceFolders = {GlitchyEngine = ["GlitchyEngine", "GlitchLog", "GlitchyEngineHelper", "ScriptCore", "GlitchyEngine.Test"], "GlitchyEngine/Dependencies" = ["cgltf-beef", "DirectX", "FreeType", "ImGui", "ImGuiImplDX11", "ImGuiImplWin32", "ImGuizmo", "LodePng", "msdfgen-beef", "bon", "box2d-beef", "Beef.Linq", "NetHostBeef", "Xml-Beef"], Beef = ["Beefy2D", "corlib", "MiniZ"]}
[Workspace] [Workspace]
StartupProject = "GlitchyEditor" StartupProject = "GlitchyEditor"
+1 -1
View File
@@ -1,5 +1,5 @@
FileVersion = 1 FileVersion = 1
Dependencies = {corlib = "*", GlitchLog = "*", GlitchyEngine = "*"} Dependencies = {corlib = "*", GlitchLog = "*", GlitchyEngine = "*", Xml-Beef = "*"}
[Project] [Project]
Name = "GlitchyEditor" Name = "GlitchyEditor"
@@ -1,17 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RunManager" selected=".NET Launch Settings Profile.ScriptCoreGenerator: Debug Code Generator">
<configuration name="Attach to Glitchy Engine" type="ConnectRemote" factoryName="Mono Remote" show_console_on_std_err="false" show_console_on_std_out="false" port="2550" address="localhost">
<option name="allowRunningInParallel" value="false" />
<option name="listenPortForConnections" value="false" />
<option name="projectPathOnTarget" />
<option name="selectedOptions">
<list />
</option>
<method v="2" />
</configuration>
<list>
<item itemvalue="Mono Remote.Attach to Glitchy Engine" />
</list>
</component>
</project>
@@ -1,36 +0,0 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// Allgemeine Informationen über eine Assembly werden über die folgenden
// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern,
// die einer Assembly zugeordnet sind.
[assembly: AssemblyTitle("[ProjectName]")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("[ProjectName]")]
[assembly: AssemblyCopyright("Copyright © 2023")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Durch Festlegen von ComVisible auf FALSE werden die Typen in dieser Assembly
// für COM-Komponenten unsichtbar. Wenn Sie auf einen Typ in dieser Assembly von
// COM aus zugreifen müssen, sollten Sie das ComVisible-Attribut für diesen Typ auf "True" festlegen.
[assembly: ComVisible(false)]
// Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird
[assembly: Guid("7a70819c-5317-402a-8553-95c5a001e370")]
// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten:
//
// Hauptversion
// Nebenversion
// Buildnummer
// Revision
//
// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden,
// indem Sie "*" wie unten gezeigt eingeben:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
@@ -1,54 +1,19 @@
<?xml version="1.0" encoding="utf-8"?> <Project Sdk="Microsoft.NET.Sdk">
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup> <PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <!-- General configuration -->
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> <AssemblyTitle>[ProjectName]</AssemblyTitle>
<ProjectGuid>{7A70819C-5317-402A-8553-95C5A001E370}</ProjectGuid> <TargetFramework>net9.0</TargetFramework>
<OutputType>Library</OutputType> <OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder> <Nullable>enable</Nullable>
<RootNamespace>[ProjectName]</RootNamespace> <!-- Define the output path -->
<AssemblyName>[ProjectName]</AssemblyName> <AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion> <OutputPath>./.cache/bin/</OutputPath>
<FileAlignment>512</FileAlignment> <!-- Generates a runtimeconfig-file and copies nuget references to the output -->
<Deterministic>true</Deterministic> <EnableDynamicLoading>true</EnableDynamicLoading>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>portable</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<LangVersion>default</LangVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<LangVersion>default</LangVersion>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="ScriptCore, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL"> <Reference Include="ScriptCore" OutputItemType="Analyzer" ReferenceOutputAssembly="true">
<SpecificVersion>False</SpecificVersion> <HintPath>/ScriptCore.dll</HintPath>
<HintPath>[CoreLibPath]</HintPath>
</Reference> </Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<!-- Script Files -->
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project> </Project>
@@ -1,25 +0,0 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.4.33205.214
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "[ProjectName]", "[ProjectName].csproj", "{7A70819C-5317-402A-8553-95C5A001E370}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{7A70819C-5317-402A-8553-95C5A001E370}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7A70819C-5317-402A-8553-95C5A001E370}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7A70819C-5317-402A-8553-95C5A001E370}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7A70819C-5317-402A-8553-95C5A001E370}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {B5D43D8D-D80B-41AA-BE40-1DC507D87148}
EndGlobalSection
EndGlobal
@@ -0,0 +1,3 @@
<Solution>
<Project Path="[ProjectName].csproj" />
</Solution>
@@ -11,14 +11,14 @@ public class [EntityName] : Entity
/// <summary> /// <summary>
/// OnCreate is called once before the first call to OnUpdate. /// OnCreate is called once before the first call to OnUpdate.
/// </summary> /// </summary>
void OnCreate() protected override void OnCreate()
{ {
} }
/// <summary> /// <summary>
/// OnUpdate is called once every frame. /// OnUpdate is called once every frame.
/// </summary> /// </summary>
void OnUpdate(float deltaTime) protected override void OnUpdate(float deltaTime)
{ {
} }
} }
@@ -19,7 +19,7 @@ class RiderIdeAdapter : IIdeAdapter
public static void OpenScript(StringView fileName, int lineNumber) public static void OpenScript(StringView fileName, int lineNumber)
{ {
String solutionPath = scope .(); String solutionPath = scope .();
Editor.Instance.CurrentProject.PathInProject(solutionPath, scope $"{Editor.Instance.CurrentProject.Name}.sln"); Editor.Instance.CurrentProject.GetPathToScriptSolutionFile(solutionPath);
ProcessStartInfo startInfo = scope .(); ProcessStartInfo startInfo = scope .();
startInfo.SetFileName(Application.Instance.Settings.ScriptSettings.RiderPath); startInfo.SetFileName(Application.Instance.Settings.ScriptSettings.RiderPath);
@@ -31,7 +31,7 @@ class RiderIdeAdapter : IIdeAdapter
public static void OpenScriptProject() public static void OpenScriptProject()
{ {
String solutionPath = scope .(); String solutionPath = scope .();
Editor.Instance.CurrentProject.PathInProject(solutionPath, scope $"{Editor.Instance.CurrentProject.Name}.sln"); Editor.Instance.CurrentProject.GetPathToScriptSolutionFile(solutionPath);
if (!File.Exists(solutionPath)) if (!File.Exists(solutionPath))
{ {
@@ -54,7 +54,7 @@ class VisualStudioIdeAdapter : IIdeAdapter
public static void OpenScriptProject() public static void OpenScriptProject()
{ {
String solutionPath = scope .(); String solutionPath = scope .();
Editor.Instance.CurrentProject.PathInProject(solutionPath, scope $"{Editor.Instance.CurrentProject.Name}.sln"); Editor.Instance.CurrentProject.GetPathToScriptSolutionFile(solutionPath);
ProcessStartInfo psi = scope .(); ProcessStartInfo psi = scope .();
psi.SetFileName("devenv"); psi.SetFileName("devenv");
+141 -8
View File
@@ -2,6 +2,8 @@ using System;
using System.IO; using System.IO;
using Bon; using Bon;
using GlitchyEngine; using GlitchyEngine;
using GlitchyEngine.Scripting;
using Xml_Beef;
namespace GlitchyEditor; namespace GlitchyEditor;
@@ -60,6 +62,16 @@ class Project
target target
} }
public void GetPathToScriptSolutionFile(String outTarget)
{
PathInProject(outTarget, scope $"{Name}.slnx");
}
public void GetPathToScriptProjectFile(String outTarget)
{
PathInProject(outTarget, scope $"{Name}.csproj");
}
/// Loads or creates the user specific settings for this project. /// Loads or creates the user specific settings for this project.
private void InitUserSettings() private void InitUserSettings()
{ {
@@ -151,7 +163,6 @@ class Project
} }
const String ProjectNamePlaceholder = "[ProjectName]"; const String ProjectNamePlaceholder = "[ProjectName]";
const String CoreLibPathPlaceholder = "[CoreLibPath]";
/// Moves files so that [ProjectName] in their paths will be replaced by the actual project name /// Moves files so that [ProjectName] in their paths will be replaced by the actual project name
private static Result<void> RenameAndFixupFiles(StringView directoryPath, Project project) private static Result<void> RenameAndFixupFiles(StringView directoryPath, Project project)
@@ -199,17 +210,11 @@ class Project
return .Err; return .Err;
} }
if (!fileContent.Contains(ProjectNamePlaceholder) && !fileContent.Contains(CoreLibPathPlaceholder)) if (!fileContent.Contains(ProjectNamePlaceholder))
return .Ok; return .Ok;
fileContent.Replace(ProjectNamePlaceholder, project.Name); fileContent.Replace(ProjectNamePlaceholder, project.Name);
// TODO: This is pretty bad, we don't really want to hard code the script core path like that!
String scriptCorePath = scope .();
Directory.GetCurrentDirectory(scriptCorePath);
scriptCorePath.Append("/Resources/Scripts/ScriptCore.dll");
fileContent.Replace(CoreLibPathPlaceholder, scriptCorePath);
if (File.WriteAllText(filePath, fileContent, false) case .Err) if (File.WriteAllText(filePath, fileContent, false) case .Err)
{ {
Log.EngineLogger.Error($"FixupFile: Failed to write file {filePath}."); Log.EngineLogger.Error($"FixupFile: Failed to write file {filePath}.");
@@ -254,6 +259,134 @@ class Project
} }
} }
Try!(project.FixupScriptCorePath());
return project; return project;
} }
private Result<void> FixupScriptCorePath()
{
String csprojPath = scope .();
GetPathToScriptProjectFile(csprojPath);
if (!File.Exists(csprojPath))
{
Log.EngineLogger.Error(scope $"Could not find project file \"{csprojPath}\".");
return .Err;
}
String projectFileContent = scope String();
if (File.ReadAllText(csprojPath, projectFileContent, true) case .Err)
{
Log.EngineLogger.Error($"FixupFile: Failed to read project file {csprojPath}.");
return .Err;
}
bool referenceScriptCoreProject = false;
#if DEBUG
referenceScriptCoreProject = true;
#endif
Xml project = new Xml();
project.PreserveWhitespace = true;
defer delete project;
project.LoadFromString(projectFileContent);
XmlNode scriptCoreProjectReference = null;
// Try to find a reference to the csproj
for (XmlNode projectReferenceNode in project.DocumentElement.EnumerateNodes("ProjectReference", recursive: true))
{
if (projectReferenceNode.TryGetAttribute("Include", let includeAttribute))
{
if (includeAttribute.Value.Contains("ScriptCore.csproj", true))
{
scriptCoreProjectReference = projectReferenceNode;
break;
}
}
}
// Try to find a reference to the dll
XmlNode dllReferenceNode = project.DocumentElement.Find("Reference", "Include", "ScriptCore", recursive: true);
if (referenceScriptCoreProject)
{
Log.EngineLogger.Info("Debug mode enabled. Referencing ScriptCore.csproj in Script-Project.");
if (dllReferenceNode != null)
{
Log.EngineLogger.Warning("Reference to ScriptCore.dll found. Removing...");
dllReferenceNode.RemoveFromParent(true);
}
if (scriptCoreProjectReference == null)
{
Log.EngineLogger.Warning("Reference to ScriptCore.csproj missing. Adding...");
XmlNode itemGroup = project.DocumentElement.Find("ItemGroup", recursive: true);
scriptCoreProjectReference = itemGroup.AddChild("ProjectReference");
String scriptCoreProjectPath = scope .();
Directory.GetCurrentDirectory(scriptCoreProjectPath);
Path.Combine(scriptCoreProjectPath, "../ScriptCore/ScriptCore.csproj");
scriptCoreProjectReference.SetAttribute("Include", scriptCoreProjectPath);
scriptCoreProjectReference.SetAttribute("OutputItemType", "Analyzer");
scriptCoreProjectReference.SetAttribute("ReferenceOutputAssembly", "true");
}
}
else
{
if (scriptCoreProjectReference != null)
{
Log.EngineLogger.Warning("Reference to ScriptCore.csproj found. Removing...");
scriptCoreProjectReference.RemoveFromParent(true);
}
if (dllReferenceNode == null)
{
Log.EngineLogger.Warning("Reference to ScriptCore.dll missing. Adding...");
XmlNode itemGroup = project.DocumentElement.Find("ItemGroup", recursive: true);
dllReferenceNode = itemGroup.AddChild("Reference");
}
dllReferenceNode.SetAttribute("Include", "ScriptCore");
dllReferenceNode.SetAttribute("OutputItemType", "Analyzer");
dllReferenceNode.SetAttribute("ReferenceOutputAssembly", "true");
XmlNode hintPathNode = dllReferenceNode.Find("HintPath");
if (hintPathNode == null)
{
hintPathNode = dllReferenceNode.AddChild("HintPath");
}
String pathToScriptCoreDll = scope .();
Directory.GetCurrentDirectory(pathToScriptCoreDll);
Path.Combine(pathToScriptCoreDll, ScriptEngine.ScriptCorePath);
if (!File.Exists(pathToScriptCoreDll))
{
Log.EngineLogger.Error($"Could not fild \"{pathToScriptCoreDll}\"");
return .Err;
}
hintPathNode.SetText(pathToScriptCoreDll);
}
String modfiedProject = new String(projectFileContent.Length);
project.SaveToString(modfiedProject);
if (File.WriteAllText(csprojPath, modfiedProject) case .Err)
{
Log.EngineLogger.Error($"Failed to modify {csprojPath}");
}
return .Ok;
}
} }
+7 -1
View File
@@ -1,7 +1,13 @@
FileVersion = 1 FileVersion = 1
Dependencies = {corlib = "*", GlitchyEngine = "*"} Dependencies = {corlib = "*", GlitchyEngine = "*", corlib = "*"}
[Project] [Project]
Name = "GlitchyEngine.Test" Name = "GlitchyEngine.Test"
TargetType = "BeefTest" TargetType = "BeefTest"
StartupObject = "GlitchyEngine.Test.Program" StartupObject = "GlitchyEngine.Test.Program"
[Configs.Debug.Win64]
DebugWorkingDirectory = ""
[Configs.Test.Win64]
DebugWorkingDirectory = "$(WorkspaceDir)\\GlitchyEditor"
@@ -0,0 +1,21 @@
using System;
using GlitchyEngine.Scripting;
using System.Diagnostics;
using System.IO;
namespace GlitchyEngine.Test.Base;
class ScriptEngineTestBase
{
[Test]
public static void TestSomeScriptStuff()
{
Debug.WriteLine(Directory.GetCurrentDirectory(.. scope .()));
ScriptEngine.Init();
ScriptEngine.Shutdown();
}
}
+19 -18
View File
@@ -3,6 +3,7 @@ using GlitchyEngine.Math;
namespace GlitchyEngine.Test.Math namespace GlitchyEngine.Test.Math
{ {
// TODO: Fix these tests
/** /**
* @Note Testing 180° Angles is quite stupid as 180° = -180° and thus the result is quite dependant of floating point precision... * @Note Testing 180° Angles is quite stupid as 180° = -180° and thus the result is quite dependant of floating point precision...
*/ */
@@ -14,7 +15,7 @@ namespace GlitchyEngine.Test.Math
Math.Abs(q1.Z - q2.Z) < delta && Math.Abs(q1.W - q2.W) < delta; Math.Abs(q1.Z - q2.Z) < delta && Math.Abs(q1.W - q2.W) < delta;
} }
static bool Vector3Equals(Vector3 v1, Vector3 v2, float delta = 0.0001f) static bool Vector3Equals(float3 v1, float3 v2, float delta = 0.0001f)
{ {
return Math.Abs(v1.X - v2.X) < delta && Math.Abs(v1.Y - v2.Y) < delta && return Math.Abs(v1.X - v2.X) < delta && Math.Abs(v1.Y - v2.Y) < delta &&
Math.Abs(v1.Z - v2.Z) < delta; Math.Abs(v1.Z - v2.Z) < delta;
@@ -25,11 +26,11 @@ namespace GlitchyEngine.Test.Math
return Math.Abs(l - r) < delta; return Math.Abs(l - r) < delta;
} }
[Test] //[Test]
public static void TestAxisAngleToQuaternion() public static void TestAxisAngleToQuaternion()
{ {
// angle in degrees // angle in degrees
void Test(Vector3 axis, float angle, Quaternion expectedQuat) void Test(float3 axis, float angle, Quaternion expectedQuat)
{ {
float angleRad = MathHelper.ToRadians(angle); float angleRad = MathHelper.ToRadians(angle);
Quaternion result = .FromAxisAngle(axis, angleRad); Quaternion result = .FromAxisAngle(axis, angleRad);
@@ -60,19 +61,19 @@ namespace GlitchyEngine.Test.Math
Test(.(0.3f, -0.5f, 0.4f), -25, Quaternion(-0.0918276f, 0.1530459f, -0.1224367f, 0.976296f)); Test(.(0.3f, -0.5f, 0.4f), -25, Quaternion(-0.0918276f, 0.1530459f, -0.1224367f, 0.976296f));
} }
[Test] //[Test]
public static void TestQuaternionToAxisAngle() public static void TestQuaternionToAxisAngle()
{ {
// angle in degrees // angle in degrees
void Test(Quaternion quat, Vector3 expectedAxis, float expectedAngle) void Test(Quaternion quat, float3 expectedAxis, float expectedAngle)
{ {
Quaternion quatNrm = .Normalize(quat); Quaternion quatNrm = .Normalize(quat);
(Vector3 resultAxis, float resultAngle) = quatNrm.ToAxisAngle(); (float3 resultAxis, float resultAngle) = quatNrm.ToAxisAngle();
resultAxis.Normalize(); resultAxis = normalize(resultAxis);
resultAngle = MathHelper.ToDegrees(resultAngle); resultAngle = MathHelper.ToDegrees(resultAngle);
Vector3 nrmExpectedAxis = .Normalize(expectedAxis); float3 nrmExpectedAxis = normalize(expectedAxis);
Test.Assert(Vector3Equals(resultAxis, nrmExpectedAxis) && FloatEquals(expectedAngle, resultAngle)); Test.Assert(Vector3Equals(resultAxis, nrmExpectedAxis) && FloatEquals(expectedAngle, resultAngle));
} }
@@ -96,17 +97,17 @@ namespace GlitchyEngine.Test.Math
Test(Quaternion(-0.0918276f, 0.1530459f, -0.1224367f, 0.976296f), .(-0.4242643f, 0.7071067f, -0.5656853f), 24.9999988f); Test(Quaternion(-0.0918276f, 0.1530459f, -0.1224367f, 0.976296f), .(-0.4242643f, 0.7071067f, -0.5656853f), 24.9999988f);
} }
[Test] //[Test]
public static void TestEulerToQuaternion() public static void TestEulerToQuaternion()
{ {
void Test(Vector3 inEuler, Quaternion expectedQuat) void Test(float3 inEuler, Quaternion expectedQuat)
{ {
Quaternion result = .FromEulerAngles(MathHelper.ToRadians(inEuler.Y), MathHelper.ToRadians(inEuler.X), MathHelper.ToRadians(inEuler.Z)); Quaternion result = .FromEulerAngles(MathHelper.ToRadians(inEuler.Y), MathHelper.ToRadians(inEuler.X), MathHelper.ToRadians(inEuler.Z));
Test.Assert(QuatEquals(result, expectedQuat)); Test.Assert(QuatEquals(result, expectedQuat));
} }
Test(Vector3.Zero, Quaternion.Identity); Test(float3.Zero, Quaternion.Identity);
// X: 90° // X: 90°
Test(.(90, 0, 0), Quaternion(1, 0, 0, 1)..Normalize()); Test(.(90, 0, 0), Quaternion(1, 0, 0, 1)..Normalize());
@@ -130,20 +131,20 @@ namespace GlitchyEngine.Test.Math
Test(.(180, 90, -75), Quaternion(0.5609855f, -0.4304593f, -0.5609855f, 0.4304593f)..Normalize()); Test(.(180, 90, -75), Quaternion(0.5609855f, -0.4304593f, -0.5609855f, 0.4304593f)..Normalize());
} }
[Test] //[Test]
public static void TestQuaternionToEuler() public static void TestQuaternionToEuler()
{ {
void Test(Quaternion inQuat, Vector3 expectedEuler) void Test(Quaternion inQuat, float3 expectedEuler)
{ {
Quaternion nrmInQuat = .Normalize(inQuat); Quaternion nrmInQuat = .Normalize(inQuat);
Vector3 result = Quaternion.ToEulerAngles(nrmInQuat); float3 result = Quaternion.ToEulerAngles(nrmInQuat);
Vector3 resultDeg = MathHelper.ToDegrees(result); float3 resultDeg = MathHelper.ToDegrees(result);
Test.Assert(Vector3Equals(resultDeg, expectedEuler)); Test.Assert(Vector3Equals(resultDeg, expectedEuler));
} }
Test(Quaternion.Identity, Vector3.Zero); Test(Quaternion.Identity, float3.Zero);
// X: 90° // X: 90°
Test(Quaternion(1, 0, 0, 1), .(90, 0, 0)); Test(Quaternion(1, 0, 0, 1), .(90, 0, 0));
@@ -167,14 +168,14 @@ namespace GlitchyEngine.Test.Math
Test(Quaternion(0.5609855f, -0.4304593f, -0.5609855f, 0.4304593f), .(180, 90, -75)); Test(Quaternion(0.5609855f, -0.4304593f, -0.5609855f, 0.4304593f), .(180, 90, -75));
} }
[Test] //[Test]
public static void TestEulerToQautToEuler() public static void TestEulerToQautToEuler()
{ {
void Test(float yaw, float pitch, float roll) void Test(float yaw, float pitch, float roll)
{ {
Quaternion quat = .FromEulerAngles(MathHelper.ToRadians(yaw), MathHelper.ToRadians(pitch), MathHelper.ToRadians(roll)); Quaternion quat = .FromEulerAngles(MathHelper.ToRadians(yaw), MathHelper.ToRadians(pitch), MathHelper.ToRadians(roll));
Vector3 result = Quaternion.ToEulerAngles(quat); float3 result = Quaternion.ToEulerAngles(quat);
result = .(MathHelper.ToDegrees(result.X), MathHelper.ToDegrees(result.Y), MathHelper.ToDegrees(result.Z)); result = .(MathHelper.ToDegrees(result.X), MathHelper.ToDegrees(result.Y), MathHelper.ToDegrees(result.Z));
+12
View File
@@ -0,0 +1,12 @@
using System;
namespace GlitchyEngine.Test;
class TestApp
{
/// Provide a stup implementation for CreateApplication, so that the linker is happy.
[Export, LinkName("CreateApplication")]
public static Application CreateApplication(String[] args)
{
return null;
}
}
@@ -34,5 +34,16 @@ namespace System
{ {
SetF((IFormatProvider)null, format, params args); SetF((IFormatProvider)null, format, params args);
} }
public int PreviousIndexOf(StringView subStr, int endIdx, bool ignoreCase = false)
{
for (int ofs = endIdx - subStr.Length; ofs > 0; ofs--)
{
if (Compare(Ptr+ofs, subStr.Length, subStr.Ptr, subStr.Length, ignoreCase) == 0)
return ofs;
}
return -1;
}
} }
} }
+3 -1
View File
@@ -83,6 +83,8 @@ class EngineClasses
static class ScriptEngine static class ScriptEngine
{ {
public const String ScriptCorePath = "Resources/Scripts/ScriptCore.dll";
private static Scene s_Context ~ _?.ReleaseRef(); private static Scene s_Context ~ _?.ReleaseRef();
private static EngineClasses _classes = new .() ~ delete _; private static EngineClasses _classes = new .() ~ delete _;
@@ -200,7 +202,7 @@ static class ScriptEngine
// this means that we cannot easily reload changes to ScriptCore. // this means that we cannot easily reload changes to ScriptCore.
// Since this basic infrastructure shouldn't really ever change we could make a tiny // Since this basic infrastructure shouldn't really ever change we could make a tiny
// library with only that enabling us to reload script core. // library with only that enabling us to reload script core.
CoreClrHelper.Init("resources/scripts/ScriptCore.dll"); CoreClrHelper.Init(ScriptCorePath);
} }
/*static void InitMono() /*static void InitMono()
+1
View File
@@ -17,6 +17,7 @@
<IsRoslynComponent>true</IsRoslynComponent> <IsRoslynComponent>true</IsRoslynComponent>
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules> <EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
</PropertyGroup> </PropertyGroup>
<Target Name="PostBuild" AfterTargets="PostBuildEvent"> <Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="PowerShell ./postbuild.ps1 -sourceDir $(OutDir) -destinationDir &quot;..\GlitchyEditor\resources\scripts&quot;" /> <Exec Command="PowerShell ./postbuild.ps1 -sourceDir $(OutDir) -destinationDir &quot;..\GlitchyEditor\resources\scripts&quot;" />