Ejemplo n.º 1
0
#pragma warning restore 649
#endif

        public void Execute(ArchetypeChunk archetypeChunk, int chunkIndex, int firstEntityIndex)
        {
            var hybridChunkInfoArray = archetypeChunk.GetNativeArray(HybridChunkInfo);
            var chunkHeaderArray     = archetypeChunk.GetNativeArray(ChunkHeader);

            for (var entityIndex = 0; entityIndex < archetypeChunk.Count; entityIndex++)
            {
                var hybridChunkInfo = hybridChunkInfoArray[entityIndex];
                if (!hybridChunkInfo.Valid)
                {
                    continue;
                }

                var chunkHeader = chunkHeaderArray[entityIndex];

#if UNITY_EDITOR
                Stats[ThreadIndex].Stats[CullingStats.kLodTotal]++;
#endif
                var internalBatchIndex = hybridChunkInfo.InternalIndex;
                var chunkInstanceCount = chunkHeader.ArchetypeChunk.Count;
                var isOrtho            = LODParams.isOrtho;

                ref var chunkCullingData = ref hybridChunkInfo.CullingData;
                ChunkInstanceLodEnabled chunkEntityLodEnabled = chunkCullingData.InstanceLodEnableds;

#if UNITY_EDITOR
                ChunkInstanceLodEnabled oldEntityLodEnabled = chunkEntityLodEnabled;
#endif
                var forceLowLOD = ForceLowLOD[internalBatchIndex];

                if (0 == (chunkCullingData.Flags & HybridChunkCullingData.kFlagHasLodData))
                {
#if UNITY_EDITOR
                    Stats[ThreadIndex].Stats[CullingStats.kLodNoRequirements]++;
#endif
                    chunkEntityLodEnabled.Enabled[0]     = 0;
                    chunkEntityLodEnabled.Enabled[1]     = 0;
                    chunkCullingData.ForceLowLODPrevious = forceLowLOD;

                    for (int i = 0; i < chunkInstanceCount; ++i)
                    {
                        int wordIndex = i >> 6;
                        int bitIndex  = i & 63;
                        chunkEntityLodEnabled.Enabled[wordIndex] |= 1ul << bitIndex;
                    }
                }
                else
                {
                    int diff = (int)chunkCullingData.MovementGraceFixed16 - CameraMoveDistanceFixed16;
                    chunkCullingData.MovementGraceFixed16 = (ushort)math.max(0, diff);

                    var graceExpired    = chunkCullingData.MovementGraceFixed16 == 0;
                    var forceLodChanged = forceLowLOD != chunkCullingData.ForceLowLODPrevious;

                    if (graceExpired || forceLodChanged || DistanceScaleChanged)
                    {
                        chunkEntityLodEnabled.Enabled[0] = 0;
                        chunkEntityLodEnabled.Enabled[1] = 0;

#if UNITY_EDITOR
                        Stats[ThreadIndex].Stats[CullingStats.kLodChunksTested]++;
#endif
                        var chunk = chunkHeader.ArchetypeChunk;

                        var rootLodRequirements     = chunk.GetNativeArray(RootLodRequirements);
                        var instanceLodRequirements = chunk.GetNativeArray(InstanceLodRequirements);

                        float graceDistance = float.MaxValue;

                        for (int i = 0; i < chunkInstanceCount; i++)
                        {
                            var rootLodRequirement = rootLodRequirements[i];

                            var rootLodDistance =
                                math.select(
                                    DistanceScale *
                                    math.length(LODParams.cameraPos - rootLodRequirement.LOD.WorldReferencePosition),
                                    DistanceScale, isOrtho);

                            float rootMinDist = math.select(rootLodRequirement.LOD.MinDist, 0.0f, forceLowLOD == 1);
                            float rootMaxDist = rootLodRequirement.LOD.MaxDist;

                            graceDistance = math.min(math.abs(rootLodDistance - rootMinDist), graceDistance);
                            graceDistance = math.min(math.abs(rootLodDistance - rootMaxDist), graceDistance);

                            var rootLodIntersect = (rootLodDistance < rootMaxDist) && (rootLodDistance >= rootMinDist);

                            if (rootLodIntersect)
                            {
                                var instanceLodRequirement = instanceLodRequirements[i];
                                var instanceDistance       =
                                    math.select(
                                        DistanceScale *
                                        math.length(LODParams.cameraPos -
                                                    instanceLodRequirement.WorldReferencePosition), DistanceScale,
                                        isOrtho);

                                var instanceLodIntersect =
                                    (instanceDistance < instanceLodRequirement.MaxDist) &&
                                    (instanceDistance >= instanceLodRequirement.MinDist);

                                graceDistance = math.min(math.abs(instanceDistance - instanceLodRequirement.MinDist),
                                                         graceDistance);
                                graceDistance = math.min(math.abs(instanceDistance - instanceLodRequirement.MaxDist),
                                                         graceDistance);

                                if (instanceLodIntersect)
                                {
                                    var index     = i;
                                    var wordIndex = index >> 6;
                                    var bitIndex  = index & 0x3f;
                                    var lodWord   = chunkEntityLodEnabled.Enabled[wordIndex];

                                    lodWord |= 1UL << bitIndex;
                                    chunkEntityLodEnabled.Enabled[wordIndex] = lodWord;
                                }
                            }
                        }

                        chunkCullingData.MovementGraceFixed16 = Fixed16CamDistance.FromFloatFloor(graceDistance);
                        chunkCullingData.ForceLowLODPrevious  = forceLowLOD;
                    }
                }


#if UNITY_EDITOR
                if (oldEntityLodEnabled.Enabled[0] != chunkEntityLodEnabled.Enabled[0] ||
                    oldEntityLodEnabled.Enabled[1] != chunkEntityLodEnabled.Enabled[1])
                {
                    Stats[ThreadIndex].Stats[CullingStats.kLodChanged]++;
                }
#endif

                chunkCullingData.InstanceLodEnableds = chunkEntityLodEnabled;
                hybridChunkInfoArray[entityIndex]    = hybridChunkInfo;
            }
                public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
                {
                    NativeArray <PhysicsCollider> chunkColliders     = chunk.GetNativeArray(PhysicsColliderType);
                    NativeArray <LocalToWorld>    chunkLocalToWorlds = chunk.GetNativeArray(LocalToWorldType);
                    //     NativeArray<Translation> chunkPositions = chunk.GetNativeArray(PositionType);
                    //      NativeArray<Rotation> chunkRotations = chunk.GetNativeArray(RotationType);

                    NativeArray <TransformPredictedState> chunkTransforms = chunk.GetNativeArray(TransformType);
                    NativeArray <Entity>            chunkEntities         = chunk.GetNativeArray(EntityType);
                    NativeArray <PhysicsCustomTags> chunkCustomTags       = chunk.GetNativeArray(PhysicsCustomTagsType);

                    int instanceCount = chunk.Count;
                    int rbIndex       = FirstBodyIndex + firstEntityIndex;

                    bool hasChunkPhysicsColliderType   = chunk.Has(PhysicsColliderType);
                    bool hasChunkPhysicsCustomTagsType = chunk.Has(PhysicsCustomTagsType);
                    bool hasChunkParentType            = chunk.Has(ParentType);
                    bool hasChunkLocalToWorldType      = chunk.Has(LocalToWorldType);


                    //    bool hasChunkPositionType = chunk.Has(PositionType);
                    //   bool hasChunkRotationType = chunk.Has(RotationType);

                    bool           hasChunkTransformType = chunk.Has(TransformType);
                    RigidTransform worldFromBody         = RigidTransform.identity;

                    for (int i = 0; i < instanceCount; i++, rbIndex++)
                    {
                        // if entities are in a transform hierarchy then Translation/Rotation are in the space of their parents
                        // in that case, LocalToWorld is the only common denominator for world space
                        if (hasChunkParentType)
                        {
                            if (hasChunkLocalToWorldType)
                            {
                                var localToWorld = chunkLocalToWorlds[i];
                                worldFromBody = Math.DecomposeRigidBodyTransform(localToWorld.Value);
                            }
                        }
                        else
                        {
                            if (hasChunkTransformType)
                            {
                                worldFromBody.pos = chunkTransforms[i].Position;
                            }
                            else if (hasChunkLocalToWorldType)
                            {
                                worldFromBody.pos = chunkLocalToWorlds[i].Position;
                            }

                            if (hasChunkTransformType)
                            {
                                worldFromBody.rot = chunkTransforms[i].Rotation;
                            }
                            else if (hasChunkLocalToWorldType)
                            {
                                var localToWorld = chunkLocalToWorlds[i];
                                worldFromBody.rot = Math.DecomposeRigidBodyOrientation(localToWorld.Value);
                            }
                        }

                        RigidBodies[rbIndex] = new RigidBody
                        {
                            WorldFromBody = new RigidTransform(worldFromBody.rot, worldFromBody.pos),
                            Collider      = hasChunkPhysicsColliderType ? chunkColliders[i].Value : default,
Ejemplo n.º 3
0
        public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
        {
            var deserializerState = new GhostDeserializerState
            {
                GhostMap = GhostMap
            };
            var ghostEntityArray             = chunk.GetNativeArray(ghostEntityType);
            var ghostSnapshotDataArray       = chunk.GetBufferAccessor(ghostSnapshotDataType);
            var predictedGhostComponentArray = chunk.GetNativeArray(predictedGhostComponentType);
            var ghostRotationArray           = chunk.GetNativeArray(ghostRotationType);
            var ghostTranslationArray        = chunk.GetNativeArray(ghostTranslationType);

#if UNITY_EDITOR || DEVELOPMENT_BUILD
            var minMaxOffset = ThreadIndex * (JobsUtility.CacheLineSize / 4);
#endif
            for (int entityIndex = 0; entityIndex < ghostEntityArray.Length; ++entityIndex)
            {
                var snapshot = ghostSnapshotDataArray[entityIndex];
#if UNITY_EDITOR || DEVELOPMENT_BUILD
                var latestTick = snapshot.GetLatestTick();
                if (latestTick != 0)
                {
                    if (minMaxSnapshotTick[minMaxOffset] == 0 || SequenceHelpers.IsNewer(minMaxSnapshotTick[minMaxOffset], latestTick))
                    {
                        minMaxSnapshotTick[minMaxOffset] = latestTick;
                    }
                    if (minMaxSnapshotTick[minMaxOffset + 1] == 0 || SequenceHelpers.IsNewer(latestTick, minMaxSnapshotTick[minMaxOffset + 1]))
                    {
                        minMaxSnapshotTick[minMaxOffset + 1] = latestTick;
                    }
                }
#endif
                LagCubeSnapshotData snapshotData;
                snapshot.GetDataAtTick(targetTick, out snapshotData);

                var predictedData         = predictedGhostComponentArray[entityIndex];
                var lastPredictedTickInst = lastPredictedTick;
                if (lastPredictedTickInst == 0 || predictedData.AppliedTick != snapshotData.Tick)
                {
                    lastPredictedTickInst = snapshotData.Tick;
                }
                else if (!SequenceHelpers.IsNewer(lastPredictedTickInst, snapshotData.Tick))
                {
                    lastPredictedTickInst = snapshotData.Tick;
                }
                if (minPredictedTick[ThreadIndex] == 0 || SequenceHelpers.IsNewer(minPredictedTick[ThreadIndex], lastPredictedTickInst))
                {
                    minPredictedTick[ThreadIndex] = lastPredictedTickInst;
                }
                predictedGhostComponentArray[entityIndex] = new PredictedGhostComponent {
                    AppliedTick = snapshotData.Tick, PredictionStartTick = lastPredictedTickInst
                };
                if (lastPredictedTickInst != snapshotData.Tick)
                {
                    continue;
                }

                var ghostRotation    = ghostRotationArray[entityIndex];
                var ghostTranslation = ghostTranslationArray[entityIndex];
                ghostRotation.Value                = snapshotData.GetRotationValue(deserializerState);
                ghostTranslation.Value             = snapshotData.GetTranslationValue(deserializerState);
                ghostRotationArray[entityIndex]    = ghostRotation;
                ghostTranslationArray[entityIndex] = ghostTranslation;
            }
        }
    public void CopyToSnapshot(ArchetypeChunk chunk, int ent, uint tick, ref Char_CapsuleSnapshotData snapshot, GhostSerializerState serializerState)
    {
        snapshot.tick = tick;
        var chunkDataCharacterInterpolatedData            = chunk.GetNativeArray(ghostCharacterInterpolatedDataType);
        var chunkDataCharacterPredictedData               = chunk.GetNativeArray(ghostCharacterPredictedDataType);
        var chunkDataCharacterReplicatedData              = chunk.GetNativeArray(ghostCharacterReplicatedDataType);
        var chunkDataCharacterControllerGroundSupportData = chunk.GetNativeArray(ghostCharacterControllerGroundSupportDataType);
        var chunkDataCharacterControllerMoveResult        = chunk.GetNativeArray(ghostCharacterControllerMoveResultType);
        var chunkDataCharacterControllerVelocity          = chunk.GetNativeArray(ghostCharacterControllerVelocityType);
        var chunkDataHealthStateData       = chunk.GetNativeArray(ghostHealthStateDataType);
        var chunkDataInventoryState        = chunk.GetNativeArray(ghostInventoryStateType);
        var chunkDataPlayerOwnerPlayerId   = chunk.GetNativeArray(ghostPlayerOwnerPlayerIdType);
        var chunkDataPlayerControlledState = chunk.GetNativeArray(ghostPlayerControlledStateType);
        var chunkDataLinkedEntityGroup     = chunk.GetBufferAccessor(ghostLinkedEntityGroupType);

        snapshot.SetCharacterInterpolatedDataPosition(chunkDataCharacterInterpolatedData[ent].Position, serializerState);
        snapshot.SetCharacterInterpolatedDatarotation(chunkDataCharacterInterpolatedData[ent].rotation, serializerState);
        snapshot.SetCharacterInterpolatedDataaimYaw(chunkDataCharacterInterpolatedData[ent].aimYaw, serializerState);
        snapshot.SetCharacterInterpolatedDataaimPitch(chunkDataCharacterInterpolatedData[ent].aimPitch, serializerState);
        snapshot.SetCharacterInterpolatedDatamoveYaw(chunkDataCharacterInterpolatedData[ent].moveYaw, serializerState);
        snapshot.SetCharacterInterpolatedDatacharAction(chunkDataCharacterInterpolatedData[ent].charAction, serializerState);
        snapshot.SetCharacterInterpolatedDatacharActionTick(chunkDataCharacterInterpolatedData[ent].charActionTick, serializerState);
        snapshot.SetCharacterInterpolatedDatadamageTick(chunkDataCharacterInterpolatedData[ent].damageTick, serializerState);
        snapshot.SetCharacterInterpolatedDatadamageDirection(chunkDataCharacterInterpolatedData[ent].damageDirection, serializerState);
        snapshot.SetCharacterInterpolatedDatasprinting(chunkDataCharacterInterpolatedData[ent].sprinting, serializerState);
        snapshot.SetCharacterInterpolatedDatasprintWeight(chunkDataCharacterInterpolatedData[ent].sprintWeight, serializerState);
        snapshot.SetCharacterInterpolatedDatacrouchWeight(chunkDataCharacterInterpolatedData[ent].crouchWeight, serializerState);
        snapshot.SetCharacterInterpolatedDataselectorTargetSource(chunkDataCharacterInterpolatedData[ent].selectorTargetSource, serializerState);
        snapshot.SetCharacterInterpolatedDatamoveAngleLocal(chunkDataCharacterInterpolatedData[ent].moveAngleLocal, serializerState);
        snapshot.SetCharacterInterpolatedDatashootPoseWeight(chunkDataCharacterInterpolatedData[ent].shootPoseWeight, serializerState);
        snapshot.SetCharacterInterpolatedDatalocomotionVector(chunkDataCharacterInterpolatedData[ent].locomotionVector, serializerState);
        snapshot.SetCharacterInterpolatedDatalocomotionPhase(chunkDataCharacterInterpolatedData[ent].locomotionPhase, serializerState);
        snapshot.SetCharacterInterpolatedDatabanking(chunkDataCharacterInterpolatedData[ent].banking, serializerState);
        snapshot.SetCharacterInterpolatedDatalandAnticWeight(chunkDataCharacterInterpolatedData[ent].landAnticWeight, serializerState);
        snapshot.SetCharacterInterpolatedDataturnStartAngle(chunkDataCharacterInterpolatedData[ent].turnStartAngle, serializerState);
        snapshot.SetCharacterInterpolatedDataturnDirection(chunkDataCharacterInterpolatedData[ent].turnDirection, serializerState);
        snapshot.SetCharacterInterpolatedDatasquashTime(chunkDataCharacterInterpolatedData[ent].squashTime, serializerState);
        snapshot.SetCharacterInterpolatedDatasquashWeight(chunkDataCharacterInterpolatedData[ent].squashWeight, serializerState);
        snapshot.SetCharacterInterpolatedDatainAirTime(chunkDataCharacterInterpolatedData[ent].inAirTime, serializerState);
        snapshot.SetCharacterInterpolatedDatajumpTime(chunkDataCharacterInterpolatedData[ent].jumpTime, serializerState);
        snapshot.SetCharacterInterpolatedDatasimpleTime(chunkDataCharacterInterpolatedData[ent].simpleTime, serializerState);
        snapshot.SetCharacterInterpolatedDatafootIkOffset(chunkDataCharacterInterpolatedData[ent].footIkOffset, serializerState);
        snapshot.SetCharacterInterpolatedDatafootIkNormalLeft(chunkDataCharacterInterpolatedData[ent].footIkNormalLeft, serializerState);
        snapshot.SetCharacterInterpolatedDatafootIkNormalRight(chunkDataCharacterInterpolatedData[ent].footIkNormalRight, serializerState);
        snapshot.SetCharacterInterpolatedDatafootIkWeight(chunkDataCharacterInterpolatedData[ent].footIkWeight, serializerState);
        snapshot.SetCharacterInterpolatedDatablendOutAim(chunkDataCharacterInterpolatedData[ent].blendOutAim, serializerState);
        snapshot.SetCharacterPredictedDatatick(chunkDataCharacterPredictedData[ent].tick, serializerState);
        snapshot.SetCharacterPredictedDataposition(chunkDataCharacterPredictedData[ent].position, serializerState);
        snapshot.SetCharacterPredictedDatavelocity(chunkDataCharacterPredictedData[ent].velocity, serializerState);
        snapshot.SetCharacterPredictedDatasprinting(chunkDataCharacterPredictedData[ent].sprinting, serializerState);
        snapshot.SetCharacterPredictedDatacameraProfile(chunkDataCharacterPredictedData[ent].cameraProfile, serializerState);
        snapshot.SetCharacterPredictedDatadamageTick(chunkDataCharacterPredictedData[ent].damageTick, serializerState);
        snapshot.SetCharacterPredictedDatadamageDirection(chunkDataCharacterPredictedData[ent].damageDirection, serializerState);
        snapshot.SetCharacterReplicatedDataheroTypeIndex(chunkDataCharacterReplicatedData[ent].heroTypeIndex, serializerState);
        snapshot.SetCharacterControllerGroundSupportDataSurfaceNormal(chunkDataCharacterControllerGroundSupportData[ent].SurfaceNormal, serializerState);
        snapshot.SetCharacterControllerGroundSupportDataSurfaceVelocity(chunkDataCharacterControllerGroundSupportData[ent].SurfaceVelocity, serializerState);
        snapshot.SetCharacterControllerGroundSupportDataSupportedState(chunkDataCharacterControllerGroundSupportData[ent].SupportedState, serializerState);
        snapshot.SetCharacterControllerMoveResultMoveResult(chunkDataCharacterControllerMoveResult[ent].MoveResult, serializerState);
        snapshot.SetCharacterControllerVelocityVelocity(chunkDataCharacterControllerVelocity[ent].Velocity, serializerState);
        snapshot.SetHealthStateDatahealth(chunkDataHealthStateData[ent].health, serializerState);
        snapshot.SetInventoryStateactiveSlot(chunkDataInventoryState[ent].activeSlot, serializerState);
        snapshot.SetPlayerOwnerPlayerIdValue(chunkDataPlayerOwnerPlayerId[ent].Value, serializerState);
        snapshot.SetPlayerControlledStateresetCommandTick(chunkDataPlayerControlledState[ent].resetCommandTick, serializerState);
        snapshot.SetPlayerControlledStateresetCommandLookYaw(chunkDataPlayerControlledState[ent].resetCommandLookYaw, serializerState);
        snapshot.SetPlayerControlledStateresetCommandLookPitch(chunkDataPlayerControlledState[ent].resetCommandLookPitch, serializerState);
        snapshot.SetChild0AbilityAbilityControlbehaviorState(ghostChild0AbilityAbilityControlType[chunkDataLinkedEntityGroup[ent][1].Value].behaviorState, serializerState);
        snapshot.SetChild0AbilityAbilityControlrequestDeactivate(ghostChild0AbilityAbilityControlType[chunkDataLinkedEntityGroup[ent][1].Value].requestDeactivate, serializerState);
        snapshot.SetChild0AbilityMovementInterpolatedStatecharLocoState(ghostChild0AbilityMovementInterpolatedStateType[chunkDataLinkedEntityGroup[ent][1].Value].charLocoState, serializerState);
        snapshot.SetChild0AbilityMovementInterpolatedStatecharLocoTick(ghostChild0AbilityMovementInterpolatedStateType[chunkDataLinkedEntityGroup[ent][1].Value].charLocoTick, serializerState);
        snapshot.SetChild0AbilityMovementInterpolatedStatecrouching(ghostChild0AbilityMovementInterpolatedStateType[chunkDataLinkedEntityGroup[ent][1].Value].crouching, serializerState);
        snapshot.SetChild0AbilityMovementPredictedStatelocoState(ghostChild0AbilityMovementPredictedStateType[chunkDataLinkedEntityGroup[ent][1].Value].locoState, serializerState);
        snapshot.SetChild0AbilityMovementPredictedStatelocoStartTick(ghostChild0AbilityMovementPredictedStateType[chunkDataLinkedEntityGroup[ent][1].Value].locoStartTick, serializerState);
        snapshot.SetChild0AbilityMovementPredictedStatejumpCount(ghostChild0AbilityMovementPredictedStateType[chunkDataLinkedEntityGroup[ent][1].Value].jumpCount, serializerState);
        snapshot.SetChild0AbilityMovementPredictedStatecrouching(ghostChild0AbilityMovementPredictedStateType[chunkDataLinkedEntityGroup[ent][1].Value].crouching, serializerState);
        snapshot.SetChild1AbilityAbilityControlbehaviorState(ghostChild1AbilityAbilityControlType[chunkDataLinkedEntityGroup[ent][2].Value].behaviorState, serializerState);
        snapshot.SetChild1AbilityAbilityControlrequestDeactivate(ghostChild1AbilityAbilityControlType[chunkDataLinkedEntityGroup[ent][2].Value].requestDeactivate, serializerState);
        snapshot.SetChild2AbilityAbilityControlbehaviorState(ghostChild2AbilityAbilityControlType[chunkDataLinkedEntityGroup[ent][3].Value].behaviorState, serializerState);
        snapshot.SetChild2AbilityAbilityControlrequestDeactivate(ghostChild2AbilityAbilityControlType[chunkDataLinkedEntityGroup[ent][3].Value].requestDeactivate, serializerState);
        snapshot.SetChild2AbilityDashPredictedStatelocoState(ghostChild2AbilityDashPredictedStateType[chunkDataLinkedEntityGroup[ent][3].Value].locoState, serializerState);
        snapshot.SetChild2AbilityDashPredictedStatelocoStartTick(ghostChild2AbilityDashPredictedStateType[chunkDataLinkedEntityGroup[ent][3].Value].locoStartTick, serializerState);
        snapshot.SetChild2AbilityDashPredictedStatestartVelocity(ghostChild2AbilityDashPredictedStateType[chunkDataLinkedEntityGroup[ent][3].Value].startVelocity, serializerState);
        snapshot.SetChild3AbilityAbilityControlbehaviorState(ghostChild3AbilityAbilityControlType[chunkDataLinkedEntityGroup[ent][4].Value].behaviorState, serializerState);
        snapshot.SetChild3AbilityAbilityControlrequestDeactivate(ghostChild3AbilityAbilityControlType[chunkDataLinkedEntityGroup[ent][4].Value].requestDeactivate, serializerState);
        snapshot.SetChild3AbilityClimbPredictedStatelocoState(ghostChild3AbilityClimbPredictedStateType[chunkDataLinkedEntityGroup[ent][4].Value].locoState, serializerState);
        snapshot.SetChild3AbilityClimbPredictedStateSurfaceNormal(ghostChild3AbilityClimbPredictedStateType[chunkDataLinkedEntityGroup[ent][4].Value].SurfaceNormal, serializerState);
        snapshot.SetChild3AbilityClimbPredictedStateSurfaceVelocity(ghostChild3AbilityClimbPredictedStateType[chunkDataLinkedEntityGroup[ent][4].Value].SurfaceVelocity, serializerState);
        snapshot.SetChild3AbilityClimbPredictedStateSupportedState(ghostChild3AbilityClimbPredictedStateType[chunkDataLinkedEntityGroup[ent][4].Value].SupportedState, serializerState);
    }
Ejemplo n.º 5
0
            public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
            {
                var shipPos      = chunk.GetNativeArray(positionType);
                var shipSphere   = chunk.GetNativeArray(sphereType);
                var shipPlayerId = chunk.GetNativeArray(playerIdType);
                var shipEntity   = chunk.GetNativeArray(entityType);

                for (int ship = 0; ship < shipPos.Length; ++ship)
                {
                    int alive       = 1;
                    var firstPos    = shipPos[ship].Value.xy;
                    var firstRadius = shipSphere[ship].radius;
                    if (firstPos.x - firstRadius < 0 || firstPos.y - firstRadius < 0 ||
                        firstPos.x + firstRadius > level[0].width ||
                        firstPos.y + firstRadius > level[0].height)
                    {
                        if (shipPlayerId.IsCreated)
                        {
                            playerClearQueue.Enqueue(shipPlayerId[ship].PlayerEntity);
                        }
                        commandBuffer.DestroyEntity(chunkIndex, shipEntity[ship]);
                        continue;
                    }

                    if (serverSettings.Length > 0 && serverSettings[0].damageShips == 0)
                    {
                        continue;
                    }

                    /*for (int bc = 0; bc < bulletChunks.Length && alive != 0; ++bc)
                     * {
                     *  var bulletAge = bulletChunks[bc].GetNativeArray(bulletAgeType);
                     *  var bulletPos = bulletChunks[bc].GetNativeArray(positionType);
                     *  var bulletSphere = bulletChunks[bc].GetNativeArray(sphereType);
                     *  for (int bullet = 0; bullet < bulletAge.Length; ++bullet)
                     *  {
                     *      if (bulletAge[bullet].age > bulletAge[bullet].maxAge)
                     *          continue;
                     *      var secondPos = bulletPos[bullet].Value.xy;
                     *      var secondRadius = bulletSphere[bullet].radius;
                     *      if (Intersect(firstRadius, secondRadius, firstPos, secondPos))
                     *      {
                     *          if (shipPlayerId.IsCreated)
                     *              playerClearQueue.Enqueue(shipPlayerId[ship].PlayerEntity);
                     *          commandBuffer.DestroyEntity(chunkIndex, shipEntity[ship]);
                     *          alive = 0;
                     *          break;
                     *      }
                     *  }
                     * }*/
                    for (int ac = 0; ac < asteroidChunks.Length && alive != 0; ++ac)
                    {
                        var asteroidPos    = asteroidChunks[ac].GetNativeArray(positionType);
                        var asteroidSphere = asteroidChunks[ac].GetNativeArray(sphereType);
                        for (int asteroid = 0; asteroid < asteroidPos.Length; ++asteroid)
                        {
                            var secondPos    = asteroidPos[asteroid].Value.xy;
                            var secondRadius = asteroidSphere[asteroid].radius;
                            if (Intersect(firstRadius, secondRadius, firstPos, secondPos))
                            {
                                if (shipPlayerId.IsCreated)
                                {
                                    playerClearQueue.Enqueue(shipPlayerId[ship].PlayerEntity);
                                }
                                commandBuffer.DestroyEntity(chunkIndex, shipEntity[ship]);
                                alive = 0;
                                break;
                            }
                        }
                    }
                }
            }
 public int CalculateImportance(ArchetypeChunk chunk)
 {
     return(__GHOST_IMPORTANCE__);
 }
        public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
        {
            var chunkInfo = chunk.GetChunkComponentData(HybridChunkInfo);

            if (!chunkInfo.Valid)
            {
                return;
            }

            var occlusionTestArray = chunk.GetNativeArray(OcclusionTest);

            var chunkData          = chunkInfo.CullingData;
            int internalBatchIndex = chunkInfo.InternalIndex;
            int externalBatchIndex = InternalToExternalRemappingTable[internalBatchIndex];

            var batch = Batches[externalBatchIndex];

            int batchOutputOffset = chunkData.StartIndex;
            int batchOutputCount  = 0;

            var indices = (int *)IndexList.GetUnsafeReadOnlyPtr() + chunkData.StartIndex;


            void *mocNative = (void *)mocNativePtrArray[mocNativeIndexToUse];

            for (var entityIndex = 0; entityIndex < chunkData.Visible; entityIndex++)
            {
                // TODO:  we could reuse the HLOD logic from the frustum culling code here, but
                // this would require some supporting structures and components.  For now, we just
                // test what was written into the index list.
                var index = indices[entityIndex] - chunkData.BatchOffset;
                var test  = occlusionTestArray[index];

                if (!test.enabled)
                {
                    batchOutputCount++;
                    continue;
                }

                INTEL_MOC.CullingResult cullingResult = INTEL_MOC.CullingResult.VISIBLE;


                cullingResult = INTEL_MOC.MOCNative.TestRect(
                    mocNative,
                    test.screenMin.x, test.screenMin.y,
                    test.screenMax.x, test.screenMax.y, test.screenMin.w);


                bool visible = (cullingResult == INTEL_MOC.CullingResult.VISIBLE);

#if UNITY_EDITOR
                visible = (visible != displayOccluded);
#endif
                int advance = visible ? 1 : 0;

#if UNITY_EDITOR
                ref var stats = ref Stats[ThreadIndex];
                stats.Stats[CullingStats.kCountOcclusionCulled] += (1 - advance);
                stats.Stats[CullingStats.kCountOcclusionInput]++;
#endif

                if (!visible)
                {
                    indices[entityIndex] = -1;
                }
                batchOutputCount += advance;
            }
Ejemplo n.º 8
0
                public unsafe void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
                {
                    NativeArray <PhysicsJoint> chunkJoint    = chunk.GetNativeArray(JointComponentType);
                    NativeArray <Entity>       chunkEntities = chunk.GetNativeArray(EntityType);

                    int instanceCount = chunk.Count;

                    for (int i = 0; i < instanceCount; i++)
                    {
                        PhysicsJoint joint = chunkJoint[i];
                        Assert.IsTrue(joint.EntityA != joint.EntityB);

                        // TODO find a reasonable way to look up the constraint body indices
                        // - stash body index in a component on the entity? But we don't have random access to Entity data in a job
                        // - make a map from entity to rigid body index? Sounds bad and I don't think there is any NativeArray-based map data structure yet

                        // If one of the entities is null, use the default static entity
                        var pair = new BodyIndexPair
                        {
                            BodyAIndex = joint.EntityA == Entity.Null ? DefaultStaticBodyIndex : -1,
                            BodyBIndex = joint.EntityB == Entity.Null ? DefaultStaticBodyIndex : -1
                        };

                        // Find the body indices
                        for (int bodyIndex = 0; bodyIndex < RigidBodies.Length; bodyIndex++)
                        {
                            if (joint.EntityA != Entity.Null)
                            {
                                if (RigidBodies[bodyIndex].Entity == joint.EntityA)
                                {
                                    pair.BodyAIndex = bodyIndex;
                                    if (pair.BodyBIndex >= 0)
                                    {
                                        break;
                                    }
                                }
                            }

                            if (joint.EntityB != Entity.Null)
                            {
                                if (RigidBodies[bodyIndex].Entity == joint.EntityB)
                                {
                                    pair.BodyBIndex = bodyIndex;
                                    if (pair.BodyAIndex >= 0)
                                    {
                                        break;
                                    }
                                }
                            }
                        }

                        Assert.IsTrue(pair.BodyAIndex != -1 && pair.BodyBIndex != -1);

                        bool isStaticStaticPair = pair.BodyAIndex >= NumDynamicBodies && pair.BodyBIndex >= NumDynamicBodies;
                        // Mark static-static constrains as invalid since they are not going to affect simulation in any way.
                        if (isStaticStaticPair)
                        {
                            pair = BodyIndexPair.Invalid;
                        }

                        Joints[firstEntityIndex + i] = new Joint
                        {
                            JointData       = (JointData *)joint.JointData.GetUnsafePtr(),
                            BodyPair        = pair,
                            Entity          = chunkEntities[i],
                            EnableCollision = joint.EnableCollision,
                        };
                    }
                }
Ejemplo n.º 9
0
            public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
            {
                //Writeable.
                NativeArray <PathFinding> pathfindingArray       = chunk.GetNativeArray(pathFindingComponentHandle);
                BufferAccessor <PathNode> pathNodeBufferAccessor = chunk.GetBufferAccessor(pathNodeBufferHandle);

                //Read Only.
                NativeArray <CurrentTarget> currentTargetArray = chunk.GetNativeArray(currentTargetComponentHandle);
                NativeArray <Translation>   translationArray   = chunk.GetNativeArray(translationComponentHandle);
                NativeArray <Entity>        entities           = chunk.GetNativeArray(entityType);

                //Create a copy of the grid for this thread and chunk.
                NativeArray2D <MapNode> gridCopy = new NativeArray2D <MapNode>(gridRef.Length0, gridRef.Length1, Allocator.Temp, NativeArrayOptions.UninitializedMemory);

                UnsafeUtility.MemCpy(gridCopy.GetUnsafePtr(), gridRef.GetUnsafePtrReadOnly(), gridRef.Length * sizeof(MapNode));

                for (int indexInChunk = 0; indexInChunk < chunk.Count; ++indexInChunk)
                {
                    //Writable.
                    PathFinding pathfinding       = pathfindingArray[indexInChunk];
                    DynamicBuffer <PathNode> path = pathNodeBufferAccessor[indexInChunk];

                    //Read Only.
                    Entity        entity        = entities[indexInChunk];
                    CurrentTarget currentTarget = currentTargetArray[indexInChunk];
                    Translation   translation   = translationArray[indexInChunk];

                    bool hasPath = chunk.Has(hasPathComponentHandle);

                    if (!pathfinding.requestedPath)
                    {
                        //We only want to remove our has path component if we didn't request a new one, to avoid re-adding later in the job if we find a new path.
                        if (pathfinding.completedPath)
                        {
                            pathfinding.completedPath = false;
                            ecb.RemoveComponent <HasPathTag>(chunkIndex, entity);
                            pathfindingArray[indexInChunk] = pathfinding;
                        }

                        continue;
                    }

                    path.Clear();
                    pathfinding.currentIndexOnPath = 0;
                    pathfinding.completedPath      = false;
                    pathfinding.requestedPath      = false;

                    //Calculate the closest nodes to us and our target position.
                    //Don't search for path if we're already at our target node.
                    pathfinding.currentNode = FindNearestNode(translation.Value, gridCopy);
                    pathfinding.targetNode  = FindNearestNode(currentTarget.targetData.targetPos, gridCopy);
                    if (pathfinding.targetNode.Equals(pathfinding.currentNode))
                    {
                        pathfindingArray[indexInChunk] = pathfinding;
                        continue;
                    }

                    CalculateGridH(gridCopy, ref pathfinding);

                    bool pathfound = SearchForPath(pathfinding.currentNode, pathfinding.targetNode, gridCopy);

                    if (pathfound)
                    {
                        ConstructPath(gridCopy, ref pathfinding, ref path);

                        if (!hasPath)
                        {
                            ecb.AddComponent <HasPathTag>(chunkIndex, entity);
                        }
                    }
                    else if (hasPath)
                    {
                        ecb.RemoveComponent <HasPathTag>(chunkIndex, entity);
                    }

                    pathfindingArray[indexInChunk] = pathfinding;
                }

                gridCopy.Dispose();
            }
        public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
        {
            var deserializerState = new GhostDeserializerState
            {
                GhostMap = GhostMap
            };
            var ghostEntityArray       = chunk.GetNativeArray(ghostEntityType);
            var ghostSnapshotDataArray = chunk.GetBufferAccessor(ghostSnapshotDataType);
            var ghostCharacterInterpolatedDataArray            = chunk.GetNativeArray(ghostCharacterInterpolatedDataType);
            var ghostCharacterReplicatedDataArray              = chunk.GetNativeArray(ghostCharacterReplicatedDataType);
            var ghostCharacterControllerGroundSupportDataArray = chunk.GetNativeArray(ghostCharacterControllerGroundSupportDataType);
            var ghostCharacterControllerMoveResultArray        = chunk.GetNativeArray(ghostCharacterControllerMoveResultType);
            var ghostCharacterControllerVelocityArray          = chunk.GetNativeArray(ghostCharacterControllerVelocityType);
            var ghostHealthStateDataArray       = chunk.GetNativeArray(ghostHealthStateDataType);
            var ghostInventoryStateArray        = chunk.GetNativeArray(ghostInventoryStateType);
            var ghostPlayerOwnerPlayerIdArray   = chunk.GetNativeArray(ghostPlayerOwnerPlayerIdType);
            var ghostPlayerControlledStateArray = chunk.GetNativeArray(ghostPlayerControlledStateType);
            var ghostLinkedEntityGroupArray     = chunk.GetBufferAccessor(ghostLinkedEntityGroupType);

#if UNITY_EDITOR || DEVELOPMENT_BUILD
            var minMaxOffset = ThreadIndex * (JobsUtility.CacheLineSize / 4);
#endif
            for (int entityIndex = 0; entityIndex < ghostEntityArray.Length; ++entityIndex)
            {
                var snapshot = ghostSnapshotDataArray[entityIndex];
#if UNITY_EDITOR || DEVELOPMENT_BUILD
                var latestTick = snapshot.GetLatestTick();
                if (latestTick != 0)
                {
                    if (minMaxSnapshotTick[minMaxOffset] == 0 || SequenceHelpers.IsNewer(minMaxSnapshotTick[minMaxOffset], latestTick))
                    {
                        minMaxSnapshotTick[minMaxOffset] = latestTick;
                    }
                    if (minMaxSnapshotTick[minMaxOffset + 1] == 0 || SequenceHelpers.IsNewer(latestTick, minMaxSnapshotTick[minMaxOffset + 1]))
                    {
                        minMaxSnapshotTick[minMaxOffset + 1] = latestTick;
                    }
                }
#endif
                Char_BanditSnapshotData snapshotData;
                snapshot.GetDataAtTick(targetTick, targetTickFraction, out snapshotData);

                var ghostCharacterInterpolatedData            = ghostCharacterInterpolatedDataArray[entityIndex];
                var ghostCharacterReplicatedData              = ghostCharacterReplicatedDataArray[entityIndex];
                var ghostCharacterControllerGroundSupportData = ghostCharacterControllerGroundSupportDataArray[entityIndex];
                var ghostCharacterControllerMoveResult        = ghostCharacterControllerMoveResultArray[entityIndex];
                var ghostCharacterControllerVelocity          = ghostCharacterControllerVelocityArray[entityIndex];
                var ghostHealthStateData                        = ghostHealthStateDataArray[entityIndex];
                var ghostInventoryState                         = ghostInventoryStateArray[entityIndex];
                var ghostPlayerOwnerPlayerId                    = ghostPlayerOwnerPlayerIdArray[entityIndex];
                var ghostPlayerControlledState                  = ghostPlayerControlledStateArray[entityIndex];
                var ghostChild0AbilityAbilityControl            = ghostAbilityAbilityControlFromEntity[ghostLinkedEntityGroupArray[entityIndex][1].Value];
                var ghostChild0AbilityMovementInterpolatedState = ghostAbilityMovementInterpolatedStateFromEntity[ghostLinkedEntityGroupArray[entityIndex][1].Value];
                var ghostChild0AbilityMovementPredictedState    = ghostAbilityMovementPredictedStateFromEntity[ghostLinkedEntityGroupArray[entityIndex][1].Value];
                var ghostChild1AbilityAbilityControl            = ghostAbilityAbilityControlFromEntity[ghostLinkedEntityGroupArray[entityIndex][2].Value];
                var ghostChild2AbilityAbilityControl            = ghostAbilityAbilityControlFromEntity[ghostLinkedEntityGroupArray[entityIndex][3].Value];
                var ghostChild2AbilityDashPredictedState        = ghostAbilityDashPredictedStateFromEntity[ghostLinkedEntityGroupArray[entityIndex][3].Value];
                var ghostChild3AbilityAbilityControl            = ghostAbilityAbilityControlFromEntity[ghostLinkedEntityGroupArray[entityIndex][4].Value];
                var ghostChild3AbilityClimbPredictedState       = ghostAbilityClimbPredictedStateFromEntity[ghostLinkedEntityGroupArray[entityIndex][4].Value];
                ghostCharacterInterpolatedData.Position                   = snapshotData.GetCharacterInterpolatedDataPosition(deserializerState);
                ghostCharacterInterpolatedData.rotation                   = snapshotData.GetCharacterInterpolatedDatarotation(deserializerState);
                ghostCharacterInterpolatedData.aimYaw                     = snapshotData.GetCharacterInterpolatedDataaimYaw(deserializerState);
                ghostCharacterInterpolatedData.aimPitch                   = snapshotData.GetCharacterInterpolatedDataaimPitch(deserializerState);
                ghostCharacterInterpolatedData.moveYaw                    = snapshotData.GetCharacterInterpolatedDatamoveYaw(deserializerState);
                ghostCharacterInterpolatedData.charAction                 = snapshotData.GetCharacterInterpolatedDatacharAction(deserializerState);
                ghostCharacterInterpolatedData.charActionTick             = snapshotData.GetCharacterInterpolatedDatacharActionTick(deserializerState);
                ghostCharacterInterpolatedData.damageTick                 = snapshotData.GetCharacterInterpolatedDatadamageTick(deserializerState);
                ghostCharacterInterpolatedData.damageDirection            = snapshotData.GetCharacterInterpolatedDatadamageDirection(deserializerState);
                ghostCharacterInterpolatedData.sprinting                  = snapshotData.GetCharacterInterpolatedDatasprinting(deserializerState);
                ghostCharacterInterpolatedData.sprintWeight               = snapshotData.GetCharacterInterpolatedDatasprintWeight(deserializerState);
                ghostCharacterInterpolatedData.crouchWeight               = snapshotData.GetCharacterInterpolatedDatacrouchWeight(deserializerState);
                ghostCharacterInterpolatedData.selectorTargetSource       = snapshotData.GetCharacterInterpolatedDataselectorTargetSource(deserializerState);
                ghostCharacterInterpolatedData.moveAngleLocal             = snapshotData.GetCharacterInterpolatedDatamoveAngleLocal(deserializerState);
                ghostCharacterInterpolatedData.shootPoseWeight            = snapshotData.GetCharacterInterpolatedDatashootPoseWeight(deserializerState);
                ghostCharacterInterpolatedData.locomotionVector           = snapshotData.GetCharacterInterpolatedDatalocomotionVector(deserializerState);
                ghostCharacterInterpolatedData.locomotionPhase            = snapshotData.GetCharacterInterpolatedDatalocomotionPhase(deserializerState);
                ghostCharacterInterpolatedData.banking                    = snapshotData.GetCharacterInterpolatedDatabanking(deserializerState);
                ghostCharacterInterpolatedData.landAnticWeight            = snapshotData.GetCharacterInterpolatedDatalandAnticWeight(deserializerState);
                ghostCharacterInterpolatedData.turnStartAngle             = snapshotData.GetCharacterInterpolatedDataturnStartAngle(deserializerState);
                ghostCharacterInterpolatedData.turnDirection              = snapshotData.GetCharacterInterpolatedDataturnDirection(deserializerState);
                ghostCharacterInterpolatedData.squashTime                 = snapshotData.GetCharacterInterpolatedDatasquashTime(deserializerState);
                ghostCharacterInterpolatedData.squashWeight               = snapshotData.GetCharacterInterpolatedDatasquashWeight(deserializerState);
                ghostCharacterInterpolatedData.inAirTime                  = snapshotData.GetCharacterInterpolatedDatainAirTime(deserializerState);
                ghostCharacterInterpolatedData.jumpTime                   = snapshotData.GetCharacterInterpolatedDatajumpTime(deserializerState);
                ghostCharacterInterpolatedData.simpleTime                 = snapshotData.GetCharacterInterpolatedDatasimpleTime(deserializerState);
                ghostCharacterInterpolatedData.footIkOffset               = snapshotData.GetCharacterInterpolatedDatafootIkOffset(deserializerState);
                ghostCharacterInterpolatedData.footIkNormalLeft           = snapshotData.GetCharacterInterpolatedDatafootIkNormalLeft(deserializerState);
                ghostCharacterInterpolatedData.footIkNormalRight          = snapshotData.GetCharacterInterpolatedDatafootIkNormalRight(deserializerState);
                ghostCharacterInterpolatedData.footIkWeight               = snapshotData.GetCharacterInterpolatedDatafootIkWeight(deserializerState);
                ghostCharacterInterpolatedData.blendOutAim                = snapshotData.GetCharacterInterpolatedDatablendOutAim(deserializerState);
                ghostCharacterReplicatedData.heroTypeIndex                = snapshotData.GetCharacterReplicatedDataheroTypeIndex(deserializerState);
                ghostCharacterControllerGroundSupportData.SurfaceNormal   = snapshotData.GetCharacterControllerGroundSupportDataSurfaceNormal(deserializerState);
                ghostCharacterControllerGroundSupportData.SurfaceVelocity = snapshotData.GetCharacterControllerGroundSupportDataSurfaceVelocity(deserializerState);
                ghostCharacterControllerGroundSupportData.SupportedState  = snapshotData.GetCharacterControllerGroundSupportDataSupportedState(deserializerState);
                ghostCharacterControllerMoveResult.MoveResult             = snapshotData.GetCharacterControllerMoveResultMoveResult(deserializerState);
                ghostCharacterControllerVelocity.Velocity                 = snapshotData.GetCharacterControllerVelocityVelocity(deserializerState);
                ghostHealthStateData.health    = snapshotData.GetHealthStateDatahealth(deserializerState);
                ghostInventoryState.activeSlot = snapshotData.GetInventoryStateactiveSlot(deserializerState);
                ghostPlayerOwnerPlayerId.Value = snapshotData.GetPlayerOwnerPlayerIdValue(deserializerState);
                ghostPlayerControlledState.resetCommandTick               = snapshotData.GetPlayerControlledStateresetCommandTick(deserializerState);
                ghostPlayerControlledState.resetCommandLookYaw            = snapshotData.GetPlayerControlledStateresetCommandLookYaw(deserializerState);
                ghostPlayerControlledState.resetCommandLookPitch          = snapshotData.GetPlayerControlledStateresetCommandLookPitch(deserializerState);
                ghostChild0AbilityAbilityControl.behaviorState            = snapshotData.GetChild0AbilityAbilityControlbehaviorState(deserializerState);
                ghostChild0AbilityAbilityControl.requestDeactivate        = snapshotData.GetChild0AbilityAbilityControlrequestDeactivate(deserializerState);
                ghostChild0AbilityMovementInterpolatedState.charLocoState = snapshotData.GetChild0AbilityMovementInterpolatedStatecharLocoState(deserializerState);
                ghostChild0AbilityMovementInterpolatedState.charLocoTick  = snapshotData.GetChild0AbilityMovementInterpolatedStatecharLocoTick(deserializerState);
                ghostChild0AbilityMovementInterpolatedState.crouching     = snapshotData.GetChild0AbilityMovementInterpolatedStatecrouching(deserializerState);
                ghostChild0AbilityMovementPredictedState.locoState        = snapshotData.GetChild0AbilityMovementPredictedStatelocoState(deserializerState);
                ghostChild0AbilityMovementPredictedState.locoStartTick    = snapshotData.GetChild0AbilityMovementPredictedStatelocoStartTick(deserializerState);
                ghostChild0AbilityMovementPredictedState.jumpCount        = snapshotData.GetChild0AbilityMovementPredictedStatejumpCount(deserializerState);
                ghostChild0AbilityMovementPredictedState.crouching        = snapshotData.GetChild0AbilityMovementPredictedStatecrouching(deserializerState);
                ghostChild1AbilityAbilityControl.behaviorState            = snapshotData.GetChild1AbilityAbilityControlbehaviorState(deserializerState);
                ghostChild1AbilityAbilityControl.requestDeactivate        = snapshotData.GetChild1AbilityAbilityControlrequestDeactivate(deserializerState);
                ghostChild2AbilityAbilityControl.behaviorState            = snapshotData.GetChild2AbilityAbilityControlbehaviorState(deserializerState);
                ghostChild2AbilityAbilityControl.requestDeactivate        = snapshotData.GetChild2AbilityAbilityControlrequestDeactivate(deserializerState);
                ghostChild2AbilityDashPredictedState.locoState            = snapshotData.GetChild2AbilityDashPredictedStatelocoState(deserializerState);
                ghostChild2AbilityDashPredictedState.locoStartTick        = snapshotData.GetChild2AbilityDashPredictedStatelocoStartTick(deserializerState);
                ghostChild2AbilityDashPredictedState.startVelocity        = snapshotData.GetChild2AbilityDashPredictedStatestartVelocity(deserializerState);
                ghostChild3AbilityAbilityControl.behaviorState            = snapshotData.GetChild3AbilityAbilityControlbehaviorState(deserializerState);
                ghostChild3AbilityAbilityControl.requestDeactivate        = snapshotData.GetChild3AbilityAbilityControlrequestDeactivate(deserializerState);
                ghostChild3AbilityClimbPredictedState.locoState           = snapshotData.GetChild3AbilityClimbPredictedStatelocoState(deserializerState);
                ghostChild3AbilityClimbPredictedState.SurfaceNormal       = snapshotData.GetChild3AbilityClimbPredictedStateSurfaceNormal(deserializerState);
                ghostChild3AbilityClimbPredictedState.SurfaceVelocity     = snapshotData.GetChild3AbilityClimbPredictedStateSurfaceVelocity(deserializerState);
                ghostChild3AbilityClimbPredictedState.SupportedState      = snapshotData.GetChild3AbilityClimbPredictedStateSupportedState(deserializerState);
                ghostAbilityAbilityControlFromEntity[ghostLinkedEntityGroupArray[entityIndex][1].Value]            = ghostChild0AbilityAbilityControl;
                ghostAbilityMovementInterpolatedStateFromEntity[ghostLinkedEntityGroupArray[entityIndex][1].Value] = ghostChild0AbilityMovementInterpolatedState;
                ghostAbilityMovementPredictedStateFromEntity[ghostLinkedEntityGroupArray[entityIndex][1].Value]    = ghostChild0AbilityMovementPredictedState;
                ghostAbilityAbilityControlFromEntity[ghostLinkedEntityGroupArray[entityIndex][2].Value]            = ghostChild1AbilityAbilityControl;
                ghostAbilityAbilityControlFromEntity[ghostLinkedEntityGroupArray[entityIndex][3].Value]            = ghostChild2AbilityAbilityControl;
                ghostAbilityDashPredictedStateFromEntity[ghostLinkedEntityGroupArray[entityIndex][3].Value]        = ghostChild2AbilityDashPredictedState;
                ghostAbilityAbilityControlFromEntity[ghostLinkedEntityGroupArray[entityIndex][4].Value]            = ghostChild3AbilityAbilityControl;
                ghostAbilityClimbPredictedStateFromEntity[ghostLinkedEntityGroupArray[entityIndex][4].Value]       = ghostChild3AbilityClimbPredictedState;
                ghostCharacterInterpolatedDataArray[entityIndex]            = ghostCharacterInterpolatedData;
                ghostCharacterReplicatedDataArray[entityIndex]              = ghostCharacterReplicatedData;
                ghostCharacterControllerGroundSupportDataArray[entityIndex] = ghostCharacterControllerGroundSupportData;
                ghostCharacterControllerMoveResultArray[entityIndex]        = ghostCharacterControllerMoveResult;
                ghostCharacterControllerVelocityArray[entityIndex]          = ghostCharacterControllerVelocity;
                ghostHealthStateDataArray[entityIndex]       = ghostHealthStateData;
                ghostInventoryStateArray[entityIndex]        = ghostInventoryState;
                ghostPlayerOwnerPlayerIdArray[entityIndex]   = ghostPlayerOwnerPlayerId;
                ghostPlayerControlledStateArray[entityIndex] = ghostPlayerControlledState;
            }
        }
Ejemplo n.º 11
0
                public unsafe void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
                {
                    NativeArray <Translation>          chunkPositions      = chunk.GetNativeArray(PositionType);
                    NativeArray <Rotation>             chunkRotations      = chunk.GetNativeArray(RotationType);
                    NativeArray <PhysicsVelocity>      chunkVelocities     = chunk.GetNativeArray(PhysicsVelocityType);
                    NativeArray <PhysicsMass>          chunkMasses         = chunk.GetNativeArray(PhysicsMassType);
                    NativeArray <PhysicsDamping>       chunkDampings       = chunk.GetNativeArray(PhysicsDampingType);
                    NativeArray <PhysicsGravityFactor> chunkGravityFactors = chunk.GetNativeArray(PhysicsGravityFactorType);

                    int motionStart   = firstEntityIndex;
                    int instanceCount = chunk.Count;

                    bool hasChunkPhysicsGravityFactorType = chunk.Has(PhysicsGravityFactorType);
                    bool hasChunkPhysicsDampingType       = chunk.Has(PhysicsDampingType);
                    bool hasChunkPhysicsMassType          = chunk.Has(PhysicsMassType);

                    // Note: Transform and AngularExpansionFactor could be calculated from PhysicsCollider.MassProperties
                    // However, to avoid the cost of accessing the collider we assume an infinite mass at the origin of a ~1m^3 box.
                    // For better performance with spheres, or better behavior for larger and/or more irregular colliders
                    // you should add a PhysicsMass component to get the true values
                    var defaultPhysicsMass = new PhysicsMass()
                    {
                        Transform              = RigidTransform.identity,
                        InverseMass            = 0.0f,
                        InverseInertia         = float3.zero,
                        AngularExpansionFactor = 1.0f,
                    };

                    // Create motion velocities
                    var defaultInverseInertiaAndMass = new float4(defaultPhysicsMass.InverseInertia, defaultPhysicsMass.InverseMass);

                    for (int i = 0, motionIndex = motionStart; i < instanceCount; i++, motionIndex++)
                    {
                        MotionVelocities[motionIndex] = new MotionVelocity
                        {
                            LinearVelocity         = chunkVelocities[i].Linear,  // world space
                            AngularVelocity        = chunkVelocities[i].Angular, // inertia space
                            InverseInertiaAndMass  = hasChunkPhysicsMassType ? new float4(chunkMasses[i].InverseInertia, chunkMasses[i].InverseMass) : defaultInverseInertiaAndMass,
                            AngularExpansionFactor = hasChunkPhysicsMassType ? chunkMasses[i].AngularExpansionFactor : defaultPhysicsMass.AngularExpansionFactor,
                        };
                    }

                    // Note: these defaults assume a dynamic body with infinite mass, hence no damping
                    var defaultPhysicsDamping = new PhysicsDamping()
                    {
                        Linear  = 0.0f,
                        Angular = 0.0f,
                    };

                    // Note: if a dynamic body infinite mass then assume no gravity should be applied
                    float defaultGravityFactor = hasChunkPhysicsMassType ? 1.0f : 0.0f;

                    // Create motion datas
                    for (int i = 0, motionIndex = motionStart; i < instanceCount; i++, motionIndex++)
                    {
                        MotionDatas[motionIndex] = CreateMotionData(
                            chunkPositions[i], chunkRotations[i],
                            hasChunkPhysicsMassType ? chunkMasses[i] : defaultPhysicsMass,
                            hasChunkPhysicsDampingType ? chunkDampings[i] : defaultPhysicsDamping,
                            hasChunkPhysicsGravityFactorType ? chunkGravityFactors[i].Value : defaultGravityFactor);
                    }
                }
        public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
        {
            var deserializerState = new GhostDeserializerState
            {
                GhostMap = GhostMap
            };
            var ghostEntityArray                  = chunk.GetNativeArray(ghostEntityType);
            var ghostSnapshotDataArray            = chunk.GetBufferAccessor(ghostSnapshotDataType);
            var predictedGhostComponentArray      = chunk.GetNativeArray(predictedGhostComponentType);
            var ghostCharacterPredictedDataArray  = chunk.GetNativeArray(ghostCharacterPredictedDataType);
            var ghostCharacterReplicatedDataArray = chunk.GetNativeArray(ghostCharacterReplicatedDataType);
            var ghostCharacterControllerGroundSupportDataArray = chunk.GetNativeArray(ghostCharacterControllerGroundSupportDataType);
            var ghostCharacterControllerMoveResultArray        = chunk.GetNativeArray(ghostCharacterControllerMoveResultType);
            var ghostCharacterControllerVelocityArray          = chunk.GetNativeArray(ghostCharacterControllerVelocityType);
            var ghostHealthStateDataArray       = chunk.GetNativeArray(ghostHealthStateDataType);
            var ghostInventoryStateArray        = chunk.GetNativeArray(ghostInventoryStateType);
            var ghostPlayerOwnerPlayerIdArray   = chunk.GetNativeArray(ghostPlayerOwnerPlayerIdType);
            var ghostPlayerControlledStateArray = chunk.GetNativeArray(ghostPlayerControlledStateType);
            var ghostLinkedEntityGroupArray     = chunk.GetBufferAccessor(ghostLinkedEntityGroupType);

#if UNITY_EDITOR || DEVELOPMENT_BUILD
            var minMaxOffset = ThreadIndex * (JobsUtility.CacheLineSize / 4);
#endif
            for (int entityIndex = 0; entityIndex < ghostEntityArray.Length; ++entityIndex)
            {
                var snapshot = ghostSnapshotDataArray[entityIndex];
#if UNITY_EDITOR || DEVELOPMENT_BUILD
                var latestTick = snapshot.GetLatestTick();
                if (latestTick != 0)
                {
                    if (minMaxSnapshotTick[minMaxOffset] == 0 || SequenceHelpers.IsNewer(minMaxSnapshotTick[minMaxOffset], latestTick))
                    {
                        minMaxSnapshotTick[minMaxOffset] = latestTick;
                    }
                    if (minMaxSnapshotTick[minMaxOffset + 1] == 0 || SequenceHelpers.IsNewer(latestTick, minMaxSnapshotTick[minMaxOffset + 1]))
                    {
                        minMaxSnapshotTick[minMaxOffset + 1] = latestTick;
                    }
                }
#endif
                Char_BanditSnapshotData snapshotData;
                snapshot.GetDataAtTick(targetTick, out snapshotData);

                var predictedData         = predictedGhostComponentArray[entityIndex];
                var lastPredictedTickInst = lastPredictedTick;
                if (lastPredictedTickInst == 0 || predictedData.AppliedTick != snapshotData.Tick)
                {
                    lastPredictedTickInst = snapshotData.Tick;
                }
                else if (!SequenceHelpers.IsNewer(lastPredictedTickInst, snapshotData.Tick))
                {
                    lastPredictedTickInst = snapshotData.Tick;
                }
                if (minPredictedTick[ThreadIndex] == 0 || SequenceHelpers.IsNewer(minPredictedTick[ThreadIndex], lastPredictedTickInst))
                {
                    minPredictedTick[ThreadIndex] = lastPredictedTickInst;
                }
                predictedGhostComponentArray[entityIndex] = new PredictedGhostComponent {
                    AppliedTick = snapshotData.Tick, PredictionStartTick = lastPredictedTickInst
                };
                if (lastPredictedTickInst != snapshotData.Tick)
                {
                    continue;
                }

                var ghostCharacterPredictedData  = ghostCharacterPredictedDataArray[entityIndex];
                var ghostCharacterReplicatedData = ghostCharacterReplicatedDataArray[entityIndex];
                var ghostCharacterControllerGroundSupportData = ghostCharacterControllerGroundSupportDataArray[entityIndex];
                var ghostCharacterControllerMoveResult        = ghostCharacterControllerMoveResultArray[entityIndex];
                var ghostCharacterControllerVelocity          = ghostCharacterControllerVelocityArray[entityIndex];
                var ghostHealthStateData                        = ghostHealthStateDataArray[entityIndex];
                var ghostInventoryState                         = ghostInventoryStateArray[entityIndex];
                var ghostPlayerOwnerPlayerId                    = ghostPlayerOwnerPlayerIdArray[entityIndex];
                var ghostPlayerControlledState                  = ghostPlayerControlledStateArray[entityIndex];
                var ghostChild0AbilityAbilityControl            = ghostAbilityAbilityControlFromEntity[ghostLinkedEntityGroupArray[entityIndex][1].Value];
                var ghostChild0AbilityMovementInterpolatedState = ghostAbilityMovementInterpolatedStateFromEntity[ghostLinkedEntityGroupArray[entityIndex][1].Value];
                var ghostChild0AbilityMovementPredictedState    = ghostAbilityMovementPredictedStateFromEntity[ghostLinkedEntityGroupArray[entityIndex][1].Value];
                var ghostChild1AbilityAbilityControl            = ghostAbilityAbilityControlFromEntity[ghostLinkedEntityGroupArray[entityIndex][2].Value];
                var ghostChild2AbilityAbilityControl            = ghostAbilityAbilityControlFromEntity[ghostLinkedEntityGroupArray[entityIndex][3].Value];
                var ghostChild2AbilityDashPredictedState        = ghostAbilityDashPredictedStateFromEntity[ghostLinkedEntityGroupArray[entityIndex][3].Value];
                var ghostChild3AbilityAbilityControl            = ghostAbilityAbilityControlFromEntity[ghostLinkedEntityGroupArray[entityIndex][4].Value];
                var ghostChild3AbilityClimbPredictedState       = ghostAbilityClimbPredictedStateFromEntity[ghostLinkedEntityGroupArray[entityIndex][4].Value];
                ghostCharacterPredictedData.tick                          = snapshotData.GetCharacterPredictedDatatick(deserializerState);
                ghostCharacterPredictedData.position                      = snapshotData.GetCharacterPredictedDataposition(deserializerState);
                ghostCharacterPredictedData.velocity                      = snapshotData.GetCharacterPredictedDatavelocity(deserializerState);
                ghostCharacterPredictedData.sprinting                     = snapshotData.GetCharacterPredictedDatasprinting(deserializerState);
                ghostCharacterPredictedData.cameraProfile                 = snapshotData.GetCharacterPredictedDatacameraProfile(deserializerState);
                ghostCharacterPredictedData.damageTick                    = snapshotData.GetCharacterPredictedDatadamageTick(deserializerState);
                ghostCharacterPredictedData.damageDirection               = snapshotData.GetCharacterPredictedDatadamageDirection(deserializerState);
                ghostCharacterReplicatedData.heroTypeIndex                = snapshotData.GetCharacterReplicatedDataheroTypeIndex(deserializerState);
                ghostCharacterControllerGroundSupportData.SurfaceNormal   = snapshotData.GetCharacterControllerGroundSupportDataSurfaceNormal(deserializerState);
                ghostCharacterControllerGroundSupportData.SurfaceVelocity = snapshotData.GetCharacterControllerGroundSupportDataSurfaceVelocity(deserializerState);
                ghostCharacterControllerGroundSupportData.SupportedState  = snapshotData.GetCharacterControllerGroundSupportDataSupportedState(deserializerState);
                ghostCharacterControllerMoveResult.MoveResult             = snapshotData.GetCharacterControllerMoveResultMoveResult(deserializerState);
                ghostCharacterControllerVelocity.Velocity                 = snapshotData.GetCharacterControllerVelocityVelocity(deserializerState);
                ghostHealthStateData.health    = snapshotData.GetHealthStateDatahealth(deserializerState);
                ghostInventoryState.activeSlot = snapshotData.GetInventoryStateactiveSlot(deserializerState);
                ghostPlayerOwnerPlayerId.Value = snapshotData.GetPlayerOwnerPlayerIdValue(deserializerState);
                ghostPlayerControlledState.resetCommandTick               = snapshotData.GetPlayerControlledStateresetCommandTick(deserializerState);
                ghostPlayerControlledState.resetCommandLookYaw            = snapshotData.GetPlayerControlledStateresetCommandLookYaw(deserializerState);
                ghostPlayerControlledState.resetCommandLookPitch          = snapshotData.GetPlayerControlledStateresetCommandLookPitch(deserializerState);
                ghostChild0AbilityAbilityControl.behaviorState            = snapshotData.GetChild0AbilityAbilityControlbehaviorState(deserializerState);
                ghostChild0AbilityAbilityControl.requestDeactivate        = snapshotData.GetChild0AbilityAbilityControlrequestDeactivate(deserializerState);
                ghostChild0AbilityMovementInterpolatedState.charLocoState = snapshotData.GetChild0AbilityMovementInterpolatedStatecharLocoState(deserializerState);
                ghostChild0AbilityMovementInterpolatedState.charLocoTick  = snapshotData.GetChild0AbilityMovementInterpolatedStatecharLocoTick(deserializerState);
                ghostChild0AbilityMovementInterpolatedState.crouching     = snapshotData.GetChild0AbilityMovementInterpolatedStatecrouching(deserializerState);
                ghostChild0AbilityMovementPredictedState.locoState        = snapshotData.GetChild0AbilityMovementPredictedStatelocoState(deserializerState);
                ghostChild0AbilityMovementPredictedState.locoStartTick    = snapshotData.GetChild0AbilityMovementPredictedStatelocoStartTick(deserializerState);
                ghostChild0AbilityMovementPredictedState.jumpCount        = snapshotData.GetChild0AbilityMovementPredictedStatejumpCount(deserializerState);
                ghostChild0AbilityMovementPredictedState.crouching        = snapshotData.GetChild0AbilityMovementPredictedStatecrouching(deserializerState);
                ghostChild1AbilityAbilityControl.behaviorState            = snapshotData.GetChild1AbilityAbilityControlbehaviorState(deserializerState);
                ghostChild1AbilityAbilityControl.requestDeactivate        = snapshotData.GetChild1AbilityAbilityControlrequestDeactivate(deserializerState);
                ghostChild2AbilityAbilityControl.behaviorState            = snapshotData.GetChild2AbilityAbilityControlbehaviorState(deserializerState);
                ghostChild2AbilityAbilityControl.requestDeactivate        = snapshotData.GetChild2AbilityAbilityControlrequestDeactivate(deserializerState);
                ghostChild2AbilityDashPredictedState.locoState            = snapshotData.GetChild2AbilityDashPredictedStatelocoState(deserializerState);
                ghostChild2AbilityDashPredictedState.locoStartTick        = snapshotData.GetChild2AbilityDashPredictedStatelocoStartTick(deserializerState);
                ghostChild2AbilityDashPredictedState.startVelocity        = snapshotData.GetChild2AbilityDashPredictedStatestartVelocity(deserializerState);
                ghostChild3AbilityAbilityControl.behaviorState            = snapshotData.GetChild3AbilityAbilityControlbehaviorState(deserializerState);
                ghostChild3AbilityAbilityControl.requestDeactivate        = snapshotData.GetChild3AbilityAbilityControlrequestDeactivate(deserializerState);
                ghostChild3AbilityClimbPredictedState.locoState           = snapshotData.GetChild3AbilityClimbPredictedStatelocoState(deserializerState);
                ghostChild3AbilityClimbPredictedState.SurfaceNormal       = snapshotData.GetChild3AbilityClimbPredictedStateSurfaceNormal(deserializerState);
                ghostChild3AbilityClimbPredictedState.SurfaceVelocity     = snapshotData.GetChild3AbilityClimbPredictedStateSurfaceVelocity(deserializerState);
                ghostChild3AbilityClimbPredictedState.SupportedState      = snapshotData.GetChild3AbilityClimbPredictedStateSupportedState(deserializerState);
                ghostAbilityAbilityControlFromEntity[ghostLinkedEntityGroupArray[entityIndex][1].Value]            = ghostChild0AbilityAbilityControl;
                ghostAbilityMovementInterpolatedStateFromEntity[ghostLinkedEntityGroupArray[entityIndex][1].Value] = ghostChild0AbilityMovementInterpolatedState;
                ghostAbilityMovementPredictedStateFromEntity[ghostLinkedEntityGroupArray[entityIndex][1].Value]    = ghostChild0AbilityMovementPredictedState;
                ghostAbilityAbilityControlFromEntity[ghostLinkedEntityGroupArray[entityIndex][2].Value]            = ghostChild1AbilityAbilityControl;
                ghostAbilityAbilityControlFromEntity[ghostLinkedEntityGroupArray[entityIndex][3].Value]            = ghostChild2AbilityAbilityControl;
                ghostAbilityDashPredictedStateFromEntity[ghostLinkedEntityGroupArray[entityIndex][3].Value]        = ghostChild2AbilityDashPredictedState;
                ghostAbilityAbilityControlFromEntity[ghostLinkedEntityGroupArray[entityIndex][4].Value]            = ghostChild3AbilityAbilityControl;
                ghostAbilityClimbPredictedStateFromEntity[ghostLinkedEntityGroupArray[entityIndex][4].Value]       = ghostChild3AbilityClimbPredictedState;
                ghostCharacterPredictedDataArray[entityIndex]  = ghostCharacterPredictedData;
                ghostCharacterReplicatedDataArray[entityIndex] = ghostCharacterReplicatedData;
                ghostCharacterControllerGroundSupportDataArray[entityIndex] = ghostCharacterControllerGroundSupportData;
                ghostCharacterControllerMoveResultArray[entityIndex]        = ghostCharacterControllerMoveResult;
                ghostCharacterControllerVelocityArray[entityIndex]          = ghostCharacterControllerVelocity;
                ghostHealthStateDataArray[entityIndex]       = ghostHealthStateData;
                ghostInventoryStateArray[entityIndex]        = ghostInventoryState;
                ghostPlayerOwnerPlayerIdArray[entityIndex]   = ghostPlayerOwnerPlayerId;
                ghostPlayerControlledStateArray[entityIndex] = ghostPlayerControlledState;
            }
        }
Ejemplo n.º 13
0
        public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
        {
            NativeArray <Entity> entityArray = chunk.GetNativeArray(entityType);
            NativeArray <HasReynoldsSeekTargetPos> reynoldsArray = chunk.GetNativeArray(reynoldsType);
            NativeArray <FollowWayPointsAction>    followWPArray = chunk.GetNativeArray(followWPType);
            NativeArray <Translation> transArray    = chunk.GetNativeArray(translationType);
            BufferAccessor <Action>   actionBuffers = chunk.GetBufferAccessor <Action>(actionBufferType);
            BufferAccessor <WayPoint> wpBuffers     = chunk.GetBufferAccessor <WayPoint>(wayPointBufferType);

            for (int i = 0; i < chunk.Count; i++)
            {
                Entity entity = entityArray[i];
                DynamicBuffer <Action>   actions   = actionBuffers[i];
                DynamicBuffer <WayPoint> wayPoints = wpBuffers[i];
                HasReynoldsSeekTargetPos seek      = reynoldsArray[i];
                FollowWayPointsAction    data      = followWPArray[i];
                Translation trans = transArray[i];


                if (actions.Length > 0)                                                                //if there are actions
                {
                    if (actions[0].id == data.id)                                                      //if the current action is the same as the action in the first position
                    {
                        if (math.distance(trans.Value, wayPoints[data.curPointNum].value) < tolerance) // if the entity is within tolerance of the waypoint
                        {
                            if (data.curPointNum < wayPoints.Length - 1)                               // if the entity has at least one more waypoint to follow
                            {
                                data.curPointNum++;                                                    // the index increases by one
                                seek.targetPos = wayPoints[data.curPointNum].value;                    // move to the next point
                            }
                            else                                                                       // if there are no more waypoints
                                   //entityCommandBuffer.DestroyEntity(actions[0].dataHolder);//demolish the storage entity
                            {
                                Debug.Log("Got to last point");
                                entityCommandBuffer.AddComponent <RemoveAction>(chunkIndex, entity, new RemoveAction { // add a component that tells the system to remove the action from the queue
                                    id = data.id
                                });
                                entityCommandBuffer.RemoveComponent <HasReynoldsSeekTargetPos>(chunkIndex, entity);
                                entityCommandBuffer.RemoveComponent <FollowWayPointsAction>(chunkIndex, entity);
                                //remove the current follow waypoints action
                            }
                        }
                    }
                    else  // if there are actions but this action is not the right one
                    {
                        Debug.Log("Gotta change!");
                        int j = 0;
                        while (j < actions.Length && actions[j].id != data.id) // find the location of the action in the actions queue
                        {
                            j++;
                        }
                        if (j < actions.Length)                                                                        // if the action was found in the queue
                        {
                            entityCommandBuffer.AddComponent <StoreWayPoints>(chunkIndex, entity, new StoreWayPoints { // store the data
                                id          = data.id,
                                dataHolder  = actions[j].dataHolder,
                                curPointNum = data.curPointNum
                            });
                        }
                        entityCommandBuffer.AddComponent <ChangeAction>(chunkIndex, entity, new ChangeAction {
                        });                                                                                      //signify that the action should be changed
                    }
                }
                else  // if there are no actions in the action queue
                {
                    Debug.Log("Nothin left!");
                    entityCommandBuffer.RemoveComponent <HasReynoldsSeekTargetPos>(chunkIndex, entity);
                    entityCommandBuffer.RemoveComponent <FollowWayPointsAction>(chunkIndex, entity);
                    entityCommandBuffer.AddComponent <ChangeAction>(chunkIndex, entity, new ChangeAction {
                    });                                                                                      //signify that the action should be changed (will remove action)
                }
            }
        }
            public void Execute(ArchetypeChunk chunk, int chunkIndex, int entityOffset)
            {
                var chunkTranslations        = chunk.GetNativeArray(TranslationType);
                var chunkNonUniformScales    = chunk.GetNativeArray(NonUniformScaleType);
                var chunkScales              = chunk.GetNativeArray(ScaleType);
                var chunkCompositeScales     = chunk.GetNativeArray(CompositeScaleType);
                var chunkRotations           = chunk.GetNativeArray(RotationType);
                var chunkCompositeRotations  = chunk.GetNativeArray(CompositeRotationType);
                var chunkLocalToParent       = chunk.GetNativeArray(LocalToParentType);
                var chunkParentScaleInverses = chunk.GetNativeArray(ParentScaleInverseType);
                var hasTranslation           = chunk.Has(TranslationType);
                var hasCompositeRotation     = chunk.Has(CompositeRotationType);
                var hasRotation              = chunk.Has(RotationType);
                var hasAnyRotation           = hasCompositeRotation || hasRotation;
                var hasNonUniformScale       = chunk.Has(NonUniformScaleType);
                var hasScale              = chunk.Has(ScaleType);
                var hasCompositeScale     = chunk.Has(CompositeScaleType);
                var hasAnyScale           = hasScale || hasNonUniformScale || hasCompositeScale;
                var hasParentScaleInverse = chunk.Has(ParentScaleInverseType);
                var count = chunk.Count;

                // #todo jump table when burst supports function pointers

                if (hasParentScaleInverse)
                {
                    if (!hasAnyRotation)
                    {
                        // 00 = invalid (must have at least one)
                        // 01
                        if (!hasTranslation && hasAnyScale)
                        {
                            for (int i = 0; i < count; i++)
                            {
                                var parentScaleInverse = chunkParentScaleInverses[i].Value;
                                var scale = hasNonUniformScale
                                    ? float4x4.Scale(chunkNonUniformScales[i].Value)
                                    : (hasScale
                                        ? float4x4.Scale(new float3(chunkScales[i].Value))
                                        : chunkCompositeScales[i].Value);

                                chunkLocalToParent[i] = new LocalToParent
                                {
                                    Value = math.mul(parentScaleInverse, scale)
                                };
                            }
                        }
                        // 10
                        else if (hasTranslation && !hasAnyScale)
                        {
                            for (int i = 0; i < count; i++)
                            {
                                var parentScaleInverse = chunkParentScaleInverses[i].Value;
                                var translation        = chunkTranslations[i].Value;

                                chunkLocalToParent[i] = new LocalToParent
                                {
                                    Value = math.mul(float4x4.Translate(translation), parentScaleInverse)
                                };
                            }
                        }
                        // 11
                        else if (hasTranslation && hasAnyScale)
                        {
                            for (int i = 0; i < count; i++)
                            {
                                var parentScaleInverse = chunkParentScaleInverses[i].Value;
                                var scale = hasNonUniformScale
                                    ? float4x4.Scale(chunkNonUniformScales[i].Value)
                                    : (hasScale
                                        ? float4x4.Scale(new float3(chunkScales[i].Value))
                                        : chunkCompositeScales[i].Value);
                                var translation = chunkTranslations[i].Value;

                                chunkLocalToParent[i] = new LocalToParent
                                {
                                    Value = math.mul(math.mul(float4x4.Translate(translation), parentScaleInverse),
                                                     scale)
                                };
                            }
                        }
                    }
                    else if (hasCompositeRotation)
                    {
                        // 00
                        if (!hasTranslation && !hasAnyScale)
                        {
                            for (int i = 0; i < count; i++)
                            {
                                var parentScaleInverse = chunkParentScaleInverses[i].Value;
                                var rotation           = chunkCompositeRotations[i].Value;

                                chunkLocalToParent[i] = new LocalToParent
                                {
                                    Value = math.mul(parentScaleInverse, rotation)
                                };
                            }
                        }
                        // 01
                        else if (!hasTranslation && hasAnyScale)
                        {
                            for (int i = 0; i < count; i++)
                            {
                                var parentScaleInverse = chunkParentScaleInverses[i].Value;
                                var rotation           = chunkCompositeRotations[i].Value;
                                var scale = hasNonUniformScale
                                    ? float4x4.Scale(chunkNonUniformScales[i].Value)
                                    : (hasScale
                                        ? float4x4.Scale(new float3(chunkScales[i].Value))
                                        : chunkCompositeScales[i].Value);

                                chunkLocalToParent[i] = new LocalToParent
                                {
                                    Value = math.mul(parentScaleInverse, math.mul(rotation, scale))
                                };
                            }
                        }
                        // 10
                        else if (hasTranslation && !hasAnyScale)
                        {
                            for (int i = 0; i < count; i++)
                            {
                                var parentScaleInverse = chunkParentScaleInverses[i].Value;
                                var rotation           = chunkCompositeRotations[i].Value;
                                var translation        = chunkTranslations[i].Value;

                                chunkLocalToParent[i] = new LocalToParent
                                {
                                    Value = math.mul(math.mul(float4x4.Translate(translation), parentScaleInverse),
                                                     rotation)
                                };
                            }
                        }
                        // 11
                        else if (hasTranslation && hasAnyScale)
                        {
                            for (int i = 0; i < count; i++)
                            {
                                var parentScaleInverse = chunkParentScaleInverses[i].Value;
                                var rotation           = chunkCompositeRotations[i].Value;
                                var translation        = chunkTranslations[i].Value;
                                var scale = hasNonUniformScale
                                    ? float4x4.Scale(chunkNonUniformScales[i].Value)
                                    : (hasScale
                                        ? float4x4.Scale(new float3(chunkScales[i].Value))
                                        : chunkCompositeScales[i].Value);

                                chunkLocalToParent[i] = new LocalToParent
                                {
                                    Value = math.mul(
                                        math.mul(math.mul(float4x4.Translate(translation), parentScaleInverse),
                                                 rotation), scale)
                                };
                            }
                        }
                    }
                    else // if (hasRotation) -- Only in same WriteGroup if !hasCompositeRotation
                    {
                        // 00
                        if (!hasTranslation && !hasAnyScale)
                        {
                            for (int i = 0; i < count; i++)
                            {
                                var parentScaleInverse = chunkParentScaleInverses[i].Value;
                                var rotation           = chunkRotations[i].Value;

                                chunkLocalToParent[i] = new LocalToParent
                                {
                                    Value = math.mul(parentScaleInverse, new float4x4(rotation, float3.zero))
                                };
                            }
                        }
                        // 01
                        else if (!hasTranslation && hasAnyScale)
                        {
                            for (int i = 0; i < count; i++)
                            {
                                var parentScaleInverse = chunkParentScaleInverses[i].Value;
                                var rotation           = chunkRotations[i].Value;
                                var scale = hasNonUniformScale
                                    ? float4x4.Scale(chunkNonUniformScales[i].Value)
                                    : (hasScale
                                        ? float4x4.Scale(new float3(chunkScales[i].Value))
                                        : chunkCompositeScales[i].Value);

                                chunkLocalToParent[i] = new LocalToParent
                                {
                                    Value = math.mul(parentScaleInverse,
                                                     math.mul(new float4x4(rotation, float3.zero), scale))
                                };
                            }
                        }
                        // 10
                        else if (hasTranslation && !hasAnyScale)
                        {
                            for (int i = 0; i < count; i++)
                            {
                                var parentScaleInverse = chunkParentScaleInverses[i].Value;
                                var rotation           = chunkRotations[i].Value;
                                var translation        = chunkTranslations[i].Value;

                                chunkLocalToParent[i] = new LocalToParent
                                {
                                    Value = math.mul(math.mul(float4x4.Translate(translation), parentScaleInverse),
                                                     new float4x4(rotation, new float3(0.0f)))
                                };
                            }
                        }
                        // 11
                        else if (hasTranslation && hasAnyScale)
                        {
                            for (int i = 0; i < count; i++)
                            {
                                var parentScaleInverse = chunkParentScaleInverses[i].Value;
                                var rotation           = chunkRotations[i].Value;
                                var translation        = chunkTranslations[i].Value;
                                var scale = hasNonUniformScale
                                    ? float4x4.Scale(chunkNonUniformScales[i].Value)
                                    : (hasScale
                                        ? float4x4.Scale(new float3(chunkScales[i].Value))
                                        : chunkCompositeScales[i].Value);

                                chunkLocalToParent[i] = new LocalToParent
                                {
                                    Value = math.mul(
                                        math.mul(math.mul(float4x4.Translate(translation), parentScaleInverse),
                                                 new float4x4(rotation, new float3(0.0f))), scale)
                                };
                            }
                        }
                    }
                }
                else // (!hasParentScaleInverse)
                {
                    if (!hasAnyRotation)
                    {
                        // 00 = invalid (must have at least one)
                        // 01
                        if (!hasTranslation && hasAnyScale)
                        {
                            for (int i = 0; i < count; i++)
                            {
                                var scale = hasNonUniformScale
                                    ? float4x4.Scale(chunkNonUniformScales[i].Value)
                                    : (hasScale
                                        ? float4x4.Scale(new float3(chunkScales[i].Value))
                                        : chunkCompositeScales[i].Value);

                                chunkLocalToParent[i] = new LocalToParent
                                {
                                    Value = scale
                                };
                            }
                        }
                        // 10
                        else if (hasTranslation && !hasAnyScale)
                        {
                            for (int i = 0; i < count; i++)
                            {
                                var translation = chunkTranslations[i].Value;

                                chunkLocalToParent[i] = new LocalToParent
                                {
                                    Value = float4x4.Translate(translation)
                                };
                            }
                        }
                        // 11
                        else if (hasTranslation && hasAnyScale)
                        {
                            for (int i = 0; i < count; i++)
                            {
                                var scale = hasNonUniformScale
                                    ? float4x4.Scale(chunkNonUniformScales[i].Value)
                                    : (hasScale
                                        ? float4x4.Scale(new float3(chunkScales[i].Value))
                                        : chunkCompositeScales[i].Value);
                                var translation = chunkTranslations[i].Value;

                                chunkLocalToParent[i] = new LocalToParent
                                {
                                    Value = math.mul(float4x4.Translate(translation), scale)
                                };
                            }
                        }
                    }
                    else if (hasCompositeRotation)
                    {
                        // 00
                        if (!hasTranslation && !hasAnyScale)
                        {
                            for (int i = 0; i < count; i++)
                            {
                                var rotation = chunkCompositeRotations[i].Value;

                                chunkLocalToParent[i] = new LocalToParent
                                {
                                    Value = rotation
                                };
                            }
                        }
                        // 01
                        else if (!hasTranslation && hasAnyScale)
                        {
                            for (int i = 0; i < count; i++)
                            {
                                var rotation = chunkCompositeRotations[i].Value;
                                var scale    = hasNonUniformScale
                                    ? float4x4.Scale(chunkNonUniformScales[i].Value)
                                    : (hasScale
                                        ? float4x4.Scale(new float3(chunkScales[i].Value))
                                        : chunkCompositeScales[i].Value);

                                chunkLocalToParent[i] = new LocalToParent
                                {
                                    Value = math.mul(rotation, scale)
                                };
                            }
                        }
                        // 10
                        else if (hasTranslation && !hasAnyScale)
                        {
                            for (int i = 0; i < count; i++)
                            {
                                var rotation    = chunkCompositeRotations[i].Value;
                                var translation = chunkTranslations[i].Value;

                                chunkLocalToParent[i] = new LocalToParent
                                {
                                    Value = math.mul(float4x4.Translate(translation), rotation)
                                };
                            }
                        }
                        // 11
                        else if (hasTranslation && hasAnyScale)
                        {
                            for (int i = 0; i < count; i++)
                            {
                                var rotation    = chunkCompositeRotations[i].Value;
                                var translation = chunkTranslations[i].Value;
                                var scale       = hasNonUniformScale
                                    ? float4x4.Scale(chunkNonUniformScales[i].Value)
                                    : (hasScale
                                        ? float4x4.Scale(new float3(chunkScales[i].Value))
                                        : chunkCompositeScales[i].Value);

                                chunkLocalToParent[i] = new LocalToParent
                                {
                                    Value = math.mul(math.mul(float4x4.Translate(translation), rotation), scale)
                                };
                            }
                        }
                    }
                    else // if (hasRotation) -- Only in same WriteGroup if !hasCompositeRotation
                    {
                        // 00
                        if (!hasTranslation && !hasAnyScale)
                        {
                            for (int i = 0; i < count; i++)
                            {
                                var rotation = chunkRotations[i].Value;

                                chunkLocalToParent[i] = new LocalToParent
                                {
                                    Value = new float4x4(rotation, float3.zero)
                                };
                            }
                        }
                        // 01
                        else if (!hasTranslation && hasAnyScale)
                        {
                            for (int i = 0; i < count; i++)
                            {
                                var rotation = chunkRotations[i].Value;
                                var scale    = hasNonUniformScale
                                    ? float4x4.Scale(chunkNonUniformScales[i].Value)
                                    : (hasScale
                                        ? float4x4.Scale(new float3(chunkScales[i].Value))
                                        : chunkCompositeScales[i].Value);

                                chunkLocalToParent[i] = new LocalToParent
                                {
                                    Value = math.mul(new float4x4(rotation, float3.zero), scale)
                                };
                            }
                        }
                        // 10
                        else if (hasTranslation && !hasAnyScale)
                        {
                            for (int i = 0; i < count; i++)
                            {
                                var rotation    = chunkRotations[i].Value;
                                var translation = chunkTranslations[i].Value;

                                chunkLocalToParent[i] = new LocalToParent
                                {
                                    Value = new float4x4(rotation, translation)
                                };
                            }
                        }
                        // 11
                        else if (hasTranslation && hasAnyScale)
                        {
                            for (int i = 0; i < count; i++)
                            {
                                var rotation    = chunkRotations[i].Value;
                                var translation = chunkTranslations[i].Value;
                                var scale       = hasNonUniformScale
                                    ? float4x4.Scale(chunkNonUniformScales[i].Value)
                                    : (hasScale
                                        ? float4x4.Scale(new float3(chunkScales[i].Value))
                                        : chunkCompositeScales[i].Value);

                                chunkLocalToParent[i] = new LocalToParent
                                {
                                    Value = math.mul(new float4x4(rotation, translation), scale)
                                };
                            }
                        }
                    }
                }
            }
            public void Execute(ArchetypeChunk chunk, int index, int entityOffset)
            {
                var chunkRotationPivotTranslations = chunk.GetNativeArray(RotationPivotTranslationTypeHandle);
                var chunkRotations          = chunk.GetNativeArray(RotationTypeHandle);
                var chunkPostRotation       = chunk.GetNativeArray(PostRotationTypeHandle);
                var chunkRotationPivots     = chunk.GetNativeArray(RotationPivotTypeHandle);
                var chunkCompositeRotations = chunk.GetNativeArray(CompositeRotationTypeHandle);

                var hasRotationPivotTranslation = chunk.Has(RotationPivotTranslationTypeHandle);
                var hasRotation      = chunk.Has(RotationTypeHandle);
                var hasPostRotation  = chunk.Has(PostRotationTypeHandle);
                var hasRotationPivot = chunk.Has(RotationPivotTypeHandle);
                var count            = chunk.Count;

                var hasAnyRotation = hasRotation || hasPostRotation;

                // 000 - Invalid. Must have at least one.
                // 001
                if (!hasAnyRotation && !hasRotationPivotTranslation && hasRotationPivot)
                {
                    var didChange = chunk.DidChange(RotationPivotTypeHandle, LastSystemVersion);
                    if (!didChange)
                    {
                        return;
                    }

                    // Only pivot? Doesn't do anything.
                    for (int i = 0; i < count; i++)
                    {
                        chunkCompositeRotations[i] = new CompositeRotation {
                            Value = float4x4.identity
                        }
                    }
                    ;
                }
                // 010
                else if (!hasAnyRotation && hasRotationPivotTranslation && !hasRotationPivot)
                {
                    var didChange = chunk.DidChange(RotationPivotTranslationTypeHandle, LastSystemVersion);
                    if (!didChange)
                    {
                        return;
                    }

                    for (int i = 0; i < count; i++)
                    {
                        var translation = chunkRotationPivotTranslations[i].Value;

                        chunkCompositeRotations[i] = new CompositeRotation
                        {
                            Value = float4x4.Translate(translation)
                        };
                    }
                }
                // 011
                else if (!hasAnyRotation && hasRotationPivotTranslation && hasRotationPivot)
                {
                    var didChange = chunk.DidChange(RotationPivotTranslationTypeHandle, LastSystemVersion);
                    if (!didChange)
                    {
                        return;
                    }

                    // Pivot without rotation doesn't affect anything. Only translation.
                    for (int i = 0; i < count; i++)
                    {
                        var translation = chunkRotationPivotTranslations[i].Value;

                        chunkCompositeRotations[i] = new CompositeRotation
                        {
                            Value = float4x4.Translate(translation)
                        };
                    }
                }
                // 100
                else if (hasAnyRotation && !hasRotationPivotTranslation && !hasRotationPivot)
                {
                    // 00 - Not valid
                    // 01
                    if (!hasPostRotation && hasRotation)
                    {
                        var didChange = chunk.DidChange(RotationTypeHandle, LastSystemVersion);
                        if (!didChange)
                        {
                            return;
                        }

                        for (int i = 0; i < count; i++)
                        {
                            var rotation = chunkRotations[i].Value;

                            chunkCompositeRotations[i] = new CompositeRotation
                            {
                                Value = new float4x4(rotation, float3.zero)
                            };
                        }
                    }
                    // 10
                    else if (hasPostRotation && !hasRotation)
                    {
                        var didChange = chunk.DidChange(PostRotationTypeHandle, LastSystemVersion);
                        if (!didChange)
                        {
                            return;
                        }

                        for (int i = 0; i < count; i++)
                        {
                            var rotation = chunkPostRotation[i].Value;

                            chunkCompositeRotations[i] = new CompositeRotation
                            {
                                Value = new float4x4(rotation, float3.zero)
                            };
                        }
                    }
                    // 11
                    else if (hasPostRotation && hasRotation)
                    {
                        var didChange = chunk.DidChange(PostRotationTypeHandle, LastSystemVersion) ||
                                        chunk.DidChange(RotationTypeHandle, LastSystemVersion);
                        if (!didChange)
                        {
                            return;
                        }

                        for (int i = 0; i < count; i++)
                        {
                            var rotation = math.mul(chunkRotations[i].Value, chunkPostRotation[i].Value);

                            chunkCompositeRotations[i] = new CompositeRotation
                            {
                                Value = new float4x4(rotation, float3.zero)
                            };
                        }
                    }
                }
                // 101
                else if (hasAnyRotation && !hasRotationPivotTranslation && hasRotationPivot)
                {
                    // 00 - Not valid
                    // 01
                    if (!hasPostRotation && hasRotation)
                    {
                        var didChange = chunk.DidChange(RotationTypeHandle, LastSystemVersion) ||
                                        chunk.DidChange(RotationPivotTypeHandle, LastSystemVersion);
                        if (!didChange)
                        {
                            return;
                        }

                        for (int i = 0; i < count; i++)
                        {
                            var rotation     = chunkRotations[i].Value;
                            var pivot        = chunkRotationPivots[i].Value;
                            var inversePivot = -1.0f * pivot;

                            chunkCompositeRotations[i] = new CompositeRotation
                            {
                                Value = math.mul(new float4x4(rotation, pivot), float4x4.Translate(inversePivot))
                            };
                        }
                    }
                    // 10
                    else if (hasPostRotation && !hasRotation)
                    {
                        var didChange = chunk.DidChange(PostRotationTypeHandle, LastSystemVersion) ||
                                        chunk.DidChange(RotationPivotTypeHandle, LastSystemVersion);
                        if (!didChange)
                        {
                            return;
                        }

                        for (int i = 0; i < count; i++)
                        {
                            var rotation     = chunkPostRotation[i].Value;
                            var pivot        = chunkRotationPivots[i].Value;
                            var inversePivot = -1.0f * pivot;

                            chunkCompositeRotations[i] = new CompositeRotation
                            {
                                Value = math.mul(new float4x4(rotation, pivot), float4x4.Translate(inversePivot))
                            };
                        }
                    }
                    // 11
                    else if (hasPostRotation && hasRotation)
                    {
                        var didChange = chunk.DidChange(PostRotationTypeHandle, LastSystemVersion) ||
                                        chunk.DidChange(RotationTypeHandle, LastSystemVersion) ||
                                        chunk.DidChange(RotationPivotTypeHandle, LastSystemVersion);
                        if (!didChange)
                        {
                            return;
                        }

                        for (int i = 0; i < count; i++)
                        {
                            var rotation     = chunkPostRotation[i].Value;
                            var pivot        = chunkRotationPivots[i].Value;
                            var inversePivot = -1.0f * pivot;

                            chunkCompositeRotations[i] = new CompositeRotation
                            {
                                Value = math.mul(new float4x4(rotation, pivot), float4x4.Translate(inversePivot))
                            };
                        }
                    }
                }
                // 110
                else if (hasAnyRotation && hasRotationPivotTranslation && !hasRotationPivot)
                {
                    // 00 - Not valid
                    // 01
                    if (!hasPostRotation && hasRotation)
                    {
                        var didChange = chunk.DidChange(RotationTypeHandle, LastSystemVersion) ||
                                        chunk.DidChange(RotationPivotTranslationTypeHandle, LastSystemVersion);
                        if (!didChange)
                        {
                            return;
                        }

                        for (int i = 0; i < count; i++)
                        {
                            var translation = chunkRotationPivotTranslations[i].Value;
                            var rotation    = chunkRotations[i].Value;

                            chunkCompositeRotations[i] = new CompositeRotation
                            {
                                Value = new float4x4(rotation, translation)
                            };
                        }
                    }
                    // 10
                    else if (hasPostRotation && !hasRotation)
                    {
                        var didChange = chunk.DidChange(PostRotationTypeHandle, LastSystemVersion) ||
                                        chunk.DidChange(RotationPivotTranslationTypeHandle, LastSystemVersion);
                        if (!didChange)
                        {
                            return;
                        }

                        for (int i = 0; i < count; i++)
                        {
                            var translation = chunkRotationPivotTranslations[i].Value;
                            var rotation    = chunkRotations[i].Value;

                            chunkCompositeRotations[i] = new CompositeRotation
                            {
                                Value = new float4x4(rotation, translation)
                            };
                        }
                    }
                    // 11
                    else if (hasPostRotation && hasRotation)
                    {
                        var didChange = chunk.DidChange(PostRotationTypeHandle, LastSystemVersion) ||
                                        chunk.DidChange(RotationPivotTranslationTypeHandle, LastSystemVersion) ||
                                        chunk.DidChange(RotationTypeHandle, LastSystemVersion);
                        if (!didChange)
                        {
                            return;
                        }

                        for (int i = 0; i < count; i++)
                        {
                            var translation = chunkRotationPivotTranslations[i].Value;
                            var rotation    = math.mul(chunkRotations[i].Value, chunkPostRotation[i].Value);

                            chunkCompositeRotations[i] = new CompositeRotation
                            {
                                Value = new float4x4(rotation, translation)
                            };
                        }
                    }
                }
                // 111
                else if (hasAnyRotation && hasRotationPivotTranslation && hasRotationPivot)
                {
                    // 00 - Not valid
                    // 01
                    if (!hasPostRotation && hasRotation)
                    {
                        var didChange = chunk.DidChange(RotationTypeHandle, LastSystemVersion) ||
                                        chunk.DidChange(RotationPivotTranslationTypeHandle, LastSystemVersion) ||
                                        chunk.DidChange(RotationPivotTypeHandle, LastSystemVersion);
                        if (!didChange)
                        {
                            return;
                        }

                        for (int i = 0; i < count; i++)
                        {
                            var translation  = chunkRotationPivotTranslations[i].Value;
                            var rotation     = chunkRotations[i].Value;
                            var pivot        = chunkRotationPivots[i].Value;
                            var inversePivot = -1.0f * pivot;

                            chunkCompositeRotations[i] = new CompositeRotation
                            {
                                Value = math.mul(float4x4.Translate(translation),
                                                 math.mul(new float4x4(rotation, pivot), float4x4.Translate(inversePivot)))
                            };
                        }
                    }
                    // 10
                    else if (hasPostRotation && !hasRotation)
                    {
                        var didChange = chunk.DidChange(PostRotationTypeHandle, LastSystemVersion) ||
                                        chunk.DidChange(RotationPivotTranslationTypeHandle, LastSystemVersion) ||
                                        chunk.DidChange(RotationPivotTypeHandle, LastSystemVersion);
                        if (!didChange)
                        {
                            return;
                        }

                        for (int i = 0; i < count; i++)
                        {
                            var translation  = chunkRotationPivotTranslations[i].Value;
                            var rotation     = chunkPostRotation[i].Value;
                            var pivot        = chunkRotationPivots[i].Value;
                            var inversePivot = -1.0f * pivot;

                            chunkCompositeRotations[i] = new CompositeRotation
                            {
                                Value = math.mul(float4x4.Translate(translation),
                                                 math.mul(new float4x4(rotation, pivot), float4x4.Translate(inversePivot)))
                            };
                        }
                    }
                    // 11
                    else if (hasPostRotation && hasRotation)
                    {
                        var didChange = chunk.DidChange(PostRotationTypeHandle, LastSystemVersion) ||
                                        chunk.DidChange(RotationTypeHandle, LastSystemVersion) ||
                                        chunk.DidChange(RotationPivotTranslationTypeHandle, LastSystemVersion) ||
                                        chunk.DidChange(RotationPivotTypeHandle, LastSystemVersion);
                        if (!didChange)
                        {
                            return;
                        }

                        for (int i = 0; i < count; i++)
                        {
                            var translation  = chunkRotationPivotTranslations[i].Value;
                            var rotation     = math.mul(chunkRotations[i].Value, chunkPostRotation[i].Value);
                            var pivot        = chunkRotationPivots[i].Value;
                            var inversePivot = -1.0f * pivot;

                            chunkCompositeRotations[i] = new CompositeRotation
                            {
                                Value = math.mul(float4x4.Translate(translation),
                                                 math.mul(new float4x4(rotation, pivot), float4x4.Translate(inversePivot)))
                            };
                        }
                    }
                }
            }
Ejemplo n.º 16
0
            public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
            {
                //BufferAccessor<Cell> accessor = this.GridChunks[0].GetBufferAccessor(this.CellTypeRO);
                //DynamicBuffer<Cell> grid = accessor[0].Reinterpret<Cell>();


                int size = DimX * DimY;
                BufferAccessor <Waypoint>            Waypoints              = chunk.GetBufferAccessor(WaypointChunkBuffer);
                NativeArray <PathRequest>            PathRequests           = chunk.GetNativeArray(PathRequestsChunkComponent);
                NativeArray <Translation>            Translations           = chunk.GetNativeArray(TranslationsChunkComponent);
                NativeArray <NavigationCapabilities> NavigationCapabilities = chunk.GetNativeArray(NavigationCapabilitiesChunkComponent);

                NativeArray <float> CostSoFar = new NativeArray <float>(size * chunk.Count, Allocator.Temp);
                NativeArray <int2>  CameFrom  = new NativeArray <int2>(size * chunk.Count, Allocator.Temp);
                NativeMinHeap       OpenSet   = new NativeMinHeap((Iterations + 1) * Neighbors.Length * chunk.Count, Allocator.Temp);

                for (int i = chunkIndex; i < chunk.Count; i++)
                {
                    NativeSlice <float> costSoFar = CostSoFar.Slice(i * size, size);
                    NativeSlice <int2>  cameFrom  = CameFrom.Slice(i * size, size);

                    int           openSetSize = (Iterations + 1) * NeighborCount;
                    NativeMinHeap openSet     = OpenSet.Slice(i * openSetSize, openSetSize);
                    PathRequest   request     = PathRequests[i];

                    // Clear our shared data
                    //var buffer = costSoFar.GetUnsafePtr();
                    //UnsafeUtility.MemClear(buffer, (long)costSoFar.Length * UnsafeUtility.SizeOf<float>());
                    //openSet.Clear();

                    Translation            currentPosition = Translations[i];
                    NavigationCapabilities capability      = NavigationCapabilities[i];

                    // cache these as they're used a lot
                    int2 start = currentPosition.Value.xy.FloorToInt();
                    int2 goal  = request.end;



                    DynamicBuffer <float3> waypoints = Waypoints[i].Reinterpret <float3>();
                    waypoints.Clear();

                    // Special case when the start is the same point as the goal
                    if (start.Equals(goal))
                    {
                        // We just set the destination as the goal, but need to get the correct height
                        int    gridIndex = this.GetIndex(goal);
                        Cell   cell      = CellArray[gridIndex];
                        float3 point     = new float3(request.Destination.x, request.Destination.y, cell.Height);
                        waypoints.Add(point);
                        continue;
                    }

                    var stash = new InstanceStash
                    {
                        Grid            = CellArray,
                        CameFrom        = cameFrom,
                        CostSoFar       = costSoFar,
                        OpenSet         = openSet,
                        Request         = request,
                        Capability      = capability,
                        CurrentPosition = currentPosition,
                        Start           = start,
                        Goal            = goal,
                        Waypoints       = waypoints,
                    };

                    if (this.ProcessPath(ref stash))
                    {
                        this.ReconstructPath(stash);
                    }
                }
                CostSoFar.Dispose();
                CameFrom.Dispose();
                OpenSet.Dispose();
            }
Ejemplo n.º 17
0
            public void Execute(ArchetypeChunk batchInChunk, int batchIndex)
            {
                bool changed =
                    batchInChunk.DidOrderChange(LastSystemVersion) ||
                    batchInChunk.DidChange(TranslationTypeHandle, LastSystemVersion) ||
                    batchInChunk.DidChange(NonUniformScaleTypeHandle, LastSystemVersion) ||
                    batchInChunk.DidChange(ScaleTypeHandle, LastSystemVersion) ||
                    batchInChunk.DidChange(CompositeScaleTypeHandle, LastSystemVersion) ||
                    batchInChunk.DidChange(RotationTypeHandle, LastSystemVersion) ||
                    batchInChunk.DidChange(CompositeRotationTypeHandle, LastSystemVersion);

                if (!changed)
                {
                    return;
                }

                var chunkTranslations       = batchInChunk.GetNativeArray(TranslationTypeHandle);
                var chunkNonUniformScales   = batchInChunk.GetNativeArray(NonUniformScaleTypeHandle);
                var chunkScales             = batchInChunk.GetNativeArray(ScaleTypeHandle);
                var chunkCompositeScales    = batchInChunk.GetNativeArray(CompositeScaleTypeHandle);
                var chunkRotations          = batchInChunk.GetNativeArray(RotationTypeHandle);
                var chunkCompositeRotations = batchInChunk.GetNativeArray(CompositeRotationTypeHandle);
                var chunkLocalToWorld       = batchInChunk.GetNativeArray(LocalToWorldTypeHandle);
                var hasTranslation          = batchInChunk.Has(TranslationTypeHandle);
                var hasCompositeRotation    = batchInChunk.Has(CompositeRotationTypeHandle);
                var hasRotation             = batchInChunk.Has(RotationTypeHandle);
                var hasAnyRotation          = hasCompositeRotation || hasRotation;
                var hasNonUniformScale      = batchInChunk.Has(NonUniformScaleTypeHandle);
                var hasScale          = batchInChunk.Has(ScaleTypeHandle);
                var hasCompositeScale = batchInChunk.Has(CompositeScaleTypeHandle);
                var hasAnyScale       = hasScale || hasNonUniformScale || hasCompositeScale;
                var count             = batchInChunk.Count;

                // #todo jump table when burst supports function pointers

                if (!hasAnyRotation)
                {
                    // 00 = invalid (must have at least one)
                    // 01
                    if (!hasTranslation && hasAnyScale)
                    {
                        for (int i = 0; i < count; i++)
                        {
                            var scale = hasNonUniformScale ? float4x4.Scale(chunkNonUniformScales[i].Value) : (hasScale ? float4x4.Scale(new float3(chunkScales[i].Value)) : chunkCompositeScales[i].Value);

                            chunkLocalToWorld[i] = new LocalToWorld
                            {
                                Value = scale
                            };
                        }
                    }
                    // 10
                    else if (hasTranslation && !hasAnyScale)
                    {
                        for (int i = 0; i < count; i++)
                        {
                            var translation = chunkTranslations[i].Value;

                            chunkLocalToWorld[i] = new LocalToWorld
                            {
                                Value = float4x4.Translate(translation)
                            };
                        }
                    }
                    // 11
                    else if (hasTranslation && hasAnyScale)
                    {
                        for (int i = 0; i < count; i++)
                        {
                            var scale       = hasNonUniformScale ? float4x4.Scale(chunkNonUniformScales[i].Value) : (hasScale ? float4x4.Scale(new float3(chunkScales[i].Value)) : chunkCompositeScales[i].Value);
                            var translation = chunkTranslations[i].Value;

                            chunkLocalToWorld[i] = new LocalToWorld
                            {
                                Value = math.mul(float4x4.Translate(translation), scale)
                            };
                        }
                    }
                }
                else if (hasCompositeRotation)
                {
                    // 00
                    if (!hasTranslation && !hasAnyScale)
                    {
                        for (int i = 0; i < count; i++)
                        {
                            var rotation = chunkCompositeRotations[i].Value;

                            chunkLocalToWorld[i] = new LocalToWorld
                            {
                                Value = rotation
                            };
                        }
                    }
                    // 01
                    else if (!hasTranslation && hasAnyScale)
                    {
                        for (int i = 0; i < count; i++)
                        {
                            var rotation = chunkCompositeRotations[i].Value;
                            var scale    = hasNonUniformScale ? float4x4.Scale(chunkNonUniformScales[i].Value) : (hasScale ? float4x4.Scale(new float3(chunkScales[i].Value)) : chunkCompositeScales[i].Value);

                            chunkLocalToWorld[i] = new LocalToWorld
                            {
                                Value = math.mul(rotation, scale)
                            };
                        }
                    }
                    // 10
                    else if (hasTranslation && !hasAnyScale)
                    {
                        for (int i = 0; i < count; i++)
                        {
                            var rotation    = chunkCompositeRotations[i].Value;
                            var translation = chunkTranslations[i].Value;

                            chunkLocalToWorld[i] = new LocalToWorld
                            {
                                Value = math.mul(float4x4.Translate(translation), rotation)
                            };
                        }
                    }
                    // 11
                    else if (hasTranslation && hasAnyScale)
                    {
                        for (int i = 0; i < count; i++)
                        {
                            var rotation    = chunkCompositeRotations[i].Value;
                            var translation = chunkTranslations[i].Value;
                            var scale       = hasNonUniformScale ? float4x4.Scale(chunkNonUniformScales[i].Value) : (hasScale ? float4x4.Scale(new float3(chunkScales[i].Value)) : chunkCompositeScales[i].Value);

                            chunkLocalToWorld[i] = new LocalToWorld
                            {
                                Value = math.mul(math.mul(float4x4.Translate(translation), rotation), scale)
                            };
                        }
                    }
                }
                else // if (hasRotation) -- Only in same WriteGroup if !hasCompositeRotation
                {
                    // 00
                    if (!hasTranslation && !hasAnyScale)
                    {
                        for (int i = 0; i < count; i++)
                        {
                            var rotation = chunkRotations[i].Value;

                            chunkLocalToWorld[i] = new LocalToWorld
                            {
                                Value = new float4x4(rotation, float3.zero)
                            };
                        }
                    }
                    // 01
                    else if (!hasTranslation && hasAnyScale)
                    {
                        for (int i = 0; i < count; i++)
                        {
                            var rotation = chunkRotations[i].Value;
                            var scale    = hasNonUniformScale ? float4x4.Scale(chunkNonUniformScales[i].Value) : (hasScale ? float4x4.Scale(new float3(chunkScales[i].Value)) : chunkCompositeScales[i].Value);

                            chunkLocalToWorld[i] = new LocalToWorld
                            {
                                Value = math.mul(new float4x4(rotation, float3.zero), scale)
                            };
                        }
                    }
                    // 10
                    else if (hasTranslation && !hasAnyScale)
                    {
                        for (int i = 0; i < count; i++)
                        {
                            var rotation    = chunkRotations[i].Value;
                            var translation = chunkTranslations[i].Value;

                            chunkLocalToWorld[i] = new LocalToWorld
                            {
                                Value = new float4x4(rotation, translation)
                            };
                        }
                    }
                    // 11
                    else if (hasTranslation && hasAnyScale)
                    {
                        for (int i = 0; i < count; i++)
                        {
                            var rotation    = chunkRotations[i].Value;
                            var translation = chunkTranslations[i].Value;
                            var scale       = hasNonUniformScale ? float4x4.Scale(chunkNonUniformScales[i].Value) : (hasScale ? float4x4.Scale(new float3(chunkScales[i].Value)) : chunkCompositeScales[i].Value);

                            chunkLocalToWorld[i] = new LocalToWorld
                            {
                                Value = math.mul(new float4x4(rotation, translation), scale)
                            };
                        }
                    }
                }
            }
Ejemplo n.º 18
0
            public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex, DynamicComponentTypeHandle *ghostChunkComponentTypesPtr, int ghostChunkComponentTypesLength)
            {
                if (!predictionState.TryGetValue(chunk, out var state) ||
                    (*(PredictionBackupState *)state).entityCapacity != chunk.Capacity)
                {
                    return;
                }

                var ghostComponents = chunk.GetNativeArray(ghostType);
                int ghostTypeId     = ghostComponents[0].ghostType;
                var typeData        = GhostTypeCollection[ghostTypeId];

                var headerSize = PredictionBackupState.GetHeaderSize();
                var entitySize = PredictionBackupState.GetEntitiesSize(chunk.Capacity, out var singleEntitySize);
                int baseOffset = typeData.FirstComponent;

                Entity *backupEntities = PredictionBackupState.GetEntities(state, headerSize);
                var     entities       = chunk.GetNativeArray(entityType);

                var predictedGhostComponents = chunk.GetNativeArray(predictedGhostType);

                byte *dataPtr           = PredictionBackupState.GetData(state, headerSize, entitySize);
                int   numBaseComponents = typeData.NumComponents - typeData.NumChildComponents;

                for (int comp = 0; comp < numBaseComponents; ++comp)
                {
                    int compIdx = GhostComponentIndex[baseOffset + comp].ComponentIndex;
#if ENABLE_UNITY_COLLECTIONS_CHECKS
                    if (compIdx >= ghostChunkComponentTypesLength)
                    {
                        throw new System.InvalidOperationException("Component index out of range");
                    }
#endif
                    if ((GhostComponentCollection[compIdx].SendMask & requiredSendMask) == 0)
                    {
                        continue;
                    }
                    var compSize = GhostComponentCollection[compIdx].ComponentSize;
                    if (chunk.Has(ghostChunkComponentTypesPtr[compIdx]))
                    {
                        var compData = (byte *)chunk.GetDynamicComponentDataArrayReinterpret <byte>(ghostChunkComponentTypesPtr[compIdx], compSize).GetUnsafeReadOnlyPtr();
                        for (int ent = 0; ent < entities.Length; ++ent)
                        {
                            // If this entity did not predict anything there was no rollback and no need to debug it
                            if (!GhostPredictionSystemGroup.ShouldPredict(tick, predictedGhostComponents[ent]))
                            {
                                continue;
                            }
                            if (entities[ent] == backupEntities[ent])
                            {
                                SmoothComponent(compData + compSize * ent, dataPtr + compSize * ent, GhostComponentCollection[compIdx].ComponentType);
                            }
                        }
                    }

                    dataPtr = PredictionBackupState.GetNextData(dataPtr, compSize, chunk.Capacity);
                }
                if (typeData.NumChildComponents > 0)
                {
                    var linkedEntityGroupAccessor = chunk.GetBufferAccessor(linkedEntityGroupType);
                    for (int comp = numBaseComponents; comp < typeData.NumComponents; ++comp)
                    {
                        int compIdx = GhostComponentIndex[baseOffset + comp].ComponentIndex;
#if ENABLE_UNITY_COLLECTIONS_CHECKS
                        if (compIdx >= ghostChunkComponentTypesLength)
                        {
                            throw new System.InvalidOperationException("Component index out of range");
                        }
#endif
                        if ((GhostComponentCollection[compIdx].SendMask & requiredSendMask) == 0)
                        {
                            continue;
                        }
                        var compSize  = GhostComponentCollection[compIdx].ComponentSize;
                        var entityIdx = GhostComponentIndex[baseOffset + comp].EntityIndex;

                        for (int ent = 0; ent < chunk.Count; ++ent)
                        {
                            // If this entity did not predict anything there was no rollback and no need to debug it
                            if (!GhostPredictionSystemGroup.ShouldPredict(tick, predictedGhostComponents[ent]))
                            {
                                continue;
                            }
                            if (entities[ent] != backupEntities[ent])
                            {
                                continue;
                            }
                            var linkedEntityGroup = linkedEntityGroupAccessor[ent];
                            if (childEntityLookup.TryGetValue(linkedEntityGroup[entityIdx].Value, out var childChunk) &&
                                childChunk.chunk.Has(ghostChunkComponentTypesPtr[compIdx]))
                            {
                                var compData = (byte *)childChunk.chunk.GetDynamicComponentDataArrayReinterpret <byte>(ghostChunkComponentTypesPtr[compIdx], compSize).GetUnsafePtr();
                                SmoothComponent(compData + compSize * childChunk.index, dataPtr + compSize * ent, GhostComponentCollection[compIdx].ComponentType);
                            }
                        }

                        dataPtr = PredictionBackupState.GetNextData(dataPtr, compSize, chunk.Capacity);
                    }
                }
            }
Ejemplo n.º 19
0
 public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
 {
 }
        public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
        {
            var entities        = chunk.GetNativeArray(EntityType);
            var translations    = chunk.GetNativeArray(TranslationType);
            var directions      = chunk.GetNativeArray(DirectionType);
            var targets         = chunk.GetNativeArray(TargetType);
            var distanceTargets = chunk.GetNativeArray(DistanceToTargetType);
            var areRats         = chunk.Has(RatType);

            for (int i = 0; i < chunk.Count; ++i)
            {
                var entity      = entities[i];
                var translation = translations[i].Value;
                var direction   = directions[i];

                var distance = distanceTargets[i].Value;
                if (distance < 1.0f)
                {
                    continue;
                }

                var index = ((int)translation.z) * BoardSize.y + (int)translation.x;
                if (index < 0 || index >= Buffer.Length)
                {
                    continue;
                }

                var cellMapValue = Buffer[index].Value;
                if ((cellMapValue & kHoleFlag) == kHoleFlag)
                {
                    CommandBuffer.AddComponent(chunkIndex, entity, new LbFall());
                    if (areRats)
                    {
                        CommandBuffer.AddComponent(chunkIndex, entity, new LbLifetime()
                        {
                            Value = 1.0f
                        });
                    }
                    else
                    {
                        CommandBuffer.SetComponent(chunkIndex, entity, new LbLifetime()
                        {
                            Value = 1.0f
                        });
                    }
                    CommandBuffer.SetComponent(chunkIndex, entity, new LbMovementSpeed()
                    {
                        Value = -2.5f
                    });
                }
                else if ((cellMapValue & kHomebaseFlag) == kHomebaseFlag)
                {
                    CommandBuffer.AddComponent(chunkIndex, entity, new LbDestroy());

                    var player = (cellMapValue >> 9) & 0x3;

                    var scoreEntity = CommandBuffer.CreateEntity(chunkIndex);
                    if (areRats)
                    {
                        CommandBuffer.AddComponent(chunkIndex, scoreEntity, new LbRatScore()
                        {
                            Player = (byte)player
                        });
                    }
                    else
                    {
                        CommandBuffer.AddComponent(chunkIndex, scoreEntity, new LbCatScore()
                        {
                            Player = (byte)player
                        });
                    }
                }
                else
                {
                    translation.y = 1.0f;
                    var currentArrow = ArrowDirectionMap[index].Value;
                    var newDirection = 0x00;
                    if ((currentArrow & 0x10) == 0x10)
                    {
                        newDirection = (byte)(currentArrow & 0x03);
                    }
                    else
                    {
                        newDirection = direction.Value;
                    }

                    var nextDirectionByte = (byte)((cellMapValue >> LbDirection.GetByteShift((byte)newDirection)) & 0x3);
                    directions[i] = new LbDirection()
                    {
                        Value = (byte)nextDirectionByte
                    };
                    targets[i] = new LbMovementTarget()
                    {
                        From = translation, To = translation + LbDirection.GetDirection((byte)nextDirectionByte)
                    };
                    distanceTargets[i] = new LbDistanceToTarget()
                    {
                        Value = 0.0f
                    };
                    CommandBuffer.SetComponent(chunkIndex, entity, new Rotation()
                    {
                        Value = LbDirection.GetRotation((byte)nextDirectionByte)
                    });
                }
            }
        }
Ejemplo n.º 21
0
 public void Execute(ArchetypeChunk chunk, int orderIndex)
 {
     data.Execute(chunk, orderIndex);
 }
Ejemplo n.º 22
0
        public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
        {
            var buffer   = FlowMap[BoardEntity];
            var entities = chunk.GetNativeArray(EntityType);
            var isRats   = chunk.Has(RatType);

            var byteShift     = 0;
            var componentType = 0;

            if (chunk.Has(DirectionNorthType))
            {
                byteShift     = 6;
                componentType = 0;
            }
            else if (chunk.Has(DirectionSouthType))
            {
                byteShift     = 2;
                componentType = 1;
            }
            else if (chunk.Has(DirectionWestType))
            {
                byteShift     = 0;
                componentType = 2;
            }
            else if (chunk.Has(DirectionEastType))
            {
                byteShift     = 4;
                componentType = 3;
            }

            var chunkTranslation = chunk.GetNativeArray(TranslationType);

            for (var i = 0; i < chunk.Count; i++)
            {
                var entity      = entities[i];
                var translation = chunkTranslation[i].Value;
                var index       = ((int)translation.z) * BoardSize.y + (int)translation.x;

                var cellMapValue = buffer[index].Value;
                if ((cellMapValue & kHoleFlag) == kHoleFlag)
                {
                    RemoveMovement(chunkIndex, entity, componentType);
                    CommandBuffer.AddComponent(chunkIndex, entity, new LbFall());
                    if (isRats)
                    {
                        CommandBuffer.AddComponent(chunkIndex, entity, new LbLifetime()
                        {
                            Value = 1.0f
                        });
                    }
                    else
                    {
                        CommandBuffer.SetComponent(chunkIndex, entity, new LbLifetime()
                        {
                            Value = 1.0f
                        });
                    }
                    CommandBuffer.SetComponent(chunkIndex, entity, new LbMovementSpeed()
                    {
                        Value = -2.5f
                    });
                }
                else if ((cellMapValue & kHomebaseFlag) == kHomebaseFlag)
                {
                    CommandBuffer.AddComponent(chunkIndex, entity, new LbDestroy());

                    var player = (cellMapValue >> 9) & 0x3;

                    var scoreEntity = CommandBuffer.CreateEntity(chunkIndex);
                    if (isRats)
                    {
                        CommandBuffer.AddComponent(chunkIndex, scoreEntity, new LbRatScore()
                        {
                            Player = (byte)player
                        });
                    }
                    else
                    {
                        CommandBuffer.AddComponent(chunkIndex, scoreEntity, new LbCatScore()
                        {
                            Player = (byte)player
                        });
                    }
                }
                else
                {
                    var nextDir = (cellMapValue >> byteShift) & 0x3;
                    RemoveMovement(chunkIndex, entity, componentType);
                    MoveToNextCell(chunkIndex, entity, nextDir);
                }

                CommandBuffer.RemoveComponent <LbReachCell>(chunkIndex, entity);
            }
        }
Ejemplo n.º 23
0
 public unsafe Runtime PrepareToExecuteOnEntitiesIn(ref ArchetypeChunk chunk)
 {
     return(new Runtime()
     {
     });
 }
Ejemplo n.º 24
0
            public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
            {
                //DeltaTime dt;
                var count            = chunk.Count;
                var chunkDeltaTime   = chunk.Has(etTp) ? chunk.GetNativeArray(dtTp) : default;
                var chunkTimeScale   = chunk.Has(tsTp) ? chunk.GetNativeArray(tsTp) : default;
                var chunkElapsedTime = chunk.Has(etTp) ? chunk.GetNativeArray(etTp) : default;
                var chunkFts         = chunk.Has(ftsTp) ? chunk.GetNativeArray(ftsTp) : default;
                var chunkSc          = chunk.Has(scTp) ? chunk.GetNativeArray(scTp) : default;

                if (chunkTimeScale != default)          //has time scale
                {
                    if (chunkElapsedTime != default)    //has ElapsedTime
                    {
                        if (chunkDeltaTime != default)  //has DeltaTime and ElapsedTime
                        {
                            if (chunkFts != default)    //has fixed time step
                            {
                                if (chunkSc != default) //has step counter
                                {
                                    for (int i = 0; i < count; i++)
                                    {
                                        var dt = chunkTimeScale[i].Scale(deltaTime);
                                        chunkElapsedTime[i] = chunkElapsedTime[i].Tick(dt);
                                        chunkDeltaTime[i]   = dt;
                                        var fst = chunkFts[i] = chunkFts[i].Tick(dt);
                                        chunkSc[i] = chunkSc[i].Tick(fst.AggSteps);
                                    }
                                }
                                else//has fixed time step no step counter
                                {
                                    for (int i = 0; i < count; i++)
                                    {
                                        var dt = chunkTimeScale[i].Scale(deltaTime);
                                        chunkElapsedTime[i] = chunkElapsedTime[i].Tick(dt);
                                        chunkDeltaTime[i]   = dt;
                                        chunkFts[i]         = chunkFts[i].Tick(dt);
                                    }
                                }
                            }
                            else//no fixed time step
                            {
                                for (int i = 0; i < count; i++)
                                {
                                    var dt = chunkTimeScale[i].Scale(deltaTime);
                                    chunkElapsedTime[i] = chunkElapsedTime[i].Tick(dt);
                                    chunkDeltaTime[i]   = dt;
                                }
                            }
                        }
                        else//has ElapsedTime no DeltaTime
                        {
                            if (chunkFts != default)//has fixed time step
                            {
                                if (chunkSc != default)//has step counter
                                {
                                    for (int i = 0; i < count; i++)
                                    {
                                        var dt = chunkTimeScale[i].Scale(deltaTime);
                                        chunkElapsedTime[i] = chunkElapsedTime[i].Tick(dt);
                                        var fst = chunkFts[i] = chunkFts[i].Tick(dt);
                                        chunkSc[i] = chunkSc[i].Tick(fst.AggSteps);
                                    }
                                }
                                else//has fixed time step no step counter
                                {
                                    for (int i = 0; i < count; i++)
                                    {
                                        var dt = chunkTimeScale[i].Scale(deltaTime);
                                        chunkElapsedTime[i] = chunkElapsedTime[i].Tick(dt);
                                        chunkFts[i]         = chunkFts[i].Tick(dt);
                                    }
                                }
                            }
                            else//no fixed time step
                            {
                                for (int i = 0; i < count; i++)
                                {
                                    var dt = chunkTimeScale[i].Scale(deltaTime);
                                    chunkElapsedTime[i] = chunkElapsedTime[i].Tick(dt);
                                }
                            }
                        }
                    }
                    else//no ElapsedTime
                    {
                        //has DeltaTime no ElapsedTime
                        if (chunkDeltaTime != default)
                        {
                            if (chunkFts != default)    //has fixed time step
                            {
                                if (chunkSc != default) //has step counter
                                {
                                    for (int i = 0; i < count; i++)
                                    {
                                        var dt = chunkTimeScale[i].Scale(deltaTime);
                                        chunkDeltaTime[i] = chunkTimeScale[i].Scale(deltaTime);
                                        var fst = chunkFts[i] = chunkFts[i].Tick(dt);
                                        chunkSc[i] = chunkSc[i].Tick(fst.AggSteps);
                                    }
                                }
                                else//has fixed time step no step counter
                                {
                                    for (int i = 0; i < count; i++)
                                    {
                                        var dt = chunkTimeScale[i].Scale(deltaTime);
                                        chunkDeltaTime[i] = chunkTimeScale[i].Scale(deltaTime);
                                        chunkFts[i]       = chunkFts[i].Tick(dt);
                                    }
                                }
                            }
                            //no fixed time step
                            else
                            {
                                for (int i = 0; i < count; i++)
                                {
                                    chunkDeltaTime[i] = chunkTimeScale[i].Scale(deltaTime);
                                }
                            }
                        }
                        else//no DeltaTime no ElapsedTime
                        {
                            if (chunkFts != default)//has fixed time step
                            {
                                if (chunkSc != default)//has step counter
                                {
                                    for (int i = 0; i < count; i++)
                                    {
                                        var dt  = chunkTimeScale[i].Scale(deltaTime);
                                        var fst = chunkFts[i] = chunkFts[i].Tick(dt);
                                        chunkSc[i] = chunkSc[i].Tick(fst.AggSteps);
                                    }
                                }
                                //has fixed time step no step counter
                                else
                                {
                                    for (int i = 0; i < count; i++)
                                    {
                                        chunkFts[i] = chunkFts[i].Tick(chunkTimeScale[i].Scale(deltaTime));
                                    }
                                }
                            }//no fixed time step
                        }
                        //else no DeltaTime no ElapsedTime no fixedtime step no update
                    }
                }
                else//no time scale
                {
                    if (chunkElapsedTime != default)//has ElapsedTime
                    {
                        if (chunkDeltaTime != default)  //has DeltaTime and ElapsedTime
                        {
                            if (chunkFts != default)    //has fixed time step
                            {
                                if (chunkSc != default) //has step counter
                                {
                                    for (int i = 0; i < count; i++)
                                    {
                                        chunkElapsedTime[i] = chunkElapsedTime[i].Tick(deltaTime);
                                        chunkDeltaTime[i]   = deltaTime;
                                        var fst = chunkFts[i] = chunkFts[i].Tick(deltaTime);
                                        chunkSc[i] = chunkSc[i].Tick(fst.AggSteps);
                                    }
                                }
                                else//has fixed time step no step counter
                                {
                                    for (int i = 0; i < count; i++)
                                    {
                                        chunkElapsedTime[i] = chunkElapsedTime[i].Tick(deltaTime);
                                        chunkDeltaTime[i]   = deltaTime;
                                        chunkFts[i]         = chunkFts[i].Tick(deltaTime);
                                    }
                                }
                            }
                            else//no fixed time step
                            {
                                for (int i = 0; i < count; i++)
                                {
                                    chunkElapsedTime[i] = chunkElapsedTime[i].Tick(deltaTime);
                                    chunkDeltaTime[i]   = deltaTime;
                                }
                            }
                        }
                        else//has ElapsedTime no DeltaTime
                        {
                            if (chunkFts != default)//has fixed time step
                            {
                                if (chunkSc != default)//has step counter
                                {
                                    for (int i = 0; i < count; i++)
                                    {
                                        chunkElapsedTime[i] = chunkElapsedTime[i].Tick(deltaTime);
                                        var fst = chunkFts[i] = chunkFts[i].Tick(deltaTime);
                                        chunkSc[i] = chunkSc[i].Tick(fst.AggSteps);
                                    }
                                }
                                else//has fixed time step no step counter
                                {
                                    for (int i = 0; i < count; i++)
                                    {
                                        chunkElapsedTime[i] = chunkElapsedTime[i].Tick(deltaTime);
                                        chunkFts[i]         = chunkFts[i].Tick(deltaTime);
                                    }
                                }
                            }
                            //no fixed time step
                            else
                            {
                                for (int i = 0; i < count; i++)
                                {
                                    chunkElapsedTime[i] = chunkElapsedTime[i].Tick(deltaTime);
                                }
                            }
                        }
                    }
                    else//no ElapsedTime
                    {
                        //has DeltaTime no ElapsedTime
                        if (chunkDeltaTime != default)
                        {
                            if (chunkFts != default)    //has fixed time step
                            {
                                if (chunkSc != default) //has step counter
                                {
                                    for (int i = 0; i < count; i++)
                                    {
                                        chunkDeltaTime[i] = deltaTime;
                                        var fst = chunkFts[i] = chunkFts[i].Tick(deltaTime);
                                        chunkSc[i] = chunkSc[i].Tick(fst.AggSteps);
                                    }
                                }
                                else//has fixed time step no step counter
                                {
                                    for (int i = 0; i < count; i++)
                                    {
                                        chunkDeltaTime[i] = deltaTime;
                                        chunkFts[i]       = chunkFts[i].Tick(deltaTime);
                                    }
                                }
                            }
                            //no fixed time step
                            else
                            {
                                for (int i = 0; i < count; i++)
                                {
                                    chunkDeltaTime[i] = deltaTime;
                                }
                            }
                        }
                        else//no DeltaTime no ElapsedTime
                        {
                            if (chunkFts != default)//has fixed time step
                            {
                                if (chunkSc != default)//has step counter
                                {
                                    for (int i = 0; i < count; i++)
                                    {
                                        var fst = chunkFts[i] = chunkFts[i].Tick(deltaTime);
                                        chunkSc[i] = chunkSc[i].Tick(fst.AggSteps);
                                    }
                                }
                                else//has fixed time step no step counter
                                {
                                    for (int i = 0; i < count; i++)
                                    {
                                        chunkFts[i] = chunkFts[i].Tick(deltaTime);
                                    }
                                }
                            }
                        }
                        //else no DeltaTime no ElapsedTime no fixedtime step no update
                    }
                }
            }
 public int CalculateImportance(ArchetypeChunk chunk)
 {
     return(1);
 }
 public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
 {
     Job.Execute(chunk, chunkIndex, firstEntityIndex, List.GetData(), List.Length);
 }
        public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
        {
            NativeArray <Entity> _entityArray = chunk.GetNativeArray(_entityHandle);

            _ecb.Instantiate(chunkIndex, _entityArray[0]);
        }
            public unsafe void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex, DynamicComponentTypeHandle *ghostChunkComponentTypesPtr, int ghostChunkComponentTypesLength)
            {
                var entityList                    = chunk.GetNativeArray(entityType);
                var snapshotDataList              = chunk.GetNativeArray(snapshotDataType);
                var snapshotDataBufferList        = chunk.GetBufferAccessor(snapshotDataBufferType);
                var snapshotDynamicDataBufferList = chunk.GetBufferAccessor(snapshotDynamicDataBufferType);

                var GhostCollection     = GhostCollectionFromEntity[GhostCollectionSingleton];
                var GhostTypeCollection = GhostTypeCollectionFromEntity[GhostCollectionSingleton];
                var ghostTypeComponent  = ghostTypeFromEntity[entityList[0]];
                int ghostType;

                for (ghostType = 0; ghostType < GhostCollection.Length; ++ghostType)
                {
                    if (GhostCollection[ghostType].GhostType == ghostTypeComponent)
                    {
                        break;
                    }
                }
                if (ghostType >= GhostCollection.Length)
                {
                    throw new InvalidOperationException("Could not find ghost type in the collection");
                }
                if (ghostType >= GhostTypeCollection.Length)
                {
                    return; // serialization data has not been loaded yet
                }
                var GhostComponentCollection = GhostComponentCollectionFromEntity[GhostCollectionSingleton];
                var GhostComponentIndex      = GhostComponentIndexFromEntity[GhostCollectionSingleton];

                var spawnList          = spawnListFromEntity[spawnListEntity];
                var typeData           = GhostTypeCollection[ghostType];
                var snapshotSize       = typeData.SnapshotSize;
                int changeMaskUints    = GhostCollectionSystem.ChangeMaskArraySizeInUInts(typeData.ChangeMaskBits);
                var snapshotBaseOffset = GhostCollectionSystem.SnapshotSizeAligned(4 + changeMaskUints * 4);
                var serializerState    = new GhostSerializerState
                {
                    GhostFromEntity = ghostFromEntity
                };
                var buffersToSerialize = new NativeList <BufferDataEntry>(Allocator.Temp);

                for (int i = 0; i < entityList.Length; ++i)
                {
                    var entity = entityList[i];

                    var ghostComponent = ghostFromEntity[entity];
                    ghostComponent.ghostType = ghostType;
                    ghostFromEntity[entity]  = ghostComponent;
                    // Set initial snapshot data
                    // Get the buffers, fill in snapshot size etc
                    snapshotDataList[i] = new SnapshotData {
                        SnapshotSize = snapshotSize, LatestIndex = 0
                    };
                    var snapshotDataBuffer = snapshotDataBufferList[i];
                    snapshotDataBuffer.ResizeUninitialized(snapshotSize * GhostSystemConstants.SnapshotHistorySize);
                    var snapshotPtr = (byte *)snapshotDataBuffer.GetUnsafePtr();
                    UnsafeUtility.MemClear(snapshotPtr, snapshotSize * GhostSystemConstants.SnapshotHistorySize);
                    *(uint *)snapshotPtr = spawnTick;
                    var snapshotOffset            = snapshotBaseOffset;
                    var dynamicSnapshotDataOffset = 0;

                    //Loop through all the serializable components and copy their data into the snapshot.
                    //For buffers, we collect what we need to serialize and then we copy the content in a second
                    //step. This is necessary because we need to resize the dynamic snapshot buffer
                    int numBaseComponents = typeData.NumComponents - typeData.NumChildComponents;
                    for (int comp = 0; comp < numBaseComponents; ++comp)
                    {
                        int compIdx       = GhostComponentIndex[typeData.FirstComponent + comp].ComponentIndex;
                        int serializerIdx = GhostComponentIndex[typeData.FirstComponent + comp].SerializerIndex;
#if ENABLE_UNITY_COLLECTIONS_CHECKS
                        if (compIdx >= ghostChunkComponentTypesLength)
                        {
                            throw new InvalidOperationException("Component index out of range");
                        }
#endif
                        var componentSnapshotSize = GhostComponentCollection[serializerIdx].ComponentType.IsBuffer
                            ? GhostCollectionSystem.SnapshotSizeAligned(GhostSystemConstants.DynamicBufferComponentSnapshotSize)
                            : GhostCollectionSystem.SnapshotSizeAligned(GhostComponentCollection[serializerIdx].SnapshotSize);
                        var compSize = GhostComponentCollection[serializerIdx].ComponentSize;

                        if (!chunk.Has(ghostChunkComponentTypesPtr[compIdx]))
                        {
                            UnsafeUtility.MemClear(snapshotPtr + snapshotOffset, componentSnapshotSize);
                        }
                        else if (!GhostComponentCollection[serializerIdx].ComponentType.IsBuffer)
                        {
                            var compData = (byte *)chunk.GetDynamicComponentDataArrayReinterpret <byte>(ghostChunkComponentTypesPtr[compIdx], compSize).GetUnsafeReadOnlyPtr();
                            GhostComponentCollection[serializerIdx].CopyToSnapshot.Ptr.Invoke((IntPtr)UnsafeUtility.AddressOf(ref serializerState), (IntPtr)snapshotPtr, snapshotOffset, snapshotSize, (IntPtr)(compData + i * compSize), compSize, 1);
                        }

                        else
                        {
                            // Collect the buffer data to serialize by storing pointers, offset and size.
                            var bufData       = chunk.GetUntypedBufferAccessor(ref ghostChunkComponentTypesPtr[compIdx]);
                            var bufferPointer = (IntPtr)bufData.GetUnsafeReadOnlyPtrAndLength(i, out var bufferLen);
                            var snapshotData  = (uint *)(snapshotPtr + snapshotOffset);
                            snapshotData[0] = (uint)bufferLen;
                            snapshotData[1] = (uint)dynamicSnapshotDataOffset;
                            buffersToSerialize.Add(new BufferDataEntry
                            {
                                offset        = dynamicSnapshotDataOffset,
                                len           = bufferLen,
                                serializerIdx = serializerIdx,
                                bufferData    = bufferPointer
                            });
                            var maskSize = SnapshotDynamicBuffersHelper.GetDynamicDataChangeMaskSize(GhostComponentCollection[serializerIdx].ChangeMaskBits, bufferLen);
                            dynamicSnapshotDataOffset += GhostCollectionSystem.SnapshotSizeAligned(maskSize + GhostComponentCollection[serializerIdx].ComponentSize * bufferLen);
                        }
                        snapshotOffset += componentSnapshotSize;
                    }
                    if (typeData.NumChildComponents > 0)
                    {
                        var linkedEntityGroupAccessor = chunk.GetBufferAccessor(linkedEntityGroupType);
                        for (int comp = numBaseComponents; comp < typeData.NumComponents; ++comp)
                        {
                            int compIdx       = GhostComponentIndex[typeData.FirstComponent + comp].ComponentIndex;
                            int serializerIdx = GhostComponentIndex[typeData.FirstComponent + comp].SerializerIndex;
#if ENABLE_UNITY_COLLECTIONS_CHECKS
                            if (compIdx >= ghostChunkComponentTypesLength)
                            {
                                throw new System.InvalidOperationException("Component index out of range");
                            }
#endif
                            var compSize = GhostComponentCollection[serializerIdx].ComponentSize;

                            var linkedEntityGroup = linkedEntityGroupAccessor[i];
                            var childEnt          = linkedEntityGroup[GhostComponentIndex[typeData.FirstComponent + comp].EntityIndex].Value;

                            var componentSnapshotSize = GhostComponentCollection[serializerIdx].ComponentType.IsBuffer
                                ? GhostCollectionSystem.SnapshotSizeAligned(GhostSystemConstants.DynamicBufferComponentSnapshotSize)
                                : GhostCollectionSystem.SnapshotSizeAligned(GhostComponentCollection[serializerIdx].SnapshotSize);

                            //We can skip here, becase the memory buffer offset is computed using the start-end entity indices
                            if (!childEntityLookup.TryGetValue(childEnt, out var childChunk) || !childChunk.chunk.Has(ghostChunkComponentTypesPtr[compIdx]))
                            {
                                UnsafeUtility.MemClear(snapshotPtr + snapshotOffset, componentSnapshotSize);
                            }
                            else if (!GhostComponentCollection[serializerIdx].ComponentType.IsBuffer)
                            {
                                var compData = (byte *)childChunk.chunk.GetDynamicComponentDataArrayReinterpret <byte>(ghostChunkComponentTypesPtr[compIdx], compSize).GetUnsafeReadOnlyPtr();
                                compData += childChunk.index * compSize;
                                GhostComponentCollection[serializerIdx].CopyToSnapshot.Ptr.Invoke((System.IntPtr)UnsafeUtility.AddressOf(ref serializerState),
                                                                                                  (System.IntPtr)snapshotPtr, snapshotOffset, snapshotSize, (System.IntPtr)compData, compSize, 1);
                            }
                            else
                            {
                                // Collect the buffer data to serialize by storing pointers, offset and size.
                                var bufData       = childChunk.chunk.GetUntypedBufferAccessor(ref ghostChunkComponentTypesPtr[compIdx]);
                                var bufferPointer = (IntPtr)bufData.GetUnsafeReadOnlyPtrAndLength(childChunk.index, out var bufferLen);
                                var snapshotData  = (uint *)(snapshotPtr + snapshotOffset);
                                snapshotData[0] = (uint)bufferLen;
                                snapshotData[1] = (uint)dynamicSnapshotDataOffset;
                                buffersToSerialize.Add(new BufferDataEntry
                                {
                                    offset        = dynamicSnapshotDataOffset,
                                    len           = bufferLen,
                                    serializerIdx = serializerIdx,
                                    bufferData    = bufferPointer
                                });
                                var maskSize = SnapshotDynamicBuffersHelper.GetDynamicDataChangeMaskSize(GhostComponentCollection[serializerIdx].ChangeMaskBits, bufferLen);
                                dynamicSnapshotDataOffset += GhostCollectionSystem.SnapshotSizeAligned(maskSize + GhostComponentCollection[serializerIdx].ComponentSize * bufferLen);
                            }
                            snapshotOffset += componentSnapshotSize;
                        }
                    }

                    //Second step (necessary only for buffers): resize the dynamicdata snapshot buffer and copy the buffer contents
                    if (GhostTypeCollection[ghostType].NumBuffers > 0 && buffersToSerialize.Length > 0)
                    {
                        var dynamicDataCapacity       = SnapshotDynamicBuffersHelper.CalculateBufferCapacity((uint)dynamicSnapshotDataOffset, out _);
                        var headerSize                = SnapshotDynamicBuffersHelper.GetHeaderSize();
                        var snapshotDynamicDataBuffer = snapshotDynamicDataBufferList[i];
                        snapshotDynamicDataBuffer.ResizeUninitialized((int)dynamicDataCapacity);
                        var snapshotDynamicDataBufferPtr = (byte *)snapshotDynamicDataBuffer.GetUnsafePtr() + headerSize;

                        ((uint *)snapshotDynamicDataBuffer.GetUnsafePtr())[0] = (uint)dynamicSnapshotDataOffset;
                        for (int buf = 0; buf < buffersToSerialize.Length; ++buf)
                        {
                            var entry           = buffersToSerialize[buf];
                            var dynamicDataSize = GhostComponentCollection[entry.serializerIdx].SnapshotSize;
                            var compSize        = GhostComponentCollection[entry.serializerIdx].ComponentSize;
                            var maskSize        = SnapshotDynamicBuffersHelper.GetDynamicDataChangeMaskSize(GhostComponentCollection[entry.serializerIdx].ChangeMaskBits, entry.len);
#if ENABLE_UNITY_COLLECTIONS_CHECKS
                            if ((maskSize + entry.offset + dynamicDataSize * entry.len) > dynamicDataCapacity)
                            {
                                throw new System.InvalidOperationException("Overflow writing data to dynamic snapshot memory buffer");
                            }
#endif
                            GhostComponentCollection[entry.serializerIdx].CopyToSnapshot.Ptr.Invoke((System.IntPtr)UnsafeUtility.AddressOf(ref serializerState),
                                                                                                    (System.IntPtr)snapshotDynamicDataBufferPtr + maskSize, entry.offset, dynamicDataSize,
                                                                                                    entry.bufferData, compSize, entry.len);
                        }
                    }

                    // Remove request component
                    commandBuffer.RemoveComponent <PredictedGhostSpawnRequestComponent>(entity);
                    // Add to list of predictive spawn component - maybe use a singleton for this so spawn systems can just access it too
                    spawnList.Add(new PredictedGhostSpawn {
                        entity = entity, ghostType = ghostType, spawnTick = spawnTick
                    });
                }
            }
            public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
            {
                var lodRequirement     = chunk.GetNativeArray(LodRequirement);
                var rootLodRequirement = chunk.GetNativeArray(RootLodRequirement);
                var meshLods           = chunk.GetNativeArray(MeshLODComponent);
                var instanceCount      = chunk.Count;

                for (int i = 0; i < instanceCount; i++)
                {
                    var meshLod        = meshLods[i];
                    var lodGroupEntity = meshLod.Group;
                    var lodMask        = meshLod.LODMask;
                    var lodGroup       = MeshLODGroupComponent[lodGroupEntity];

                    // Cannot take LocalToWorld from the instances, because they might not all share the same pivot
                    lodRequirement[i] = new LodRequirement(lodGroup, LocalToWorldLookup[lodGroupEntity], lodMask);
                }

                var rootLodIndex           = -1;
                var lastLodRootMask        = 0;
                var lastLodRootGroupEntity = Entity.Null;

                for (int i = 0; i < instanceCount; i++)
                {
                    var meshLod           = meshLods[i];
                    var lodGroupEntity    = meshLod.Group;
                    var lodGroup          = MeshLODGroupComponent[lodGroupEntity];
                    var parentMask        = lodGroup.ParentMask;
                    var parentGroupEntity = lodGroup.ParentGroup;

                    //@TODO: Bring this optimization back
                    //var changedRoot = parentGroupEntity != lastLodRootGroupEntity || parentMask != lastLodRootMask || i == 0;
                    var changedRoot = true;

                    if (changedRoot)
                    {
                        rootLodIndex++;
                        RootLodRequirement rootLod;
                        rootLod.InstanceCount = 1;

                        if (parentGroupEntity == Entity.Null)
                        {
                            rootLod.LOD.WorldReferencePosition = new float3(0, 0, 0);
                            rootLod.LOD.MinDist = 0;
                            rootLod.LOD.MaxDist = 64000.0f;
                        }
                        else
                        {
                            var parentLodGroup = MeshLODGroupComponent[parentGroupEntity];
                            rootLod.LOD           = new LodRequirement(parentLodGroup, LocalToWorldLookup[parentGroupEntity], parentMask);
                            rootLod.InstanceCount = 1;

                            if (parentLodGroup.ParentGroup != Entity.Null)
                            {
                                throw new System.NotImplementedException("Deep HLOD is not supported yet");
                            }
                        }

                        rootLodRequirement[rootLodIndex] = rootLod;
                        lastLodRootGroupEntity           = parentGroupEntity;
                        lastLodRootMask = parentMask;
                    }
                    else
                    {
                        var lastRoot = rootLodRequirement[rootLodIndex];
                        lastRoot.InstanceCount++;
                        rootLodRequirement[rootLodIndex] = lastRoot;
                    }
                }

/*
 *              var foundRootInstanceCount = 0;
 *              for (int i = 0; i < rootLodIndex + 1; i++)
 *              {
 *                  var lastRoot = rootLodRequirement[i];
 *                  foundRootInstanceCount += lastRoot.InstanceCount;
 *              }
 *
 *              if (chunk.Count != foundRootInstanceCount)
 *              {
 *                  throw new System.ArgumentException("Out of bounds");
 *              }
 */
            }
        private void snippets()
        {
            #region component-list-chunk-component

            ComponentType[] compTypes =
            {
                ComponentType.ChunkComponent <ChunkComponentA>(),
                ComponentType.ReadOnly <GeneralPurposeComponentA>()
            };
            Entity entity = EntityManager.CreateEntity(compTypes);
            #endregion

            #region em-snippet

            EntityManager.AddChunkComponentData <ChunkComponentA>(entity);
            #endregion

            #region desc-chunk-component

            EntityQueryDesc ChunksWithoutComponentADesc
                = new EntityQueryDesc()
                {
                None = new ComponentType[] {
                    ComponentType.ChunkComponent <ChunkComponentA>()
                }
                };
            EntityQuery ChunksWithoutChunkComponentA
                = GetEntityQuery(ChunksWithoutComponentADesc);

            EntityManager.AddChunkComponentData <ChunkComponentA>(
                ChunksWithoutChunkComponentA,
                new ChunkComponentA()
            {
                Value = 4
            });
            #endregion

            #region use-chunk-component

            EntityQueryDesc ChunksWithChunkComponentADesc
                = new EntityQueryDesc()
                {
                All = new ComponentType[] {
                    ComponentType.ChunkComponent <ChunkComponentA>()
                }
                };
            #endregion

            #region archetype-chunk-component

            EntityArchetype ArchetypeWithChunkComponent
                = EntityManager.CreateArchetype(
                      ComponentType.ChunkComponent(typeof(ChunkComponentA)),
                      ComponentType.ReadWrite <GeneralPurposeComponentA>());
            Entity newEntity
                = EntityManager.CreateEntity(ArchetypeWithChunkComponent);
            #endregion
            {
                EntityQuery ChunksWithChunkComponentA = default;
                #region read-chunk-component

                NativeArray <ArchetypeChunk> chunks
                    = ChunksWithChunkComponentA.CreateArchetypeChunkArray(
                          Allocator.TempJob);

                foreach (var chunk in chunks)
                {
                    var compValue =
                        EntityManager.GetChunkComponentData <ChunkComponentA>(chunk);
                    //..
                }
                chunks.Dispose();
                #endregion
            }

            #region read-entity-chunk-component

            if (EntityManager.HasChunkComponent <ChunkComponentA>(entity))
            {
                ChunkComponentA chunkComponentValue =
                    EntityManager.GetChunkComponentData <ChunkComponentA>(entity);
            }
            #endregion

            {
                ArchetypeChunk chunk = default;
                #region set-chunk-component

                EntityManager.SetChunkComponentData <ChunkComponentA>(
                    chunk, new ChunkComponentA()
                {
                    Value = 7
                });
                #endregion
            }

            #region set-entity-chunk-component

            var entityChunk = EntityManager.GetChunk(entity);
            EntityManager.SetChunkComponentData <ChunkComponentA>(
                entityChunk,
                new ChunkComponentA()
            {
                Value = 8
            });
            #endregion
        }