mirror of
https://github.com/aharabada/glitchy-engine-beef.git
synced 2026-11-04 12:51:48 +00:00
Compare commits
22
Commits
e27237360f
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
73392f58f7 | ||
|
|
6718279a9f | ||
|
|
2674836cca | ||
|
|
ed94213435 | ||
|
|
fa3f734341 | ||
|
|
a7d0ef830b | ||
|
|
1b10e98f8c | ||
|
|
4488bd7d9c | ||
|
|
9c90b6bb3f | ||
|
|
d392eb5ba5 | ||
|
|
a18426658a | ||
|
|
25cbf58106 | ||
|
|
ba8b5ed47b | ||
|
|
a664dc2047 | ||
|
|
8341097b7e | ||
|
|
125872a157 | ||
|
|
a6d4aa047b | ||
|
|
c3053db27b | ||
|
|
101200306e | ||
|
|
f62adf8390 | ||
|
|
14c1568e98 | ||
|
|
da349465fd |
@@ -0,0 +1,19 @@
|
||||
name: Trigger docs build
|
||||
|
||||
# Rebuilds the documentation website (aharabada/glitchy-engine-docs) whenever main changes
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
workflow_dispatch:
|
||||
|
||||
permissions: {}
|
||||
|
||||
jobs:
|
||||
dispatch:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Notify docs repository
|
||||
env:
|
||||
# Fine-grained PAT, only for glitchy-engine-docs, permission "Contents: Read and write"
|
||||
GH_TOKEN: ${{ secrets.DOCS_DISPATCH_TOKEN }}
|
||||
run: gh api repos/aharabada/glitchy-engine-docs/dispatches -f event_type=engine-updated
|
||||
+11
-2
@@ -1,8 +1,10 @@
|
||||
FileVersion = 1
|
||||
Locked = ["ImGui"]
|
||||
Unlocked = ["corlib"]
|
||||
|
||||
[Workspace]
|
||||
StartupProject = "GlitchyEditor"
|
||||
PreprocessorMacros = ["IMGUI"]
|
||||
|
||||
[Projects]
|
||||
GlitchyEngine = {Path = "GlitchyEngine"}
|
||||
@@ -20,17 +22,24 @@ 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"}
|
||||
"GlitchyEngine.Benchmark" = {Path = "GlitchyEngine.Benchmark"}
|
||||
"Beef.Linq" = {Path = "GlitchyEngine/vendor/Beef.Linq"}
|
||||
"Oregano.git" = {Git = "https://github.com/zerkawei/Oregano.git"}
|
||||
|
||||
[WorkspaceFolders]
|
||||
GlitchyEngine = ["GlitchyEngine", "GlitchLog", "GlitchyEngineHelper", "ScriptCore", "GlitchyEngine.Test", "GlitchyEngine.Benchmark"]
|
||||
"GlitchyEngine/Dependencies" = ["cgltf-beef", "DirectX", "FreeType", "ImGui", "ImGuiImplDX11", "ImGuiImplWin32", "ImGuizmo", "LodePng", "msdfgen-beef", "bon", "box2d-beef", "Beef.Linq", "NetHostBeef", "Xml-Beef"]
|
||||
"GlitchyEngine/Dependencies" = ["cgltf-beef", "DirectX", "FreeType", "ImGui", "ImGuiImplDX11", "ImGuiImplWin32", "ImGuizmo", "LodePng", "msdfgen-beef", "bon", "box2d-beef", "NetHostBeef", "Xml-Beef", "Beef.Linq"]
|
||||
Beef = ["Beefy2D", "corlib"]
|
||||
|
||||
[Configs.Debug.Win64]
|
||||
AllocStackTraceDepth = 12
|
||||
ConfigSelections = {"GlitchyEngine.Test" = {Enabled = false}}
|
||||
|
||||
[Configs.Release.Win64]
|
||||
Toolset = "Microsoft"
|
||||
LTOType = "None"
|
||||
ConfigSelections = {"GlitchyEngine.Test" = {Enabled = false}}
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
FileVersion = 1
|
||||
|
||||
[Locks."Oregano.git".Git]
|
||||
URL = "https://github.com/zerkawei/Oregano.git"
|
||||
Tag = ""
|
||||
Hash = "0811b2dc6a878c472d2bc08b37ebc0862f853290"
|
||||
@@ -15,13 +15,14 @@ ImGuiImplDX11 = "*"
|
||||
ImGuiImplWin32 = "*"
|
||||
ImGuizmo = "*"
|
||||
"Beef.Linq" = "*"
|
||||
"Oregano.git" = {Git = "https://github.com/zerkawei/Oregano.git"}
|
||||
|
||||
[Platform.Windows]
|
||||
IconFile = "$(ProjectDir)/Resources/Textures/GlitchyEngineIcon.ico"
|
||||
|
||||
[Configs.Debug.Win64]
|
||||
PostBuildCmds = ["CopyFilesIfNewer(\"$(WorkspaceDir)/bin/vswhere.exe\", \"$(TargetDir)\")"]
|
||||
DebugCommandArguments = "\"$(ProjectDir)/../GlitchyEngine.Test/content/TestProject\""
|
||||
DebugCommandArguments = "\"D:\\Development\\Git\\SingleStateToOrbit\\\""
|
||||
PreprocessorMacros = ["DEBUG", "IMGUI"]
|
||||
|
||||
[Configs.Release.Win64]
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<!-- General configuration -->
|
||||
<AssemblyTitle>[ProjectName]</AssemblyTitle>
|
||||
@@ -10,6 +10,7 @@
|
||||
<OutputPath>./.cache/bin/</OutputPath>
|
||||
<!-- Generates a runtimeconfig-file and copies nuget references to the output -->
|
||||
<EnableDynamicLoading>true</EnableDynamicLoading>
|
||||
<DefaultItemExcludes>$(DefaultItemExcludes);**/*.ass</DefaultItemExcludes>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="ScriptCore" OutputItemType="Analyzer" ReferenceOutputAssembly="true">
|
||||
|
||||
@@ -33,6 +33,10 @@ class AssetHierarchy
|
||||
|
||||
public TreeNode<AssetNode> RootNode => _assetRootNode;
|
||||
|
||||
private append ScriptProjectDirtyManager _scriptProjectDirtyManager = .();
|
||||
|
||||
public ScriptProjectDirtyManager ScriptProjectDirtyManager => _scriptProjectDirtyManager;
|
||||
|
||||
public StringView ResourcesDirectory
|
||||
{
|
||||
get => _resourcesDirectory;
|
||||
@@ -235,6 +239,8 @@ class AssetHierarchy
|
||||
//SetupResourcesFileSystemWatcher();
|
||||
|
||||
UpdateFiles();
|
||||
|
||||
ScriptProjectDirtyManager.SetVeryDirty();
|
||||
}
|
||||
|
||||
/// Sets path to the directory that contains the game assets.
|
||||
@@ -322,18 +328,24 @@ class AssetHierarchy
|
||||
Log.EngineLogger.Trace($"File content changed (\"{filename}\")");
|
||||
|
||||
FileContentChanged(filename);
|
||||
|
||||
ScriptProjectDirtyManager.AssetChanged(filename);
|
||||
});
|
||||
|
||||
fsw.OnCreated.Add(new (filename) => {
|
||||
Log.EngineLogger.Trace($"File created (\"{filename}\")");
|
||||
|
||||
DeferFileTreeUpdate();
|
||||
|
||||
ScriptProjectDirtyManager.AssetChanged(filename);
|
||||
});
|
||||
|
||||
fsw.OnDeleted.Add(new (filename) => {
|
||||
Log.EngineLogger.Trace($"File deleted (\"{filename}\")");
|
||||
|
||||
DeferFileTreeUpdate();
|
||||
|
||||
ScriptProjectDirtyManager.AssetChanged(filename);
|
||||
});
|
||||
|
||||
fsw.OnRenamed.Add(new (oldName, newName) => {
|
||||
@@ -342,6 +354,9 @@ class AssetHierarchy
|
||||
FileRenamed(oldName, newName);
|
||||
|
||||
DeferFileTreeUpdate();
|
||||
|
||||
ScriptProjectDirtyManager.AssetChanged(oldName);
|
||||
ScriptProjectDirtyManager.AssetChanged(newName);
|
||||
});
|
||||
|
||||
fsw.StartRaisingEvents();
|
||||
|
||||
@@ -0,0 +1,187 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Collections;
|
||||
using Oregano;
|
||||
using System.Diagnostics;
|
||||
using GlitchyEditor.Settings;
|
||||
|
||||
namespace GlitchyEditor.Assets;
|
||||
|
||||
class ScriptProjectDirtyManager
|
||||
{
|
||||
private bool _anyAssetDirty;
|
||||
private bool _projectFileDirty;
|
||||
private bool _forceRebuild;
|
||||
|
||||
public void AssetChanged(StringView assetPath)
|
||||
{
|
||||
_anyAssetDirty = true;
|
||||
|
||||
_projectFileDirty |= CheckIfProjectFile(assetPath);
|
||||
}
|
||||
|
||||
private bool CheckIfProjectFile(StringView assetPath)
|
||||
{
|
||||
for (Regex regex in _patterns)
|
||||
{
|
||||
if (regex.IsMatch(assetPath))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void SetClean()
|
||||
{
|
||||
_anyAssetDirty = false;
|
||||
_projectFileDirty = false;
|
||||
_forceRebuild = false;
|
||||
}
|
||||
|
||||
public void SetVeryDirty()
|
||||
{
|
||||
_forceRebuild = true;
|
||||
}
|
||||
|
||||
public bool NeedsRebuild(RebuildOnPlay rebuildMode)
|
||||
{
|
||||
switch (rebuildMode)
|
||||
{
|
||||
case .Off:
|
||||
return _forceRebuild;
|
||||
case .Always:
|
||||
return true;
|
||||
case .WhenAnyAssetsChanged:
|
||||
return _anyAssetDirty || _forceRebuild;
|
||||
case .UseFastUpToDateCheck:
|
||||
return _projectFileDirty || _forceRebuild;
|
||||
}
|
||||
}
|
||||
|
||||
private static List<StringView> patterns = new .(){
|
||||
"**/*.cs", // C# source files
|
||||
"**/*.csproj", // C# Project file
|
||||
"**/*.props", // MSBuild properties
|
||||
"**/*.targets", // MSBuild targets
|
||||
"**/*.resx", // Embedded .NET-Ressources
|
||||
"**/*.editorconfig", // Compiler- and Analyzer-config
|
||||
"**/*.globalconfig", // Global Analyzer-config
|
||||
"**/global.json",
|
||||
"**/NuGet.Config",
|
||||
"**/packages.lock.json",
|
||||
"**/runtimeconfig.template.json"
|
||||
} ~ delete _;
|
||||
|
||||
private List<Regex> _patterns = new .() ~ DeleteContainerAndItems!(_);
|
||||
// Oregano's Regex doesn't copy the pattern but keeps StringViews into it, so the strings must live as long as the regexes.
|
||||
private List<String> _patternStrings = new .() ~ DeleteContainerAndItems!(_);
|
||||
|
||||
public this()
|
||||
{
|
||||
for (StringView pattern in patterns)
|
||||
{
|
||||
String regexString = new .();
|
||||
|
||||
if (CompileRegexFromGlob(pattern, regexString) case .Ok(let regex))
|
||||
{
|
||||
_patternStrings.Add(regexString);
|
||||
_patterns.Add(regex);
|
||||
}
|
||||
else
|
||||
{
|
||||
delete regexString;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Converts the glob into a regex string (written to outRegex) and compiles it.
|
||||
/// The returned Regex references outRegex, so outRegex must outlive it.
|
||||
private static Result<Regex> CompileRegexFromGlob(StringView glob, String outRegex)
|
||||
{
|
||||
outRegex.Append('^');
|
||||
|
||||
int inBrackets = 0;
|
||||
bool isInBrackets() => inBrackets > 0;
|
||||
|
||||
bool isWildcard = false;
|
||||
bool wasDoubleWildcard = false;
|
||||
|
||||
for (char8 c in glob)
|
||||
{
|
||||
if (isWildcard)
|
||||
{
|
||||
isWildcard = false;
|
||||
if (c == '*')
|
||||
{
|
||||
// **
|
||||
outRegex.Append(@"(?:.*[\\/])?");
|
||||
wasDoubleWildcard = true;
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
outRegex.Append(@"[^\\/]*");
|
||||
}
|
||||
}
|
||||
|
||||
if (c == '[')
|
||||
{
|
||||
inBrackets++;
|
||||
outRegex.Append(c);
|
||||
continue;
|
||||
}
|
||||
else if (c == ']')
|
||||
{
|
||||
inBrackets--;
|
||||
outRegex.Append(c);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (c == '.')
|
||||
{
|
||||
if (isInBrackets())
|
||||
outRegex.Append('.');
|
||||
else
|
||||
outRegex.Append(@"\.");
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (isInBrackets())
|
||||
{
|
||||
outRegex.Append(c);
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (c == '?')
|
||||
{
|
||||
outRegex.Append(@"[^\\/]");
|
||||
continue;
|
||||
}
|
||||
else if (c == '*')
|
||||
{
|
||||
isWildcard = true;
|
||||
continue;
|
||||
}
|
||||
else if (c == '/')
|
||||
{
|
||||
if (!wasDoubleWildcard)
|
||||
outRegex.Append(@"\/");
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
outRegex.Append(c);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
outRegex.Append('$');
|
||||
|
||||
return Regex.Compile(outRegex);
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,6 @@ using GlitchyEngine;
|
||||
using GlitchyEngine.Content;
|
||||
using GlitchyEngine.Scripting;
|
||||
using GlitchyEngine.Core;
|
||||
using Mono;
|
||||
using GlitchyEngine.World.Components;
|
||||
|
||||
namespace GlitchyEditor.EditWindows
|
||||
@@ -179,7 +178,7 @@ namespace GlitchyEditor.EditWindows
|
||||
|
||||
float2 buttonSize = ImGui.GetTextLineHeight().XX;
|
||||
|
||||
ImGui.PushStyleColor(.Button, .(0, 0, 0, 0));
|
||||
ImGui.PushStyleColor(.Button, ColorRGBA(0, 0, 0, 0));
|
||||
|
||||
if (showComponentContextMenu != null)
|
||||
{
|
||||
|
||||
@@ -604,7 +604,7 @@ namespace GlitchyEditor.EditWindows
|
||||
|
||||
if (ImGui.MenuItem("Open C# Project..."))
|
||||
{
|
||||
Editor.Instance.IdeAdapter.OpenScriptProject();
|
||||
Editor.Instance.OpenScriptProject();
|
||||
}
|
||||
|
||||
ImGui.AttachTooltip("Opens the C# Solution of this project.");
|
||||
@@ -1434,7 +1434,7 @@ namespace GlitchyEditor.EditWindows
|
||||
// Special treatment for scripts, open them in Visual Studio.
|
||||
if (entry->Path.EndsWith(".cs"))
|
||||
{
|
||||
Editor.Instance.IdeAdapter.OpenScript(entry->Path);
|
||||
Editor.Instance.OpenScript(entry->Path);
|
||||
}
|
||||
else if (Path.OpenFolder(entry->Path) case .Err)
|
||||
Log.EngineLogger.Error("Failed to open file.");
|
||||
|
||||
@@ -9,6 +9,8 @@ using GlitchyEngine.Renderer;
|
||||
using GlitchyEngine;
|
||||
using GlitchyEditor.CodeEditors;
|
||||
using System.IO;
|
||||
using GlitchyEditor.Settings;
|
||||
using GlitchyEngine.Math;
|
||||
|
||||
namespace GlitchyEditor.EditWindows;
|
||||
|
||||
@@ -137,7 +139,7 @@ class LogWindow : EditorWindow
|
||||
if (_visibleMessageTypes.HasFlag(.Trace))
|
||||
ImGui.PushStyleColor(.Button, *col);
|
||||
else
|
||||
ImGui.PushStyleColor(.Button, .(0, 0, 0, 0));
|
||||
ImGui.PushStyleColor(.Button, ColorRGBA(0, 0, 0, 0));
|
||||
|
||||
if (ImGui.ImageButtonEx(1, s_TraceIcon, buttonSize, .Zero, .Ones))
|
||||
_visibleMessageTypes ^= .Trace;
|
||||
@@ -147,7 +149,7 @@ class LogWindow : EditorWindow
|
||||
if (_visibleMessageTypes.HasFlag(.Info))
|
||||
ImGui.PushStyleColor(.Button, *col);
|
||||
else
|
||||
ImGui.PushStyleColor(.Button, .(0, 0, 0, 0));
|
||||
ImGui.PushStyleColor(.Button, ColorRGBA(0, 0, 0, 0));
|
||||
|
||||
if (ImGui.ImageButtonEx(2, s_InfoIcon, buttonSize, .Zero, .Ones))
|
||||
_visibleMessageTypes ^= .Info;
|
||||
@@ -157,7 +159,7 @@ class LogWindow : EditorWindow
|
||||
if (_visibleMessageTypes.HasFlag(.Warning))
|
||||
ImGui.PushStyleColor(.Button, *col);
|
||||
else
|
||||
ImGui.PushStyleColor(.Button, .(0, 0, 0, 0));
|
||||
ImGui.PushStyleColor(.Button, ColorRGBA(0, 0, 0, 0));
|
||||
|
||||
if (ImGui.ImageButtonEx(3, s_WarningIcon, buttonSize, .Zero, .Ones))
|
||||
_visibleMessageTypes ^= .Warning;
|
||||
@@ -167,7 +169,7 @@ class LogWindow : EditorWindow
|
||||
if (_visibleMessageTypes.HasFlag(.Error))
|
||||
ImGui.PushStyleColor(.Button, *col);
|
||||
else
|
||||
ImGui.PushStyleColor(.Button, .(0, 0, 0, 0));
|
||||
ImGui.PushStyleColor(.Button, ColorRGBA(0, 0, 0, 0));
|
||||
|
||||
|
||||
if (ImGui.ImageButtonEx(4, s_ErrorIcon, buttonSize, .Zero, .Ones))
|
||||
@@ -316,8 +318,7 @@ class LogWindow : EditorWindow
|
||||
float width = ImGui.CalcTextSize(lineBuffer.CStr()).x;
|
||||
if (ImGui.Selectable(lineBuffer, false, .None, .(width, 0)))
|
||||
{
|
||||
// TODO: Columns?
|
||||
Editor.Instance.IdeAdapter.OpenScript(frameInfo.FileName, frameInfo.Line, frameInfo.Column);
|
||||
Editor.Instance.OpenScript(frameInfo.FileName, frameInfo.Line, frameInfo.Column);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -336,13 +337,13 @@ class LogWindow : EditorWindow
|
||||
{
|
||||
if (message.Source.MessageOrigin != null)
|
||||
{
|
||||
Editor.Instance.IdeAdapter.OpenScript(message.Source.MessageOrigin.FileName, message.Source.MessageOrigin.LineNumber);
|
||||
Editor.Instance.OpenScript(message.Source.MessageOrigin.FileName, message.Source.MessageOrigin.LineNumber);
|
||||
}
|
||||
else if (message.Source.Exception != null)
|
||||
{
|
||||
// TODO: Column?
|
||||
let firstFrame = message.Source.Exception.StackTrace.Frames[0];
|
||||
Editor.Instance.IdeAdapter.OpenScript(firstFrame.FileName, firstFrame.Line);
|
||||
Editor.Instance.OpenScript(firstFrame.FileName, firstFrame.Line);
|
||||
//message.Source.Exception.StackTrace
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,9 @@ using GlitchyEditor.EditWindows;
|
||||
using GlitchyEngine;
|
||||
using GlitchyEditor.Assets;
|
||||
using GlitchyEditor.CodeEditors;
|
||||
using GlitchyEditor.Settings;
|
||||
using GlitchyEditor.Multithreading;
|
||||
using GlitchyEngine.Scripting;
|
||||
|
||||
namespace GlitchyEditor
|
||||
{
|
||||
@@ -177,5 +180,85 @@ namespace GlitchyEditor
|
||||
{
|
||||
_settingsWindow.Open = true;
|
||||
}
|
||||
|
||||
private void OpenIdeConfigurationPopup() {
|
||||
PopupService.Instance.OpenPopup("No IDE configured.", new (close) => {
|
||||
close = false;
|
||||
|
||||
ImGui.TextUnformatted("In order to open a source file or the script project you need to configure an IDE to use.");
|
||||
|
||||
if (ImGui.Button("Go to settings..."))
|
||||
{
|
||||
ShowSettings();
|
||||
SettingsWindow.HighlightSetting("Tools", "ide");
|
||||
close = true;
|
||||
}
|
||||
|
||||
ImGui.SameLine();
|
||||
|
||||
if (ImGui.Button("Cancel"))
|
||||
{
|
||||
close = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// Wrapper for IdeAdapter.OpenScript that check whether or not an IDE Adapter is configured.
|
||||
/// If not, a popup will be show.
|
||||
public void OpenScript(StringView fileName, int lineNumber = 0, int columnNumber = 0)
|
||||
{
|
||||
if (IdeAdapter == null)
|
||||
{
|
||||
OpenIdeConfigurationPopup();
|
||||
}
|
||||
else
|
||||
{
|
||||
IdeAdapter.OpenScript(fileName, lineNumber, columnNumber);
|
||||
}
|
||||
}
|
||||
|
||||
/// Wrapper for IdeAdapter.OpenScript that check whether or not an IDE Adapter is configured.
|
||||
/// If not, a popup will be show.
|
||||
public void OpenScriptProject()
|
||||
{
|
||||
if (IdeAdapter == null)
|
||||
{
|
||||
OpenIdeConfigurationPopup();
|
||||
}
|
||||
else
|
||||
{
|
||||
IdeAdapter.OpenScriptProject();
|
||||
}
|
||||
}
|
||||
|
||||
/// Rebuilds the C# scripts.
|
||||
public BuildScriptsBackgroundTask BuildScripts(bool reloadAfterBuild = true, bool doCleanRebuild = false)
|
||||
{
|
||||
ScriptEngine.SuspendAssemblyWatcher();
|
||||
|
||||
BuildScriptsBackgroundTask task = new .(EditorApp.Instance.Settings.ScriptSettings.DotNetExecutablePath, EditorApp.Instance.EditorLayer.CurrentProject, releaseBuild: false, doCleanRebuild){ DeleteWhenEnded = true };
|
||||
task.ContinueWith(new (task) => {
|
||||
ScriptEngine.ResumeAssemblyWatcher();
|
||||
|
||||
EditorApp.Instance.ContentManager.AssetHierarchy.ScriptProjectDirtyManager.SetClean();
|
||||
|
||||
if (reloadAfterBuild)
|
||||
{
|
||||
EditorApp.Instance.InvokeOnMainThread(new () => {
|
||||
ScriptEngine.ReloadAssemblies(retainScriptData: true);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
EditorApp.Instance.BackgroundTaskManager.StartBackgroundTask(task);
|
||||
|
||||
return task;
|
||||
}
|
||||
|
||||
public void ReloadScripts()
|
||||
{
|
||||
ScriptEngine.ReloadAssemblies(retainScriptData: true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,8 @@ namespace GlitchyEditor
|
||||
|
||||
public new static EditorApp Instance => Application.Instance as EditorApp;
|
||||
|
||||
public new EditorContentManager ContentManager => _contentManager;
|
||||
|
||||
private append BackgroundTaskManager _backgroundTaskManager = .();
|
||||
|
||||
public BackgroundTaskManager BackgroundTaskManager => _backgroundTaskManager;
|
||||
|
||||
@@ -820,10 +820,28 @@ namespace GlitchyEditor
|
||||
append ScriptInstanceSerializer _scriptSerializer = .();
|
||||
|
||||
/// Starts the play mode for the current scene
|
||||
private void OnScenePlay(SceneState newSceneState)
|
||||
private void OnScenePlay(SceneState newSceneState, bool allowRebuild = true)
|
||||
{
|
||||
Debug.Profiler.ProfileFunction!();
|
||||
|
||||
if (allowRebuild && _contentManager.AssetHierarchy.ScriptProjectDirtyManager.NeedsRebuild(EditorApp.Instance.Settings.ScriptSettings.RebuildOnPlayMode))
|
||||
{
|
||||
// Don't immediately reload the scripts after the build, because SetActiveScene will do that anyway.
|
||||
var task = _editor.BuildScripts(reloadAfterBuild: false);
|
||||
|
||||
task.ContinueWith(new (t) => {
|
||||
// Continuations run in worker threads, invoke play on main thread!
|
||||
EditorApp.Instance.InvokeOnMainThread(new () => {
|
||||
// Remember not to rebuild this time!
|
||||
OnScenePlay(newSceneState, allowRebuild: false);
|
||||
return true;
|
||||
});
|
||||
}, .RunOnFinished);
|
||||
|
||||
// Don't play just yet, the continuation will do that.
|
||||
return;
|
||||
}
|
||||
|
||||
Runtime.Assert(newSceneState == .Play || newSceneState == .Simulate, "newSceneState must either be Play or Simulate");
|
||||
|
||||
Log.EngineLogger.AssertDebug(_scriptSerializer.SerializedObjectCount == 0, "Somehow some entities are serialized.");
|
||||
@@ -1520,8 +1538,20 @@ namespace GlitchyEditor
|
||||
|
||||
if(ImGui.BeginMenu("Tools", true))
|
||||
{
|
||||
if(ImGui.MenuItem("Reload Scripts"))
|
||||
ScriptEngine.ReloadAssemblies(retainScriptData: true);
|
||||
if(ImGui.MenuItem("Build Scripts", "Ctrl+B"))
|
||||
_editor.BuildScripts();
|
||||
|
||||
ImGui.AttachTooltip("Compiles the C# script project.");
|
||||
|
||||
if(ImGui.MenuItem("Clean and build Scripts", "Ctrl+Shift+B"))
|
||||
_editor.BuildScripts(doCleanRebuild: true);
|
||||
|
||||
ImGui.AttachTooltip("Makes a clean rebuild of the C# script project.");
|
||||
|
||||
if(ImGui.MenuItem("Reload Scripts", "Ctrl+Shift+R"))
|
||||
_editor.ReloadScripts();
|
||||
|
||||
ImGui.AttachTooltip("Unloads and reloads the compiled scripts.");
|
||||
|
||||
#if GE_EDITOR_IMGUI_DEMO
|
||||
ImGui.Checkbox("Show ImGui Demo", &_showImguiDemoWindow);
|
||||
@@ -1624,6 +1654,17 @@ namespace GlitchyEditor
|
||||
// "Save Scene"
|
||||
SaveCurrentScene();
|
||||
|
||||
return true;
|
||||
case .B:
|
||||
// "Compile scripts"
|
||||
_editor.BuildScripts();
|
||||
|
||||
return true;
|
||||
case .R:
|
||||
if (shift)
|
||||
// "Compile scripts"
|
||||
_editor.ReloadScripts();
|
||||
|
||||
return true;
|
||||
default:
|
||||
}
|
||||
|
||||
@@ -535,6 +535,35 @@ namespace ImGui
|
||||
ImGui.EndTooltip();
|
||||
}
|
||||
|
||||
/// Provides a text input field that allows to edit the given string directly. The string will grow as needed.
|
||||
/// Returns true if the text was changed.
|
||||
public static bool InputText(char8* label, String str, InputTextFlags flags = .None)
|
||||
{
|
||||
return ImGui.InputText(label, str.CStr(), (.)str.AllocSize, flags | .CallbackResize, => StringResizeCallback, Internal.UnsafeCastToPtr(str));
|
||||
}
|
||||
|
||||
private static int StringResizeCallback(InputTextCallbackData* data)
|
||||
{
|
||||
if (data.EventFlag != .CallbackResize)
|
||||
return 0;
|
||||
|
||||
String str = (String)Internal.UnsafeCastToObject(data.UserData);
|
||||
|
||||
int newLength = data.BufTextLen;
|
||||
|
||||
// PrepareBuffer increases the length and reserves room for the null terminator.
|
||||
if (newLength > str.Length)
|
||||
str.PrepareBuffer(newLength - str.Length);
|
||||
else
|
||||
str.Length = newLength;
|
||||
|
||||
// The string might have been reallocated.
|
||||
data.Buf = str.Ptr;
|
||||
data.BufSize = (.)str.AllocSize;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
[Comptime]
|
||||
private static DataType GetDataType<T>()
|
||||
{
|
||||
@@ -744,6 +773,43 @@ namespace ImGui
|
||||
}
|
||||
}
|
||||
|
||||
public static mixin PushScopedStyleColor(ImGui.Col idx, uint32 color)
|
||||
{
|
||||
PushStyleColor(idx, color);
|
||||
defer:mixin PopStyleColor();
|
||||
}
|
||||
|
||||
public static mixin PushScopedStyleColor(ImGui.Col idx, Vec4 color)
|
||||
{
|
||||
PushStyleColor(idx, color);
|
||||
defer:mixin PopStyleColor();
|
||||
}
|
||||
|
||||
public static mixin PushScopedStyleColor(ImGui.Col idx, GlitchyEngine.Math.Color color)
|
||||
{
|
||||
PushStyleColor(idx, color);
|
||||
defer:mixin PopStyleColor();
|
||||
}
|
||||
|
||||
public static void PushStyleColor(ImGui.Col idx, GlitchyEngine.Math.Color color)
|
||||
{
|
||||
#unwarn
|
||||
uint32 bitColor = *(uint32*)(void*)&color;
|
||||
|
||||
ImGui.PushStyleColor(.Text, bitColor);
|
||||
}
|
||||
|
||||
public static mixin PushScopedStyleColor(ImGui.Col idx, GlitchyEngine.Math.ColorRGBA color)
|
||||
{
|
||||
PushStyleColor(idx, color);
|
||||
defer:mixin PopStyleColor();
|
||||
}
|
||||
|
||||
public static void PushStyleColor(ImGui.Col idx, GlitchyEngine.Math.ColorRGBA color)
|
||||
{
|
||||
ImGui.PushStyleColor(.Text, ((Color)color).Value);
|
||||
}
|
||||
|
||||
public struct DisabledScope : IDisposable
|
||||
{
|
||||
public this(bool disabled = true)
|
||||
|
||||
@@ -17,6 +17,15 @@ abstract class BackgroundTask
|
||||
|
||||
internal BackgroundTaskManager _taskManager;
|
||||
|
||||
public delegate void Continuation(BackgroundTask);
|
||||
|
||||
internal append List<(TaskContinuationOptions ContinuationOptions, Continuation Continuation)> _continuations = .() ~ {
|
||||
for (let entry in _)
|
||||
{
|
||||
delete entry.Continuation;
|
||||
}
|
||||
};
|
||||
|
||||
public enum RunState
|
||||
{
|
||||
Ready,
|
||||
@@ -24,7 +33,8 @@ abstract class BackgroundTask
|
||||
Paused,
|
||||
Running,
|
||||
Aborted,
|
||||
Finished
|
||||
Finished,
|
||||
Failed
|
||||
}
|
||||
|
||||
public enum RunResult
|
||||
@@ -34,9 +44,11 @@ abstract class BackgroundTask
|
||||
/// The task gives up it's runtime, because it cannot continue without user intervention through the UI.
|
||||
Pause,
|
||||
/// The task finished and wont run again.
|
||||
Finished,
|
||||
Finish,
|
||||
/// The operation was aborted, the task will not run again.
|
||||
Abort
|
||||
Abort,
|
||||
/// The task failed and wont run again.
|
||||
Fail
|
||||
}
|
||||
|
||||
public RunState State { get; internal set; } = .Ready;
|
||||
@@ -46,9 +58,10 @@ abstract class BackgroundTask
|
||||
public bool Blocked => State == .Blocked;
|
||||
public bool Running => State == .Running;
|
||||
public bool Aborted => State == .Aborted;
|
||||
public bool Failed => State == .Failed;
|
||||
public bool Finished => State == .Finished;
|
||||
|
||||
public bool Ended => Finished || Aborted;
|
||||
public bool Ended => Finished || Aborted || Failed;
|
||||
|
||||
public bool DeleteWhenEnded { get; set; }
|
||||
|
||||
@@ -70,4 +83,36 @@ abstract class BackgroundTask
|
||||
{
|
||||
_taskManager.AbortTask(this);
|
||||
}
|
||||
|
||||
public enum TaskContinuationOptions
|
||||
{
|
||||
/// Same as Default
|
||||
None = 0,
|
||||
|
||||
RunOnFinished = 1,
|
||||
RunOnFailed = 2,
|
||||
RunOnAborted = 4,
|
||||
|
||||
Default = RunOnFinished | RunOnFailed | RunOnAborted
|
||||
}
|
||||
|
||||
/// Creates a continuation that executes when the target Task completes.
|
||||
public void ContinueWith(Continuation ownContinuation, TaskContinuationOptions continuationOptions = .Default)
|
||||
{
|
||||
var continuationOptions;
|
||||
|
||||
if (continuationOptions == .None)
|
||||
{
|
||||
continuationOptions = .Default;
|
||||
}
|
||||
|
||||
if (Ended)
|
||||
{
|
||||
ownContinuation(this);
|
||||
}
|
||||
else
|
||||
{
|
||||
_continuations.Add((continuationOptions, ownContinuation));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ class BackgroundTaskList
|
||||
{
|
||||
BackgroundTask _sentinel = new BackgroundTask()
|
||||
{
|
||||
public override BackgroundTask.RunResult Run() => .Finished;
|
||||
public override BackgroundTask.RunResult Run() => .Finish;
|
||||
public override void OnRenderPopup() { }
|
||||
_next = _,
|
||||
_previous = _,
|
||||
|
||||
@@ -59,7 +59,7 @@ class BackgroundTaskManager
|
||||
if (_deferredStateChanges.TryGetValue(task, let desiredState))
|
||||
{
|
||||
// If the task already finished or aborted by itself, we don't care about the desired state, because it no longer applies.
|
||||
if (runResult != .Finished && runResult != .Abort)
|
||||
if (runResult != .Finish && runResult != .Abort && runResult != .Fail)
|
||||
{
|
||||
switch (desiredState)
|
||||
{
|
||||
@@ -75,6 +75,8 @@ class BackgroundTaskManager
|
||||
_deferredStateChanges.Remove(task);
|
||||
}
|
||||
|
||||
BackgroundTask.TaskContinuationOptions endStateFlag = .None;
|
||||
|
||||
switch (runResult)
|
||||
{
|
||||
case .Continue:
|
||||
@@ -89,15 +91,27 @@ class BackgroundTaskManager
|
||||
{
|
||||
_waitingTasks.AddLast(task);
|
||||
}
|
||||
case .Finished:
|
||||
case .Finish:
|
||||
task.State = .Finished;
|
||||
|
||||
if (task.DeleteWhenEnded)
|
||||
{
|
||||
delete task;
|
||||
}
|
||||
endStateFlag = .RunOnFinished;
|
||||
case .Abort:
|
||||
task.State = .Aborted;
|
||||
endStateFlag = .RunOnAborted;
|
||||
case .Fail:
|
||||
task.State = .Failed;
|
||||
endStateFlag = .RunOnFailed;
|
||||
}
|
||||
|
||||
if (task.Ended)
|
||||
{
|
||||
// Run the appropriate continuations
|
||||
for (let (options, continuation) in task._continuations)
|
||||
{
|
||||
if (options.HasFlag(endStateFlag))
|
||||
{
|
||||
continuation(task);
|
||||
}
|
||||
}
|
||||
|
||||
if (task.DeleteWhenEnded)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,145 @@
|
||||
using GlitchyEngine;
|
||||
using System.Collections;
|
||||
using GlitchyEditor.CodeEditors;
|
||||
using System.IO;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using ImGui;
|
||||
using GlitchyEditor.Multithreading;
|
||||
using GlitchyEngine.Scripting;
|
||||
using GlitchyEditor.Settings;
|
||||
using System.Threading;
|
||||
|
||||
namespace GlitchyEditor.Multithreading;
|
||||
|
||||
class BuildScriptsBackgroundTask : BackgroundTask
|
||||
{
|
||||
private bool _isAborting = false;
|
||||
|
||||
private Project _project;
|
||||
private bool _releaseBuild;
|
||||
private StringView _dotnetPath;
|
||||
private bool _doCleanRebuild;
|
||||
|
||||
private String _buildLog = new .() ~ delete _;
|
||||
|
||||
private SpawnedProcess _process ~ delete _;
|
||||
|
||||
public this(StringView dotnetPath, Project project, bool releaseBuild, bool doCleanRebuild)
|
||||
{
|
||||
_dotnetPath = dotnetPath;
|
||||
_project = project;
|
||||
_releaseBuild = releaseBuild;
|
||||
_doCleanRebuild = doCleanRebuild;
|
||||
}
|
||||
|
||||
public override RunResult Run()
|
||||
{
|
||||
return BuildScripts();
|
||||
}
|
||||
|
||||
public override void OnRenderPopup()
|
||||
{
|
||||
if (ImGui.Begin(!_isAborting ? "Compiling scripts..." : "Aborting compilation...", null, .NoDocking | .NoCollapse | .Modal | .NoResize | .AlwaysAutoResize))
|
||||
{
|
||||
if (ImGui.BeginChild("##BuildLog", .(550, ImGui.GetTextLineHeightWithSpacing() * 6), .None, .HorizontalScrollbar))
|
||||
{
|
||||
ImGui.TextUnformatted(_buildLog);
|
||||
}
|
||||
|
||||
if (ImGui.GetScrollY() >= ImGui.GetScrollMaxY())
|
||||
ImGui.SetScrollHereY(1.0f);
|
||||
|
||||
ImGui.EndChild();
|
||||
|
||||
if (ImGui.Button("Cancel"))
|
||||
{
|
||||
_isAborting = true;
|
||||
|
||||
_process.Kill();
|
||||
}
|
||||
|
||||
ImGui.End();
|
||||
}
|
||||
}
|
||||
|
||||
private RunResult BuildScripts()
|
||||
{
|
||||
RunResult result;
|
||||
|
||||
Log.EngineLogger.Info($"Building Scripts ({(_releaseBuild ? "Release" : "Debug")})...");
|
||||
|
||||
String exeFile = scope .();
|
||||
Environment.GetExecutableFilePath(exeFile);
|
||||
|
||||
String exeDirectory = scope .();
|
||||
Path.GetDirectoryPath(exeFile, exeDirectory);
|
||||
|
||||
ProcessStartInfo processInfo = scope .();
|
||||
processInfo.UseShellExecute = false;
|
||||
processInfo.RedirectStandardOutput = true;
|
||||
processInfo.CreateNoWindow = true;
|
||||
processInfo.SetWorkingDirectory(_project.WorkspacePath);
|
||||
|
||||
processInfo.SetFileName(EditorApp.Instance.Settings.ScriptSettings.DotNetExecutablePath);
|
||||
|
||||
StringView target;
|
||||
|
||||
if (_doCleanRebuild)
|
||||
{
|
||||
target = "build -t:Rebuild";
|
||||
}
|
||||
else
|
||||
{
|
||||
target = "build";
|
||||
}
|
||||
|
||||
|
||||
// -sc|--self-contained... Publish the .NET runtime with your application so the runtime doesn't need to be installed on the target machine.
|
||||
// -> This might be useful to build the final game
|
||||
// -o|--ouput <OUTPUT_DIRECTORY>... might be useful for building the final game
|
||||
processInfo.SetArguments(scope $"{target} -c {(_releaseBuild ? "Release" : "Debug")}");
|
||||
|
||||
_process = new SpawnedProcess();
|
||||
|
||||
if (_process.Start(processInfo) case .Ok)
|
||||
{
|
||||
FileStream outputStream = scope FileStream();
|
||||
_process.AttachStandardOutput(outputStream);
|
||||
|
||||
StreamReader outputReader = scope .(outputStream);
|
||||
|
||||
while (!_process.HasExited)
|
||||
{
|
||||
outputReader.ReadToEnd(_buildLog).IgnoreError();
|
||||
}
|
||||
|
||||
_process.WaitFor(-1);
|
||||
|
||||
if (_isAborting)
|
||||
{
|
||||
Log.EngineLogger.Warning($"Build was aborted:\n{_buildLog}");
|
||||
result = .Abort;
|
||||
}
|
||||
else if (_process.ExitCode == 0)
|
||||
{
|
||||
Log.EngineLogger.Info($"Scripts compiled successfully:\n{_buildLog}");
|
||||
result = .Finish;
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.EngineLogger.Error($"Script compilation failed:\n{_buildLog}");
|
||||
result = .Fail;
|
||||
}
|
||||
|
||||
DeleteAndNullify!(_process);
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.EngineLogger.Error("Failed to execute `dotnet build`");
|
||||
result = .Fail;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -249,7 +249,7 @@ class CopyBackgroundTask : BackgroundTask
|
||||
delete currentPath;
|
||||
}
|
||||
|
||||
return .Finished;
|
||||
return .Finish;
|
||||
}
|
||||
|
||||
private Result<void, CopyError> CopyPath(CopyInfo copyInfo)
|
||||
|
||||
@@ -141,7 +141,7 @@ class DeleteBackgroundTask : BackgroundTask
|
||||
delete currentPath;
|
||||
}
|
||||
|
||||
return .Finished;
|
||||
return .Finish;
|
||||
}
|
||||
|
||||
private Result<void, DeleteError> DeletePath(StringView deletePath)
|
||||
|
||||
@@ -252,7 +252,7 @@ class MoveFilesBackgroundTask : BackgroundTask
|
||||
delete currentPath;
|
||||
}
|
||||
|
||||
return .Finished;
|
||||
return .Finish;
|
||||
}
|
||||
|
||||
private Result<void, CopyError> MovePath(CopyInfo copyInfo)
|
||||
|
||||
@@ -0,0 +1,267 @@
|
||||
using GlitchyEngine;
|
||||
using System.Collections;
|
||||
using GlitchyEditor.CodeEditors;
|
||||
using System.IO;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using ImGui;
|
||||
using GlitchyEditor.Multithreading;
|
||||
using GlitchyEngine.Scripting;
|
||||
using GlitchyEditor.Settings;
|
||||
|
||||
namespace GlitchyEditor.Multithreading;
|
||||
|
||||
class TestDotnetBackgroundTask : BackgroundTask
|
||||
{
|
||||
private ScriptSettings _settings;
|
||||
private Project _project;
|
||||
|
||||
public enum TestResult
|
||||
{
|
||||
None,
|
||||
Ok,
|
||||
Timeout,
|
||||
FailedToExecute,
|
||||
NoSdksFound,
|
||||
TooOld
|
||||
}
|
||||
|
||||
private TestResult _testResult;
|
||||
|
||||
public TestResult TestResult => _testResult;
|
||||
|
||||
public this(ScriptSettings settings, Project project)
|
||||
{
|
||||
_settings = settings;
|
||||
_project = project;
|
||||
}
|
||||
|
||||
public override RunResult Run()
|
||||
{
|
||||
if (QueryAvailableSdks() case .Err)
|
||||
{
|
||||
return .Fail;
|
||||
}
|
||||
|
||||
if (CheckMinimumVersion() case .Err)
|
||||
{
|
||||
return .Fail;
|
||||
}
|
||||
|
||||
if (_project != null)
|
||||
{
|
||||
CheckProjectVersion();
|
||||
}
|
||||
|
||||
_testResult = .Ok;
|
||||
|
||||
return .Finish;
|
||||
}
|
||||
|
||||
public override void OnRenderPopup()
|
||||
{
|
||||
if (ImGui.Begin("Testing .Net Installation...", null, .NoDocking | .NoCollapse | .Modal | .NoResize | .AlwaysAutoResize))
|
||||
{
|
||||
ImGui.Text("...");
|
||||
|
||||
ImGui.End();
|
||||
}
|
||||
}
|
||||
|
||||
private Result<void> QueryAvailableSdks()
|
||||
{
|
||||
_settings.DotNetSdks.Clear();
|
||||
|
||||
Log.EngineLogger.Info("Listing .Net SDKs...");
|
||||
|
||||
String exeFile = scope .();
|
||||
Environment.GetExecutableFilePath(exeFile);
|
||||
|
||||
String exeDirectory = scope .();
|
||||
Path.GetDirectoryPath(exeFile, exeDirectory);
|
||||
|
||||
ProcessStartInfo processInfo = scope .();
|
||||
processInfo.UseShellExecute = false;
|
||||
processInfo.RedirectStandardOutput = true;
|
||||
processInfo.CreateNoWindow = true;
|
||||
|
||||
processInfo.SetFileName(_settings.DotNetExecutablePath);
|
||||
// Lists all installed sdks
|
||||
StringView argumentList = "--list-sdks";
|
||||
processInfo.SetArguments(argumentList);
|
||||
|
||||
let process = scope SpawnedProcess();
|
||||
|
||||
if (process.Start(processInfo) case .Ok)
|
||||
{
|
||||
FileStream outputStream = scope FileStream();
|
||||
process.AttachStandardOutput(outputStream);
|
||||
|
||||
if (!process.WaitFor(1000))
|
||||
{
|
||||
Log.EngineLogger.Error($"`dotnet --list-sdks` timed out.");
|
||||
process.Kill();
|
||||
_testResult = .Timeout;
|
||||
return .Err;
|
||||
}
|
||||
|
||||
StreamReader sr = scope .(outputStream);
|
||||
|
||||
String line = scope .(256);
|
||||
while (sr.ReadLine(line..Clear()) case .Ok)
|
||||
{
|
||||
Log.EngineLogger.Info($"Detecting .Net SDK version from line: {line}");
|
||||
// A line for a normal verion looks like this:
|
||||
// 10.0.402 [C:\Program Files\dotnet\sdk]
|
||||
// A line for a snapshot looks like this:
|
||||
// 9.0.100-preview.7.24407.12 [C:\Program Files\dotnet\sdk]
|
||||
// A line for a release candidate looks like this:
|
||||
// 11.0.100-rc.2.26504.105 [C:\Program Files\dotnet\sdk]
|
||||
|
||||
// We must have a number at the start so we can at least grab a major version.
|
||||
if (!line[0].IsDigit)
|
||||
{
|
||||
Log.EngineLogger.Error("This line doesn't appear to show an SDK version.");
|
||||
continue;
|
||||
}
|
||||
|
||||
DotNetVersion detectedVersion = default;
|
||||
|
||||
int indexOfSpace = line.IndexOf(' ');
|
||||
int indexOfDash = line.IndexOf('-');
|
||||
|
||||
int versionNumberEnd = line.Length;
|
||||
|
||||
if (indexOfDash > 0)
|
||||
versionNumberEnd = indexOfDash;
|
||||
else if (indexOfSpace > 0)
|
||||
versionNumberEnd = indexOfSpace;
|
||||
|
||||
StringView versionString = line.Substring(0, versionNumberEnd);
|
||||
|
||||
List<StringView> versionSplits = scope .(versionString.Split('.'));
|
||||
|
||||
if (versionSplits.IsEmpty)
|
||||
{
|
||||
Log.EngineLogger.Error("Line doesn't contain a valid version number.");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (versionSplits.Count >= 1 && int.Parse(versionSplits[0]) not case .Ok(out detectedVersion.Major))
|
||||
{
|
||||
Log.EngineLogger.Error($"Failed to parse \"major\" part of version ({versionSplits[0]}).");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (versionSplits.Count >= 2 && int.Parse(versionSplits[1]) not case .Ok(out detectedVersion.Minor))
|
||||
{
|
||||
Log.EngineLogger.Error($"Failed to parse \"minor\" part of version ({versionSplits[1]}).");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (versionSplits.Count >= 3 && int.Parse(versionSplits[2]) not case .Ok(out detectedVersion.Patch))
|
||||
{
|
||||
Log.EngineLogger.Error($"Failed to parse \"patch\" part of version ({versionSplits[2]}).");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (indexOfDash > 0)
|
||||
{
|
||||
StringView previewString = line.Substring(indexOfDash + 1);
|
||||
|
||||
int previewNumberStart = previewString.IndexOf('.') + 1;
|
||||
int secondDot = previewString.IndexOf('.', previewNumberStart);
|
||||
|
||||
int previewNumber = 0;
|
||||
|
||||
if (previewNumberStart > 0)
|
||||
{
|
||||
int length = previewString.Length - previewNumberStart;
|
||||
|
||||
if (secondDot > 0)
|
||||
{
|
||||
length = secondDot - previewNumberStart;
|
||||
}
|
||||
|
||||
StringView previewNumberString = previewString.Substring(previewNumberStart, length);
|
||||
|
||||
if (int.Parse(previewNumberString) not case .Ok(out previewNumber))
|
||||
{
|
||||
Log.EngineLogger.Warning("Could not determine the preview number.");
|
||||
}
|
||||
}
|
||||
|
||||
if (previewString.StartsWith("preview"))
|
||||
{
|
||||
detectedVersion.Type = .Preview(previewNumber);
|
||||
}
|
||||
else if (previewString.StartsWith("rc"))
|
||||
{
|
||||
detectedVersion.Type = .ReleaseCandidate(previewNumber);
|
||||
}
|
||||
else
|
||||
{
|
||||
detectedVersion.Type = .Unknown;
|
||||
Log.EngineLogger.Warning("Could not determine the preview-type for SDK.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
detectedVersion.Type = .Normal;
|
||||
}
|
||||
|
||||
Log.EngineLogger.Info($"Detected .Net SDK: {detectedVersion}.");
|
||||
|
||||
_settings.DotNetSdks.Add(detectedVersion);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.EngineLogger.Error($"Failed to execute `{_settings.DotNetExecutablePath} {argumentList}`");
|
||||
_testResult = .FailedToExecute;
|
||||
return .Err;
|
||||
}
|
||||
|
||||
if (_settings.DotNetSdks.Count == 0)
|
||||
{
|
||||
_testResult = .NoSdksFound;
|
||||
return .Err;
|
||||
}
|
||||
|
||||
return .Ok;
|
||||
}
|
||||
|
||||
/// Checks if one of the detected SDKs is at least the minimum required dotnet version.
|
||||
private Result<void> CheckMinimumVersion()
|
||||
{
|
||||
DotNetVersion maxVersion = _settings.GetLatestInstalledDotNetVersion();
|
||||
|
||||
if (maxVersion < ScriptEngine.MinDotNetVersion)
|
||||
{
|
||||
Log.EngineLogger.Error($"The latest detected .Net SDK ({maxVersion}) is older than the required minimum Version ({ScriptEngine.MinDotNetVersion}). Please install a newer .Net SDK or configure the dotnet executable in the settings.");
|
||||
_testResult = .TooOld;
|
||||
return .Err;
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.EngineLogger.Info($"Latest detected .Net SDK: {maxVersion}.");
|
||||
|
||||
return .Ok;
|
||||
}
|
||||
}
|
||||
|
||||
/// Checks if one of the detected SDKs is at least the minimum required dotnet version for the current project.
|
||||
void CheckProjectVersion()
|
||||
{
|
||||
/*DotNetVersion maxVersion = GetMaxVersion();
|
||||
|
||||
if (maxVersion < ScriptEngine.MinDotNetVersion)
|
||||
{
|
||||
Log.EngineLogger.Error($"The latest detected .Net SDK ({maxVersion}) is older than the required minimum Version ({ScriptEngine.MinDotNetVersion}). Please install a newer .Net SDK or configure the dotnet executable in the settings.");
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.EngineLogger.Info($"Latest detected .Net SDK: {maxVersion}.");
|
||||
}*/
|
||||
}
|
||||
}
|
||||
@@ -51,7 +51,7 @@ class DetectIDEsBackgroundTask : BackgroundTask
|
||||
_stage = .SearchRider;
|
||||
FindRider();
|
||||
|
||||
return .Finished;
|
||||
return .Finish;
|
||||
}
|
||||
|
||||
public override void OnRenderPopup()
|
||||
|
||||
@@ -6,6 +6,9 @@ using Bon;
|
||||
using GlitchyEngine;
|
||||
using System.Threading;
|
||||
using System.Linq;
|
||||
using GlitchyEngine.Scripting;
|
||||
using GlitchyEditor.Multithreading;
|
||||
using GlitchyEngine.Math;
|
||||
|
||||
using static GlitchyEditor.SettingsWindow;
|
||||
|
||||
@@ -50,6 +53,20 @@ struct SettingAttribute : Attribute
|
||||
}
|
||||
}
|
||||
|
||||
/// Fields with this Attribute will be exposed as settings.
|
||||
[AttributeUsage(AttributeTargets.StaticField, .ReflectAttribute)]
|
||||
struct SettingValueAttribute : Attribute
|
||||
{
|
||||
public String Name;
|
||||
public String Tooltip;
|
||||
|
||||
public this(String name, String tooltip = "")
|
||||
{
|
||||
Name = name;
|
||||
Tooltip = tooltip;
|
||||
}
|
||||
}
|
||||
|
||||
/// Fields with this Attribute will be exposed as settings.
|
||||
[AttributeUsage(.Method, .ReflectAttribute | .AlwaysIncludeTarget)]
|
||||
struct CustomSettingRendererAttribute : Attribute
|
||||
@@ -236,9 +253,40 @@ class IdeInstallation
|
||||
// This would however be quite complicated to implement well, when looking at how different Visual Studio and Rider already are.
|
||||
}
|
||||
|
||||
[Reflect]
|
||||
enum RebuildOnPlay
|
||||
{
|
||||
[SettingValue("Off", "The scripts will not be rebuild when entering play mode.")]
|
||||
Off,
|
||||
[SettingValue("Always", "The scripts will always be rebuild when entering play mode.")]
|
||||
Always,
|
||||
[SettingValue("When any Asset changed", """
|
||||
The scripts will automatically be rebuild when any asset in asset-directory changed, even if it is not necessary for the build process.
|
||||
This can be helpful if you include files in your build-process that are not detected by the heuristic up to date check.
|
||||
""")]
|
||||
WhenAnyAssetsChanged,
|
||||
[SettingValue("When the fancy dancy heuristic check says so.", """
|
||||
A highly sophisticated heuristic will determine if a rebuild is required.
|
||||
""")]
|
||||
UseFastUpToDateCheck
|
||||
}
|
||||
|
||||
[Reflect]
|
||||
class ScriptSettings
|
||||
{
|
||||
private List<DotNetVersion> _dotNetSdks = new .() ~ delete _;
|
||||
public List<DotNetVersion> DotNetSdks => _dotNetSdks;
|
||||
|
||||
[BonInclude]
|
||||
private String _dotnetExePath = new .("dotnet") ~ delete _;
|
||||
private TestDotnetBackgroundTask.TestResult _dotnetTestResult = .None;
|
||||
|
||||
public StringView DotNetExecutablePath
|
||||
{
|
||||
get => _dotnetExePath;
|
||||
set => String.NewOrSet!(_dotnetExePath, value);
|
||||
}
|
||||
|
||||
[BonInclude]
|
||||
private List<IdeInstallation> _ideInstallations = new .() ~ DeleteContainerAndItems!(_);
|
||||
|
||||
@@ -254,6 +302,12 @@ class ScriptSettings
|
||||
private bool _lookedForVs = false;
|
||||
private bool _lookedForRider = false;
|
||||
|
||||
[Setting("Tools", "Rebuild scripts on play mode", "Configures if and how the scripts will be rebuilt every time the play mode is entered."), BonInclude]
|
||||
public RebuildOnPlay RebuildOnPlayMode = .UseFastUpToDateCheck;
|
||||
|
||||
[Setting("Tools", "Automatically rebuild changed scripts", "If active, the scripts will be rebuilt every time the user presses play."), BonInclude]
|
||||
public bool AutoRebuildOnChange = true;
|
||||
|
||||
/// Enters the lock and gets the list of Ide installations.
|
||||
public Monitor.MonitorLockInstance EnterAndGetIdeInstallations(out List<IdeInstallation> ideInstallations)
|
||||
{
|
||||
@@ -275,6 +329,18 @@ class ScriptSettings
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (_dotNetSdks.Count == 0)
|
||||
{
|
||||
TestDotnetInstallation();
|
||||
}
|
||||
}
|
||||
|
||||
private TestDotnetBackgroundTask TestDotnetInstallation()
|
||||
{
|
||||
TestDotnetBackgroundTask task = new TestDotnetBackgroundTask(this, null){ DeleteWhenEnded = true };
|
||||
EditorApp.Instance.BackgroundTaskManager.StartBackgroundTask(task);
|
||||
return task;
|
||||
}
|
||||
|
||||
[CustomSettingRenderer("Tools")]
|
||||
@@ -282,7 +348,16 @@ class ScriptSettings
|
||||
{
|
||||
bool settingsChanged = false;
|
||||
|
||||
ImGui.Text("IDE:");
|
||||
ImGui.Text("IDE");
|
||||
|
||||
ImGui.SameLine(ImGui.GetContentRegionAvail().x - ImGui.CalcTextSize("Detect IDEs...").x - 2 * ImGui.GetStyle().FramePadding.x);
|
||||
|
||||
if (ImGui.Button("Detect IDEs..."))
|
||||
{
|
||||
EditorApp.Instance.BackgroundTaskManager.StartBackgroundTask(new DetectIDEsBackgroundTask(this){ DeleteWhenEnded = true });
|
||||
}
|
||||
|
||||
ImGui.TableNextColumn();
|
||||
|
||||
if (ImGui.BeginCombo("##ide", ActiveIde?.Name.ToScopeCStr!()))
|
||||
{
|
||||
@@ -327,13 +402,71 @@ class ScriptSettings
|
||||
ImGui.EndCombo();
|
||||
}
|
||||
|
||||
if (ImGui.Button("Detect IDEs..."))
|
||||
ImGui.TableNextRow();
|
||||
ImGui.TableNextColumn();
|
||||
|
||||
ImGui.Text("DotNet Executable Path");
|
||||
|
||||
ImGui.SameLine(ImGui.GetContentRegionAvail().x - ImGui.CalcTextSize("Test").x - 2 * ImGui.GetStyle().FramePadding.x);
|
||||
|
||||
if (ImGui.Button("Test"))
|
||||
{
|
||||
EditorApp.Instance.BackgroundTaskManager.StartBackgroundTask(new DetectIDEsBackgroundTask(this){ DeleteWhenEnded = true });
|
||||
_dotnetTestResult = .None;
|
||||
TestDotnetInstallation().ContinueWith(new (task) => {
|
||||
_dotnetTestResult = ((TestDotnetBackgroundTask)task).TestResult;
|
||||
});
|
||||
}
|
||||
|
||||
ImGui.TableNextColumn();
|
||||
|
||||
if (ImGui.InputText("##dotnetPath", _dotnetExePath))
|
||||
{
|
||||
settingsChanged = true;
|
||||
}
|
||||
|
||||
switch (_dotnetTestResult)
|
||||
{
|
||||
case .None:
|
||||
// Nothing to do.
|
||||
case .Ok:
|
||||
ImGui.PushStyleColor(.Text, ColorRGBA.Green);
|
||||
ImGui.TextUnformatted(scope $"Dotnet works and found latest version: {GetLatestInstalledDotNetVersion()}");
|
||||
ImGui.PopStyleColor();
|
||||
case .Timeout:
|
||||
ImGui.PushStyleColor(.Text, ColorRGBA.Red);
|
||||
ImGui.TextUnformatted(scope $"Dotnet timed out.");
|
||||
ImGui.PopStyleColor();
|
||||
case .FailedToExecute:
|
||||
ImGui.PushStyleColor(.Text, ColorRGBA.Red);
|
||||
ImGui.TextUnformatted(scope $"Failed to execute dotnet.");
|
||||
ImGui.PopStyleColor();
|
||||
case .NoSdksFound:
|
||||
ImGui.PushStyleColor(.Text, ColorRGBA.Red);
|
||||
ImGui.TextUnformatted(scope $"Dotnet works but no SDK found.");
|
||||
ImGui.PopStyleColor();
|
||||
case .TooOld:
|
||||
ImGui.PushStyleColor(.Text, ColorRGBA.Red);
|
||||
ImGui.TextUnformatted(scope $"Dotnet works but latest installed version {GetLatestInstalledDotNetVersion()} is too old.");
|
||||
ImGui.PopStyleColor();
|
||||
}
|
||||
|
||||
return settingsChanged;
|
||||
}
|
||||
|
||||
public DotNetVersion GetLatestInstalledDotNetVersion()
|
||||
{
|
||||
DotNetVersion maxVersion = .(-1, -1, -1, .Unknown);
|
||||
|
||||
for (DotNetVersion version in _dotNetSdks)
|
||||
{
|
||||
if (version > maxVersion)
|
||||
{
|
||||
maxVersion = version;
|
||||
}
|
||||
}
|
||||
|
||||
return maxVersion;
|
||||
}
|
||||
}
|
||||
|
||||
[Reflect]
|
||||
|
||||
@@ -106,8 +106,6 @@ namespace GlitchyEditor
|
||||
|
||||
void ScanForSettings(Object container)
|
||||
{
|
||||
Log.EngineLogger.Info($"Visiting type: {container.GetType().GetName(.. scope .())}");
|
||||
|
||||
Type type = container.GetType();
|
||||
|
||||
for (var field in type.GetFields())
|
||||
@@ -138,8 +136,6 @@ namespace GlitchyEditor
|
||||
|
||||
for (let method in type.GetMethods(.Instance | .Static | .Public | .NonPublic))
|
||||
{
|
||||
Log.EngineLogger.Info($"Visiting method: {method.Name}");
|
||||
|
||||
Result<CustomSettingRendererAttribute> rendererResult = method.GetCustomAttribute<CustomSettingRendererAttribute>();
|
||||
|
||||
if (rendererResult case .Ok(let rendererInfo))
|
||||
@@ -367,12 +363,23 @@ namespace GlitchyEditor
|
||||
// TODO: handle multiple Flags (as a separate enum type handler though!)
|
||||
|
||||
StringView currentName = "";
|
||||
StringView currentTooltip = "";
|
||||
|
||||
for (let (name, value) in Enum.GetEnumerator(fieldInfo.FieldType))
|
||||
{
|
||||
if (value == underlyingValue)
|
||||
{
|
||||
if (fieldInfo.FieldType.GetField(@name.Index) case .Ok(FieldInfo info) &&
|
||||
info.GetCustomAttribute<SettingValueAttribute>() case .Ok(SettingValueAttribute settingValue))
|
||||
{
|
||||
currentName = settingValue.Name;
|
||||
currentTooltip = settingValue.Tooltip;
|
||||
}
|
||||
else
|
||||
{
|
||||
currentName = name;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -383,7 +390,17 @@ namespace GlitchyEditor
|
||||
{
|
||||
bool isSelected = (name == currentName);
|
||||
|
||||
if (ImGui.Selectable(name.ToScopeCStr!(), isSelected))
|
||||
StringView valueName = name;
|
||||
StringView valueTooltip = "";
|
||||
|
||||
if (fieldInfo.FieldType.GetField(@name.Index) case .Ok(FieldInfo info) &&
|
||||
info.GetCustomAttribute<SettingValueAttribute>() case .Ok(SettingValueAttribute settingValue))
|
||||
{
|
||||
valueName = settingValue.Name;
|
||||
valueTooltip = settingValue.Tooltip;
|
||||
}
|
||||
|
||||
if (ImGui.Selectable(valueName.ToScopeCStr!(), isSelected))
|
||||
{
|
||||
// Set value in field reference
|
||||
switch (fieldInfo.FieldType.Size)
|
||||
@@ -397,10 +414,20 @@ namespace GlitchyEditor
|
||||
if (!isSelected)
|
||||
_settingsChanged = true;
|
||||
}
|
||||
|
||||
if (!valueTooltip.IsEmpty)
|
||||
{
|
||||
ImGui.AttachTooltip(valueTooltip);
|
||||
}
|
||||
}
|
||||
|
||||
ImGui.EndCombo();
|
||||
}
|
||||
|
||||
if (!currentTooltip.IsEmpty)
|
||||
{
|
||||
ImGui.AttachTooltip(currentTooltip);
|
||||
}
|
||||
}
|
||||
|
||||
if (setting.Name == _SettingToHighlight)
|
||||
@@ -420,6 +447,9 @@ namespace GlitchyEditor
|
||||
|
||||
for (let methodBinding in category._methodBindings)
|
||||
{
|
||||
ImGui.TableNextRow();
|
||||
ImGui.TableNextColumn();
|
||||
|
||||
if (methodBinding.Method.Invoke(methodBinding.Method.IsStatic ? null : methodBinding.SettingsObject, category) case .Ok(var returnValue))
|
||||
{
|
||||
_settingsChanged |= returnValue.Get<bool>();
|
||||
|
||||
@@ -17,7 +17,7 @@ class BasicBenchmark
|
||||
Console.WriteLine(Directory.GetCurrentDirectory(.. scope .()));
|
||||
ScriptEngine.Init();
|
||||
|
||||
ScriptEngine.SetAppAssemblyPath(@"..\GlitchyEngine.Test\content\TestProject\.cache\bin\TestProject.dll");
|
||||
ScriptEngine.SetAppAssemblyPath(@"..\GlitchyEngine.Test\content\TestProject\.cache\bin\TestProject.dll", false);
|
||||
}
|
||||
|
||||
protected static void Shutdown()
|
||||
|
||||
@@ -0,0 +1,179 @@
|
||||
{
|
||||
Version = 1,
|
||||
Entities = [
|
||||
{
|
||||
Id = 8893155135649576304,
|
||||
NameComponent = {
|
||||
Name = "Camera"
|
||||
},
|
||||
TransformComponent = {
|
||||
Position = {
|
||||
X = 0,
|
||||
Y = 2,
|
||||
Z = -5
|
||||
},
|
||||
Rotation = {
|
||||
X = 0,
|
||||
Y = 0.21643962,
|
||||
Z = 0,
|
||||
W = 0.976296
|
||||
},
|
||||
Scale = {
|
||||
X = 1,
|
||||
Y = 1,
|
||||
Z = 1
|
||||
},
|
||||
EditorEulerRotation = {
|
||||
X = 0,
|
||||
Y = 0.43633237,
|
||||
Z = 0
|
||||
}
|
||||
},
|
||||
CameraComponent = {
|
||||
Primary = true,
|
||||
ProjectionType = .InfinitePerspective,
|
||||
PerspectiveFovY = 1.3089969,
|
||||
PerspectiveNearPlane = 0.1,
|
||||
PerspectiveFarPlane = 10000,
|
||||
OrthographicHeight = 10,
|
||||
OrthographicNearPlane = 0,
|
||||
OrthographicFarPlane = 10,
|
||||
AspectRatio = 1.9840086,
|
||||
FixedAspectRatio = false
|
||||
},
|
||||
Editor = {
|
||||
Flags = .Default
|
||||
}
|
||||
},
|
||||
{
|
||||
Id = 14812165297099037146,
|
||||
NameComponent = {
|
||||
Name = "Light"
|
||||
},
|
||||
TransformComponent = {
|
||||
Position = {
|
||||
X = -3,
|
||||
Y = 4,
|
||||
Z = -1.5
|
||||
},
|
||||
Rotation = {
|
||||
X = 0.23977584,
|
||||
Y = 0.6143275,
|
||||
Z = 0.031567074,
|
||||
W = 0.7510744
|
||||
},
|
||||
Scale = {
|
||||
X = 1,
|
||||
Y = 1,
|
||||
Z = 1
|
||||
},
|
||||
EditorEulerRotation = {
|
||||
X = 0.3490659,
|
||||
Y = 1.3089968,
|
||||
Z = 0.34906587
|
||||
}
|
||||
},
|
||||
LightComponent = {
|
||||
LightType = .Directional,
|
||||
Illuminance = 10,
|
||||
Color = {
|
||||
R = 1,
|
||||
G = 0.9500002,
|
||||
B = 0.8
|
||||
}
|
||||
},
|
||||
Editor = {
|
||||
Flags = .Default
|
||||
}
|
||||
},
|
||||
{
|
||||
Id = 4185051642788402424,
|
||||
NameComponent = {
|
||||
Name = "Entity"
|
||||
},
|
||||
TransformComponent = {
|
||||
Position = {
|
||||
X = 0,
|
||||
Y = 0,
|
||||
Z = 0
|
||||
},
|
||||
Rotation = {
|
||||
X = 0,
|
||||
Y = 0,
|
||||
Z = 0,
|
||||
W = 1
|
||||
},
|
||||
Scale = {
|
||||
X = 1,
|
||||
Y = 1,
|
||||
Z = 1
|
||||
},
|
||||
EditorEulerRotation = {
|
||||
X = 0,
|
||||
Y = 0,
|
||||
Z = 0
|
||||
}
|
||||
},
|
||||
ScriptComponent = {
|
||||
ScriptClass = "TestProject.Assets.Scripts.AdvancedSerializationTest",
|
||||
Fields = (TestProject.Assets.Scripts.AdvancedSerializationTest){
|
||||
ID = 4185051642788402424,
|
||||
LeTuple.Item1 = (int32)101,
|
||||
LeTuple.Item2.X = (float)49,
|
||||
LeTuple.Item2.Y = (float)31,
|
||||
LeTuple.Item3 = &16946239429800937368,
|
||||
LeListDeTuple = &13357518334354818316,
|
||||
GenericStructField.MyField = (float)-56,
|
||||
GenericClassField = &6770493598825812026
|
||||
}
|
||||
},
|
||||
Editor = {
|
||||
Flags = .Default
|
||||
}
|
||||
}
|
||||
],
|
||||
ReferencedObjects = [
|
||||
(TestProject.BClass){
|
||||
ID = 16946239429800937368,
|
||||
F = (float)131
|
||||
},
|
||||
(System.Collections.Generic.List`1[System.ValueTuple`3[System.Int32,GlitchyEngine.Math.float2,TestProject.BClass]]){
|
||||
ID = 13357518334354818316,
|
||||
Count = (int32)4,
|
||||
0.Item1 = (int32)64,
|
||||
0.Item2.X = (float)-81,
|
||||
0.Item2.Y = (float)-118,
|
||||
0.Item3 = &14597969159961685574,
|
||||
1.Item1 = (int32)0,
|
||||
1.Item2.X = (float)0,
|
||||
1.Item2.Y = (float)0,
|
||||
1.Item3 = &0,
|
||||
2.Item1 = (int32)73,
|
||||
2.Item2.X = (float)165,
|
||||
2.Item2.Y = (float)115,
|
||||
2.Item3 = &15752578204681304901,
|
||||
3.Item1 = (int32)0,
|
||||
3.Item2.X = (float)0,
|
||||
3.Item2.Y = (float)0,
|
||||
3.Item3 = &0
|
||||
},
|
||||
(TestProject.BClass){
|
||||
ID = 14597969159961685574,
|
||||
F = (float)23
|
||||
},
|
||||
(TestProject.BClass){
|
||||
ID = 15752578204681304901,
|
||||
F = (float)159
|
||||
},
|
||||
(TestProject.Assets.Scripts.SimpleGenericClass`1[System.Double]){
|
||||
ID = 6770493598825812026,
|
||||
MyField = (double)0.9599999785423279
|
||||
}
|
||||
],
|
||||
StaticFields = [
|
||||
(TestProject.SerializationTest){
|
||||
ID = 1460275328679732402,
|
||||
StaticNumber = (int32)0
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
{
|
||||
AssetLoader = null,
|
||||
Config = null,
|
||||
Importer = null,
|
||||
ImporterConfig = null,
|
||||
Processor = null,
|
||||
ProcessorConfig = null,
|
||||
Exporter = null,
|
||||
ExporterConfig = null,
|
||||
AssetHandle = 4008662279183989969
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
using GlitchyEngine;
|
||||
using GlitchyEngine.Math;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace TestProject.Assets.Scripts;
|
||||
|
||||
public class SimpleGenericClass<T>
|
||||
{
|
||||
public T MyField;
|
||||
}
|
||||
|
||||
public struct SimpleGenericStruct<T>
|
||||
{
|
||||
public T MyField;
|
||||
}
|
||||
|
||||
public class AdvancedSerializationTest : Entity
|
||||
{
|
||||
public (int Prim, float2 Struc, BClass Ref) LeTuple;
|
||||
|
||||
public List<(int Prim, float2 Struc, BClass Ref)> LeListDeTuple;
|
||||
|
||||
public SimpleGenericStruct<float> GenericStructField = new SimpleGenericStruct<float>();
|
||||
|
||||
public SimpleGenericClass<double> GenericClassField = new SimpleGenericClass<double>();
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
{
|
||||
AssetLoader = null,
|
||||
Config = null,
|
||||
Importer = null,
|
||||
ImporterConfig = null,
|
||||
Processor = null,
|
||||
ProcessorConfig = null,
|
||||
Exporter = null,
|
||||
ExporterConfig = null,
|
||||
AssetHandle = 16179505410974622627
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
{
|
||||
AssetLoader = null,
|
||||
Config = null,
|
||||
Importer = null,
|
||||
ImporterConfig = null,
|
||||
Processor = null,
|
||||
ProcessorConfig = null,
|
||||
Exporter = null,
|
||||
ExporterConfig = null,
|
||||
AssetHandle = 13036819508142753970
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
{
|
||||
AssetLoader = null,
|
||||
Config = null,
|
||||
Importer = null,
|
||||
ImporterConfig = null,
|
||||
Processor = null,
|
||||
ProcessorConfig = null,
|
||||
Exporter = null,
|
||||
ExporterConfig = null,
|
||||
AssetHandle = 2840305762073418465
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
<PropertyGroup>
|
||||
<!-- General configuration -->
|
||||
<AssemblyTitle>TestProject</AssemblyTitle>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<OutputType>Library</OutputType>
|
||||
<Nullable>enable</Nullable>
|
||||
<!-- Define the output path -->
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
<Solution>
|
||||
<Project Path="TestProject.csproj"/>
|
||||
<Project Path="D:\Development\Projects\Beef\GlitchyEngine\ScriptCore\ScriptCore.csproj"/>
|
||||
<Project Path="D:\Development\Projects\Beef\GlitchyEngine\ScriptCoreGenerator\ScriptCoreGenerator.csproj"/>
|
||||
<Project Path="D:\Development\Projects\Beef\GlitchyEngine\ScriptCoreGenerator.Test\ScriptCoreGenerator.Test.csproj"/>
|
||||
<Project Path="D:\Development\Projects\Beef\GlitchyEngine\vendor\ImGui.NET\src\ImGui.NET\ImGui.NET.csproj"/>
|
||||
</Solution>
|
||||
+57
-7
@@ -1,11 +1,28 @@
|
||||
// Based on the Decimal implementation from the Mono Runtime: https://github.com/mono/mono/blob/0f53e9e151d92944cacab3e24ac359410c606df6/mcs/class/referencesource/mscorlib/system/decimal.cs
|
||||
// Originally licensed under the MIT license.
|
||||
|
||||
using System;
|
||||
using Bon.Integrated;
|
||||
using Bon;
|
||||
using Bon.Integrated;
|
||||
|
||||
namespace GlitchyEngine.Scripting;
|
||||
|
||||
/// A struct providing access to the components of a mono decimal.
|
||||
struct MonoDecimal
|
||||
/// A struct compatible with the Decimal type form the .Net Runtime.
|
||||
struct Decimal
|
||||
{
|
||||
// Sign mask for the flags field. A value of zero in this bit indicates a
|
||||
// positive Decimal value, and a value of one in this bit indicates a
|
||||
// negative Decimal value.
|
||||
//
|
||||
// Look at OleAut's DECIMAL_NEG constant to check for negative values
|
||||
// in native code.
|
||||
private const uint32 SignMask = 0x80000000u;
|
||||
|
||||
// Scale mask for the flags field. This byte in the flags field contains
|
||||
// the power of 10 to divide the Decimal value by. The scale byte must
|
||||
// contain a value between 0 and 28 inclusive.
|
||||
private const uint32 ScaleMask = 0x00FF0000u;
|
||||
|
||||
[Bitfield<uint16>(.Private, .BitsAt(16, 0), "_dontUse", .Read)]
|
||||
[Bitfield<uint8>(.Public, .BitsAt(8, 16), "Exponent")]
|
||||
[Bitfield<uint8>(.Private, .BitsAt(7, 24), "_dontUse2")]
|
||||
@@ -20,15 +37,48 @@ struct MonoDecimal
|
||||
|
||||
static this
|
||||
{
|
||||
gBonEnv.typeHandlers.Add(typeof(MonoDecimal),
|
||||
gBonEnv.typeHandlers.Add(typeof(Decimal),
|
||||
((.)new => AssetSerialize, new => AssetDeserialize));
|
||||
}
|
||||
|
||||
public this()
|
||||
{
|
||||
_high = 0;
|
||||
_low = 0;
|
||||
_mid = 0;
|
||||
_flags = 0;
|
||||
}
|
||||
|
||||
public this(int value)
|
||||
{
|
||||
var value;
|
||||
if (value >= 0)
|
||||
{
|
||||
_flags = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
_flags = SignMask;
|
||||
value = -value;
|
||||
}
|
||||
_low = (uint32)value;
|
||||
_mid = (uint32)(value >> 32);
|
||||
_high = 0;
|
||||
}
|
||||
|
||||
public this(uint value)
|
||||
{
|
||||
_flags = 0;
|
||||
_low = (uint32)value;
|
||||
_mid = (uint32)(value >> 32);
|
||||
_high = 0;
|
||||
}
|
||||
|
||||
static void AssetSerialize(BonWriter writer, ValueView value, BonEnvironment environment, SerializeValueState state)
|
||||
{
|
||||
Log.EngineLogger.Assert(value.type == typeof(Self));
|
||||
|
||||
MonoDecimal decimal = value.Get<MonoDecimal>();
|
||||
Decimal decimal = value.Get<Decimal>();
|
||||
|
||||
decimal.ToString(writer.outStr);
|
||||
}
|
||||
@@ -86,11 +136,11 @@ struct MonoDecimal
|
||||
strBuffer.Append('m');
|
||||
}
|
||||
|
||||
public static Result<MonoDecimal> Parse(StringView strBuffer)
|
||||
public static Result<Decimal> Parse(StringView strBuffer)
|
||||
{
|
||||
var strBuffer;
|
||||
|
||||
MonoDecimal result = .();
|
||||
Decimal result = .();
|
||||
|
||||
if (strBuffer.StartsWith('-'))
|
||||
{
|
||||
@@ -0,0 +1,87 @@
|
||||
using System;
|
||||
namespace GlitchyEngine.Scripting;
|
||||
|
||||
enum DotNetVersionType
|
||||
{
|
||||
case Normal;
|
||||
case Preview(int Number);
|
||||
case ReleaseCandidate(int Number);
|
||||
case Unknown;
|
||||
|
||||
public int GetSortingOrder()
|
||||
{
|
||||
switch (this)
|
||||
{
|
||||
case .Normal:
|
||||
return 3;
|
||||
case .ReleaseCandidate:
|
||||
return 2;
|
||||
case .Preview:
|
||||
return 1;
|
||||
case .Unknown:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct DotNetVersion
|
||||
{
|
||||
public int Major;
|
||||
public int Minor;
|
||||
public int Patch;
|
||||
|
||||
public DotNetVersionType Type;
|
||||
|
||||
public this()
|
||||
{
|
||||
this = default;
|
||||
}
|
||||
|
||||
public this(int major, int minor, int patch, DotNetVersionType type)
|
||||
{
|
||||
Major = major;
|
||||
Minor = minor;
|
||||
Patch = patch;
|
||||
Type = type;
|
||||
}
|
||||
|
||||
public override void ToString(String outBuffer)
|
||||
{
|
||||
outBuffer.AppendF($"{Major}.{Minor}.{Patch}");
|
||||
|
||||
switch (Type)
|
||||
{
|
||||
case .Normal:
|
||||
// Nothing to do.
|
||||
case .Preview(int Number):
|
||||
outBuffer.AppendF($" (Preview {Number})");
|
||||
case .ReleaseCandidate(int Number):
|
||||
outBuffer.AppendF($" (Release Candidate {Number})");
|
||||
case .Unknown:
|
||||
outBuffer.Append(" (Unknown release type)");
|
||||
}
|
||||
}
|
||||
|
||||
public static int operator <=>(DotNetVersion lhs, DotNetVersion rhs)
|
||||
{
|
||||
if (lhs.Major != rhs.Major)
|
||||
if (lhs.Major > rhs.Major)
|
||||
return 1;
|
||||
else
|
||||
return -1;
|
||||
|
||||
if (lhs.Minor != rhs.Minor)
|
||||
if (lhs.Minor > rhs.Minor)
|
||||
return 1;
|
||||
else
|
||||
return -1;
|
||||
|
||||
if (lhs.Patch != rhs.Patch)
|
||||
if (lhs.Patch > rhs.Patch)
|
||||
return 1;
|
||||
else
|
||||
return -1;
|
||||
|
||||
return lhs.Type.GetSortingOrder() <=> rhs.Type.GetSortingOrder();
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using Mono;
|
||||
using GlitchyEngine.Core;
|
||||
using System.Diagnostics;
|
||||
|
||||
|
||||
@@ -48,17 +48,6 @@ class EntitySerializerWrapper : NewScriptClass
|
||||
_createSerializationContextMethod(serializerPtr);
|
||||
}
|
||||
|
||||
/*public void ClearSerializationContext(ScriptInstanceSerializer serializer)
|
||||
{
|
||||
void* serializerPtr = Internal.UnsafeCastToPtr(serializer);
|
||||
|
||||
MonoException* exception = null;
|
||||
_clearSerializationContextMethod(serializerPtr, &exception);
|
||||
|
||||
if (exception != null)
|
||||
ScriptEngine.[Friend]HandleMonoException(exception, null);
|
||||
}*/
|
||||
|
||||
public void DestroySerializationContext(ScriptInstanceSerializer serializer)
|
||||
{
|
||||
void* serializerPtr = Internal.UnsafeCastToPtr(serializer);
|
||||
|
||||
@@ -89,6 +89,9 @@ static class ScriptEngine
|
||||
// This would probably require a separate small project that just handles the script-engine interface.
|
||||
public const String ScriptCorePath = "Resources/Scripts/ScriptCore.dll";
|
||||
|
||||
/// The minimum supported .Net Version.
|
||||
public const DotNetVersion MinDotNetVersion = .(10, 0, 0, .Normal);
|
||||
|
||||
private static Scene s_Context ~ _?.ReleaseRef();
|
||||
|
||||
private static EngineClasses _classes = new .() ~ delete _;
|
||||
@@ -186,7 +189,6 @@ static class ScriptEngine
|
||||
public static void Init()
|
||||
{
|
||||
InitRuntime();
|
||||
//InitMono();
|
||||
|
||||
LoadScriptAssemblies();
|
||||
}
|
||||
@@ -210,6 +212,22 @@ static class ScriptEngine
|
||||
}
|
||||
|
||||
static bool _requestingReload = false;
|
||||
static bool _assemblyWatcherSuspended = false;
|
||||
|
||||
public static void SuspendAssemblyWatcher()
|
||||
{
|
||||
Log.EngineLogger.Trace("Suspending assembly watching");
|
||||
|
||||
_assemblyWatcherSuspended = true;
|
||||
_userAssemblyWatcher?.StopRaisingEvents();
|
||||
}
|
||||
|
||||
public static void ResumeAssemblyWatcher()
|
||||
{
|
||||
Log.EngineLogger.Trace("Resuming assembly watching");
|
||||
_assemblyWatcherSuspended = false;
|
||||
_userAssemblyWatcher?.StartRaisingEvents();
|
||||
}
|
||||
|
||||
static void InitAssemblyWatcher()
|
||||
{
|
||||
@@ -242,6 +260,7 @@ static class ScriptEngine
|
||||
ReloadAssemblies(retainScriptData: true);
|
||||
|
||||
_requestingReload = false;
|
||||
if (_assemblyWatcherSuspended)
|
||||
_userAssemblyWatcher.StartRaisingEvents();
|
||||
|
||||
return true;
|
||||
@@ -250,6 +269,7 @@ static class ScriptEngine
|
||||
});
|
||||
}
|
||||
|
||||
if (_assemblyWatcherSuspended)
|
||||
_userAssemblyWatcher.StartRaisingEvents();
|
||||
}
|
||||
|
||||
@@ -354,8 +374,6 @@ static class ScriptEngine
|
||||
if (script.Instance != null)
|
||||
script.Instance = null;
|
||||
|
||||
script.ScriptClassName = null;
|
||||
|
||||
DestroyInstance(entityId);
|
||||
}
|
||||
|
||||
@@ -435,26 +453,20 @@ static class ScriptEngine
|
||||
|
||||
LoadScriptAssemblies();
|
||||
|
||||
|
||||
if (retainScriptData)
|
||||
{
|
||||
if (Context != null)
|
||||
{
|
||||
Debug.Profiler.ProfileScope!("Initialize Instances");
|
||||
|
||||
// We need to create a new instance for every entity
|
||||
for (let (id, scriptInstance) in _entityScriptInstances)
|
||||
for (let (ecsEntity, scriptComponent) in Context.GetEntities<ScriptComponent>())
|
||||
{
|
||||
if (Context.GetEntityByID(id) case .Ok(let entity))
|
||||
{
|
||||
ScriptComponent* script = entity.GetComponent<ScriptComponent>();
|
||||
InitializeInstance(entity, script);
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.EngineLogger.AssertDebug(false, "Entities script was just serialized but the entity doesn't exist anymore.");
|
||||
}
|
||||
InitializeInstance(Entity(ecsEntity, Context), scriptComponent);
|
||||
}
|
||||
}
|
||||
|
||||
if (retainScriptData)
|
||||
{
|
||||
contextSerializer.DeserializeScriptInstances();
|
||||
}
|
||||
|
||||
|
||||
@@ -59,6 +59,12 @@ struct RegisterCallAttribute : Attribute
|
||||
{
|
||||
public bool EngineResultAsBool { get; set mut; }
|
||||
public bool IsExtension { get; set mut; }
|
||||
/**
|
||||
* If true, marks the method as guaranteed short running.
|
||||
* A GuaranteedShortRunning function should have a VERY short runtime (< 1μs), must NEVER block, and NEVER call back into managed code!
|
||||
* This allows the script glue infrastructure to apply some optimizations (i.e. SuppressGCTransition in C#)
|
||||
*/
|
||||
public bool GuaranteedShortRunning {get; set mut; }
|
||||
}
|
||||
|
||||
struct TypeTranslationTemplate
|
||||
@@ -147,6 +153,7 @@ struct EngineFunctionsGeneratorAttribute : Attribute, IComptimeTypeApply
|
||||
{{
|
||||
"name": "{method.Name}",
|
||||
"return_type": "{GetTypeInfo(method.ReturnType, registerCallAttribute)}",
|
||||
"guaranteed_short_running": {registerCallAttribute.GuaranteedShortRunning ? "true" : "false"},
|
||||
"parameters": [{parameters}
|
||||
]
|
||||
}},
|
||||
@@ -337,7 +344,7 @@ static class ScriptGlue
|
||||
});
|
||||
}
|
||||
|
||||
/// Gets the entity with the given id. Throws a mono exception, if the entity doesn't exist.
|
||||
/// Gets the entity with the given id. Returns an .Err if it doesn't exist.
|
||||
static Result<Entity> GetEntitySafe(UUID entityId)
|
||||
{
|
||||
if (ScriptEngine.Context.GetEntityByID(entityId) case .Ok(let entity))
|
||||
@@ -453,7 +460,7 @@ static class ScriptGlue
|
||||
}
|
||||
}
|
||||
|
||||
[RegisterCall, CallingConvention(.Cdecl)]
|
||||
[RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
|
||||
static StringView GetLastExceptionMessage()
|
||||
{
|
||||
return _lastExceptionMessage;
|
||||
@@ -509,32 +516,32 @@ static class ScriptGlue
|
||||
|
||||
#region Input
|
||||
|
||||
[RegisterCall, CallingConvention(.Cdecl)]
|
||||
[RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
|
||||
static bool Input_IsKeyPressed(Key key) => Input.IsKeyPressed(key);
|
||||
|
||||
[RegisterCall, CallingConvention(.Cdecl)]
|
||||
[RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
|
||||
static bool Input_IsKeyReleased(Key key) => Input.IsKeyReleased(key);
|
||||
|
||||
[RegisterCall, CallingConvention(.Cdecl)]
|
||||
[RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
|
||||
static bool Input_IsKeyToggled(Key key) => Input.IsKeyToggled(key);
|
||||
|
||||
[RegisterCall, CallingConvention(.Cdecl)]
|
||||
[RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
|
||||
static bool Input_IsKeyPressing(Key key) => Input.IsKeyPressing(key);
|
||||
|
||||
[RegisterCall, CallingConvention(.Cdecl)]
|
||||
[RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
|
||||
static bool Input_IsKeyReleasing(Key key) => Input.IsKeyReleasing(key);
|
||||
|
||||
|
||||
[RegisterCall, CallingConvention(.Cdecl)]
|
||||
[RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
|
||||
static bool Input_IsMouseButtonPressed(MouseButton mouseButton) => Input.IsMouseButtonPressed(mouseButton);
|
||||
|
||||
[RegisterCall, CallingConvention(.Cdecl)]
|
||||
[RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
|
||||
static bool Input_IsMouseButtonReleased(MouseButton mouseButton) => Input.IsMouseButtonReleased(mouseButton);
|
||||
|
||||
[RegisterCall, CallingConvention(.Cdecl)]
|
||||
[RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
|
||||
static bool Input_IsMouseButtonPressing(MouseButton mouseButton) => Input.IsMouseButtonPressing(mouseButton);
|
||||
|
||||
[RegisterCall, CallingConvention(.Cdecl)]
|
||||
[RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
|
||||
static bool Input_IsMouseButtonReleasing(MouseButton mouseButton) => Input.IsMouseButtonReleasing(mouseButton);
|
||||
|
||||
#endregion Input
|
||||
@@ -618,7 +625,6 @@ static class ScriptGlue
|
||||
return .ArgumentError;
|
||||
}
|
||||
|
||||
//return scriptComponent.Instance.MonoInstance;
|
||||
return .Ok;
|
||||
}
|
||||
|
||||
@@ -632,7 +638,7 @@ static class ScriptGlue
|
||||
return .Ok;
|
||||
}
|
||||
|
||||
[RegisterCall, CallingConvention(.Cdecl)]
|
||||
[RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
|
||||
static StringView Entity_GetName(UUID entityId)
|
||||
{
|
||||
Result<Entity> foundEntity = ScriptEngine.Context.GetEntityByID(entityId);
|
||||
@@ -675,7 +681,7 @@ static class ScriptGlue
|
||||
|
||||
#region TransformComponent
|
||||
|
||||
[RegisterCall, CallingConvention(.Cdecl)]
|
||||
[RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
|
||||
static EngineResult Transform_GetParent(UUID entityId, out UUID parentId)
|
||||
{
|
||||
parentId = .Zero;
|
||||
@@ -702,7 +708,7 @@ static class ScriptGlue
|
||||
return .Ok;
|
||||
}
|
||||
|
||||
[RegisterCall, CallingConvention(.Cdecl)]
|
||||
[RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
|
||||
static EngineResult Transform_GetTranslation(UUID entityId, out float3 translation)
|
||||
{
|
||||
translation = ?;
|
||||
@@ -727,7 +733,7 @@ static class ScriptGlue
|
||||
return .Ok;
|
||||
}
|
||||
|
||||
[RegisterCall, CallingConvention(.Cdecl)]
|
||||
[RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
|
||||
static EngineResult Transform_GetWorldTranslation(UUID entityId, out float3 translationWorld)
|
||||
{
|
||||
translationWorld = ?;
|
||||
@@ -757,7 +763,7 @@ static class ScriptGlue
|
||||
// TODO: we need to handle repositioning of colliders that are children of the entity with rigidbody...
|
||||
}
|
||||
|
||||
[RegisterCall, CallingConvention(.Cdecl)]
|
||||
[RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
|
||||
static EngineResult Transform_TransformPointToWorld(UUID entityId, float3 point, out float3 pointWorld)
|
||||
{
|
||||
pointWorld = ?;
|
||||
@@ -769,7 +775,7 @@ static class ScriptGlue
|
||||
return .Ok;
|
||||
}
|
||||
|
||||
[RegisterCall, CallingConvention(.Cdecl)]
|
||||
[RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
|
||||
static EngineResult Transform_GetRotation(UUID entityId, out Quaternion rotation)
|
||||
{
|
||||
rotation = ?;
|
||||
@@ -794,7 +800,7 @@ static class ScriptGlue
|
||||
return .Ok;
|
||||
}
|
||||
|
||||
[RegisterCall, CallingConvention(.Cdecl)]
|
||||
[RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
|
||||
static EngineResult Transform_GetRotationEuler(UUID entityId, out float3 rotationEuler)
|
||||
{
|
||||
rotationEuler = ?;
|
||||
@@ -831,7 +837,7 @@ static class ScriptGlue
|
||||
}
|
||||
}
|
||||
|
||||
[RegisterCall, CallingConvention(.Cdecl)]
|
||||
[RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
|
||||
static EngineResult Transform_GetRotationAxisAngle(UUID entityId, out AxisAngle rotationAxisAngle)
|
||||
{
|
||||
rotationAxisAngle = ?;
|
||||
@@ -855,7 +861,7 @@ static class ScriptGlue
|
||||
return .Ok;
|
||||
}
|
||||
|
||||
[RegisterCall, CallingConvention(.Cdecl)]
|
||||
[RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
|
||||
static EngineResult Transform_GetScale(UUID entityId, out float3 scale)
|
||||
{
|
||||
scale = ?;
|
||||
@@ -865,7 +871,7 @@ static class ScriptGlue
|
||||
return .Ok;
|
||||
}
|
||||
|
||||
[RegisterCall, CallingConvention(.Cdecl)]
|
||||
[RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
|
||||
static EngineResult Transform_SetScale(UUID entityId, float3 scale)
|
||||
{
|
||||
Entity entity = GetEntityOrReturnError!(entityId);
|
||||
@@ -883,14 +889,14 @@ static class ScriptGlue
|
||||
|
||||
#region Rigidbody2
|
||||
|
||||
[RegisterCall, CallingConvention(.Cdecl)]
|
||||
[RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
|
||||
static void Rigidbody2D_ApplyForce(UUID entityId, in float2 force, in float2 point, bool wakeUp)
|
||||
{
|
||||
Rigidbody2DComponent* rigidBody = GetComponentSafe<Rigidbody2DComponent>(entityId);
|
||||
Box2D.Body.ApplyForce(rigidBody.[Friend]RuntimeBody, force, point, wakeUp);
|
||||
}
|
||||
|
||||
[RegisterCall, CallingConvention(.Cdecl)]
|
||||
[RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
|
||||
static void Rigidbody2D_ApplyForceToCenter(UUID entityId, in float2 force, bool wakeUp)
|
||||
{
|
||||
Rigidbody2DComponent* rigidBody = GetComponentSafe<Rigidbody2DComponent>(entityId);
|
||||
@@ -904,7 +910,7 @@ static class ScriptGlue
|
||||
rigidBody.SetPosition(position);
|
||||
}
|
||||
|
||||
[RegisterCall, CallingConvention(.Cdecl)]
|
||||
[RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
|
||||
static void Rigidbody2D_GetPosition(UUID entityId, out float2 position)
|
||||
{
|
||||
Rigidbody2DComponent* rigidBody = GetComponentSafe<Rigidbody2DComponent>(entityId);
|
||||
@@ -918,42 +924,42 @@ static class ScriptGlue
|
||||
rigidBody.SetAngle(rotation);
|
||||
}
|
||||
|
||||
[RegisterCall, CallingConvention(.Cdecl)]
|
||||
[RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
|
||||
static void Rigidbody2D_GetRotation(UUID entityId, out float rotation)
|
||||
{
|
||||
Rigidbody2DComponent* rigidBody = GetComponentSafe<Rigidbody2DComponent>(entityId);
|
||||
rotation = rigidBody.GetAngle();
|
||||
}
|
||||
|
||||
[RegisterCall, CallingConvention(.Cdecl)]
|
||||
[RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
|
||||
static void Rigidbody2D_GetLinearVelocity(UUID entityId, out float2 velocity)
|
||||
{
|
||||
Rigidbody2DComponent* rigidBody = GetComponentSafe<Rigidbody2DComponent>(entityId);
|
||||
velocity = rigidBody.GetLinearVelocity();
|
||||
}
|
||||
|
||||
[RegisterCall, CallingConvention(.Cdecl)]
|
||||
[RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
|
||||
static void Rigidbody2D_SetLinearVelocity(UUID entityId, in float2 velocity)
|
||||
{
|
||||
Rigidbody2DComponent* rigidBody = GetComponentSafe<Rigidbody2DComponent>(entityId);
|
||||
rigidBody.SetLinearVelocity(velocity);
|
||||
}
|
||||
|
||||
[RegisterCall, CallingConvention(.Cdecl)]
|
||||
[RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
|
||||
static void Rigidbody2D_GetAngularVelocity(UUID entityId, out float velocity)
|
||||
{
|
||||
Rigidbody2DComponent* rigidBody = GetComponentSafe<Rigidbody2DComponent>(entityId);
|
||||
velocity = rigidBody.GetAngularVelocity();
|
||||
}
|
||||
|
||||
[RegisterCall, CallingConvention(.Cdecl)]
|
||||
[RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
|
||||
static void Rigidbody2D_SetAngularVelocity(UUID entityId, float velocity)
|
||||
{
|
||||
Rigidbody2DComponent* rigidBody = GetComponentSafe<Rigidbody2DComponent>(entityId);
|
||||
rigidBody.SetAngularVelocity(velocity);
|
||||
}
|
||||
|
||||
[RegisterCall, CallingConvention(.Cdecl)]
|
||||
[RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
|
||||
static void Rigidbody2D_GetBodyType(UUID entityId, out Rigidbody2DComponent.BodyType bodyType)
|
||||
{
|
||||
Rigidbody2DComponent* rigidBody = GetComponentSafe<Rigidbody2DComponent>(entityId);
|
||||
@@ -967,7 +973,7 @@ static class ScriptGlue
|
||||
rigidBody.BodyType = bodyType;
|
||||
}
|
||||
|
||||
[RegisterCall, CallingConvention(.Cdecl)]
|
||||
[RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
|
||||
static void Rigidbody2D_IsFixedRotation(UUID entityId, out bool isFixedRotation)
|
||||
{
|
||||
Rigidbody2DComponent* rigidBody = GetComponentSafe<Rigidbody2DComponent>(entityId);
|
||||
@@ -981,14 +987,14 @@ static class ScriptGlue
|
||||
rigidBody.FixedRotation = isFixedRotation;
|
||||
}
|
||||
|
||||
[RegisterCall, CallingConvention(.Cdecl)]
|
||||
[RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
|
||||
static void Rigidbody2D_GetGravityScale(UUID entityId, out float gravityScale)
|
||||
{
|
||||
Rigidbody2DComponent* rigidBody = GetComponentSafe<Rigidbody2DComponent>(entityId);
|
||||
gravityScale = rigidBody.GravityScale;
|
||||
}
|
||||
|
||||
[RegisterCall, CallingConvention(.Cdecl)]
|
||||
[RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
|
||||
static void Rigidbody2D_SetGravityScale(UUID entityId, float gravityScale)
|
||||
{
|
||||
Rigidbody2DComponent* rigidBody = GetComponentSafe<Rigidbody2DComponent>(entityId);
|
||||
@@ -999,126 +1005,126 @@ static class ScriptGlue
|
||||
|
||||
#region Camera
|
||||
|
||||
[RegisterCall, CallingConvention(.Cdecl)]
|
||||
[RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
|
||||
static void Camera_GetProjectionType(UUID entityId, out SceneCamera.ProjectionType projectionType)
|
||||
{
|
||||
CameraComponent* camera = GetComponentSafe<CameraComponent>(entityId);
|
||||
projectionType = camera.Camera.ProjectionType;
|
||||
}
|
||||
|
||||
[RegisterCall, CallingConvention(.Cdecl)]
|
||||
[RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
|
||||
static void Camera_SetProjectionType(UUID entityId, SceneCamera.ProjectionType projectionType)
|
||||
{
|
||||
CameraComponent* camera = GetComponentSafe<CameraComponent>(entityId);
|
||||
camera.Camera.ProjectionType = projectionType;
|
||||
}
|
||||
|
||||
[RegisterCall, CallingConvention(.Cdecl)]
|
||||
[RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
|
||||
static void Camera_GetPerspectiveFovY(UUID entityId, out float fovY)
|
||||
{
|
||||
CameraComponent* camera = GetComponentSafe<CameraComponent>(entityId);
|
||||
fovY = camera.Camera.PerspectiveFovY;
|
||||
}
|
||||
|
||||
[RegisterCall, CallingConvention(.Cdecl)]
|
||||
[RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
|
||||
static void Camera_SetPerspectiveFovY(UUID entityId, float fovY)
|
||||
{
|
||||
CameraComponent* camera = GetComponentSafe<CameraComponent>(entityId);
|
||||
camera.Camera.PerspectiveFovY = fovY;
|
||||
}
|
||||
|
||||
[RegisterCall, CallingConvention(.Cdecl)]
|
||||
[RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
|
||||
static void Camera_GetPerspectiveNearPlane(UUID entityId, out float nearPlane)
|
||||
{
|
||||
CameraComponent* camera = GetComponentSafe<CameraComponent>(entityId);
|
||||
nearPlane = camera.Camera.PerspectiveNearPlane;
|
||||
}
|
||||
|
||||
[RegisterCall, CallingConvention(.Cdecl)]
|
||||
[RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
|
||||
static void Camera_SetPerspectiveNearPlane(UUID entityId, float nearPlane)
|
||||
{
|
||||
CameraComponent* camera = GetComponentSafe<CameraComponent>(entityId);
|
||||
camera.Camera.PerspectiveNearPlane = nearPlane;
|
||||
}
|
||||
|
||||
[RegisterCall, CallingConvention(.Cdecl)]
|
||||
[RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
|
||||
static void Camera_GetPerspectiveFarPlane(UUID entityId, out float farPlane)
|
||||
{
|
||||
CameraComponent* camera = GetComponentSafe<CameraComponent>(entityId);
|
||||
farPlane = camera.Camera.PerspectiveFarPlane;
|
||||
}
|
||||
|
||||
[RegisterCall, CallingConvention(.Cdecl)]
|
||||
[RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
|
||||
static void Camera_SetPerspectiveFarPlane(UUID entityId, float farPlane)
|
||||
{
|
||||
CameraComponent* camera = GetComponentSafe<CameraComponent>(entityId);
|
||||
camera.Camera.PerspectiveFarPlane = farPlane;
|
||||
}
|
||||
|
||||
[RegisterCall, CallingConvention(.Cdecl)]
|
||||
[RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
|
||||
static void Camera_GetOrthographicHeight(UUID entityId, out float height)
|
||||
{
|
||||
CameraComponent* camera = GetComponentSafe<CameraComponent>(entityId);
|
||||
height = camera.Camera.OrthographicHeight;
|
||||
}
|
||||
|
||||
[RegisterCall, CallingConvention(.Cdecl)]
|
||||
[RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
|
||||
static void Camera_SetOrthographicHeight(UUID entityId, float height)
|
||||
{
|
||||
CameraComponent* camera = GetComponentSafe<CameraComponent>(entityId);
|
||||
camera.Camera.OrthographicHeight = height;
|
||||
}
|
||||
|
||||
[RegisterCall, CallingConvention(.Cdecl)]
|
||||
[RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
|
||||
static void Camera_SetOrthographicNearPlane(UUID entityId, float nearPlane)
|
||||
{
|
||||
CameraComponent* camera = GetComponentSafe<CameraComponent>(entityId);
|
||||
camera.Camera.OrthographicNearPlane = nearPlane;
|
||||
}
|
||||
|
||||
[RegisterCall, CallingConvention(.Cdecl)]
|
||||
[RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
|
||||
static void Camera_GetOrthographicNearPlane(UUID entityId, out float nearPlane)
|
||||
{
|
||||
CameraComponent* camera = GetComponentSafe<CameraComponent>(entityId);
|
||||
nearPlane = camera.Camera.OrthographicNearPlane;
|
||||
}
|
||||
|
||||
[RegisterCall, CallingConvention(.Cdecl)]
|
||||
[RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
|
||||
static void Camera_SetOrthographicFarPlane(UUID entityId, float farPlane)
|
||||
{
|
||||
CameraComponent* camera = GetComponentSafe<CameraComponent>(entityId);
|
||||
camera.Camera.OrthographicFarPlane = farPlane;
|
||||
}
|
||||
|
||||
[RegisterCall, CallingConvention(.Cdecl)]
|
||||
[RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
|
||||
static void Camera_GetOrthographicFarPlane(UUID entityId, out float farPlane)
|
||||
{
|
||||
CameraComponent* camera = GetComponentSafe<CameraComponent>(entityId);
|
||||
farPlane = camera.Camera.OrthographicFarPlane;
|
||||
}
|
||||
|
||||
[RegisterCall, CallingConvention(.Cdecl)]
|
||||
[RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
|
||||
static void Camera_SetAspectRatio(UUID entityId, float aspectRatio)
|
||||
{
|
||||
CameraComponent* camera = GetComponentSafe<CameraComponent>(entityId);
|
||||
camera.Camera.AspectRatio = aspectRatio;
|
||||
}
|
||||
|
||||
[RegisterCall, CallingConvention(.Cdecl)]
|
||||
[RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
|
||||
static void Camera_GetAspectRatio(UUID entityId, out float aspectRatio)
|
||||
{
|
||||
CameraComponent* camera = GetComponentSafe<CameraComponent>(entityId);
|
||||
aspectRatio = camera.Camera.AspectRatio;
|
||||
}
|
||||
|
||||
[RegisterCall, CallingConvention(.Cdecl)]
|
||||
[RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
|
||||
static void Camera_SetFixedAspectRatio(UUID entityId, bool fixedAspectRatio)
|
||||
{
|
||||
CameraComponent* camera = GetComponentSafe<CameraComponent>(entityId);
|
||||
camera.Camera.FixedAspectRatio = fixedAspectRatio;
|
||||
}
|
||||
|
||||
[RegisterCall, CallingConvention(.Cdecl)]
|
||||
[RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
|
||||
static void Camera_GetFixedAspectRatio(UUID entityId, out bool fixedAspectRatio)
|
||||
{
|
||||
CameraComponent* camera = GetComponentSafe<CameraComponent>(entityId);
|
||||
@@ -1131,7 +1137,7 @@ static class ScriptGlue
|
||||
|
||||
// TODO: We need a wrapper class!
|
||||
|
||||
[RegisterCall, CallingConvention(.Cdecl)]
|
||||
[RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
|
||||
static void Physics2D_GetGravity(out float2 gravity)
|
||||
{
|
||||
Scene scene = ScriptEngine.Context;
|
||||
@@ -1139,7 +1145,7 @@ static class ScriptGlue
|
||||
gravity = scene.Physics2DSettings.Gravity;
|
||||
}
|
||||
|
||||
[RegisterCall, CallingConvention(.Cdecl)]
|
||||
[RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
|
||||
static void Physics2D_SetGravity(in float2 gravity)
|
||||
{
|
||||
Scene scene = ScriptEngine.Context;
|
||||
@@ -1152,42 +1158,42 @@ static class ScriptGlue
|
||||
// TODO: Do we even need the circle renderer?
|
||||
#region CircleRenderer
|
||||
|
||||
[RegisterCall, CallingConvention(.Cdecl)]
|
||||
[RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
|
||||
static void CircleRenderer_GetColor(UUID entityId, out ColorRGBA color)
|
||||
{
|
||||
CircleRendererComponent* circleRenderer = GetComponentSafe<CircleRendererComponent>(entityId);
|
||||
color = circleRenderer.Color;
|
||||
}
|
||||
|
||||
[RegisterCall, CallingConvention(.Cdecl)]
|
||||
[RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
|
||||
static void CircleRenderer_SetColor(UUID entityId, ColorRGBA color)
|
||||
{
|
||||
CircleRendererComponent* circleRenderer = GetComponentSafe<CircleRendererComponent>(entityId);
|
||||
circleRenderer.Color = color;
|
||||
}
|
||||
|
||||
[RegisterCall, CallingConvention(.Cdecl)]
|
||||
[RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
|
||||
static void CircleRenderer_GetUvTransform(UUID entityId, out float4 uvTransform)
|
||||
{
|
||||
CircleRendererComponent* circleRenderer = GetComponentSafe<CircleRendererComponent>(entityId);
|
||||
uvTransform = circleRenderer.UvTransform;
|
||||
}
|
||||
|
||||
[RegisterCall, CallingConvention(.Cdecl)]
|
||||
[RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
|
||||
static void CircleRenderer_SetUvTransform(UUID entityId, float4 uvTransform)
|
||||
{
|
||||
CircleRendererComponent* circleRenderer = GetComponentSafe<CircleRendererComponent>(entityId);
|
||||
circleRenderer.UvTransform = uvTransform;
|
||||
}
|
||||
|
||||
[RegisterCall, CallingConvention(.Cdecl)]
|
||||
[RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
|
||||
static void CircleRenderer_GetInnerRadius(UUID entityId, out float innerRadius)
|
||||
{
|
||||
CircleRendererComponent* circleRenderer = GetComponentSafe<CircleRendererComponent>(entityId);
|
||||
innerRadius = circleRenderer.InnerRadius;
|
||||
}
|
||||
|
||||
[RegisterCall, CallingConvention(.Cdecl)]
|
||||
[RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
|
||||
static void CircleRenderer_SetInnerRadius(UUID entityId, float innerRadius)
|
||||
{
|
||||
CircleRendererComponent* circleRenderer = GetComponentSafe<CircleRendererComponent>(entityId);
|
||||
@@ -1198,7 +1204,7 @@ static class ScriptGlue
|
||||
|
||||
#region SpriteRenderer
|
||||
|
||||
[RegisterCall, CallingConvention(.Cdecl)]
|
||||
[RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
|
||||
static EngineResult SpriteRenderer_GetColor(UUID entityId, out ColorRGBA color)
|
||||
{
|
||||
color = ?;
|
||||
@@ -1207,7 +1213,7 @@ static class ScriptGlue
|
||||
return .Ok;
|
||||
}
|
||||
|
||||
[RegisterCall, CallingConvention(.Cdecl)]
|
||||
[RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
|
||||
static EngineResult SpriteRenderer_SetColor(UUID entityId, ColorRGBA color)
|
||||
{
|
||||
SpriteRendererComponent* spriteRenderer = GetComponentOrReturn!<SpriteRendererComponent>(entityId);
|
||||
@@ -1215,7 +1221,7 @@ static class ScriptGlue
|
||||
return .Ok;
|
||||
}
|
||||
|
||||
[RegisterCall, CallingConvention(.Cdecl)]
|
||||
[RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
|
||||
static EngineResult SpriteRenderer_GetUvTransform(UUID entityId, out float4 uvTransform)
|
||||
{
|
||||
uvTransform = ?;
|
||||
@@ -1224,7 +1230,7 @@ static class ScriptGlue
|
||||
return .Ok;
|
||||
}
|
||||
|
||||
[RegisterCall, CallingConvention(.Cdecl)]
|
||||
[RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
|
||||
static EngineResult SpriteRenderer_SetUvTransform(UUID entityId, float4 uvTransform)
|
||||
{
|
||||
SpriteRendererComponent* spriteRenderer = GetComponentOrReturn!<SpriteRendererComponent>(entityId);
|
||||
@@ -1267,14 +1273,14 @@ static class ScriptGlue
|
||||
|
||||
#region TextRenderer
|
||||
|
||||
[RegisterCall(EngineResultAsBool = true), CallingConvention(.Cdecl)]
|
||||
[RegisterCall(EngineResultAsBool = true, GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
|
||||
static EngineResult TextRenderer_GetIsRichText(UUID entityId)
|
||||
{
|
||||
TextRendererComponent* textComponent = GetComponentOrReturn!<TextRendererComponent>(entityId);
|
||||
return textComponent.IsRichText ? .Ok : .False;
|
||||
}
|
||||
|
||||
[RegisterCall, CallingConvention(.Cdecl)]
|
||||
[RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
|
||||
static EngineResult TextRenderer_SetIsRichText(UUID entityId, bool isRichText)
|
||||
{
|
||||
TextRendererComponent* textComponent = GetComponentOrReturn!<TextRendererComponent>(entityId);
|
||||
@@ -1285,7 +1291,7 @@ static class ScriptGlue
|
||||
return .Ok;
|
||||
}
|
||||
|
||||
[RegisterCall, CallingConvention(.Cdecl)]
|
||||
[RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
|
||||
static EngineResult TextRenderer_GetText(UUID entityId, out StringView text)
|
||||
{
|
||||
text = ?;
|
||||
@@ -1306,7 +1312,7 @@ static class ScriptGlue
|
||||
return .Ok;
|
||||
}
|
||||
|
||||
[RegisterCall, CallingConvention(.Cdecl)]
|
||||
[RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
|
||||
static EngineResult TextRenderer_GetColor(UUID entityId, out ColorRGBA color)
|
||||
{
|
||||
color = ?;
|
||||
@@ -1316,7 +1322,7 @@ static class ScriptGlue
|
||||
return .Ok;
|
||||
}
|
||||
|
||||
[RegisterCall, CallingConvention(.Cdecl)]
|
||||
[RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
|
||||
static EngineResult TextRenderer_SetColor(UUID entityId, ColorRGBA color)
|
||||
{
|
||||
TextRendererComponent* textComponent = GetComponentOrReturn!<TextRendererComponent>(entityId);
|
||||
@@ -1326,7 +1332,7 @@ static class ScriptGlue
|
||||
return .Ok;
|
||||
}
|
||||
|
||||
[RegisterCall, CallingConvention(.Cdecl)]
|
||||
[RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
|
||||
static EngineResult TextRenderer_GetHorizontalAlignment(UUID entityId, [GlueParam("out HorizontalTextAlignment")] out HorizontalTextAlignment horizontalAlignment)
|
||||
{
|
||||
horizontalAlignment = ?;
|
||||
@@ -1335,7 +1341,7 @@ static class ScriptGlue
|
||||
return .Ok;
|
||||
}
|
||||
|
||||
[RegisterCall, CallingConvention(.Cdecl)]
|
||||
[RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
|
||||
static EngineResult TextRenderer_SetHorizontalAlignment(UUID entityId, [GlueParam("HorizontalTextAlignment")] HorizontalTextAlignment horizontalAlignment)
|
||||
{
|
||||
TextRendererComponent* textComponent = GetComponentOrReturn!<TextRendererComponent>(entityId);
|
||||
@@ -1344,7 +1350,7 @@ static class ScriptGlue
|
||||
return .Ok;
|
||||
}
|
||||
|
||||
[RegisterCall, CallingConvention(.Cdecl)]
|
||||
[RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
|
||||
static EngineResult TextRenderer_GetFontSize(UUID entityId, out float fontSize)
|
||||
{
|
||||
fontSize = ?;
|
||||
@@ -1353,7 +1359,7 @@ static class ScriptGlue
|
||||
return .Ok;
|
||||
}
|
||||
|
||||
[RegisterCall, CallingConvention(.Cdecl)]
|
||||
[RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
|
||||
static EngineResult TextRenderer_SetFontSize(UUID entityId, float fontSize)
|
||||
{
|
||||
TextRendererComponent* textComponent = GetComponentOrReturn!<TextRendererComponent>(entityId);
|
||||
@@ -1422,25 +1428,25 @@ static class ScriptGlue
|
||||
|
||||
#region Math
|
||||
|
||||
[RegisterCall, CallingConvention(.Cdecl)]
|
||||
[RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
|
||||
static float Math_ModfFloat(float x, out float integerPart)
|
||||
{
|
||||
return modf(x, out integerPart);
|
||||
}
|
||||
|
||||
[RegisterCall, CallingConvention(.Cdecl)]
|
||||
[RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
|
||||
static float2 Math_ModfFloat2(float2 x, out float2 integerPart)
|
||||
{
|
||||
return modf(x, out integerPart);
|
||||
}
|
||||
|
||||
[RegisterCall, CallingConvention(.Cdecl)]
|
||||
[RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
|
||||
static float3 Math_ModfFloat3(float3 x, out float3 integerPart)
|
||||
{
|
||||
return modf(x, out integerPart);
|
||||
}
|
||||
|
||||
[RegisterCall, CallingConvention(.Cdecl)]
|
||||
[RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
|
||||
static float4 Math_ModfFloat4(float4 x, out float4 integerPart)
|
||||
{
|
||||
return modf(x, out integerPart);
|
||||
@@ -1448,7 +1454,7 @@ static class ScriptGlue
|
||||
|
||||
#endregion
|
||||
|
||||
[RegisterCall, CallingConvention(.Cdecl)]
|
||||
[RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
|
||||
static void UUID_Create(out UUID id)
|
||||
{
|
||||
id = UUID.Create();
|
||||
@@ -1456,25 +1462,25 @@ static class ScriptGlue
|
||||
|
||||
#region Application
|
||||
|
||||
[RegisterCall, CallingConvention(.Cdecl)]
|
||||
[RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
|
||||
static bool Application_IsEditor()
|
||||
{
|
||||
return ScriptEngine.ApplicationInfo.IsEditor;
|
||||
}
|
||||
|
||||
[RegisterCall, CallingConvention(.Cdecl)]
|
||||
[RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
|
||||
static bool Application_IsPlayer()
|
||||
{
|
||||
return ScriptEngine.ApplicationInfo.IsPlayer;
|
||||
}
|
||||
|
||||
[RegisterCall, CallingConvention(.Cdecl)]
|
||||
[RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
|
||||
static bool Application_IsInEditMode()
|
||||
{
|
||||
return ScriptEngine.ApplicationInfo.IsInEditMode;
|
||||
}
|
||||
|
||||
[RegisterCall, CallingConvention(.Cdecl)]
|
||||
[RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
|
||||
static bool Application_IsInPlayMode()
|
||||
{
|
||||
return ScriptEngine.ApplicationInfo.IsInPlayMode;
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using GlitchyEngine.Core;
|
||||
using GlitchyEngine.Scripting;
|
||||
using Mono;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using Bon.Integrated;
|
||||
@@ -315,7 +314,7 @@ class SerializedObject
|
||||
Serialize.Value(writer, GetFieldDataAs<double>(field.Data), environment);
|
||||
case .Decimal:
|
||||
writer.Type("decimal");
|
||||
Serialize.Value(writer, GetFieldDataAs<MonoDecimal>(field.Data), environment);
|
||||
Serialize.Value(writer, GetFieldDataAs<Decimal>(field.Data), environment);
|
||||
|
||||
case .Enum:
|
||||
writer.Type("Enum");
|
||||
@@ -499,7 +498,7 @@ class SerializedObject
|
||||
if (reader.inStr.StartsWith('m'))
|
||||
reader.inStr.RemoveFromStart(1);
|
||||
|
||||
MonoDecimal decimalValue = Try!(MonoDecimal.Parse(numberView));
|
||||
Decimal decimalValue = Try!(Decimal.Parse(numberView));
|
||||
fieldType = .Decimal;
|
||||
object.SetRawData(fieldType, decimalValue, ref fieldData);
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@ using GlitchyEngine.Core;
|
||||
using Box2D;
|
||||
using GlitchyEngine.Content;
|
||||
using GlitchyEngine.Scripting;
|
||||
using Mono;
|
||||
|
||||
namespace GlitchyEngine.World
|
||||
{
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
namespace Mono;
|
||||
|
||||
class Jit
|
||||
{
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace Mono.Metadata;
|
||||
|
||||
class Assembly
|
||||
{
|
||||
[LinkName(.C)]
|
||||
public static extern void mono_set_assemblies_path(char8* path);
|
||||
}
|
||||
@@ -1,601 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace Mono;
|
||||
|
||||
static class Mono
|
||||
{
|
||||
typealias mono_bool = System.Windows.IntBool;
|
||||
|
||||
[LinkName(.C)]
|
||||
public static extern void mono_set_assemblies_path(char8* path);
|
||||
|
||||
[LinkName(.C)]
|
||||
public static extern MonoDomain* mono_jit_init(char8* file);
|
||||
|
||||
[LinkName(.C)]
|
||||
public static extern void mono_jit_parse_options(int32 argc, char8** argv);
|
||||
|
||||
[LinkName(.C)]
|
||||
public static extern void mono_jit_cleanup(MonoDomain* domain);
|
||||
|
||||
[LinkName(.C)]
|
||||
public static extern MonoDomain* mono_domain_create_appdomain(char8* friendly_name, char8* configuration_file);
|
||||
|
||||
[LinkName(.C)]
|
||||
public static extern mono_bool mono_domain_set(MonoDomain* domain, mono_bool force);
|
||||
|
||||
[LinkName(.C)]
|
||||
public static extern MonoImage* mono_image_open_from_data_full(uint8* data, uint32 data_len,
|
||||
mono_bool need_copy, MonoImageOpenStatus* status, mono_bool refonly);
|
||||
|
||||
[LinkName(.C)]
|
||||
public static extern MonoImage* mono_assembly_get_image(MonoAssembly* assembly);
|
||||
|
||||
[LinkName(.C)]
|
||||
public static extern void mono_assembly_close(MonoAssembly* assembly);
|
||||
|
||||
[LinkName(.C)]
|
||||
public static extern void mono_image_close(MonoImage* image);
|
||||
|
||||
[LinkName(.C)]
|
||||
public static extern char8* mono_image_strerror(MonoImageOpenStatus status);
|
||||
|
||||
[LinkName(.C)]
|
||||
public static extern MonoAssembly* mono_assembly_load_from_full(MonoImage* image, char8* fileName,
|
||||
MonoImageOpenStatus* status, mono_bool refonly);
|
||||
|
||||
|
||||
[LinkName(.C)]
|
||||
public static extern MonoTableInfo* mono_image_get_table_info(MonoImage* image, MonoMetaTableEnum table_id);
|
||||
|
||||
[LinkName(.C)]
|
||||
public static extern int32 mono_image_get_table_rows(MonoImage *image, MonoMetaTableEnum table_id);
|
||||
|
||||
[LinkName(.C)]
|
||||
public static extern int32 mono_table_info_get_rows(MonoTableInfo* table);
|
||||
|
||||
[LinkName(.C)]
|
||||
public static extern void mono_metadata_decode_row (MonoTableInfo* t,
|
||||
int32 idx,
|
||||
uint32* res,
|
||||
int32 res_size);
|
||||
|
||||
[LinkName(.C)]
|
||||
public static extern char8* mono_metadata_string_heap(MonoImage* meta, uint32 table_index);
|
||||
[LinkName(.C)]
|
||||
public static extern uint8* mono_metadata_blob_heap(MonoImage* meta, uint32 index);
|
||||
[LinkName(.C)]
|
||||
public static extern uint32 mono_metadata_decode_blob_size(uint8* xptr, out uint8* newPosition);
|
||||
|
||||
typealias gconstpointer = void*;
|
||||
typealias gpointer = void*;
|
||||
|
||||
[LinkName(.C)]
|
||||
public static extern void mono_add_internal_call(char8* name, gconstpointer method);
|
||||
|
||||
[LinkName(.C)]
|
||||
public static extern MonoString* mono_string_new(MonoDomain* domain, char8* text);
|
||||
|
||||
[LinkName(.C)]
|
||||
public static extern MonoString* mono_string_new_len(MonoDomain* domain, char8* text, uint32 length);
|
||||
|
||||
[LinkName(.C)]
|
||||
public static extern MonoDomain* mono_domain_get();
|
||||
|
||||
[LinkName(.C)]
|
||||
public static extern MonoClass* mono_class_from_name(MonoImage* image, char8* name_space,
|
||||
char8* name);
|
||||
|
||||
[LinkName(.C)]
|
||||
public static extern MonoClass* mono_class_from_mono_type(MonoType* type);
|
||||
|
||||
[LinkName(.C)]
|
||||
public static extern char8* mono_class_get_name(MonoClass* monoClass);
|
||||
|
||||
[LinkName(.C)]
|
||||
public static extern MonoType* mono_class_get_type(MonoClass* monoClass);
|
||||
|
||||
[LinkName(.C)]
|
||||
public static extern int32 mono_class_instance_size(MonoClass* @class);
|
||||
|
||||
[LinkName(.C)]
|
||||
public static extern char8* mono_class_get_namespace(MonoClass* monoClass);
|
||||
|
||||
[LinkName(.C)]
|
||||
public static extern MonoImage* mono_class_get_image(MonoClass* monoClass);
|
||||
|
||||
[LinkName(.C)]
|
||||
public static extern MonoClass* mono_class_load_from_name(MonoImage* image, char8* name_space,
|
||||
char8* name);
|
||||
|
||||
[LinkName(.C)]
|
||||
public static extern MonoObject* mono_object_new(MonoDomain* domain, MonoClass* klass);
|
||||
|
||||
[LinkName(.C)]
|
||||
public static extern void mono_runtime_object_init(MonoObject* this_obj);
|
||||
|
||||
[LinkName(.C)]
|
||||
public static extern MonoMethod* mono_class_get_methods(MonoClass* klass, gpointer* iter);
|
||||
|
||||
[LinkName(.C)]
|
||||
public static extern MonoMethod* mono_class_get_method_from_name(MonoClass* klass, char8* name, int param_count);
|
||||
|
||||
[LinkName(.C)]
|
||||
public static extern MonoObject* mono_runtime_invoke(MonoMethod* method, void* obj, void** param, MonoObject** exc);
|
||||
|
||||
[LinkName(.C)]
|
||||
public static extern MonoMethod* mono_object_get_virtual_method(MonoObject* obj, MonoMethod* method);
|
||||
|
||||
[LinkName(.C)]
|
||||
public static extern void* mono_object_unbox(MonoObject* obj);
|
||||
|
||||
[LinkName(.C)]
|
||||
public static extern void* mono_domain_unload(MonoDomain* domain);
|
||||
|
||||
|
||||
[LinkName(.C)]
|
||||
public static extern gpointer mono_method_get_unmanaged_thunk(MonoMethod *method);
|
||||
|
||||
[LinkName(.C)]
|
||||
public static extern char8* mono_method_get_name(MonoMethod *method);
|
||||
|
||||
[LinkName(.C)]
|
||||
public static extern MonoMethodSignature* mono_method_signature(MonoMethod *method);
|
||||
|
||||
[LinkName(.C)]
|
||||
public static extern uint32 mono_signature_get_param_count(MonoMethodSignature *sig);
|
||||
|
||||
[LinkName(.C)]
|
||||
public static extern MonoType* mono_signature_get_params(MonoMethodSignature *sig, gpointer *iter);
|
||||
|
||||
[LinkName(.C)]
|
||||
public static extern mono_bool mono_class_is_subclass_of(MonoClass *monoClass, MonoClass *parentClass,
|
||||
mono_bool check_interfaces);
|
||||
|
||||
[LinkName(.C)]
|
||||
public static extern uint32 mono_gchandle_new(MonoObject* obj, mono_bool pinned);
|
||||
|
||||
[LinkName(.C)]
|
||||
public static extern void mono_gchandle_free(uint32 gchandle);
|
||||
|
||||
[LinkName(.C)]
|
||||
public static extern char8* mono_string_to_utf8(MonoString *s);
|
||||
|
||||
[LinkName(.C)]
|
||||
public static extern char8* mono_string_to_utf8_checked(MonoString *s, MonoError* error);
|
||||
|
||||
[LinkName(.C)]
|
||||
public static extern void mono_free(void* ptr);
|
||||
|
||||
[LinkName(.C)]
|
||||
public static extern MonoClassField* mono_class_get_field_from_name(MonoClass* monoClass, char8* name);
|
||||
|
||||
[LinkName(.C)]
|
||||
public static extern void mono_field_set_value(MonoObject* obj, MonoClassField* field, void* value);
|
||||
|
||||
[LinkName(.C)]
|
||||
public static extern MonoType* mono_reflection_type_from_name(char8* name, MonoImage* image);
|
||||
|
||||
[LinkName(.C)]
|
||||
public static extern MonoType* mono_reflection_type_get_type(MonoReflectionType* reflectionType);
|
||||
|
||||
[LinkName(.C)]
|
||||
public static extern MonoReflectionType* mono_type_get_object(MonoDomain *domain, MonoType *type);
|
||||
|
||||
[LinkName(.C)]
|
||||
public static extern MonoClassField* mono_class_get_fields(MonoClass* klass, gpointer* iter);
|
||||
|
||||
[LinkName(.C)]
|
||||
public static extern MonoClass* mono_class_get_parent(MonoClass* klass);
|
||||
|
||||
[LinkName(.C)]
|
||||
public static extern char8* mono_field_get_name(MonoClassField* field);
|
||||
|
||||
[LinkName(.C)]
|
||||
public static extern MonoType* mono_field_get_type(MonoClassField* field);
|
||||
|
||||
[LinkName(.C)]
|
||||
public static extern MonoClass* mono_field_get_parent(MonoClassField* field);
|
||||
|
||||
[LinkName(.C)]
|
||||
public static extern uint32 mono_field_get_flags(MonoClassField* field);
|
||||
|
||||
[LinkName(.C)]
|
||||
public static extern uint8* mono_field_get_data(MonoClassField* field);
|
||||
|
||||
[LinkName(.C)]
|
||||
public static extern void mono_field_get_value(MonoObject* object, MonoClassField* field, void* value);
|
||||
|
||||
[LinkName(.C)]
|
||||
public static extern void mono_field_static_get_value(MonoVTable* vt, MonoClassField* field, void* value);
|
||||
|
||||
/// Gets the field as object, boxes the value if it is a valuetype.
|
||||
[LinkName(.C)]
|
||||
public static extern MonoObject* mono_field_get_value_object(MonoDomain* domain, MonoClassField* field, MonoObject* obj);
|
||||
|
||||
[LinkName(.C)]
|
||||
public static extern MonoCustomAttrInfo* mono_custom_attrs_from_class(MonoClass *klass);
|
||||
|
||||
[LinkName(.C)]
|
||||
public static extern MonoCustomAttrInfo* mono_custom_attrs_from_field(MonoClass* monoClass, MonoClassField* field);
|
||||
|
||||
[LinkName(.C)]
|
||||
public static extern mono_bool mono_custom_attrs_has_attr(MonoCustomAttrInfo* attributeInfo, MonoClass* attributeClass);
|
||||
|
||||
[LinkName(.C)]
|
||||
public static extern MonoObject* mono_custom_attrs_get_attr(MonoCustomAttrInfo* attributeInfo, MonoClass* attributeClass);
|
||||
|
||||
[LinkName(.C)]
|
||||
public static extern Mono.MonoTypeEnum mono_type_get_type(MonoType* type);
|
||||
|
||||
[LinkName(.C)]
|
||||
public static extern char8* mono_type_get_name(MonoType* type);
|
||||
|
||||
[LinkName(.C)]
|
||||
public static extern char8* mono_type_full_name(MonoType* type);
|
||||
|
||||
[LinkName(.C)]
|
||||
public static extern MonoClass* mono_type_get_class(MonoType* type);
|
||||
|
||||
/// MonoError
|
||||
|
||||
[LinkName(.C)]
|
||||
public static extern void mono_error_cleanup(MonoError* error);
|
||||
|
||||
[LinkName(.C)]
|
||||
public static extern mono_bool mono_error_ok(MonoError* error);
|
||||
|
||||
[LinkName(.C)]
|
||||
public static extern char8* mono_error_get_message(MonoError* error);
|
||||
|
||||
[LinkName(.C)]
|
||||
public static extern void mono_debug_init(DebugFormat debugFormat);
|
||||
|
||||
[LinkName(.C)]
|
||||
public static extern void mono_debug_domain_create(MonoDomain* domain);
|
||||
|
||||
[LinkName(.C)]
|
||||
public static extern void mono_debug_domain_unload(MonoDomain* domain);
|
||||
|
||||
[LinkName(.C)]
|
||||
public static extern void mono_debug_open_image_from_memory(MonoImage *image, uint8* raw_contents, int32 size);
|
||||
|
||||
[LinkName(.C)]
|
||||
public static extern void mono_thread_set_main(MonoThread* thread);
|
||||
|
||||
[LinkName(.C)]
|
||||
public static extern MonoThread* mono_thread_current();
|
||||
|
||||
#region Property
|
||||
|
||||
[LinkName(.C)]
|
||||
public static extern MonoProperty* mono_class_get_property_from_name(MonoClass *klass, char8* name);
|
||||
|
||||
[LinkName(.C)]
|
||||
public static extern void mono_property_set_value(MonoProperty *prop, void *obj, void **@params, MonoObject **exc);
|
||||
|
||||
[LinkName(.C)]
|
||||
public static extern MonoObject* mono_property_get_value(MonoProperty *prop, void *obj, void** @params, MonoObject** exc);
|
||||
|
||||
#endregion
|
||||
|
||||
#region Exception
|
||||
|
||||
[LinkName(.C), NoReturn]
|
||||
public static extern void mono_raise_exception(MonoException *ex);
|
||||
|
||||
[LinkName(.C)]
|
||||
public static extern char8* mono_exception_get_managed_backtrace(MonoException* exc);
|
||||
|
||||
[LinkName(.C)]
|
||||
public static extern MonoException* mono_exception_from_name_msg(MonoImage *image, char8* name_space, char8* name, char8* msg);
|
||||
|
||||
[LinkName(.C)]
|
||||
public static extern MonoException* mono_get_exception_argument(char8* arg, char8* msg);
|
||||
|
||||
[LinkName(.C)]
|
||||
public static extern MonoException* mono_get_exception_invalid_operation(char8* msg);
|
||||
|
||||
[LinkName(.C)]
|
||||
public static extern MonoException* mono_get_exception_not_implemented(char8* msg);
|
||||
|
||||
#endregion
|
||||
|
||||
[LinkName(.C)]
|
||||
public static extern MonoClass* mono_object_get_class(MonoObject* obj);
|
||||
|
||||
|
||||
[LinkName(.C)]
|
||||
public static extern mono_bool mono_class_is_enum(MonoClass* @class);
|
||||
|
||||
|
||||
[LinkName(.C)]
|
||||
public static extern MonoVTable* mono_class_vtable(MonoDomain* domain, MonoClass* @class);
|
||||
|
||||
|
||||
[LinkName(.C)]
|
||||
public static extern MonoObject* mono_value_box(MonoDomain* domain, MonoClass* klass, gpointer value);
|
||||
|
||||
#region MonoArray
|
||||
|
||||
typealias uintptr_t = uint;
|
||||
typealias intptr_t = int;
|
||||
|
||||
[LinkName(.C)]
|
||||
public static extern MonoArray* mono_array_new(MonoDomain *domain, MonoClass *eclass, uintptr_t length);
|
||||
|
||||
[LinkName(.C)]
|
||||
public static extern MonoArray* mono_array_new_checked(MonoDomain *domain, MonoClass *eclass, uintptr_t length, MonoError *error);
|
||||
|
||||
[LinkName(.C)]
|
||||
public static extern MonoArray* mono_array_new_full(MonoDomain *domain, MonoClass *array_class, uintptr_t* lengths, uintptr_t* lower_bounds);
|
||||
|
||||
[LinkName(.C)]
|
||||
public static extern MonoArray* mono_array_new_full_checked(MonoDomain *domain, MonoClass *array_class, uintptr_t* lengths, uintptr_t* lower_bounds, MonoError *error);
|
||||
|
||||
[LinkName(.C)]
|
||||
public static extern void mono_array_full_copy(MonoArray* src, MonoArray* dest);
|
||||
|
||||
[LinkName(.C)]
|
||||
public static extern MonoArray* mono_array_clone(MonoArray* array);
|
||||
|
||||
[LinkName(.C)]
|
||||
public static extern MonoArray* mono_array_clone_checked(MonoArray* array, MonoError* error);
|
||||
|
||||
[LinkName(.C)]
|
||||
public static extern void* mono_array_addr_with_size(MonoArray *array, int32 size, uintptr_t idx);
|
||||
|
||||
[LinkName(.C)]
|
||||
public static extern uintptr_t mono_array_length(MonoArray *array);
|
||||
|
||||
[Inline]
|
||||
public static T* mono_array_addr<T>(MonoArray* array, uintptr_t index)
|
||||
{
|
||||
return (T*)mono_array_addr_with_size(array, sizeof(T), index);
|
||||
}
|
||||
|
||||
[Inline]
|
||||
public static T mono_array_get<T>(MonoArray* array, uintptr_t index)
|
||||
{
|
||||
return *mono_array_addr<T>(array, index);
|
||||
}
|
||||
|
||||
[Inline]
|
||||
public static void mono_array_set<T>(MonoArray* array, uintptr_t index, T value)
|
||||
{
|
||||
T* entryPtr = mono_array_addr<T>(array, index);
|
||||
*entryPtr = value;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region DebugHelpers
|
||||
|
||||
[LinkName(.C)]
|
||||
public static extern MonoMethod* mono_method_desc_search_in_class(MonoMethodDesc* desc, MonoClass* klass);
|
||||
|
||||
[LinkName(.C)]
|
||||
public static extern MonoMethodDesc* mono_method_desc_new(char8* name, mono_bool include_namespace);
|
||||
|
||||
[LinkName(.C)]
|
||||
public static extern void mono_method_desc_free(MonoMethodDesc* decs);
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
struct MonoMethodDesc;
|
||||
|
||||
struct MonoDomain;
|
||||
|
||||
struct MonoAssembly;
|
||||
|
||||
struct MonoImage;
|
||||
|
||||
struct MonoTableInfo;
|
||||
|
||||
struct MonoString;
|
||||
|
||||
struct MonoClass;
|
||||
|
||||
struct MonoObject;
|
||||
|
||||
struct MonoMethod;
|
||||
|
||||
struct MonoMethodSignature;
|
||||
|
||||
struct MonoProperty;
|
||||
|
||||
struct MonoThread;
|
||||
|
||||
struct MonoVTable;
|
||||
|
||||
struct MonoArray;
|
||||
|
||||
struct MonoException
|
||||
{
|
||||
void* _bla;
|
||||
void* _bla2;
|
||||
void* _bla3;
|
||||
public MonoString* Message;
|
||||
}
|
||||
|
||||
struct MonoClassField;
|
||||
|
||||
struct MonoType;
|
||||
|
||||
struct MonoError
|
||||
{
|
||||
private uint32 bla;
|
||||
private void*[12] bla2;
|
||||
}
|
||||
|
||||
struct MonoReflectionType;
|
||||
|
||||
struct MonoCustomAttrInfo;
|
||||
|
||||
enum MonoImageOpenStatus
|
||||
{
|
||||
Ok,
|
||||
Error_Errno,
|
||||
MissingAssemblyRef,
|
||||
ImageInvalid
|
||||
}
|
||||
|
||||
enum SOME_RANDOM_ENUM{
|
||||
MONO_TYPEDEF_FLAGS,
|
||||
MONO_TYPEDEF_NAME,
|
||||
MONO_TYPEDEF_NAMESPACE,
|
||||
MONO_TYPEDEF_EXTENDS,
|
||||
MONO_TYPEDEF_FIELD_LIST,
|
||||
MONO_TYPEDEF_METHOD_LIST,
|
||||
MONO_TYPEDEF_SIZE
|
||||
}
|
||||
|
||||
enum FIELD_TABLE_FLAGS : uint32
|
||||
{
|
||||
MONO_FIELD_FLAGS,
|
||||
MONO_FIELD_NAME,
|
||||
MONO_FIELD_SIGNATURE,
|
||||
MONO_FIELD_SIZE
|
||||
}
|
||||
|
||||
enum MonoMetaTableEnum : int32
|
||||
{
|
||||
MONO_TABLE_MODULE,
|
||||
MONO_TABLE_TYPEREF,
|
||||
MONO_TABLE_TYPEDEF,
|
||||
MONO_TABLE_FIELD_POINTER,
|
||||
MONO_TABLE_FIELD,
|
||||
MONO_TABLE_METHOD_POINTER,
|
||||
MONO_TABLE_METHOD,
|
||||
MONO_TABLE_PARAM_POINTER,
|
||||
MONO_TABLE_PARAM,
|
||||
MONO_TABLE_INTERFACEIMPL,
|
||||
MONO_TABLE_MEMBERREF, /* 0xa */
|
||||
MONO_TABLE_CONSTANT,
|
||||
MONO_TABLE_CUSTOMATTRIBUTE,
|
||||
MONO_TABLE_FIELDMARSHAL,
|
||||
MONO_TABLE_DECLSECURITY,
|
||||
MONO_TABLE_CLASSLAYOUT,
|
||||
MONO_TABLE_FIELDLAYOUT, /* 0x10 */
|
||||
MONO_TABLE_STANDALONESIG,
|
||||
MONO_TABLE_EVENTMAP,
|
||||
MONO_TABLE_EVENT_POINTER,
|
||||
MONO_TABLE_EVENT,
|
||||
MONO_TABLE_PROPERTYMAP,
|
||||
MONO_TABLE_PROPERTY_POINTER,
|
||||
MONO_TABLE_PROPERTY,
|
||||
MONO_TABLE_METHODSEMANTICS,
|
||||
MONO_TABLE_METHODIMPL,
|
||||
MONO_TABLE_MODULEREF, /* 0x1a */
|
||||
MONO_TABLE_TYPESPEC,
|
||||
MONO_TABLE_IMPLMAP,
|
||||
MONO_TABLE_FIELDRVA,
|
||||
MONO_TABLE_ENCLOG,
|
||||
MONO_TABLE_ENCMAP,
|
||||
MONO_TABLE_ASSEMBLY, /* 0x20 */
|
||||
MONO_TABLE_ASSEMBLYPROCESSOR,
|
||||
MONO_TABLE_ASSEMBLYOS,
|
||||
MONO_TABLE_ASSEMBLYREF,
|
||||
MONO_TABLE_ASSEMBLYREFPROCESSOR,
|
||||
MONO_TABLE_ASSEMBLYREFOS,
|
||||
MONO_TABLE_FILE,
|
||||
MONO_TABLE_EXPORTEDTYPE,
|
||||
MONO_TABLE_MANIFESTRESOURCE,
|
||||
MONO_TABLE_NESTEDCLASS,
|
||||
MONO_TABLE_GENERICPARAM, /* 0x2a */
|
||||
MONO_TABLE_METHODSPEC,
|
||||
MONO_TABLE_GENERICPARAMCONSTRAINT,
|
||||
MONO_TABLE_UNUSED8,
|
||||
MONO_TABLE_UNUSED9,
|
||||
MONO_TABLE_UNUSED10,
|
||||
/* Portable PDB tables */
|
||||
MONO_TABLE_DOCUMENT, /* 0x30 */
|
||||
MONO_TABLE_METHODBODY,
|
||||
MONO_TABLE_LOCALSCOPE,
|
||||
MONO_TABLE_LOCALVARIABLE,
|
||||
MONO_TABLE_LOCALCONSTANT,
|
||||
MONO_TABLE_IMPORTSCOPE,
|
||||
MONO_TABLE_STATEMACHINEMETHOD,
|
||||
MONO_TABLE_CUSTOMDEBUGINFORMATION
|
||||
|
||||
//#define MONO_TABLE_LAST MONO_TABLE_CUSTOMDEBUGINFORMATION
|
||||
//#define MONO_TABLE_NUM (MONO_TABLE_LAST + 1)
|
||||
|
||||
}
|
||||
|
||||
enum DebugFormat : uint32
|
||||
{
|
||||
None,
|
||||
Mono,
|
||||
/** Deprecated, the mdb debugger is not longer supported. */
|
||||
Debugger
|
||||
}
|
||||
|
||||
enum FieldAttribute
|
||||
{
|
||||
FieldAccessMask = 0x0007,
|
||||
CompilerControlled = 0x0000,
|
||||
Private = 0x0001,
|
||||
FamAndAssem = 0x0002,
|
||||
Assembly = 0x0003,
|
||||
Family = 0x0004,
|
||||
FamOrAssem = 0x0005,
|
||||
Public = 0x0006,
|
||||
Static = 0x0010,
|
||||
InitOnly = 0x0020,
|
||||
Literal = 0x0040,
|
||||
NotSerialized = 0x0080,
|
||||
SpecialName = 0x0200,
|
||||
PinvokeImpl = 0x2000,
|
||||
/** For runtime use only */
|
||||
ReservedMask = 0x9500,
|
||||
/** For runtime use only */
|
||||
RtSpecialName = 0x0400,
|
||||
/** For runtime use only */
|
||||
HasFieldMarshal = 0x1000,
|
||||
/** For runtime use only */
|
||||
HasDefault = 0x8000,
|
||||
/** For runtime use only */
|
||||
HasFieldRva = 0x0100
|
||||
}
|
||||
|
||||
enum MonoTypeEnum : int32
|
||||
{
|
||||
End = 0x00, /* End of List */
|
||||
Void = 0x01,
|
||||
Boolean = 0x02,
|
||||
Char = 0x03,
|
||||
I1 = 0x04,
|
||||
U1 = 0x05,
|
||||
I2 = 0x06,
|
||||
U2 = 0x07,
|
||||
I4 = 0x08,
|
||||
U4 = 0x09,
|
||||
I8 = 0x0a,
|
||||
U8 = 0x0b,
|
||||
R4 = 0x0c,
|
||||
R8 = 0x0d,
|
||||
String = 0x0e,
|
||||
Ptr = 0x0f, /* arg: <type> token */
|
||||
Byref = 0x10, /* arg: <type> token */
|
||||
Valuetype = 0x11, /* arg: <type> token */
|
||||
Class = 0x12, /* arg: <type> token */
|
||||
Var = 0x13, /* number */
|
||||
Array = 0x14, /* type, rank, boundsCount, bound1, loCount, lo1 */
|
||||
Genericinst = 0x15, /* <type> <type-arg-count> <type-1> \x{2026} <type-n> */
|
||||
Typedbyref = 0x16,
|
||||
I = 0x18,
|
||||
U = 0x19,
|
||||
Fnptr = 0x1b, /* arg: full method signature */
|
||||
Object = 0x1c,
|
||||
SzArray = 0x1d, /* 0-based one-dim-array */
|
||||
Mvar = 0x1e, /* number */
|
||||
CmodReqd = 0x1f, /* arg: typedef or typeref token */
|
||||
CmodOpt = 0x20, /* optional arg: typedef or typref token */
|
||||
Internal = 0x21, /* CLR internal type */
|
||||
Modifier = 0x40, /* Or with the following types */
|
||||
Sentinel = 0x41, /* Sentinel for varargs method signature */
|
||||
Pinned = 0x45, /* Local var that points to pinned object */
|
||||
Enum = 0x55 /* an enumeration */
|
||||
}
|
||||
@@ -613,17 +613,10 @@ internal class EntityEditor
|
||||
{
|
||||
|
||||
}
|
||||
else if (fieldType.IsGenericType)
|
||||
{
|
||||
if (fieldType.GetGenericTypeDefinition() == typeof(List<>))
|
||||
else if (fieldType.IsGenericType && fieldType.GetGenericTypeDefinition() == typeof(List<>))
|
||||
{
|
||||
newValue = ShowListEditor(fieldType, reference, fieldName);
|
||||
}
|
||||
else
|
||||
{
|
||||
ImGui.TextColored(new Vector4(1, 0, 0, 1), $"{fieldName}: Type {fieldType} is not implemented.");
|
||||
}
|
||||
}
|
||||
else if (fieldType.IsArray)
|
||||
{
|
||||
newValue = ShowArrayEditor(fieldType, reference, fieldName);
|
||||
|
||||
@@ -21,7 +21,7 @@ public partial class Entity : EngineObject
|
||||
/// </summary>
|
||||
public string Name
|
||||
{
|
||||
get => "TODO!";//ScriptGlue.Entity_GetName(_uuid);
|
||||
get => ScriptGlue.Entity_GetName(_uuid);
|
||||
set => ScriptGlue.Entity_SetName(_uuid, value);
|
||||
}
|
||||
|
||||
|
||||
+24
-18
@@ -18,6 +18,12 @@ using System.Text;
|
||||
using System.Threading;
|
||||
using System.Xml.Linq;
|
||||
|
||||
// This attribute is NOT optional, removing it silently breaks every engine function that takes or returns a bool!
|
||||
// With runtime marshalling enabled the CLR treats bool in an unmanaged function pointer as a 4-byte Win32 BOOL and checks all of eax,
|
||||
// but Beef only writes al (1 byte). The upper bytes are garbage, so the result is (almost) always true. Everything would still compile.
|
||||
// The price: in/ref/out are not allowed in unmanaged signatures of this assembly, which is why the generator emits raw pointers and pins with fixed.
|
||||
[assembly: DisableRuntimeMarshalling]
|
||||
|
||||
namespace GlitchyEngine;
|
||||
|
||||
/// <summary>
|
||||
@@ -679,6 +685,15 @@ internal static unsafe partial class ScriptGlue
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Layout stand-in to get a reference to the contents of a boxed value type via <see cref="Unsafe.As{T}(object)"/>.
|
||||
/// Never instantiated.
|
||||
/// </summary>
|
||||
private sealed class RawData
|
||||
{
|
||||
public byte Data;
|
||||
}
|
||||
|
||||
public static void Serialization_SerializeField(IntPtr serializationContext, SerializationType type, string fieldName, object? valueObject, string? fullTypeName)
|
||||
{
|
||||
StringView fieldNameConverted;
|
||||
@@ -730,7 +745,7 @@ internal static unsafe partial class ScriptGlue
|
||||
nativeString = new StringView(pointer, bytes);
|
||||
}
|
||||
|
||||
_engineFunctions.Serialization_SerializeField((void*)serializationContext, type, fieldNameConverted, &nativeString, fullTypeNameConverted);
|
||||
_engineFunctions.Serialization_SerializeField((void*)serializationContext, type, &fieldNameConverted, &nativeString, &fullTypeNameConverted);
|
||||
|
||||
if (onHeap)
|
||||
StringView.FreeNativeMemory(nativeString);
|
||||
@@ -738,25 +753,16 @@ internal static unsafe partial class ScriptGlue
|
||||
default:
|
||||
if (valueObject is not null)
|
||||
{
|
||||
// This is probably the dirtiest piece of C# Code, that I have ever seen.
|
||||
// We first take a pointer the Object (which itself is a reference type -> object* is a double pointer!)
|
||||
// We then dereference this double pointer, which gives us a pointer to the objects internals.
|
||||
// These are Header (64bit), Method Table (64bit), and the objects content (at least another 64bit)
|
||||
// I believe, that the actual reference points to the method table however and not the header (compare gcenv.object.h)
|
||||
// Below we calculate a pointer to the objects contents by adding the size of a pointer.
|
||||
|
||||
#pragma warning disable CS8500 // This takes the address of, gets the size of, or declares a pointer to a managed type
|
||||
object?* objectRef = &valueObject;
|
||||
// Skip Object Header (IntPtr) + Method Table (IntPtr)
|
||||
byte* valueRef = (byte*)*(IntPtr*)objectRef + sizeof(IntPtr);
|
||||
float* fRef = (float*)(void*)valueRef;
|
||||
_engineFunctions.Serialization_SerializeField((void*)serializationContext, type, fieldNameConverted, valueRef, fullTypeNameConverted);
|
||||
// valueObject is a boxed value type. An object reference points to the method table pointer, the boxed value starts right behind it.
|
||||
// That's exactly where the first field of RawData lives, so reinterpreting the box gives us a reference to the first byte of the value.
|
||||
// We have to pin it: During the native call this thread is in preemptive mode and a GC is free to move the box.
|
||||
fixed (byte* valueRef = &Unsafe.As<RawData>(valueObject).Data)
|
||||
{
|
||||
_engineFunctions.Serialization_SerializeField((void*)serializationContext, type, &fieldNameConverted, valueRef, &fullTypeNameConverted);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
//StringView.FreeNativeMemory(fieldNameConverted);
|
||||
//StringView.FreeNativeMemory(fullTypeNameConverted);
|
||||
}
|
||||
|
||||
public static void Serialization_SerializeValueType<T>(IntPtr serializationContext, SerializationType type, string fieldName, in T value, string? fullTypeName) where T : unmanaged
|
||||
@@ -782,7 +788,7 @@ internal static unsafe partial class ScriptGlue
|
||||
|
||||
fixed (T* valuePtr = &value)
|
||||
{
|
||||
_engineFunctions.Serialization_SerializeField((void*)serializationContext, type, fieldNameConverted, valuePtr, fullTypeNameConverted);
|
||||
_engineFunctions.Serialization_SerializeField((void*)serializationContext, type, &fieldNameConverted, valuePtr, &fullTypeNameConverted);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -324,7 +324,9 @@ public class DeserializationObject
|
||||
return deserializedValue;
|
||||
}
|
||||
|
||||
if (fieldType.IsPrimitive)
|
||||
// Decimals are not actually primitives, but we treat them as if they were, because they are a built-in type
|
||||
// and it makes more sense to send them over to the engine as a binary type than to serialize their underlying fields (which would happen when we treated them as a struct).
|
||||
if (fieldType.IsPrimitive || fieldType == typeof(decimal))
|
||||
{
|
||||
return DeserializePrimitive(fieldName, fieldType);
|
||||
}
|
||||
@@ -364,7 +366,7 @@ public class DeserializationObject
|
||||
|
||||
public object? DeserializePrimitive(string fieldName, Type fieldType)
|
||||
{
|
||||
Debug.Assert(fieldType.IsPrimitive, $"{fieldType} is not a primitive type.");
|
||||
Debug.Assert(fieldType.IsPrimitive || fieldType == typeof(decimal), $"{fieldType} is not a primitive type.");
|
||||
|
||||
SerializationType expectedType = SerializationType.None;
|
||||
|
||||
|
||||
@@ -176,6 +176,11 @@ public class SerializedObject
|
||||
|
||||
public void SerializeField(string fieldName, object? fieldValue, Type fieldType)
|
||||
{
|
||||
if (TryCustomSerializer(fieldName, fieldValue, fieldType))
|
||||
return;
|
||||
|
||||
// Decimals are not actually primitives, but we treat them as if they were, because they are a built-in type
|
||||
// and it makes more sense to send them over to the engine as a binary type than to serialize their underlying fields (which would happen when we treated them as a struct).
|
||||
if (fieldType.IsPrimitive || fieldType == typeof(decimal))
|
||||
{
|
||||
// Primitives can't be null
|
||||
@@ -200,38 +205,17 @@ public class SerializedObject
|
||||
|
||||
SerializeList(fieldName, fieldValue, fieldType, fieldType.GetElementType()!);
|
||||
}
|
||||
else if (fieldType.IsGenericType)
|
||||
{
|
||||
if (TryCustomSerializer(fieldName, fieldValue, fieldType))
|
||||
return;
|
||||
|
||||
if (fieldType.GetGenericTypeDefinition() == typeof(List<>))
|
||||
else if (fieldType.IsGenericType && fieldType.GetGenericTypeDefinition() == typeof(List<>))
|
||||
{
|
||||
SerializeList(fieldName, fieldValue, fieldType, fieldType.GetGenericArguments()[0]);
|
||||
}
|
||||
//else if (fieldType.GetGenericTypeDefinition() == typeof(Dictionary<,>))
|
||||
//{
|
||||
// ImGui.Text($"{fieldName} Dictionary");
|
||||
//}
|
||||
else
|
||||
{
|
||||
// TODO: what to do?
|
||||
Log.Error($"Generic class serialization not yet implemented");
|
||||
}
|
||||
}
|
||||
else if (fieldType.IsValueType)
|
||||
{
|
||||
if (TryCustomSerializer(fieldName, fieldValue, fieldType))
|
||||
return;
|
||||
|
||||
// Value Types cant be null
|
||||
SerializeStruct(fieldName, fieldValue!, fieldType);
|
||||
}
|
||||
else if (fieldType.IsClass)
|
||||
{
|
||||
if (TryCustomSerializer(fieldName, fieldValue, fieldType))
|
||||
return;
|
||||
|
||||
SerializeClass(fieldName, fieldValue, fieldType);
|
||||
}
|
||||
else
|
||||
|
||||
@@ -9,8 +9,11 @@ using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Threading;
|
||||
using Microsoft.CodeAnalysis;
|
||||
using Microsoft.CodeAnalysis.CSharp;
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
|
||||
using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory;
|
||||
|
||||
namespace ScriptCoreGenerator;
|
||||
|
||||
internal class GlueMethod
|
||||
@@ -19,6 +22,8 @@ internal class GlueMethod
|
||||
public string Name { get; set; }
|
||||
[JsonPropertyName("return_type")]
|
||||
public string ReturnType { get; set; }
|
||||
[JsonPropertyName("guaranteed_short_running")]
|
||||
public bool GuaranteedShortRunning { get; set; }
|
||||
[JsonPropertyName("parameters")]
|
||||
public List<Parameter> Parameters { get; set; }
|
||||
|
||||
@@ -292,23 +297,13 @@ public class ScriptGlueGenerator : IIncrementalGenerator
|
||||
var (parameterType, parameterModifier) = DecodeType(param.Type, beefTypeToMappedType);
|
||||
parameters.Add(parameterType);
|
||||
|
||||
switch (parameterModifier)
|
||||
{
|
||||
case TypeModifier.In:
|
||||
parameterText.Append("in ");
|
||||
break;
|
||||
case TypeModifier.Out:
|
||||
parameterText.Append("out ");
|
||||
break;
|
||||
case TypeModifier.Ref:
|
||||
parameterText.Append("ref ");
|
||||
break;
|
||||
}
|
||||
|
||||
parameterText.Append(parameterType.CSharpTypeName);
|
||||
|
||||
switch (parameterModifier)
|
||||
{
|
||||
case TypeModifier.In:
|
||||
case TypeModifier.Out:
|
||||
case TypeModifier.Ref:
|
||||
case TypeModifier.Pointer:
|
||||
parameterText.Append("*");
|
||||
break;
|
||||
@@ -317,17 +312,35 @@ public class ScriptGlueGenerator : IIncrementalGenerator
|
||||
parameterText.Append(", ");
|
||||
}
|
||||
|
||||
output.AppendLine($" public delegate* unmanaged[Cdecl]<{parameterText}{returnType.CSharpTypeName}> {method.Name};");
|
||||
string callingConvention = "Cdecl";
|
||||
|
||||
#if !DEBUG
|
||||
// Normally when calling into unmanaged code the current thread transitions
|
||||
// from cooperative GC mode (all threads block for GC collection) to preemtive (other threads can gc independently from us).
|
||||
// This is done to prevent long running native code (e.g. native code opens a message box) from blocking all threads because
|
||||
// they wait for GC to happen, which can lead to problems. If we know however that the called native function is very short
|
||||
// (short than the GC transition itself) then we can explicitly prevent the suppression.
|
||||
// We rely on the engine (ScriptGlue.bf) to tell us that information.
|
||||
//
|
||||
// A GuaranteedShortRunning function should have a VERY short runtime (< 1μs), must NEVER block, and NEVER call back into managed code!
|
||||
//
|
||||
// We only enable it in release builds, as it will prevent the mixed mode debugger from stepping over the managed-native-border.
|
||||
if (method.GuaranteedShortRunning)
|
||||
{
|
||||
callingConvention += ", SuppressGCTransition";
|
||||
}
|
||||
#endif
|
||||
|
||||
output.AppendLine($" public delegate* unmanaged[{callingConvention}]<{parameterText}{returnType.CSharpTypeName}> {method.Name};");
|
||||
}
|
||||
|
||||
private static void GenerateWrapper(GlueMethod method, Dictionary<string, MappedType> beefTypeToMappedType, StringBuilder output)
|
||||
{
|
||||
// MappedType returnType = DecodeType(method.ReturnType, beefTypeToMappedType);
|
||||
//
|
||||
List<MappedType> parameters = new();
|
||||
StringBuilder parameterText = new();
|
||||
StringBuilder parameterConversion = new();
|
||||
StringBuilder cleanup = new();
|
||||
List<string> parameterConversions = new();
|
||||
List<string> cleanups = new();
|
||||
List<string> afterReturnCleanups = new();
|
||||
StringBuilder call = new();
|
||||
|
||||
var (returnType, _) = DecodeType(method.ReturnType, beefTypeToMappedType);
|
||||
@@ -370,33 +383,31 @@ public class ScriptGlueGenerator : IIncrementalGenerator
|
||||
|
||||
parameterText.Append($" {param.Name}");
|
||||
|
||||
switch (parameterModifier)
|
||||
{
|
||||
case TypeModifier.In:
|
||||
call.Append("in ");
|
||||
break;
|
||||
case TypeModifier.Out:
|
||||
call.Append("out ");
|
||||
break;
|
||||
case TypeModifier.Ref:
|
||||
call.Append("ref ");
|
||||
break;
|
||||
}
|
||||
|
||||
if (parameterModifier == TypeModifier.Out && parameterType.WrapperOutConversion is not null)
|
||||
{
|
||||
string tmpArgName = $"{param.Name}Tmp";
|
||||
|
||||
call.Append($"var {tmpArgName}");
|
||||
call.Append($"&{tmpArgName}");
|
||||
|
||||
cleanup.Append("\t\t");
|
||||
cleanup.AppendFormat(parameterType.WrapperOutConversion, tmpArgName, param.Name);
|
||||
cleanup.AppendLine();
|
||||
parameterConversions.Add($"{parameterType.CSharpTypeName} {tmpArgName} = default;");
|
||||
cleanups.Add(string.Format(parameterType.WrapperOutConversion, tmpArgName, param.Name));
|
||||
}
|
||||
else if (parameterType.WrapperConvertInput is not null)
|
||||
{
|
||||
switch (parameterModifier)
|
||||
{
|
||||
case TypeModifier.In:
|
||||
case TypeModifier.Out:
|
||||
case TypeModifier.Ref:
|
||||
case TypeModifier.Pointer:
|
||||
call.Append("&");
|
||||
break;
|
||||
}
|
||||
|
||||
string convertedParamName = $"{param.Name}Converted";
|
||||
|
||||
StringBuilder parameterConversion = new();
|
||||
StringBuilder cleanup = new();
|
||||
parameterConversion.AppendLine();
|
||||
parameterConversion.Append("\t\t");
|
||||
parameterConversion.AppendFormat(parameterType.WrapperConvertInput, convertedParamName, param.Name);
|
||||
@@ -409,23 +420,40 @@ public class ScriptGlueGenerator : IIncrementalGenerator
|
||||
}
|
||||
|
||||
call.Append(convertedParamName);
|
||||
parameterConversions.Add(parameterConversion.ToString());
|
||||
cleanups.Add(cleanup.ToString());
|
||||
}
|
||||
else
|
||||
{
|
||||
call.Append(param.Name);
|
||||
string paramName = param.Name;
|
||||
|
||||
switch (parameterModifier)
|
||||
{
|
||||
case TypeModifier.In:
|
||||
case TypeModifier.Out:
|
||||
case TypeModifier.Ref:
|
||||
paramName = "__" + param.Name + "FixedPtr";
|
||||
parameterConversions.Add($"fixed ({parameterType.CSharpTypeName}* {paramName} = &{param.Name}) {{");
|
||||
afterReturnCleanups.Add("}");
|
||||
break;
|
||||
}
|
||||
|
||||
call.Append(paramName);
|
||||
}
|
||||
}
|
||||
|
||||
call.Append(");");
|
||||
|
||||
output.AppendLine($$"""
|
||||
output.AppendLine(
|
||||
$$"""
|
||||
public static {{returnType.CSharpWrapperType}} {{method.Name}}({{parameterText}})
|
||||
{{{parameterConversion}}
|
||||
{
|
||||
{{string.Join("\n", parameterConversions)}}
|
||||
{{call}}
|
||||
{{cleanup}}
|
||||
{{string.Join("\n", Enumerable.Reverse(cleanups))}}
|
||||
{{returnType.ReturnValueConversion}}
|
||||
{{string.Join("\n", afterReturnCleanups)}}
|
||||
}
|
||||
|
||||
""");
|
||||
|
||||
|
||||
@@ -470,6 +498,7 @@ public class ScriptGlueGenerator : IIncrementalGenerator
|
||||
|
||||
unsafe internal partial struct EngineFunctions
|
||||
{
|
||||
|
||||
""");
|
||||
|
||||
wrappers.Append("""
|
||||
@@ -483,6 +512,7 @@ public class ScriptGlueGenerator : IIncrementalGenerator
|
||||
|
||||
internal static unsafe partial class ScriptGlue
|
||||
{
|
||||
|
||||
""");
|
||||
|
||||
List<GlueMethod> methods = new List<GlueMethod>();
|
||||
@@ -505,11 +535,13 @@ public class ScriptGlueGenerator : IIncrementalGenerator
|
||||
}
|
||||
}
|
||||
|
||||
engineFunctions.Append("\n}");
|
||||
engineFunctions.Append("}");
|
||||
wrappers.Append("\n}");
|
||||
|
||||
var parsedWrappers = ParseCompilationUnit(wrappers.ToString());
|
||||
|
||||
context.AddSource("EngineFunctions.g.cs", engineFunctions.ToString());
|
||||
context.AddSource("ScriptGlue.g.cs", wrappers.ToString());
|
||||
context.AddSource("ScriptGlue.g.cs", parsedWrappers.NormalizeWhitespace().ToFullString());
|
||||
}
|
||||
|
||||
private static bool IsScriptGlueClass(
|
||||
|
||||
Reference in New Issue
Block a user