@@ -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 }
0 commit comments