Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using TripleG.ClientAndServer;
- using Unity.Entities;
- using Unity.Jobs;
- using Unity.NetCode;
- using UnityEngine;
- namespace TripleG.Client
- {
- [UpdateInWorld(UpdateInWorld.TargetWorld.Client)]
- [UpdateInGroup(typeof(GhostPredictionSystemGroup))]
- [UpdateAfter(typeof(ResetControllablesCommandsSystem))]
- [UpdateBefore(typeof(CharacterMovementSystem))]
- [UpdateBefore(typeof(SpaceShipMovementSystem))]
- public class SetControllablesCommandsSystem : JobComponentSystem
- {
- private GhostPredictionSystemGroup m_predictionGroup;
- protected override void OnCreate()
- {
- base.OnCreate();
- m_predictionGroup = World.GetOrCreateSystem<GhostPredictionSystemGroup>();
- }
- protected override JobHandle OnUpdate(JobHandle inputDeps)
- {
- var controllableDataFromEntity = GetComponentDataFromEntity<ControllableData>(false);
- var inputEntity = GetSingletonEntity<LocalInputData>();
- var clientCommandBufferFromEntity = GetBufferFromEntity<ClientCommand>();
- var tick = m_predictionGroup.PredictingTick;
- // Here we only care of our own, so we can either go over input, or local client
- inputDeps = Entities.WithNativeDisableParallelForRestriction(controllableDataFromEntity).WithNativeDisableParallelForRestriction(clientCommandBufferFromEntity).WithAll<LocalClientTag>().ForEach((ControllingData controllingData) =>
- {
- if (controllingData.controlledEntity != Entity.Null)
- {
- var clientCommandBuffer = clientCommandBufferFromEntity[inputEntity];
- // Get controlledData
- if(clientCommandBuffer.GetDataAtTick(tick, out ClientCommand commandData))
- {
- var data = controllableDataFromEntity[controllingData.controlledEntity];
- data.currentCommand = commandData;
- controllableDataFromEntity[controllingData.controlledEntity] = data;
- }
- }
- }).Schedule(inputDeps);
- return inputDeps;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement