Compare commits
No commits in common. "60b85960ff2b54a3329c76ce97485591c04176af" and "777059489c0e461d51d63d02170c8f53280a3cc2" have entirely different histories.
60b85960ff
...
777059489c
9
.gitignore
vendored
9
.gitignore
vendored
@ -451,13 +451,8 @@ FodyWeavers.xsd
|
||||
|
||||
#------------------------- Nerfed -------------------------
|
||||
|
||||
Bin/
|
||||
Intermediate/
|
||||
|
||||
imgui.ini
|
||||
|
||||
# include libs
|
||||
!/Native/lib64
|
||||
!/Native/x64
|
||||
|
||||
|
||||
!/libs/lib64
|
||||
!/libs/x64
|
@ -2,10 +2,5 @@
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="Git" />
|
||||
<mapping directory="$PROJECT_DIR$/Nerfed.Runtime/Libraries/FAudio" vcs="Git" />
|
||||
<mapping directory="$PROJECT_DIR$/Nerfed.Runtime/Libraries/RefreshCS" vcs="Git" />
|
||||
<mapping directory="$PROJECT_DIR$/Nerfed.Runtime/Libraries/SDL2CS" vcs="Git" />
|
||||
<mapping directory="$PROJECT_DIR$/Nerfed.Runtime/Libraries/WellspringCS" vcs="Git" />
|
||||
<mapping directory="$PROJECT_DIR$/Nerfed.Runtime/Libraries/dav1dfile" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
@ -1,7 +0,0 @@
|
||||
<Project>
|
||||
<PropertyGroup>
|
||||
<OutDir>../Bin/$(MSBuildProjectName)</OutDir>
|
||||
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">../Intermediate/$(MSBuildProjectName)</BaseIntermediateOutputPath>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
|
@ -1,129 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.ComponentModel;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Nerfed.Builder;
|
||||
|
||||
|
||||
public class ArgsParser<TArgs> where TArgs : new()
|
||||
{
|
||||
private enum ArgType
|
||||
{
|
||||
None,
|
||||
Key,
|
||||
Value
|
||||
}
|
||||
|
||||
public TArgs Arguments { get; }
|
||||
|
||||
private readonly string[] args;
|
||||
private readonly Dictionary<string, PropertyInfo> argKeyPropertyMap = new Dictionary<string, PropertyInfo>();
|
||||
|
||||
public ArgsParser(string[] args)
|
||||
{
|
||||
this.args = args;
|
||||
Arguments = new TArgs();
|
||||
PropertyInfo[] properties = Arguments.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public);
|
||||
foreach (PropertyInfo property in properties)
|
||||
{
|
||||
ArgumentAttribute argAttribute = property.GetCustomAttribute<ArgumentAttribute>();
|
||||
if (argAttribute == null || string.IsNullOrEmpty(argAttribute.ArgKey))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
argKeyPropertyMap.Add(argAttribute.ArgKey, property);
|
||||
}
|
||||
}
|
||||
|
||||
public bool Parse()
|
||||
{
|
||||
PropertyInfo property = null;
|
||||
ArgType lastArgType = ArgType.None;
|
||||
|
||||
for (int i = 0; i < args.Length; i++)
|
||||
{
|
||||
string arg = args[i];
|
||||
if (arg[0] == '-')
|
||||
{
|
||||
if (!argKeyPropertyMap.TryGetValue(arg, out property))
|
||||
{
|
||||
Console.Error.WriteLine($"Invalid argument: {arg}, no such argument key exists");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Boolean arguments require no value, set to true immidiately.
|
||||
if (property.PropertyType == typeof(bool))
|
||||
{
|
||||
property.SetValue(Arguments, true);
|
||||
lastArgType = ArgType.Value;
|
||||
}
|
||||
else
|
||||
{
|
||||
lastArgType = ArgType.Key;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (lastArgType == ArgType.None)
|
||||
{
|
||||
Console.Error.WriteLine($"Invalid argument: {arg}, no argument key was provided");
|
||||
return false;
|
||||
}
|
||||
|
||||
Type propertyType = property.PropertyType;
|
||||
if (propertyType.IsArray)
|
||||
{
|
||||
throw new InvalidOperationException("Arrays are not supported, use List<T> instead");
|
||||
}
|
||||
|
||||
bool propertyTypeIsList = propertyType.IsGenericType && propertyType.GetGenericTypeDefinition() == typeof(List<>);
|
||||
if (propertyTypeIsList)
|
||||
{
|
||||
propertyType = propertyType.GenericTypeArguments[0];
|
||||
}
|
||||
|
||||
TypeConverter typeConverter = TypeDescriptor.GetConverter(propertyType);
|
||||
object value = typeConverter.ConvertFromString(arg);
|
||||
|
||||
if (value is string stringValue)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(stringValue))
|
||||
{
|
||||
if (stringValue[0] == '"')
|
||||
{
|
||||
stringValue = stringValue.Substring(1, stringValue.Length - 1);
|
||||
}
|
||||
|
||||
if (stringValue[^1] == '"')
|
||||
{
|
||||
stringValue = stringValue.Substring(0, stringValue.Length - 1);
|
||||
}
|
||||
|
||||
value = stringValue;
|
||||
}
|
||||
}
|
||||
|
||||
if (propertyTypeIsList)
|
||||
{
|
||||
IList list = (IList)property.GetValue(Arguments);
|
||||
if (list == null)
|
||||
{
|
||||
list = (IList)Activator.CreateInstance(property.PropertyType);
|
||||
property.SetValue(Arguments, list);
|
||||
}
|
||||
|
||||
list.Add(value);
|
||||
}
|
||||
else
|
||||
{
|
||||
property.SetValue(Arguments, value);
|
||||
}
|
||||
|
||||
lastArgType = ArgType.Value;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
namespace Nerfed.Builder;
|
||||
|
||||
public class ArgumentAttribute : Attribute
|
||||
{
|
||||
public string ArgKey { get; }
|
||||
|
||||
public ArgumentAttribute(string argKey)
|
||||
{
|
||||
ArgKey = argKey;
|
||||
}
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
namespace Nerfed.Builder;
|
||||
|
||||
public class BuildArgs
|
||||
{
|
||||
[Argument("-build")]
|
||||
public bool Build { get; set; }
|
||||
|
||||
[Argument("-projectPath")]
|
||||
public string ProjectPath { get; set; }
|
||||
|
||||
[Argument("-platform")]
|
||||
public string Platform { get; set; }
|
||||
|
||||
[Argument("-content")]
|
||||
public List<string> ContentFiles { get; set; }
|
||||
}
|
@ -1,149 +0,0 @@
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace Nerfed.Builder;
|
||||
|
||||
public class Builder : IDisposable
|
||||
{
|
||||
private readonly Dictionary<string, IImporter> importers = new Dictionary<string, IImporter>();
|
||||
private readonly RawFileImporter rawFileImporter;
|
||||
|
||||
public Builder()
|
||||
{
|
||||
rawFileImporter = new RawFileImporter();
|
||||
|
||||
ShaderImporter shaderImporter = new ShaderImporter();
|
||||
importers.Add(".vert", shaderImporter); // Vertex shader
|
||||
importers.Add(".frag", shaderImporter); // Fragment shader
|
||||
importers.Add(".tesc", shaderImporter); // Tessellation control shader
|
||||
importers.Add(".tese", shaderImporter); // Tessellation evaluation shader
|
||||
importers.Add(".geom", shaderImporter); // Geometry shader
|
||||
importers.Add(".comp", shaderImporter); // Compute shader
|
||||
}
|
||||
|
||||
public void Run(BuildArgs args)
|
||||
{
|
||||
Stopwatch stopwatch = new Stopwatch();
|
||||
stopwatch.Start();
|
||||
|
||||
CopyLibs(args.ProjectPath);
|
||||
|
||||
List<string> contentFiles = args.ContentFiles;
|
||||
string absContentPath = $"{args.ProjectPath}/{PathUtil.ContentFolderName}";
|
||||
|
||||
// If no files are provided, build all content.
|
||||
if (args.ContentFiles == null)
|
||||
{
|
||||
contentFiles = [];
|
||||
CollectAssetFiles(absContentPath, absContentPath, ref contentFiles);
|
||||
}
|
||||
|
||||
string importPath = $"{args.ProjectPath}/{PathUtil.ImportFolderName}";
|
||||
|
||||
ParallelOptions parallelOptions = new ParallelOptions
|
||||
{
|
||||
MaxDegreeOfParallelism = contentFiles.Count
|
||||
};
|
||||
Parallel.ForEach(contentFiles, parallelOptions, relativeFile =>
|
||||
{
|
||||
try
|
||||
{
|
||||
string inFile = $"{args.ProjectPath}/{PathUtil.ContentFolderName}/{relativeFile}";
|
||||
|
||||
if (!File.Exists(inFile))
|
||||
{
|
||||
Console.Error.WriteLine($"Asset file '{relativeFile}' not found");
|
||||
return;
|
||||
}
|
||||
|
||||
string outFile = $"{importPath}/{relativeFile}{PathUtil.ImportedFileExtension}";
|
||||
|
||||
FileInfo inFileInfo = new FileInfo(inFile);
|
||||
FileInfo outFileInfo = new FileInfo(outFile);
|
||||
|
||||
if (!FileUtil.IsNewer(inFileInfo, outFileInfo))
|
||||
{
|
||||
// File has not changed since last build, no need to build this one.
|
||||
return;
|
||||
}
|
||||
|
||||
string outDir = Path.GetDirectoryName(outFile);
|
||||
if (!Directory.Exists(outDir))
|
||||
{
|
||||
Directory.CreateDirectory(outDir);
|
||||
}
|
||||
|
||||
string ext = Path.GetExtension(inFile).ToLower();
|
||||
if (importers.TryGetValue(ext, out IImporter importer))
|
||||
{
|
||||
importer.Import(inFile, outFile);
|
||||
}
|
||||
else
|
||||
{
|
||||
rawFileImporter.Import(inFile, outFile);
|
||||
}
|
||||
|
||||
Console.WriteLine(relativeFile);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.Error.WriteLine($"Import error on asset '{relativeFile}': {e.Message}");
|
||||
}
|
||||
});
|
||||
|
||||
Console.WriteLine($"Build content completed in {stopwatch.Elapsed.TotalSeconds:F2} seconds");
|
||||
}
|
||||
|
||||
private void CopyLibs(string projectPath)
|
||||
{
|
||||
string libDir = $"{Directory.GetCurrentDirectory()}/../../Native/";
|
||||
if (OperatingSystem.IsWindows())
|
||||
{
|
||||
libDir += "x64";
|
||||
}
|
||||
else if (OperatingSystem.IsLinux())
|
||||
{
|
||||
libDir += "lib64";
|
||||
}
|
||||
else if (OperatingSystem.IsMacOS())
|
||||
{
|
||||
libDir += "osx";
|
||||
}
|
||||
|
||||
libDir = Path.GetFullPath(libDir);
|
||||
foreach (string libFile in Directory.EnumerateFiles(libDir))
|
||||
{
|
||||
FileInfo srcFileInfo = new FileInfo(libFile);
|
||||
FileInfo dstFileInfo = new FileInfo($"{projectPath}/{PathUtil.BuildFolderName}/{Path.GetFileName(libFile)}");
|
||||
if (FileUtil.IsNewer(srcFileInfo, dstFileInfo))
|
||||
{
|
||||
FileUtil.Copy(srcFileInfo, dstFileInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void CollectAssetFiles(string assetDir, string dir, ref List<string> files)
|
||||
{
|
||||
foreach (string file in Directory.EnumerateFiles(dir))
|
||||
{
|
||||
if (Path.GetExtension(file).Equals(PathUtil.ImportFileExtension, StringComparison.CurrentCultureIgnoreCase))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
string relativeFile = file.Substring(assetDir.Length, file.Length - assetDir.Length);
|
||||
if (relativeFile[0] == Path.DirectorySeparatorChar || relativeFile[0] == Path.AltDirectorySeparatorChar)
|
||||
{
|
||||
relativeFile = relativeFile.Substring(1, relativeFile.Length - 1);
|
||||
}
|
||||
|
||||
files.Add(relativeFile);
|
||||
}
|
||||
|
||||
foreach (string subDir in Directory.EnumerateDirectories(dir))
|
||||
{
|
||||
CollectAssetFiles(assetDir, subDir, ref files);
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose() { }
|
||||
}
|
@ -1,49 +0,0 @@
|
||||
namespace Nerfed.Builder;
|
||||
|
||||
public static class FileUtil
|
||||
{
|
||||
public static void Copy(FileInfo srcFile, FileInfo dstFile)
|
||||
{
|
||||
Copy(srcFile.FullName, dstFile.FullName);
|
||||
}
|
||||
|
||||
public static void Copy(string srcFile, string dstFile)
|
||||
{
|
||||
string dstDir = Path.GetDirectoryName(dstFile);
|
||||
if (!Directory.Exists(dstDir))
|
||||
{
|
||||
Directory.CreateDirectory(dstDir);
|
||||
}
|
||||
|
||||
File.Copy(srcFile, dstFile, true);
|
||||
UpdateFileTimeAttributes(dstFile);
|
||||
}
|
||||
|
||||
public static void WriteBytes(string dstFile, byte[] bytes)
|
||||
{
|
||||
File.WriteAllBytes(dstFile, bytes);
|
||||
UpdateFileTimeAttributes(dstFile);
|
||||
}
|
||||
|
||||
public static void UpdateFileTimeAttributes(string file)
|
||||
{
|
||||
// Copy over date time attributes so we can check if the file changed.
|
||||
FileInfo dstFileInfo = new FileInfo(file);
|
||||
DateTime now = DateTime.Now;
|
||||
DateTime utcNow = DateTime.UtcNow;
|
||||
dstFileInfo.CreationTime = now;
|
||||
dstFileInfo.CreationTimeUtc = utcNow;
|
||||
dstFileInfo.LastWriteTime = now;
|
||||
dstFileInfo.LastWriteTimeUtc = utcNow;
|
||||
dstFileInfo.LastAccessTime = now;
|
||||
dstFileInfo.LastAccessTimeUtc = utcNow;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// True if the inFileInfo is newer than the outFileInfo.
|
||||
/// </summary>
|
||||
public static bool IsNewer(FileInfo inFileInfo, FileInfo outFileInfo)
|
||||
{
|
||||
return !outFileInfo.Exists || outFileInfo.LastWriteTime <= inFileInfo.LastWriteTime;
|
||||
}
|
||||
}
|
@ -1,6 +0,0 @@
|
||||
namespace Nerfed.Builder;
|
||||
|
||||
public interface IImporter
|
||||
{
|
||||
void Import(string inFile, string outFile);
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
namespace Nerfed.Builder;
|
||||
|
||||
public class RawFileImporter : IImporter
|
||||
{
|
||||
public void Import(string inFile, string outFile)
|
||||
{
|
||||
FileUtil.Copy(inFile, outFile);
|
||||
}
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace Nerfed.Builder;
|
||||
|
||||
public class ShaderImporter : IImporter
|
||||
{
|
||||
public void Import(string inFile, string outFile)
|
||||
{
|
||||
using (Process proc = new Process())
|
||||
{
|
||||
string glslc;
|
||||
if (OperatingSystem.IsWindows())
|
||||
{
|
||||
glslc = "Win64/glslc.exe";
|
||||
}
|
||||
else if (OperatingSystem.IsLinux())
|
||||
{
|
||||
glslc = "Linux/glslc";
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new PlatformNotSupportedException("No shader compiler found for current platform");
|
||||
}
|
||||
|
||||
proc.StartInfo.FileName = glslc;
|
||||
proc.StartInfo.Arguments = @$"""{inFile}"" -o ""{outFile}"" -c";
|
||||
proc.StartInfo.CreateNoWindow = true;
|
||||
proc.StartInfo.UseShellExecute = false;
|
||||
proc.Start();
|
||||
proc.WaitForExit();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>disable</Nullable>
|
||||
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
|
||||
<IsPackable>false</IsPackable>
|
||||
<Configurations>Debug;Test;Release</Configurations>
|
||||
<Platforms>x64</Platforms>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x64' ">
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Test|x64' ">
|
||||
<Optimize>true</Optimize>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x64' ">
|
||||
<Optimize>true</Optimize>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
@ -1,4 +0,0 @@
|
||||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=builder/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=builder_005Cimporters/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=packager/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
|
@ -1,6 +0,0 @@
|
||||
namespace Nerfed.Builder;
|
||||
|
||||
public class PackageArgs
|
||||
{
|
||||
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
namespace Nerfed.Builder;
|
||||
|
||||
public class Packager : IDisposable
|
||||
{
|
||||
public void Run(PackageArgs args)
|
||||
{
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
}
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
namespace Nerfed.Builder;
|
||||
|
||||
public static class PathUtil
|
||||
{
|
||||
public const string ImportedFileExtension = ".bin";
|
||||
public const string BuildFolderName = ".build";
|
||||
public const string ImportFileExtension = ".import";
|
||||
public const string ImportFolderName = $"{BuildFolderName}/Import";
|
||||
public const string ContentFolderName = "Content";
|
||||
}
|
@ -1,70 +0,0 @@
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace Nerfed.Builder;
|
||||
|
||||
internal class Program
|
||||
{
|
||||
private static int Main(string[] args)
|
||||
{
|
||||
if (Debugger.IsAttached)
|
||||
{
|
||||
return Run(args);
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
return Run(args);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.Error.WriteLine(e.Message);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static int Run(string[] rawArgs)
|
||||
{
|
||||
if (rawArgs.Length == 0)
|
||||
{
|
||||
Console.Error.WriteLine($"Invalid build type '{rawArgs[0]}' expected '-build' or '-package'");
|
||||
return -1;
|
||||
}
|
||||
|
||||
string buildType = rawArgs[0].ToLower();
|
||||
if (buildType == "-build")
|
||||
{
|
||||
ArgsParser<BuildArgs> parser = new ArgsParser<BuildArgs>(rawArgs);
|
||||
if (!parser.Parse())
|
||||
{
|
||||
Console.Error.Write("Failed to parse build arguments");
|
||||
return -1;
|
||||
}
|
||||
|
||||
using (Builder builder = new Builder())
|
||||
{
|
||||
builder.Run(parser.Arguments);
|
||||
}
|
||||
}
|
||||
else if (buildType == "-package")
|
||||
{
|
||||
ArgsParser<PackageArgs> parser = new ArgsParser<PackageArgs>(rawArgs);
|
||||
if (!parser.Parse())
|
||||
{
|
||||
Console.Error.Write("Failed to parse package arguments");
|
||||
return -1;
|
||||
}
|
||||
|
||||
using (Packager packager = new Packager())
|
||||
{
|
||||
packager.Run(parser.Arguments);
|
||||
}
|
||||
|
||||
Console.Error.WriteLine("Packaging not yet implemented");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Target Name="Runtime ID" AfterTargets="Build">
|
||||
<Message Text="Runtime ID: $(RuntimeIdentifier)" Importance="high"/>
|
||||
</Target>
|
||||
|
||||
<ItemGroup Condition="$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Windows)))">
|
||||
<Libs Include="..\Native\x64\**\*.*"/>
|
||||
</ItemGroup>
|
||||
<ItemGroup Condition="$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Linux)))">
|
||||
<Libs Include="..\Native\lib64\**\*.*"/>
|
||||
</ItemGroup>
|
||||
<ItemGroup Condition="$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::OSX)))">
|
||||
<Libs Include="..\Native\osx\**\*.*"/>
|
||||
</ItemGroup>
|
||||
|
||||
<Target Name="CopyLibs" AfterTargets="Build">
|
||||
<Copy SourceFiles="@(Libs)" DestinationFolder="$(OutDir)" SkipUnchangedFiles="true" OverwriteReadOnlyFiles="true"/>
|
||||
</Target>
|
||||
|
||||
</Project>
|
@ -1,71 +0,0 @@
|
||||
using ImGuiNET;
|
||||
using Nerfed.Runtime;
|
||||
using Nerfed.Runtime.Graphics;
|
||||
using Nerfed.Runtime.Gui;
|
||||
|
||||
namespace Nerfed.Editor
|
||||
{
|
||||
internal static class EditorGui
|
||||
{
|
||||
private static GuiController guiController;
|
||||
|
||||
internal static void Initialize()
|
||||
{
|
||||
// Create GuiController.
|
||||
guiController = new GuiController(Engine.GraphicsDevice, Engine.MainWindow, Color.DimGray);
|
||||
// Subscribe to GUI update.
|
||||
// GuiController.OnGui call => UpdateDock;
|
||||
// GuiController.OnGui call => UpdateEditorWindows;
|
||||
// GuiController.OnGui call => ...;
|
||||
guiController.OnGui += HandleOnGui;
|
||||
}
|
||||
|
||||
internal static void Update()
|
||||
{
|
||||
// Update GuiController.
|
||||
guiController.Update(Engine.Timestep.TotalSeconds);
|
||||
}
|
||||
|
||||
internal static void Render()
|
||||
{
|
||||
// Reneder GuiController.
|
||||
guiController.Render();
|
||||
}
|
||||
|
||||
internal static void Quit()
|
||||
{
|
||||
guiController.Dispose();
|
||||
}
|
||||
|
||||
private static void UpdateDock()
|
||||
{
|
||||
// Setup default dockspace for the main window.
|
||||
uint id = ImGui.GetID("MainDockSpace");
|
||||
ImGui.DockSpaceOverViewport(id, ImGui.GetMainViewport(), ImGuiDockNodeFlags.None);
|
||||
}
|
||||
|
||||
private static void UpdateMainMenu()
|
||||
{
|
||||
if (ImGui.BeginMainMenuBar())
|
||||
{
|
||||
if (ImGui.BeginMenu("File"))
|
||||
{
|
||||
if (ImGui.MenuItem("Exit"))
|
||||
{
|
||||
Engine.Quit();
|
||||
}
|
||||
ImGui.EndMenu();
|
||||
}
|
||||
ImGui.EndMainMenuBar();
|
||||
}
|
||||
}
|
||||
|
||||
private static void HandleOnGui()
|
||||
{
|
||||
UpdateMainMenu();
|
||||
UpdateDock();
|
||||
|
||||
ImGui.ShowDemoWindow();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,30 +0,0 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>disable</Nullable>
|
||||
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
|
||||
<IsPackable>false</IsPackable>
|
||||
<Configurations>Debug;Test;Release</Configurations>
|
||||
<Platforms>x64</Platforms>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x64' ">
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Test|x64' ">
|
||||
<Optimize>true</Optimize>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x64' ">
|
||||
<Optimize>true</Optimize>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Nerfed.Runtime\Nerfed.Runtime.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<Import Project=".\CopyLibs.targets" />
|
||||
</Project>
|
@ -1,42 +0,0 @@
|
||||
using Nerfed.Runtime;
|
||||
|
||||
namespace Nerfed.Editor;
|
||||
|
||||
internal class Program
|
||||
{
|
||||
private static void Main(string[] args)
|
||||
{
|
||||
Engine.OnInitialize += HandleOnInitialize;
|
||||
Engine.OnUpdate += HandleOnUpdate;
|
||||
Engine.OnRender += HandleOnRender;
|
||||
Engine.OnQuit += HandleOnQuit;
|
||||
|
||||
Engine.Run(args);
|
||||
}
|
||||
|
||||
private static void HandleOnInitialize()
|
||||
{
|
||||
// Open project.
|
||||
// Setip EditorGui.
|
||||
EditorGui.Initialize();
|
||||
}
|
||||
|
||||
private static void HandleOnUpdate()
|
||||
{
|
||||
// Editor Update.
|
||||
EditorGui.Update();
|
||||
|
||||
|
||||
// Try Catch UserCode Update.
|
||||
}
|
||||
|
||||
private static void HandleOnRender()
|
||||
{
|
||||
EditorGui.Render();
|
||||
}
|
||||
|
||||
private static void HandleOnQuit()
|
||||
{
|
||||
EditorGui.Quit();
|
||||
}
|
||||
}
|
27
Nerfed.Runtime/CopyLibs.targets
Normal file
27
Nerfed.Runtime/CopyLibs.targets
Normal file
@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
|
||||
<Target Name="Runtime ID" AfterTargets="Build">
|
||||
<Message Text="Runtime ID: $(RuntimeIdentifier)" Importance="high"/>
|
||||
</Target>
|
||||
|
||||
<ItemGroup Condition="$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Windows)))">
|
||||
<Content Include="..\libs\x64\**\*.*" >
|
||||
<Link>%(RecursiveDir)%(Filename)%(Extension)</Link>
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
<ItemGroup Condition="$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Linux)))">
|
||||
<Content Include="..\libs\lib64\**\*.*" >
|
||||
<Link>%(RecursiveDir)%(Filename)%(Extension)</Link>
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
<ItemGroup Condition="$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::OSX)))">
|
||||
<Content Include="..\libs\osx\**\*.*" >
|
||||
<Link>%(RecursiveDir)%(Filename)%(Extension)</Link>
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -7,11 +7,6 @@ namespace Nerfed.Runtime;
|
||||
|
||||
public static class Engine
|
||||
{
|
||||
public static event Action OnInitialize;
|
||||
public static event Action OnUpdate;
|
||||
public static event Action OnRender;
|
||||
public static event Action OnQuit;
|
||||
|
||||
public static TimeSpan MaxDeltaTime { get; set; } = TimeSpan.FromMilliseconds(100);
|
||||
public static bool VSync { get; set; }
|
||||
|
||||
@ -24,7 +19,6 @@ public static class Engine
|
||||
private static Stopwatch gameTimer;
|
||||
private static long previousTicks = 0;
|
||||
private static TimeSpan accumulatedUpdateTime = TimeSpan.Zero;
|
||||
|
||||
private static TimeSpan accumulatedDrawTime = TimeSpan.Zero;
|
||||
|
||||
// must be a power of 2 so we can do a bitmask optimization when checking worst case
|
||||
@ -44,7 +38,9 @@ public static class Engine
|
||||
private const string WindowTitle = "Nerfed";
|
||||
//..
|
||||
|
||||
public static void Run(string[] args)
|
||||
private static Gui.GuiController Controller;
|
||||
|
||||
internal static void Run(string[] args)
|
||||
{
|
||||
Timestep = TimeSpan.FromTicks(TimeSpan.TicksPerSecond / TargetTimestep);
|
||||
gameTimer = Stopwatch.StartNew();
|
||||
@ -59,7 +55,7 @@ public static void Run(string[] args)
|
||||
{
|
||||
throw new Exception("Failed to init SDL");
|
||||
}
|
||||
|
||||
|
||||
GraphicsDevice = new GraphicsDevice(BackendFlags.All);
|
||||
|
||||
MainWindow = new Window(GraphicsDevice, new WindowCreateInfo(WindowTitle, WindowWidth, WindowHeight, ScreenMode.Windowed));
|
||||
@ -68,17 +64,23 @@ public static void Run(string[] args)
|
||||
throw new Exception("Failed to claim window");
|
||||
}
|
||||
|
||||
MainWindow.OnCloseEvent += (w) => {
|
||||
Quit();
|
||||
};
|
||||
|
||||
AudioDevice = new AudioDevice();
|
||||
|
||||
OnInitialize?.Invoke();
|
||||
Controller = new Gui.GuiController(GraphicsDevice, MainWindow, Color.DarkOliveGreen);
|
||||
Controller.OnGui += () => {
|
||||
ImGuiNET.ImGui.ShowDemoWindow();
|
||||
};
|
||||
|
||||
while (!quit)
|
||||
{
|
||||
Tick();
|
||||
}
|
||||
|
||||
OnQuit?.Invoke();
|
||||
|
||||
Controller.Dispose();
|
||||
GraphicsDevice.UnclaimWindow(MainWindow);
|
||||
MainWindow.Dispose();
|
||||
GraphicsDevice.Dispose();
|
||||
@ -155,7 +157,7 @@ private static void Tick()
|
||||
ProcessSDLEvents();
|
||||
|
||||
// Tick game here...
|
||||
OnUpdate?.Invoke();
|
||||
Controller.Update((float)Timestep.TotalSeconds);
|
||||
|
||||
AudioDevice.WakeThread();
|
||||
accumulatedUpdateTime -= Timestep;
|
||||
@ -164,7 +166,7 @@ private static void Tick()
|
||||
double alpha = accumulatedUpdateTime / Timestep;
|
||||
|
||||
// Render here..
|
||||
OnRender?.Invoke();
|
||||
Controller.Render();
|
||||
|
||||
accumulatedDrawTime -= framerateCapTimeSpan;
|
||||
}
|
||||
|
@ -9,7 +9,7 @@
|
||||
|
||||
namespace Nerfed.Runtime.Gui;
|
||||
|
||||
public class GuiController : IDisposable
|
||||
internal class GuiController : IDisposable
|
||||
{
|
||||
public event Action OnGui;
|
||||
|
||||
@ -144,13 +144,9 @@ public GuiController(GraphicsDevice graphicsDevice, Window mainWindow, Color cle
|
||||
io.BackendFlags |= ImGuiBackendFlags.HasSetMousePos;
|
||||
io.BackendFlags |= ImGuiBackendFlags.PlatformHasViewports;
|
||||
io.BackendFlags |= ImGuiBackendFlags.RendererHasViewports;
|
||||
|
||||
UpdatePerFrameImGuiData(1.0 / 60.0);
|
||||
ImGui.NewFrame();
|
||||
frameBegun = true;
|
||||
}
|
||||
|
||||
public void Update(double deltaTime)
|
||||
public void Update(float deltaTime)
|
||||
{
|
||||
if (frameBegun)
|
||||
{
|
||||
@ -171,12 +167,12 @@ public void Update(double deltaTime)
|
||||
ImGui.EndFrame();
|
||||
}
|
||||
|
||||
private void UpdatePerFrameImGuiData(double deltaSeconds)
|
||||
private void UpdatePerFrameImGuiData(float deltaSeconds)
|
||||
{
|
||||
ImGuiIOPtr io = ImGui.GetIO();
|
||||
io.DisplaySize = new Vector2(mainWindow.Width, mainWindow.Height);
|
||||
io.DisplayFramebufferScale = new Vector2(1, 1);
|
||||
io.DeltaTime = (float)deltaSeconds; // DeltaTime is in seconds.
|
||||
io.DeltaTime = deltaSeconds; // DeltaTime is in seconds.
|
||||
}
|
||||
|
||||
private void UpdateInput()
|
||||
|
@ -1,43 +1,33 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<DefaultItemExcludes>$(DefaultItemExcludes);Libraries\**\*</DefaultItemExcludes>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="Libraries\SDL2CS\src\SDL2.cs" />
|
||||
<Compile Include="Libraries\RefreshCS\RefreshCS.cs" />
|
||||
<Compile Include="Libraries\FAudio\csharp\FAudio.cs" />
|
||||
<Compile Include="Libraries\WellspringCS\WellspringCS.cs" />
|
||||
<Compile Include="Libraries\dav1dfile\csharp\dav1dfile.cs" />
|
||||
<Compile Include="Libraries\ImGui.NET\src\ImGui.NET\**\*.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include="Content\**\*.*">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>disable</Nullable>
|
||||
<PublishAot>true</PublishAot>
|
||||
<InvariantGlobalization>true</InvariantGlobalization>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
|
||||
<IsPackable>false</IsPackable>
|
||||
<Configurations>Debug;Test;Release</Configurations>
|
||||
<Platforms>x64</Platforms>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<DefaultItemExcludes>$(DefaultItemExcludes);Libraries\**\*</DefaultItemExcludes>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x64' ">
|
||||
<DefineConstants>TRACE;LOG_INFO;PROFILING</DefineConstants>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Test|x64' ">
|
||||
<DefineConstants>TRACE;LOG_ERROR;PROFILING</DefineConstants>
|
||||
<Optimize>true</Optimize>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x64' ">
|
||||
<DefineConstants>TRACE;LOG_ERROR</DefineConstants>
|
||||
<Optimize>true</Optimize>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="Libraries\SDL2CS\src\SDL2.cs"/>
|
||||
<Compile Include="Libraries\RefreshCS\RefreshCS.cs"/>
|
||||
<Compile Include="Libraries\FAudio\csharp\FAudio.cs"/>
|
||||
<Compile Include="Libraries\WellspringCS\WellspringCS.cs"/>
|
||||
<Compile Include="Libraries\dav1dfile\csharp\dav1dfile.cs"/>
|
||||
<Compile Include="Libraries\ImGui.NET\src\ImGui.NET\**\*.cs"/>
|
||||
</ItemGroup>
|
||||
|
||||
<Import Project=".\CopyLibs.targets" />
|
||||
</Project>
|
@ -17,12 +17,12 @@ public void Dispose() {
|
||||
|
||||
public static class Profiler
|
||||
{
|
||||
[Conditional("PROFILING")]
|
||||
[Conditional("PROFILER")]
|
||||
public static void BeginSample(string label) {
|
||||
|
||||
}
|
||||
|
||||
[Conditional("PROFILING")]
|
||||
[Conditional("PROFILER")]
|
||||
public static void EndSample() {
|
||||
|
||||
}
|
||||
|
9
Nerfed.Runtime/Program.cs
Normal file
9
Nerfed.Runtime/Program.cs
Normal file
@ -0,0 +1,9 @@
|
||||
namespace Nerfed.Runtime;
|
||||
|
||||
internal class Program
|
||||
{
|
||||
private static void Main(string[] args)
|
||||
{
|
||||
Engine.Run(args);
|
||||
}
|
||||
}
|
31
Nerfed.sln
31
Nerfed.sln
@ -5,35 +5,16 @@ VisualStudioVersion = 17.10.35013.160
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Nerfed.Runtime", "Nerfed.Runtime\Nerfed.Runtime.csproj", "{98E09BAF-587F-4238-89BD-7693C036C233}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nerfed.Builder", "Nerfed.Builder\Nerfed.Builder.csproj", "{1B88DE56-2AD8-441E-9B10-073AA43840BF}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nerfed.Editor", "Nerfed.Editor\Nerfed.Editor.csproj", "{FF7D032D-7F0B-4700-A818-0606D66AECF8}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Test|x64 = Test|x64
|
||||
Release|x64 = Release|x64
|
||||
Debug|x64 = Debug|x64
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{1B88DE56-2AD8-441E-9B10-073AA43840BF}.Test|x64.ActiveCfg = Test|x64
|
||||
{1B88DE56-2AD8-441E-9B10-073AA43840BF}.Test|x64.Build.0 = Test|x64
|
||||
{1B88DE56-2AD8-441E-9B10-073AA43840BF}.Release|x64.ActiveCfg = Release|x64
|
||||
{1B88DE56-2AD8-441E-9B10-073AA43840BF}.Release|x64.Build.0 = Release|x64
|
||||
{1B88DE56-2AD8-441E-9B10-073AA43840BF}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{1B88DE56-2AD8-441E-9B10-073AA43840BF}.Debug|x64.Build.0 = Debug|x64
|
||||
{FF7D032D-7F0B-4700-A818-0606D66AECF8}.Test|x64.ActiveCfg = Test|x64
|
||||
{FF7D032D-7F0B-4700-A818-0606D66AECF8}.Test|x64.Build.0 = Test|x64
|
||||
{FF7D032D-7F0B-4700-A818-0606D66AECF8}.Release|x64.ActiveCfg = Release|x64
|
||||
{FF7D032D-7F0B-4700-A818-0606D66AECF8}.Release|x64.Build.0 = Release|x64
|
||||
{FF7D032D-7F0B-4700-A818-0606D66AECF8}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{FF7D032D-7F0B-4700-A818-0606D66AECF8}.Debug|x64.Build.0 = Debug|x64
|
||||
{98E09BAF-587F-4238-89BD-7693C036C233}.Test|x64.ActiveCfg = Test|x64
|
||||
{98E09BAF-587F-4238-89BD-7693C036C233}.Test|x64.Build.0 = Test|x64
|
||||
{98E09BAF-587F-4238-89BD-7693C036C233}.Release|x64.ActiveCfg = Release|x64
|
||||
{98E09BAF-587F-4238-89BD-7693C036C233}.Release|x64.Build.0 = Release|x64
|
||||
{98E09BAF-587F-4238-89BD-7693C036C233}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{98E09BAF-587F-4238-89BD-7693C036C233}.Debug|x64.Build.0 = Debug|x64
|
||||
{98E09BAF-587F-4238-89BD-7693C036C233}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{98E09BAF-587F-4238-89BD-7693C036C233}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{98E09BAF-587F-4238-89BD-7693C036C233}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{98E09BAF-587F-4238-89BD-7693C036C233}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
Binary file not shown.
@ -1,23 +0,0 @@
|
||||
{
|
||||
"runtimeTarget": {
|
||||
"name": ".NETCoreApp,Version=v8.0",
|
||||
"signature": ""
|
||||
},
|
||||
"compilationOptions": {},
|
||||
"targets": {
|
||||
".NETCoreApp,Version=v8.0": {
|
||||
"Nerfed.Builder/1.0.0": {
|
||||
"runtime": {
|
||||
"Nerfed.Builder.dll": {}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"libraries": {
|
||||
"Nerfed.Builder/1.0.0": {
|
||||
"type": "project",
|
||||
"serviceable": false,
|
||||
"sha512": ""
|
||||
}
|
||||
}
|
||||
}
|
BIN
Tools/Nerfed.Builder/Nerfed.Builder.dll
(Stored with Git LFS)
BIN
Tools/Nerfed.Builder/Nerfed.Builder.dll
(Stored with Git LFS)
Binary file not shown.
@ -1,13 +0,0 @@
|
||||
{
|
||||
"runtimeOptions": {
|
||||
"tfm": "net8.0",
|
||||
"framework": {
|
||||
"name": "Microsoft.NETCore.App",
|
||||
"version": "8.0.0"
|
||||
},
|
||||
"configProperties": {
|
||||
"System.Reflection.Metadata.MetadataUpdater.IsSupported": false,
|
||||
"System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": false
|
||||
}
|
||||
}
|
||||
}
|
Binary file not shown.
BIN
Tools/glslc/Win64/glslc.exe
(Stored with Git LFS)
BIN
Tools/glslc/Win64/glslc.exe
(Stored with Git LFS)
Binary file not shown.
Loading…
Reference in New Issue
Block a user