forked from actionk/Morpeh.Queries
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQuerySystem.cs
63 lines (52 loc) · 1.58 KB
/
QuerySystem.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
using System;
using Scellecs.Morpeh.Collections;
using Unity.Collections;
using Unity.Jobs;
namespace Scellecs.Morpeh
{
public abstract class QuerySystem : ISystem
{
private readonly FastList<Action> m_executors = new();
public World World { get; set; }
protected float deltaTime;
public virtual void OnAwake()
{
Configure();
}
protected abstract void Configure();
public virtual void Dispose()
{
}
public virtual void OnUpdate(float newDeltaTime)
{
deltaTime = newDeltaTime;
foreach (var executor in m_executors)
executor.Invoke();
#if MORPEH_BURST
if (m_jobHandles.length > 0)
{
var jobHandles = new NativeArray<JobHandle>(m_jobHandles.length, Allocator.Temp);
for (var i = 0; i < m_jobHandles.length; i++)
jobHandles[i] = m_jobHandles.data[i].jobHandle;
JobHandle.CombineDependencies(jobHandles).Complete();
jobHandles.Dispose();
}
#endif
}
protected QueryBuilder CreateQuery()
{
return new QueryBuilder(this);
}
internal void AddExecutor(Action newQueryExecutor)
{
m_executors.Add(newQueryExecutor);
}
#if MORPEH_BURST
private readonly FastList<QueryBuilderJobHandle> m_jobHandles = new();
internal void AddJobHandle(QueryBuilderJobHandle jobHandles)
{
m_jobHandles.Add(jobHandles);
}
#endif
}
}