Skip to content

Commit

Permalink
update shit
Browse files Browse the repository at this point in the history
  • Loading branch information
Rikarin committed Apr 13, 2024
1 parent 600f4df commit 6e3262c
Show file tree
Hide file tree
Showing 46 changed files with 657 additions and 355 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Create game engine with requirements:

## Topics (TODO)

- Consider replacing UI.State with Signal implementation
- Explicitly use RootNamespace
- Generic interface for wrapping Vulkan & OpenGL
- Rendering Pipelines
Expand Down
6 changes: 3 additions & 3 deletions Tests/Vixen.Core.Design.Tests/Vixen.Core.Design.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0-release-23619-01" />
<PackageReference Include="xunit" Version="2.7.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0-release-23619-01"/>
<PackageReference Include="xunit" Version="2.7.0"/>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Vixen.Core.Design\Vixen.Core.Design.csproj" />
<ProjectReference Include="..\..\Vixen.Core.Design\Vixen.Core.Design.csproj"/>
</ItemGroup>
</Project>
12 changes: 6 additions & 6 deletions Tests/Vixen.Core.Shaders.Tests/Vixen.Core.Shaders.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0-release-23619-01" />
<PackageReference Include="xunit" Version="2.7.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0-release-23619-01"/>
<PackageReference Include="xunit" Version="2.7.0"/>
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\Vixen.Core.Shaders\Vixen.Core.Shaders.csproj" />
<ProjectReference Include="..\..\Vixen.Core.Shaders\Vixen.Core.Shaders.csproj"/>
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion Tests/Vixen.Core.Yaml.Tests/DescriptorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public class TestObject {

public ICollection<string> Collection { get; set; }

public ICollection<string> CollectionReadOnly { get; private set; }
public ICollection<string> CollectionReadOnly { get; set; }

[DataMemberIgnore]
public string DontSerialize { get; set; }
Expand Down
16 changes: 16 additions & 0 deletions Tests/Vixen.Core.Yaml.Tests/Serialization/SerializationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@ public void Roundtrip() {
}
}

[Fact]
public void ThrowWithoutEmptyCtor() {
try {
SerializeThenDeserialize(new ClassWithNonEmptyCtor(default));
Assert.Fail(
"An exception should have been thrown by this method before hitting this line, the class provided does not have an empty constructor"
);
} catch (Exception ex) {
Assert.IsType<DefaultObjectFactory.InstanceCreationException>(ex.InnerException);
}
}

[Fact]
public void RoundtripWithDefaults() {
var settings = new SerializerSettings { EmitDefaultValues = true };
Expand Down Expand Up @@ -690,6 +702,10 @@ T SerializeThenDeserialize<T>(T input) {
return serializer.Deserialize<T>(new StringReader(serialized));
}

class ClassWithNonEmptyCtor {
public ClassWithNonEmptyCtor(bool parameter) { }
}

class Y {
public Y Child { get; set; }
public Y Child2 { get; set; }
Expand Down
18 changes: 12 additions & 6 deletions Tests/Vixen.Core.Yaml.Tests/Serialization/SerializationTests2.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Collections;
using System.ComponentModel;
using Vixen.Core.Reflection;
using Vixen.Core.Reflection.MemberDescriptors;
using Vixen.Core.Reflection.TypeDescriptors;
using Vixen.Core.Yaml.Serialization;
Expand All @@ -9,6 +10,10 @@
namespace Vixen.Core.Yaml.Tests.Serialization;

public class SerializationTests2 {
public SerializationTests2() {
// AssemblyRegistry.RegisterScanTypes();
}

[Fact]
public void TestHelloWorld() {
var serializer = new Serializer();
Expand Down Expand Up @@ -886,7 +891,7 @@ public class MyObject {

public int[] Array { get; set; }

public int[] ArrayContent { get; private set; }
public int[] ArrayContent { get; set; }

public MyObject() {
ArrayContent = new int[2];
Expand Down Expand Up @@ -992,7 +997,7 @@ public class MyCustomClassWithSpecialMembers {
/// value of the list stored in this instance instead of
/// creating a new List&lt;T&gtl instance.
/// </summary>
public List<string> StringListByContent { get; private set; }
public List<string> StringListByContent { get; set; }

/// <summary>
/// Gets or sets the basic map.
Expand All @@ -1011,19 +1016,19 @@ public class MyCustomClassWithSpecialMembers {
/// Idem as for <see cref="StringListByContent" /> but for dictionary.
/// </summary>
/// <value>The content of the string mapby.</value>
public Dictionary<string, object> StringMapbyContent { get; private set; }
public Dictionary<string, object> StringMapByContent { get; set; }

/// <summary>
/// For this property, the deserializer is using the actual
/// value of the list stored in this instance instead of
/// creating a new List&lt;T&gtl instance.
/// </summary>
/// <value>The content of the list by.</value>
public IList ListByContent { get; private set; }
public IList<string> ListByContent { get; private set; }

public MyCustomClassWithSpecialMembers() {
StringListByContent = new();
StringMapbyContent = new();
StringMapByContent = new();
ListByContent = new List<string>();
}
}
Expand Down Expand Up @@ -1470,7 +1475,8 @@ public class ObjectWithMask {
}

public class ClassWithImplicitMemberType {
public object Test { get; protected set; }
[DataMember]
public object Test { get; init; }

public ClassWithImplicitMemberType() {
Test = new ClassWithImplicitMemberTypeInner { String = "test" };
Expand Down
8 changes: 4 additions & 4 deletions Tests/Vixen.Core.Yaml.Tests/Vixen.Core.Yaml.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0-preview-23503-02" />
<PackageReference Include="xunit" Version="2.7.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0-preview-23503-02"/>
<PackageReference Include="xunit" Version="2.7.0"/>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Vixen.Core.Yaml\Vixen.Core.Yaml.csproj" />
<EmbeddedResource Include="files\*.yaml" />
<ProjectReference Include="..\..\Vixen.Core.Yaml\Vixen.Core.Yaml.csproj"/>
<EmbeddedResource Include="files\*.yaml"/>
</ItemGroup>
</Project>
8 changes: 4 additions & 4 deletions Vixen.BuildEngine.Common/Vixen.BuildEngine.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Vixen.Core.IO\Vixen.Core.IO.csproj" />
<ProjectReference Include="..\Vixen.Core.MicroThreading\Vixen.Core.MicroThreading.csproj" />
<ProjectReference Include="..\Vixen.Core.Serialization\Vixen.Core.Serialization.csproj" />
<ProjectReference Include="..\Vixen.Core\Vixen.Core.csproj" />
<ProjectReference Include="..\Vixen.Core.IO\Vixen.Core.IO.csproj"/>
<ProjectReference Include="..\Vixen.Core.MicroThreading\Vixen.Core.MicroThreading.csproj"/>
<ProjectReference Include="..\Vixen.Core.Serialization\Vixen.Core.Serialization.csproj"/>
<ProjectReference Include="..\Vixen.Core\Vixen.Core.csproj"/>
</ItemGroup>
</Project>
5 changes: 5 additions & 0 deletions Vixen.Core.Assets/AssetItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public sealed class AssetItem : IFileSynchronizable {
/// Gets the location of this asset.
/// </summary>
/// <value>The location.</value>
[DataMember]
public UFile Location {
get => location;
internal set => location = value ?? throw new ArgumentNullException(nameof(value));
Expand Down Expand Up @@ -51,6 +52,7 @@ public UFile Location {
/// Gets the package where this asset is stored.
/// </summary>
/// <value>The package.</value>
[DataMember]
public Package Package { get; internal set; }

/// <summary>
Expand Down Expand Up @@ -97,6 +99,7 @@ public UFile FullPath {
/// Gets or sets the asset.
/// </summary>
/// <value>The asset.</value>
[DataMember]
public Asset Asset {
get => asset;
internal set => asset = value ?? throw new ArgumentNullException(nameof(value));
Expand All @@ -111,11 +114,13 @@ public Asset Asset {
/// true
/// , this time will get current time of modification.
/// </remarks>
[DataMember]
public DateTime ModifiedTime { get; internal set; }

/// <summary>
/// Gets the asset version incremental counter, increased everytime the asset is edited.
/// </summary>
[DataMember]
public long Version {
get => Interlocked.Read(ref version);
internal set => Interlocked.Exchange(ref version, value);
Expand Down
4 changes: 2 additions & 2 deletions Vixen.Core.Assets/AssetReference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ public sealed class AssetReference : IReference, IEquatable<AssetReference> {
/// </summary>
/// <value>The unique identifier of the reference asset..</value>
[DataMember(10)]
public AssetId Id { get; }
public AssetId Id { get; init; }

/// <summary>
/// Gets or sets the location of the asset.
/// </summary>
/// <value>The location.</value>
[DataMember(20)]
public string Location { get; }
public string Location { get; init; }

/// <summary>
/// Initializes a new instance of the <see cref="AssetReference" /> class.
Expand Down
14 changes: 13 additions & 1 deletion Vixen.Core.Assets/Compiler/AssetCompilerRegistry.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Serilog;
using System.Diagnostics;
using System.Reflection;
using Vixen.Core.Reflection;

Expand Down Expand Up @@ -159,7 +160,7 @@ void RegisterAssembly(Assembly assembly) {

void RegisterCompilersFromAssembly(Assembly assembly) {
// Process Asset types.
foreach (var type in assembly.GetTypes()) {
foreach (var type in GetFullyLoadedTypes(assembly)) {
// Only process Asset types
if (!typeof(IAssetCompiler).IsAssignableFrom(type) || !type.IsClass) {
continue;
Expand All @@ -181,6 +182,17 @@ void RegisterCompilersFromAssembly(Assembly assembly) {
);
}
}

// Taken from https://stackoverflow.com/questions/7889228/how-to-prevent-reflectiontypeloadexception-when-calling-assembly-gettypes
[DebuggerNonUserCode]
IEnumerable<Type> GetFullyLoadedTypes(Assembly assembly) {
try {
return assembly.GetTypes();
} catch (ReflectionTypeLoadException ex) {
log.Warning($"Could not load all types from assembly {assembly.FullName}", ex);
return ex.Types.Where(t => t != null);
}
}
}

void UnregisterAssembly(Assembly assembly) {
Expand Down
8 changes: 4 additions & 4 deletions Vixen.Core.Assets/Vixen.Core.Assets.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Vixen.BuildEngine.Common\Vixen.BuildEngine.Common.csproj" />
<ProjectReference Include="..\Vixen.Core.Design\Vixen.Core.Design.csproj" />
<ProjectReference Include="..\Vixen.Core.Serialization\Vixen.Core.Serialization.csproj" />
<ProjectReference Include="..\Vixen.Core\Vixen.Core.csproj" />
<ProjectReference Include="..\Vixen.BuildEngine.Common\Vixen.BuildEngine.Common.csproj"/>
<ProjectReference Include="..\Vixen.Core.Design\Vixen.Core.Design.csproj"/>
<ProjectReference Include="..\Vixen.Core.Serialization\Vixen.Core.Serialization.csproj"/>
<ProjectReference Include="..\Vixen.Core\Vixen.Core.csproj"/>
</ItemGroup>
</Project>
4 changes: 2 additions & 2 deletions Vixen.Core.Design/Vixen.Core.Design.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Vixen.Core.Common\Vixen.Core.Common.csproj" />
<ProjectReference Include="..\Vixen.Core\Vixen.Core.csproj" />
<ProjectReference Include="..\Vixen.Core.Common\Vixen.Core.Common.csproj"/>
<ProjectReference Include="..\Vixen.Core\Vixen.Core.csproj"/>
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion Vixen.Core.IO/Vixen.Core.IO.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Vixen.Core\Vixen.Core.csproj" />
<ProjectReference Include="..\Vixen.Core\Vixen.Core.csproj"/>
</ItemGroup>
</Project>
4 changes: 2 additions & 2 deletions Vixen.Core.MicroThreading/Vixen.Core.MicroThreading.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Serilog" Version="3.1.1" />
<PackageReference Include="Serilog" Version="3.1.1"/>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Vixen.Core\Vixen.Core.csproj" />
<ProjectReference Include="..\Vixen.Core\Vixen.Core.csproj"/>
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,9 @@ public class FieldDescriptor : MemberDescriptorBase {
/// </summary>
/// <value>The property information.</value>
public FieldInfo FieldInfo { get; }

public override Type Type => FieldInfo.FieldType;

public override bool IsPublic => FieldInfo.IsPublic;

public override bool HasSet => true;
public override bool HasSet => !FieldInfo.IsInitOnly;

public FieldDescriptor(ITypeDescriptor typeDescriptor, FieldInfo fieldInfo, StringComparer defaultNameComparer)
: base(fieldInfo, defaultNameComparer) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,8 @@ StringComparer defaultNameComparer
}

PropertyInfo = propertyInfo;

getMethod = propertyInfo.GetGetMethod(false) ?? propertyInfo.GetGetMethod(true);
if (propertyInfo.CanWrite && propertyInfo.GetSetMethod(!IsPublic) != null) {
setMethod = propertyInfo.GetSetMethod(!IsPublic);
}

getMethod = propertyInfo.GetMethod;
setMethod = propertyInfo.SetMethod;
TypeDescriptor = typeDescriptor;
}

Expand Down
16 changes: 5 additions & 11 deletions Vixen.Core.Reflection.Yaml/TypeDescriptorFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,7 @@ protected virtual ITypeDescriptor Create(Type type) {

if (PrimitiveDescriptor.IsPrimitive(type)) {
descriptor = new PrimitiveDescriptor(this, type, emitDefaultValues, namingConvention);
} else if
(DictionaryDescriptor
.IsDictionary(type)) // resolve dictionary before collections, as they are also collections
{
} else if (DictionaryDescriptor.IsDictionary(type)) { // resolve dictionary before collections, as they are also collections
// IDictionary
descriptor = new DictionaryDescriptor(this, type, emitDefaultValues, namingConvention);
} else if (ListDescriptor.IsList(type)) {
Expand All @@ -90,13 +87,10 @@ protected virtual ITypeDescriptor Create(Type type) {
} else if (SetDescriptor.IsSet(type)) {
// ISet
descriptor = new SetDescriptor(this, type, emitDefaultValues, namingConvention);
}
// TODO(Jiu): Verify if this can be removed
// else if (CollectionDescriptor.IsCollection(type)) {
// // ICollection
// descriptor = new OldCollectionDescriptor(this, type, emitDefaultValues, namingConvention);
// }
else if (type.IsArray) {
} else if (CollectionDescriptor.IsCollection(type)) {
// ICollection
descriptor = new OldCollectionDescriptor(this, type, emitDefaultValues, namingConvention);
} else if (type.IsArray) {
if (type.GetArrayRank() == 1 && !type.GetElementType().IsArray) {
// array[] - only single dimension array is supported
descriptor = new ArrayDescriptor(this, type, emitDefaultValues, namingConvention);
Expand Down
Loading

0 comments on commit 6e3262c

Please sign in to comment.