-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathStartAvatarMatricesCalculationSystem.cs
More file actions
68 lines (58 loc) · 2.54 KB
/
Copy pathStartAvatarMatricesCalculationSystem.cs
File metadata and controls
68 lines (58 loc) · 2.54 KB
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
64
65
66
67
68
using Arch.Core;
using Arch.System;
using Arch.SystemGroups;
using DCL.AvatarRendering.AvatarShape.Components;
using DCL.AvatarRendering.AvatarShape.UnityInterface;
using DCL.Character.Components;
using ECS.Abstract;
using ECS.LifeCycle.Components;
namespace DCL.AvatarRendering.AvatarShape
{
/// <summary>
/// It is crucial to schedule it as early as possible to give Unity some space to decide
/// how to distribute workload
/// </summary>
[UpdateInGroup(typeof(AvatarGroup))]
[UpdateAfter(typeof(AvatarInstantiatorSystem))] // right after AvatarBase is instantiated
public partial class StartAvatarMatricesCalculationSystem : BaseUnityLoopSystem
{
private readonly AvatarTransformMatrixJobWrapper avatarTransformMatrixBatchJob;
internal StartAvatarMatricesCalculationSystem(World world, AvatarTransformMatrixJobWrapper jobWrapper) :
base(world)
{
avatarTransformMatrixBatchJob = jobWrapper;
}
protected override void Update(float t)
{
RegisterMainPlayerQuery(World);
RegisterRemoteAvatarsQuery(World);
RefreshBoneCountsQuery(World);
avatarTransformMatrixBatchJob.ScheduleBoneMatrixCalculation();
}
[Query]
[All(typeof(PlayerComponent))]
[None(typeof(DeleteEntityIntention))]
private void RegisterMainPlayer(ref AvatarBase avatarBase, ref AvatarTransformMatrixComponent transformMatrixComponent)
{
//Already registered
if (transformMatrixComponent.IndexInGlobalJobArray.IsValid())
return;
avatarTransformMatrixBatchJob.RegisterMainPlayerAvatar(avatarBase, ref transformMatrixComponent);
}
[Query]
[None(typeof(PlayerComponent), typeof(DeleteEntityIntention))]
private void RegisterRemoteAvatars(ref AvatarBase avatarBase, ref AvatarTransformMatrixComponent transformMatrixComponent)
{
//Already registered
if (transformMatrixComponent.IndexInGlobalJobArray.IsValid())
return;
avatarTransformMatrixBatchJob.RegisterAvatar(avatarBase, ref transformMatrixComponent);
}
[Query]
[None(typeof(DeleteEntityIntention))]
private void RefreshBoneCounts(ref AvatarTransformMatrixComponent transformMatrixComponent, ref AvatarCustomSkinningComponent skinningComponent)
{
avatarTransformMatrixBatchJob.SetBoneCount(ref transformMatrixComponent, skinningComponent.BoneCount);
}
}
}