Skip to content

1.2.0 #160

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 34 commits into from
Jul 26, 2021
Merged

1.2.0 #160

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
a89c84e
delegate registry
quabug Mar 4, 2021
f776fe2
tests of delegate registry.
quabug Mar 4, 2021
a878358
hide tests out from essential package.
quabug Mar 4, 2021
3816975
add packages lock file
quabug Mar 4, 2021
fb197a6
able to ignore certain behavior node for testing purpose.
quabug Mar 5, 2021
95f881e
use `DelegateRegistry` replace `VariantRegistry`
quabug Mar 5, 2021
1b17445
declare variant interfaces to be covariant.
quabug Mar 5, 2021
a95f836
preserve delegate classes and methods.
quabug Mar 5, 2021
ab042b6
remove preserve from registered delegate method.
quabug Mar 5, 2021
dd95439
Merge branch 'master' into expression-variant
quabug Mar 21, 2021
15a388a
fix `SaveToLocalVariant`
quabug Mar 21, 2021
5ccfeb4
ignore tests
quabug Jul 18, 2021
cc2d673
ignore tests
quabug Jul 18, 2021
c07e885
integrate expression-evaluation by using DynamicExpresso
quabug Jul 22, 2021
70b54b0
fix building
quabug Jul 23, 2021
2e0bb51
SerializedVariant and its drawer
quabug Jul 25, 2021
2c5b8af
code generator of variant classes
quabug Jul 25, 2021
91eda8a
fix codegen of math types.
quabug Jul 25, 2021
8901e35
add missing dll files of DynamicExpresso
quabug Jul 25, 2021
1d33f0f
simplify component builder.
quabug Jul 25, 2021
58fbb1e
fix samples
quabug Jul 25, 2021
1875b8b
fix sample of variant
quabug Jul 26, 2021
897df7b
fix sample of character control
quabug Jul 26, 2021
1e6b87e
generate Assembly-CSharp.dll for samples.
quabug Jul 26, 2021
2601ea2
move samples and tests into sample package.
quabug Jul 26, 2021
ea98c1e
upgrade version of packages
quabug Jul 26, 2021
6cfc54f
update packages-locks
quabug Jul 26, 2021
7ee8819
make `Reset` optional.
quabug Jul 26, 2021
de3dbc9
fix samples
quabug Jul 26, 2021
c650b48
get object value from array of serialized property.
quabug Jul 26, 2021
7aeffba
add search bar for drawer of SerializeReference
quabug Jul 26, 2021
c17eb03
use behavior tree id as part of expression lambda id
quabug Jul 26, 2021
1b28496
update serialized behavior tree of sample.
quabug Jul 26, 2021
3f5c07a
fix unit test.
quabug Jul 26, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,9 @@ Assets/Plugins.meta


.DS_Store
Packages/essential/Tests
Packages/essential/Tests.meta
Packages/variant.expression/Tests/
Packages/codegen/Tests
Packages/codegen/Tests.meta
Packages/variant.expression/Tests.meta
Empty file removed Assets/_
Empty file.
2 changes: 2 additions & 0 deletions Assets/___.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// for generating Assembly-CSharp.dll
public class ___ { }

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

70 changes: 4 additions & 66 deletions Packages/builder.component/Editor/ComponentFieldCodeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,7 @@ public string GenerateBuild(FieldInfo fi)

public class BlobVariantFieldCodeGenerator : INodeDataFieldCodeGenerator
{
protected const string HEAD_LINE = "// Automatically generated by `BlobVariantFieldCodeGenerator`";

public bool ShouldGenerateVariantInterface = true;
public string VariantInterfaceDirectory = "Variant";
public string VariantInterfaceNamespace = "EntitiesBT.Variant";
public string VariantPropertyNameSuffix = "Variant";
public NodeCodeGenerator Generator;
public AssemblyDefinitionAsset Assembly;

private ISet<Assembly> _referenceAssemblies;

private bool IsReferenceType(Type type)
{
_referenceAssemblies ??= Assembly.ToAssembly().FindReferenceAssemblies();
return _referenceAssemblies.Contains(type.Assembly);
}

public bool ShouldGenerate(FieldInfo fi)
{
Expand All @@ -81,63 +66,16 @@ public string GenerateField(FieldInfo fi)
{
var valueType = fi.FieldType.GetGenericArguments()[0];
var variantType = fi.FieldType.GetGenericTypeDefinition();
var readerSuffix = $"{VariantPropertyNameSuffix}Reader";
var writerSuffix = $"{VariantPropertyNameSuffix}Writer";
var readerAndWriterSuffix = $"{VariantPropertyNameSuffix}ReaderAndWriter";
if (ShouldGenerateVariantInterface)
{
if (variantType == typeof(BlobVariantReaderAndWriter<>))
{
GenerateVariantInterface(valueType, readerSuffix, VariantGenerator.CreateReaderVariants);
GenerateVariantInterface(valueType, writerSuffix, VariantGenerator.CreateWriterVariants);
GenerateVariantInterface(valueType, readerAndWriterSuffix, (writer, valueType, isReferenceType, suffix) =>
{
writer.CreateReaderAndWriterVariants(valueType, isReferenceType, suffix);
writer.CreateSerializedReaderAndWriterVariant(valueType, suffix, $"{VariantPropertyNameSuffix}Reader", $"{VariantPropertyNameSuffix}Writer");
});
}
else if (variantType == typeof(BlobVariantReader<>))
{
GenerateVariantInterface(valueType, readerSuffix, VariantGenerator.CreateReaderVariants);
}
else if (variantType == typeof(BlobVariantWriter<>))
{
GenerateVariantInterface(valueType, writerSuffix, VariantGenerator.CreateWriterVariants);
}
}

if (variantType == typeof(BlobVariantReaderAndWriter<>))
return $"public {VariantInterfaceNamespace}.{valueType.Name}SerializedReaderAndWriterVariant {fi.Name};";

var suffix = variantType == typeof(BlobVariantReader<>) ? readerSuffix : writerSuffix;
var stringBuilder = new StringBuilder();
stringBuilder.Append("[UnityEngine.SerializeReference, SerializeReferenceButton]");
stringBuilder.Append(" ");
stringBuilder.AppendLine($"public {VariantInterfaceNamespace}.{valueType.Name}{suffix} {fi.Name};");
return stringBuilder.ToString();
return $"public {VariantInterfaceNamespace}.SerializedVariantRW<{valueType.FullName}> {fi.Name};";
if (variantType == typeof(BlobVariantReader<>))
return $"public {VariantInterfaceNamespace}.SerializedVariantRO<{valueType.FullName}> {fi.Name};";
return $"public {VariantInterfaceNamespace}.SerializedVariantWO<{valueType.FullName}> {fi.Name};";
}

public string GenerateBuild(FieldInfo fi)
{
return $"{fi.Name}.Allocate(ref builder, ref data.{fi.Name}, Self, tree);";
}

private void GenerateVariantInterface(Type valueType, string suffix, CreateVariants createVariants)
{
var directory = Path.GetDirectoryName(AssetDatabase.GetAssetPath(Generator)) + "/" + VariantInterfaceDirectory;
if (!Directory.Exists(directory)) Directory.CreateDirectory(directory);

var filepath = $"{directory}/{valueType.Name}{suffix}.cs";
if (!File.Exists(filepath) || File.ReadLines(filepath).FirstOrDefault() == HEAD_LINE)
{
using var writer = new StreamWriter(filepath);
writer.WriteLine(HEAD_LINE);
writer.WriteLine(VariantGenerator.NamespaceBegin(VariantInterfaceNamespace));
createVariants(writer, valueType, IsReferenceType, suffix);
writer.WriteLine(VariantGenerator.NamespaceEnd());
}
}

private delegate void CreateVariants(StreamWriter writer, Type valueType, Predicate<Type> isReferenceType, string suffix);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace EntitiesBT.Components
{
public class BTDelayTimer : BTNode<EntitiesBT.Nodes.DelayTimerNode>
{
public EntitiesBT.Variant.SingleSerializedReaderAndWriterVariant TimerSeconds;
public EntitiesBT.Variant.SerializedVariantRW<System.Single> TimerSeconds;
protected override void Build(ref EntitiesBT.Nodes.DelayTimerNode data, BlobBuilder builder, ITreeNode<INodeDataBuilder>[] tree)
{
TimerSeconds.Allocate(ref builder, ref data.TimerSeconds, Self, tree);
Expand Down
2 changes: 1 addition & 1 deletion Packages/builder.component/Runtime/Components/BTTimer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace EntitiesBT.Components
{
public class BTTimer : BTNode<EntitiesBT.Nodes.TimerNode>
{
public EntitiesBT.Variant.SingleSerializedReaderAndWriterVariant CountdownSeconds;
public EntitiesBT.Variant.SerializedVariantRW<System.Single> CountdownSeconds;
public EntitiesBT.Core.NodeState BreakReturnState;
protected override void Build(ref EntitiesBT.Nodes.TimerNode data, BlobBuilder builder, ITreeNode<INodeDataBuilder>[] tree)
{
Expand Down
6 changes: 0 additions & 6 deletions Packages/builder.component/Runtime/NodeCodeGenerator.asset
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,6 @@ MonoBehaviour:
00000005:
type: {class: BlobVariantFieldCodeGenerator, ns: EntitiesBT.Editor, asm: EntitiesBT.Components.Editor}
data:
ShouldGenerateVariantInterface: 1
VariantInterfaceDirectory: Variant
VariantInterfaceNamespace: EntitiesBT.Variant
VariantPropertyNameSuffix: Variant
Generator: {fileID: 11400000}
Assembly: {fileID: 5897886265953266890, guid: c7babe7561eb244059259745ef27b866,
type: 3}
00000006:
type: {class: DefaultNodeDataFieldCodeGenerator, ns: EntitiesBT.Editor, asm: EntitiesBT.Editor}
20 changes: 10 additions & 10 deletions Packages/builder.component/Runtime/Variant/NodeVariant.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using Unity.Collections.LowLevel.Unsafe;
using Unity.Entities;
using UnityEngine;
using UnityEngine.Scripting;
using static EntitiesBT.Core.Utilities;

namespace EntitiesBT.Variant
Expand All @@ -21,8 +20,12 @@ public VariantNodeObjectAttribute(string nodeObjectFieldName)
}
}

[VariantClass(ID_RUNTIME_NODE_VARIANT)]
public class NodeVariant
{
public const string ID_RUNTIME_NODE = "220681AA-D884-4E87-90A8-5A8657A734BD";
public const string ID_RUNTIME_NODE_VARIANT = "7DE6DCA5-71DF-4145-91A6-17EB813B9DEB";

// TODO: check loop ref?
[Serializable]
public class Any<T> : IVariant where T : unmanaged
Expand All @@ -40,23 +43,20 @@ public unsafe IntPtr Allocate(ref BlobBuilder builder, ref BlobVariant blobVaria
[Serializable] public class Writer<T> : Any<T>, IVariantWriter<T> where T : unmanaged {}
[Serializable] public class ReaderAndWriter<T> : Any<T>, IVariantReaderAndWriter<T> where T : unmanaged {}

public const string ID_RUNTIME_NODE = "220681AA-D884-4E87-90A8-5A8657A734BD";
public const string ID_RUNTIME_NODE_VARIANT = "7DE6DCA5-71DF-4145-91A6-17EB813B9DEB";

[Preserve, WriterMethod(ID_RUNTIME_NODE_VARIANT)]
[WriterMethod]
private static unsafe void WriteVariableFunc<T, TNodeBlob, TBlackboard>(ref BlobVariant blobVariant, int index, ref TNodeBlob blob, ref TBlackboard bb, T value)
where T : unmanaged
where TNodeBlob : struct, INodeBlob
where TBlackboard : struct, IBlackboard
{
ref var data = ref blobVariant.Value<DynamicNodeRefData>();
ref var data = ref blobVariant.As<DynamicNodeRefData>();
var ptr = blob.GetRuntimeDataPtr(data.Index);
ref var variable = ref UnsafeUtility.AsRef<BlobVariantReader<T>>(IntPtr.Add(ptr, data.Offset).ToPointer());
// TODO: check writable on editor?
variable.Value.WriteWithRefFallback(index, ref blob, ref bb, value);
}

[Preserve, RefReaderMethod(ID_RUNTIME_NODE)]
[RefReaderMethod(OverrideGuid = ID_RUNTIME_NODE)]
private static ref T GetRuntimeNodeData<T, TNodeBlob, TBlackboard>(ref BlobVariant blobVariant, int index, ref TNodeBlob blob, ref TBlackboard bb)
where T : unmanaged
where TNodeBlob : struct, INodeBlob
Expand All @@ -65,21 +65,21 @@ private static ref T GetRuntimeNodeData<T, TNodeBlob, TBlackboard>(ref BlobVaria
return ref GetValue<T>(ref blobVariant, blob.GetRuntimeDataPtr);
}

[Preserve, ReaderMethod(ID_RUNTIME_NODE_VARIANT)]
[ReaderMethod]
private static unsafe T GetRuntimeNodeVariable<T, TNodeBlob, TBlackboard>(ref BlobVariant blobVariant, int index, ref TNodeBlob blob, ref TBlackboard bb)
where T : unmanaged
where TNodeBlob : struct, INodeBlob
where TBlackboard : struct, IBlackboard
{
ref var data = ref blobVariant.Value<DynamicNodeRefData>();
ref var data = ref blobVariant.As<DynamicNodeRefData>();
var ptr = blob.GetRuntimeDataPtr(data.Index);
ref var variable = ref UnsafeUtility.AsRef<BlobVariantReader<T>>(IntPtr.Add(ptr, data.Offset).ToPointer());
return variable.Read(index, ref blob, ref bb);
}

private static unsafe ref T GetValue<T>(ref BlobVariant blobVariant, Func<int, IntPtr> ptrFunc) where T : unmanaged
{
ref var data = ref blobVariant.Value<DynamicNodeRefData>();
ref var data = ref blobVariant.As<DynamicNodeRefData>();
var ptr = ptrFunc(data.Index);
return ref UnsafeUtility.AsRef<T>(IntPtr.Add(ptr, data.Offset).ToPointer());
}
Expand Down
13 changes: 0 additions & 13 deletions Packages/builder.component/Runtime/Variant/SingleVariantReader.cs

This file was deleted.

This file was deleted.

This file was deleted.

11 changes: 0 additions & 11 deletions Packages/builder.component/Runtime/Variant/SingleVariantWriter.cs

This file was deleted.

5 changes: 2 additions & 3 deletions Packages/builder.component/package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
{
"name": "com.quabug.entities-bt.builder.component",
"description": "Behavior Tree for Unity Entities - Component Builder",
"version": "1.0.2",
"version": "1.2.0",
"unity": "2020.2",
"displayName": "EntitiesBT - Component Builder",
"dependencies": {
"com.quabug.entities-bt.essential": "1.0.1",
"com.quabug.entities-bt.variable.scriptable-object": "1.0.1"
"com.quabug.entities-bt.essential": "1.2.0"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
"EntitiesBT.Runtime",
"EntitiesBT.Builder.Odin"
],
"includePlatforms": [],
"includePlatforms": [
"Editor"
],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": true,
Expand Down
12 changes: 10 additions & 2 deletions Packages/builder.odin/Runtime/OdinEditorUtilities.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 10 additions & 2 deletions Packages/builder.odin/Runtime/OdinNode.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 10 additions & 2 deletions Packages/builder.odin/Runtime/OdinNodeVariant.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 10 additions & 2 deletions Packages/builder.odin/Runtime/OdinSerializedVariant.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Packages/builder.odin/Runtime/SaveToLocalVariant.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace EntitiesBT.Components.Odin
{
[VariantClass(GUID)]
public class SaveToLocalVariant
{
[Serializable]
Expand All @@ -27,7 +28,7 @@ public IntPtr Allocate(ref BlobBuilder builder, ref BlobVariant blobVariant, INo

public const string GUID = "F315684E-2AA1-4780-B31B-2791A93359F1";

[Preserve, RefReaderMethod(GUID)]
[RefReaderMethod]
private static ref T Read<T, TNodeBlob, TBlackboard>(ref BlobVariant blobVariant, int index, ref TNodeBlob blob, ref TBlackboard bb)
where T : unmanaged
where TNodeBlob : struct, INodeBlob
Expand Down
Loading