Skip to content

Commit

Permalink
Merge pull request #27 from crashkonijn/fix/collections-2-1-breaking-…
Browse files Browse the repository at this point in the history
…package

Fixed Collections >= 2.1 breaking package
  • Loading branch information
crashkonijn authored May 15, 2023
2 parents ec36688 + ac02626 commit f83a4f9
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 2 deletions.
11 changes: 10 additions & 1 deletion Package/Runtime/CrashKonijn.Goap.Resolver/GraphResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ public class GraphResolver : IGraphResolver
{
private readonly List<Node> indexList;
private readonly List<IAction> actionIndexList;

#if UNITY_COLLECTIONS_2_1
private NativeParallelMultiHashMap<int, int> map;
#else
private NativeMultiHashMap<int, int> map;
#endif

private GraphResolverJob job;
private JobHandle handle;
Expand All @@ -25,8 +30,12 @@ public GraphResolver(IAction[] actions, IActionKeyResolver keyResolver)

this.indexList = this.graph.AllNodes.ToList();
this.actionIndexList = this.indexList.Select(x => x.Action).ToList();


#if UNITY_COLLECTIONS_2_1
var map = new NativeParallelMultiHashMap<int, int>(this.indexList.Count, Allocator.Persistent);
#else
var map = new NativeMultiHashMap<int, int>(this.indexList.Count, Allocator.Persistent);
#endif

for (var i = 0; i < this.indexList.Count; i++)
{
Expand Down
4 changes: 4 additions & 0 deletions Package/Runtime/CrashKonijn.Goap.Resolver/GraphResolverJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ public int Compare(NodeData x, NodeData y)
public struct GraphResolverJob : IJob
{
// Graph specific
#if UNITY_COLLECTIONS_2_1
[ReadOnly] public NativeParallelMultiHashMap<int, int> Connections;
#else
[ReadOnly] public NativeMultiHashMap<int, int> Connections;
#endif

// Resolve specific
[ReadOnly] public RunData RunData;
Expand Down
15 changes: 15 additions & 0 deletions Package/Runtime/CrashKonijn.Goap.Resolver/ResolveHandle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,20 @@ public class ResolveHandle : IResolveHandle
private GraphResolverJob job;
private RunData runData;

#if UNITY_COLLECTIONS_2_1
public ResolveHandle(GraphResolver graphResolver, NativeParallelMultiHashMap<int, int> connections, RunData runData)
{
this.graphResolver = graphResolver;
this.job = new GraphResolverJob
{
Connections = connections,
RunData = runData,
Result = new NativeList<NodeData>(Allocator.TempJob)
};

this.handle = this.job.Schedule();
}
#else
public ResolveHandle(GraphResolver graphResolver, NativeMultiHashMap<int, int> connections, RunData runData)
{
this.graphResolver = graphResolver;
Expand All @@ -24,6 +38,7 @@ public ResolveHandle(GraphResolver graphResolver, NativeMultiHashMap<int, int> c

this.handle = this.job.Schedule();
}
#endif

public IAction[] Complete()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"versionDefines": [
{
"name": "com.unity.collections",
"expression": "2.1",
"define": "UNITY_COLLECTIONS_2_1"
}
],
"noEngineReferences": false
}

0 comments on commit f83a4f9

Please sign in to comment.