This repository has been archived by the owner on Jan 18, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
QBI query component filtering (#1338)
- Loading branch information
Paul Balaji
authored
Apr 3, 2020
1 parent
15d0fcf
commit b03b212
Showing
19 changed files
with
254 additions
and
204 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file was deleted.
Oops, something went wrong.
132 changes: 132 additions & 0 deletions
132
workers/unity/Assets/Playground/Config/EntityTemplates.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
using System.Collections.Generic; | ||
using Improbable; | ||
using Improbable.Gdk.Core; | ||
using Improbable.Gdk.PlayerLifecycle; | ||
using Improbable.Gdk.QueryBasedInterest; | ||
using Improbable.Gdk.TransformSynchronization; | ||
using UnityEngine; | ||
|
||
namespace Playground | ||
{ | ||
public static class EntityTemplates | ||
{ | ||
private const int CheckoutRadius = 25; | ||
|
||
public static EntityTemplate CreatePlayerEntityTemplate(EntityId entityId, string clientWorkerId, byte[] playerCreationArguments) | ||
{ | ||
var clientAttribute = EntityTemplate.GetWorkerAccessAttribute(clientWorkerId); | ||
|
||
var template = new EntityTemplate(); | ||
|
||
template.AddComponent(new Position.Snapshot(), clientAttribute); | ||
template.AddComponent(new Metadata.Snapshot("Character"), WorkerUtils.UnityGameLogic); | ||
template.AddComponent(new PlayerInput.Snapshot(), clientAttribute); | ||
template.AddComponent(new Launcher.Snapshot(100, 0), WorkerUtils.UnityGameLogic); | ||
template.AddComponent(new Score.Snapshot(), WorkerUtils.UnityGameLogic); | ||
template.AddComponent(new CubeSpawner.Snapshot(new List<EntityId>()), WorkerUtils.UnityGameLogic); | ||
|
||
TransformSynchronizationHelper.AddTransformSynchronizationComponents(template, clientAttribute); | ||
PlayerLifecycleHelper.AddPlayerLifecycleComponents(template, clientWorkerId, WorkerUtils.UnityGameLogic); | ||
|
||
var clientSelfInterest = InterestQuery.Query(Constraint.EntityId(entityId)).FilterResults(new[] | ||
{ | ||
Position.ComponentId, Metadata.ComponentId, TransformInternal.ComponentId, CubeSpawner.ComponentId, | ||
Score.ComponentId, Launcher.ComponentId | ||
}); | ||
|
||
var clientRangeInterest = InterestQuery.Query(Constraint.RelativeCylinder(radius: CheckoutRadius)) | ||
.FilterResults(new[] | ||
{ | ||
Position.ComponentId, Metadata.ComponentId, TransformInternal.ComponentId, Collisions.ComponentId, | ||
SpinnerColor.ComponentId, SpinnerRotation.ComponentId, CubeColor.ComponentId, Score.ComponentId, | ||
Launchable.ComponentId | ||
}); | ||
|
||
var serverSelfInterest = InterestQuery.Query(Constraint.EntityId(entityId)).FilterResults(new[] | ||
{ | ||
Position.ComponentId, Metadata.ComponentId, TransformInternal.ComponentId, Score.ComponentId | ||
}); | ||
|
||
var serverRangeInterest = InterestQuery.Query(Constraint.RelativeCylinder(radius: CheckoutRadius)) | ||
.FilterResults(new[] | ||
{ | ||
Position.ComponentId, Metadata.ComponentId, TransformInternal.ComponentId, Collisions.ComponentId, | ||
SpinnerColor.ComponentId, SpinnerRotation.ComponentId, Score.ComponentId | ||
}); | ||
|
||
var interest = InterestTemplate.Create() | ||
.AddQueries<Position.Component>(clientSelfInterest, clientRangeInterest) | ||
.AddQueries<Metadata.Component>(serverSelfInterest, serverRangeInterest); | ||
template.AddComponent(interest.ToSnapshot()); | ||
|
||
template.SetReadAccess(WorkerUtils.MobileClient, WorkerUtils.UnityClient, WorkerUtils.UnityGameLogic); | ||
|
||
return template; | ||
} | ||
|
||
public static EntityTemplate CreateCubeEntityTemplate(Vector3 location) | ||
{ | ||
var template = new EntityTemplate(); | ||
template.AddComponent(new Position.Snapshot(location.ToCoordinates()), WorkerUtils.UnityGameLogic); | ||
template.AddComponent(new Metadata.Snapshot("Cube"), WorkerUtils.UnityGameLogic); | ||
template.AddComponent(new Persistence.Snapshot(), WorkerUtils.UnityGameLogic); | ||
template.AddComponent(new CubeColor.Snapshot(), WorkerUtils.UnityGameLogic); | ||
template.AddComponent(new CubeTargetVelocity.Snapshot(new Vector3f(-2.0f, 0, 0)), | ||
WorkerUtils.UnityGameLogic); | ||
template.AddComponent(new Launchable.Snapshot(), WorkerUtils.UnityGameLogic); | ||
|
||
TransformSynchronizationHelper.AddTransformSynchronizationComponents(template, WorkerUtils.UnityGameLogic, Quaternion.identity, location); | ||
|
||
var query = InterestQuery.Query(Constraint.RelativeCylinder(radius: CheckoutRadius)).FilterResults(new[] | ||
{ | ||
Position.ComponentId, Metadata.ComponentId, TransformInternal.ComponentId | ||
}); | ||
|
||
var interest = InterestTemplate.Create() | ||
.AddQueries<Position.Component>(query); | ||
template.AddComponent(interest.ToSnapshot()); | ||
|
||
template.SetReadAccess(WorkerUtils.MobileClient, WorkerUtils.UnityClient, WorkerUtils.UnityGameLogic); | ||
|
||
return template; | ||
} | ||
|
||
public static EntityTemplate CreateSpinnerEntityTemplate(Coordinates coords) | ||
{ | ||
var transform = TransformUtils.CreateTransformSnapshot(coords.ToUnityVector(), Quaternion.identity); | ||
|
||
var template = new EntityTemplate(); | ||
template.AddComponent(new Position.Snapshot(coords), WorkerUtils.UnityGameLogic); | ||
template.AddComponent(new Metadata.Snapshot("Spinner"), WorkerUtils.UnityGameLogic); | ||
template.AddComponent(transform, WorkerUtils.UnityGameLogic); | ||
template.AddComponent(new Persistence.Snapshot(), WorkerUtils.UnityGameLogic); | ||
template.AddComponent(new Collisions.Snapshot(), WorkerUtils.UnityGameLogic); | ||
template.AddComponent(new SpinnerColor.Snapshot(Color.BLUE), WorkerUtils.UnityGameLogic); | ||
template.AddComponent(new SpinnerRotation.Snapshot(), WorkerUtils.UnityGameLogic); | ||
|
||
var query = InterestQuery.Query(Constraint.RelativeCylinder(radius: CheckoutRadius)).FilterResults(new[] | ||
{ | ||
Position.ComponentId, Metadata.ComponentId, TransformInternal.ComponentId | ||
}); | ||
|
||
var interest = InterestTemplate.Create() | ||
.AddQueries<Position.Component>(query); | ||
template.AddComponent(interest.ToSnapshot()); | ||
|
||
template.SetReadAccess(WorkerUtils.MobileClient, WorkerUtils.UnityClient, WorkerUtils.UnityGameLogic); | ||
|
||
return template; | ||
} | ||
|
||
public static EntityTemplate CreatePlayerSpawnerEntityTemplate(Coordinates playerSpawnerLocation) | ||
{ | ||
var template = new EntityTemplate(); | ||
template.AddComponent(new Position.Snapshot(playerSpawnerLocation), WorkerUtils.UnityGameLogic); | ||
template.AddComponent(new Metadata.Snapshot("PlayerCreator"), WorkerUtils.UnityGameLogic); | ||
template.AddComponent(new Persistence.Snapshot(), WorkerUtils.UnityGameLogic); | ||
template.AddComponent(new PlayerCreator.Snapshot(), WorkerUtils.UnityGameLogic); | ||
|
||
return template; | ||
} | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...layground/Scripts/UI/InitUISystem.cs.meta → ...Playground/Config/EntityTemplates.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
11 changes: 0 additions & 11 deletions
11
workers/unity/Assets/Playground/Config/PlayerTemplate.cs.meta
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.