Skip to content
This repository was archived by the owner on Oct 20, 2021. It is now read-only.

Commit b1e0390

Browse files
author
Paul Balaji
authored
QBI query component filtering (#264)
1 parent d54af3d commit b1e0390

File tree

8 files changed

+58
-26
lines changed

8 files changed

+58
-26
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@
66

77
- The FPS Starter Project now requires Unity 2019.3. [#263](https://github.com/spatialos/gdk-for-unity-fps-starter-project/pull/263)
88

9+
## Added
10+
11+
- Added component result type filters to QBI queries. [#264](https://github.com/spatialos/gdk-for-unity-fps-starter-project/pull/264)
12+
13+
## Changed
14+
15+
- Updated project to support `com.unity.entities` package upgrade. [#264](https://github.com/spatialos/gdk-for-unity-fps-starter-project/pull/264)
16+
917
## `0.3.4` - 2020-03-25
1018

1119
## Breaking Changes

gdk.pinned

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
develop 79dc4b1c77fdf58ba082dc448d6519462cec7159
1+
develop b03b2129f9c2fccc7058f49fbf3a89c61376a881

snapshots/cloud.snapshot

-28 Bytes
Binary file not shown.

snapshots/default.snapshot

-28 Bytes
Binary file not shown.

workers/unity/Assets/Fps/Scripts/Config/FpsEntityTemplates.cs

Lines changed: 41 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,6 @@ public static EntityTemplate Spawner(Coordinates spawnerCoordinates)
2222
template.AddComponent(new Persistence.Snapshot(), WorkerUtils.UnityGameLogic);
2323
template.AddComponent(new PlayerCreator.Snapshot(), WorkerUtils.UnityGameLogic);
2424

25-
var query = InterestQuery.Query(Constraint.RelativeCylinder(150));
26-
var interest = InterestTemplate.Create()
27-
.AddQueries<Position.Component>(query);
28-
template.AddComponent(interest.ToSnapshot(), WorkerUtils.UnityGameLogic);
29-
30-
template.SetReadAccess(WorkerUtils.UnityGameLogic);
31-
template.SetComponentWriteAccess(EntityAcl.ComponentId, WorkerUtils.UnityGameLogic);
32-
3325
return template;
3426
}
3527

@@ -90,16 +82,51 @@ public static EntityTemplate Player(EntityId entityId, string workerId, byte[] a
9082
const int serverRadius = 150;
9183
var clientRadius = workerId.Contains(WorkerUtils.MobileClient) ? 60 : 150;
9284

93-
var serverQuery = InterestQuery.Query(Constraint.RelativeCylinder(serverRadius));
94-
var clientQuery = InterestQuery.Query(Constraint.RelativeCylinder(clientRadius));
85+
// Position, Metadata, OwningWorker and ServerMovement are included in all queries, since these
86+
// components are required by the GameObject creator.
87+
88+
// HealthComponent is needed by the LookAtRagdoll script for respawn behaviour.
89+
// GunComponent is needed by the GunManager script.
90+
var clientSelfInterest = InterestQuery.Query(Constraint.EntityId(entityId)).FilterResults(new[]
91+
{
92+
Position.ComponentId, Metadata.ComponentId, OwningWorker.ComponentId,
93+
ServerMovement.ComponentId, HealthComponent.ComponentId, GunComponent.ComponentId
94+
});
95+
96+
// ClientRotation is used for rendering other players.
97+
// GunComponent is required by the GunManager script.
98+
// GunStateComponent and ShootingComponent are needed for rendering other players' shots.
99+
var clientRangeInterest = InterestQuery.Query(Constraint.RelativeCylinder(clientRadius)).FilterResults(new[]
100+
{
101+
Position.ComponentId, Metadata.ComponentId, OwningWorker.ComponentId,
102+
ServerMovement.ComponentId, ClientRotation.ComponentId, HealthComponent.ComponentId,
103+
GunComponent.ComponentId, GunStateComponent.ComponentId, ShootingComponent.ComponentId
104+
});
105+
106+
// ClientMovement is used by the ServerMovementDriver script.
107+
// ShootingComponent is used by the ServerShootingSystem.
108+
var serverSelfInterest = InterestQuery.Query(Constraint.EntityId(entityId)).FilterResults(new[]
109+
{
110+
ClientMovement.ComponentId, ShootingComponent.ComponentId
111+
});
112+
113+
// ClientRotation is used for driving player proxies.
114+
// HealthComponent is required by the VisiblityAndCollision script.
115+
// ShootingComponent is used by the ServerShootingSystem.
116+
var serverRangeInterest = InterestQuery.Query(Constraint.RelativeCylinder(serverRadius)).FilterResults(new[]
117+
{
118+
Position.ComponentId, Metadata.ComponentId, OwningWorker.ComponentId,
119+
ServerMovement.ComponentId, ClientRotation.ComponentId, HealthComponent.ComponentId,
120+
ShootingComponent.ComponentId
121+
});
95122

96123
var interest = InterestTemplate.Create()
97-
.AddQueries<Position.Component>(serverQuery)
98-
.AddQueries<ClientMovement.Component>(clientQuery);
99-
template.AddComponent(interest.ToSnapshot(), WorkerUtils.UnityGameLogic);
124+
.AddQueries<ClientMovement.Component>(clientSelfInterest, clientRangeInterest)
125+
.AddQueries<ServerMovement.Component>(serverSelfInterest, serverRangeInterest);
126+
127+
template.AddComponent(interest.ToSnapshot());
100128

101129
template.SetReadAccess(WorkerUtils.UnityClient, WorkerUtils.UnityGameLogic, WorkerUtils.MobileClient);
102-
template.SetComponentWriteAccess(EntityAcl.ComponentId, WorkerUtils.UnityGameLogic);
103130

104131
return template;
105132
}

workers/unity/Assets/Fps/Scripts/Config/OneTimeInitialisation.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ private static void Init()
1818
}
1919

2020
initialized = true;
21-
PlayerLoopManager.RegisterDomainUnload(WorldsInitializationHelper.DomainUnloadShutdown, 1000);
2221

2322
// Setup template to use for player on connecting client
2423
PlayerLifecycleConfig.CreatePlayerEntityTemplate = FpsEntityTemplates.Player;

workers/unity/Assets/Fps/Scripts/Health/Systems/HealthRegenSystem.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,16 @@ protected override void OnCreate()
3333
initGroup = GetEntityQuery(
3434
ComponentType.ReadOnly<HealthRegenComponent.Component>(),
3535
ComponentType.Exclude<HealthRegenData>(),
36-
ComponentType.ReadOnly<HealthComponent.ComponentAuthority>()
36+
ComponentType.ReadOnly<HealthComponent.HasAuthority>()
3737
);
38-
initGroup.SetFilter(HealthComponent.ComponentAuthority.Authoritative);
3938

4039
regenGroup = GetEntityQuery(
4140
ComponentType.ReadWrite<HealthRegenComponent.Component>(),
4241
ComponentType.ReadWrite<HealthRegenData>(),
4342
ComponentType.ReadOnly<HealthComponent.Component>(),
4443
ComponentType.ReadOnly<SpatialEntityId>(),
45-
ComponentType.ReadOnly<HealthComponent.ComponentAuthority>()
44+
ComponentType.ReadOnly<HealthComponent.HasAuthority>()
4645
);
47-
regenGroup.SetFilter(HealthComponent.ComponentAuthority.Authoritative);
4846
}
4947

5048
protected override void OnUpdate()
@@ -142,7 +140,7 @@ private void ApplyHealthRegen()
142140
// If damaged recently, tick down the timer.
143141
if (regenComponent.DamagedRecently)
144142
{
145-
regenData.DamagedRecentlyTimer -= Time.deltaTime;
143+
regenData.DamagedRecentlyTimer -= Time.DeltaTime;
146144

147145
if (regenData.DamagedRecentlyTimer <= 0)
148146
{
@@ -153,7 +151,7 @@ private void ApplyHealthRegen()
153151
else
154152
{
155153
// Send a spatial update once every CooldownSyncInterval.
156-
regenData.NextSpatialSyncTimer -= Time.deltaTime;
154+
regenData.NextSpatialSyncTimer -= Time.DeltaTime;
157155
if (regenData.NextSpatialSyncTimer <= 0)
158156
{
159157
regenData.NextSpatialSyncTimer += regenComponent.CooldownSyncInterval;
@@ -167,7 +165,7 @@ private void ApplyHealthRegen()
167165
// If not damaged recently, and not already fully healed, regen.
168166
if (healthComponent.Health < healthComponent.MaxHealth)
169167
{
170-
regenData.NextRegenTimer -= Time.deltaTime;
168+
regenData.NextRegenTimer -= Time.DeltaTime;
171169
if (regenData.NextRegenTimer <= 0)
172170
{
173171
regenData.NextRegenTimer += regenComponent.RegenInterval;

workers/unity/Assets/Fps/Scripts/Metrics/MetricSendSystem.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ protected override void OnCreate()
3636
? DefaultTargetFrameRate
3737
: Application.targetFrameRate;
3838

39-
lastFrameCount = Time.frameCount;
39+
lastFrameCount = UnityEngine.Time.frameCount;
4040
calculatedFps = targetFps;
4141

4242
timeOfLastUpdate = DateTime.Now;
@@ -69,8 +69,8 @@ private double CalculateLoad()
6969

7070
private void CalculateFps()
7171
{
72-
var frameCount = Time.frameCount - lastFrameCount;
73-
lastFrameCount = Time.frameCount;
72+
var frameCount = UnityEngine.Time.frameCount - lastFrameCount;
73+
lastFrameCount = UnityEngine.Time.frameCount;
7474
var rawFps = frameCount / (DateTime.Now - timeOfLastUpdate).TotalSeconds;
7575
calculatedFps = (rawFps * (1 - smoothing)) + (calculatedFps * smoothing);
7676
}

0 commit comments

Comments
 (0)