Beispiel #1
0
            public void Execute(CollisionEvent ev)
            {
                Entity point;

                if (PlayerEntity == ev.Entities.EntityA)
                {
                    point = ev.Entities.EntityB;
                }
                else if (PlayerEntity == ev.Entities.EntityB)
                {
                    point = ev.Entities.EntityA;
                }
                else
                {
                    return;
                }
                if (!DestroyableAccessor.Exists(point) || !PointAccessor.Exists(point) || DestroyableAccessor[point].ShouldDestroy)
                {
                    return;
                }
                DestroyableAccessor[point] = new DestroyableComponentData()
                {
                    ShouldDestroy = true
                };
                Interlocked.Add(ref *PointPtr, PointAccessor[point].Value);
            }
Beispiel #2
0
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            var shouldDestroy = new DestroyableComponentData {
                ShouldDestroy = true
            };
            var syncChunks      = _query.CreateArchetypeChunkArray(Allocator.TempJob);
            var typeDestroyable = GetArchetypeChunkComponentType <DestroyableComponentData>();

            for (var chunkIndex = 0; chunkIndex < syncChunks.Length; chunkIndex++)
            {
                var syncChunk = syncChunks[chunkIndex];
                var destroyableComponentDatas = syncChunk.GetNativeArray(typeDestroyable);
                for (var j = 0; j < destroyableComponentDatas.Length; j++)
                {
                    destroyableComponentDatas[j] = shouldDestroy;
                }
            }
            var job = new Job
            {
                CurrentTimestamp    = PhotonNetwork.ServerTimestamp,
                TypeTeamTag         = GetArchetypeChunkComponentType <TeamTag>(true),
                TypeSyncInfoTag     = GetArchetypeChunkComponentType <SyncInfoTag>(true),
                TypeTranslation     = GetArchetypeChunkComponentType <Translation>(),
                TypeRotation        = GetArchetypeChunkComponentType <Rotation>(),
                TypePhysicsVelocity = GetArchetypeChunkComponentType <PhysicsVelocity>(),
                TypeDestroyable     = typeDestroyable,
                SyncChunks          = syncChunks,
            };

            return(job.Schedule(_dstQuery, inputDeps));
        }
Beispiel #3
0
            public void Execute(ArchetypeChunk chunk, int ci, int firstEntityIndex)
            {
                var shouldDestroy = new DestroyableComponentData {
                    ShouldDestroy = true
                };
                var dstTranslations = chunk.GetNativeArray(TypeTranslation);
                var dstTeamTags     = chunk.GetNativeArray(TypeTeamTag);
                var dstRotations    = chunk.GetNativeArray(TypeRotation);
                var dstVelocities   = chunk.GetNativeArray(TypePhysicsVelocity);

                const float ratio = 0f / 16f;

                for (int i = 0; i < dstTeamTags.Length; i++)
                {
                    var team = dstTeamTags[i].Id;

                    for (var chunkIndex = 0; chunkIndex < SyncChunks.Length; chunkIndex++)
                    {
                        var syncChunk = SyncChunks[chunkIndex];
                        var destroyableComponentDatas = syncChunk.GetNativeArray(TypeDestroyable);
                        for (var j = 0; j < destroyableComponentDatas.Length; j++)
                        {
                            destroyableComponentDatas[j] = shouldDestroy;
                        }
                        var syncInfoTags = syncChunk.GetNativeArray(TypeSyncInfoTag);
                        var teams        = syncChunk.GetNativeArray(TypeTeamTag);
                        var translations = syncChunk.GetNativeArray(TypeTranslation);
                        var rotations    = syncChunk.GetNativeArray(TypeRotation);
                        var velocities   = syncChunk.GetNativeArray(TypePhysicsVelocity);
                        for (var index = 0; index < teams.Length; index++)
                        {
                            if (teams[index].Id != team)
                            {
                                continue;
                            }
                            dstTranslations[i] = new Translation
                            {
                                Value = translations[index].Value
                                        + velocities[index].Linear
                                        * (CurrentTimestamp - syncInfoTags[index].SentServerTimestamp)
                                        * 0.001f
                            };
                            dstRotations[i] = new Rotation
                            {
                                Value = rotations[index].Value.value
                            };
                            dstVelocities[i] = velocities[index];
                            goto LOOPEND;
                        }
                    }
                    LOOPEND :;
                }
            }
Beispiel #4
0
        protected override unsafe void OnUpdate()
        {
            var typeMoveCommand     = GetArchetypeChunkComponentType <MoveCommand>(true);
            var typeDestroyable     = GetArchetypeChunkComponentType <DestroyableComponentData>();
            var typeTicks           = GetArchetypeChunkComponentType <DateTimeTicksToProcess>(true);
            var typeTeamTag         = GetArchetypeChunkComponentType <TeamTag>(true);
            var typePhysicsVelocity = GetArchetypeChunkComponentType <PhysicsVelocity>();
            var currentTicks        = DateTime.Now.Ticks;

            using (var moveCommandChunks = _queryMoveCommand.CreateArchetypeChunkArray(Allocator.TempJob))
                using (var velocitiesChunks = _query.CreateArchetypeChunkArray(Allocator.TempJob))
                {
                    foreach (var moveCommandChunk in moveCommandChunks)
                    {
                        var moveCommands = moveCommandChunk.GetNativeArray(typeMoveCommand);
                        var destroys     = moveCommandChunk.GetNativeArray(typeDestroyable);
                        var ticks        = moveCommandChunk.GetNativeArray(typeTicks);
                        for (var i = 0; i < ticks.Length; i++)
                        {
                            if (ticks[i].Value < currentTicks || destroys[i].ShouldDestroy)
                            {
                                continue;
                            }
                            destroys[i] = new DestroyableComponentData()
                            {
                                ShouldDestroy = true
                            };
                            foreach (var velocitiesChunk in velocitiesChunks)
                            {
                                var teamTags          = velocitiesChunk.GetNativeArray(typeTeamTag);
                                var physicsVelocities = velocitiesChunk.GetNativeArray(typePhysicsVelocity);
                                for (var j = 0; j < teamTags.Length; j++)
                                {
                                    if (teamTags[j].Id != moveCommands[i].Id)
                                    {
                                        continue;
                                    }
                                    UnsafeUtilityEx
                                    .ArrayElementAsRef <PhysicsVelocity>(NativeArrayUnsafeUtility.GetUnsafeBufferPointerWithoutChecks(physicsVelocities), j)
                                    .Linear += moveCommands[i].DeltaVelocity;
                                }
                            }
                        }
                    }
                }
        }
Beispiel #5
0
        protected override void OnUpdate()
        {
            var typeMoveCommand     = GetArchetypeChunkComponentType <MoveCommandMoreComplex>(true);
            var typeDestroyable     = GetArchetypeChunkComponentType <DestroyableComponentData>();
            var typeTicks           = GetArchetypeChunkComponentType <DateTimeTicksToProcess>(true);
            var typeTeamTag         = GetArchetypeChunkComponentType <TeamTag>(true);
            var typePhysicsVelocity = GetArchetypeChunkComponentType <PhysicsVelocity>();
            var currentTicks        = DateTime.Now.Ticks;

            using (var moveCommandChunks = _queryMoveCommand.CreateArchetypeChunkArray(Allocator.TempJob))
                using (var velocitiesChunks = _query.CreateArchetypeChunkArray(Allocator.TempJob))
                {
                    foreach (var moveCommandChunk in moveCommandChunks)
                    {
                        var moveCommands    = moveCommandChunk.GetNativeArray(typeMoveCommand);
                        var destroys        = moveCommandChunk.GetNativeArray(typeDestroyable);
                        var commandTeamTags = moveCommandChunk.GetNativeArray(typeTeamTag);
                        var ticks           = moveCommandChunk.GetNativeArray(typeTicks);
                        for (var i = 0; i < ticks.Length; i++)
                        {
                            if (ticks[i].Value < currentTicks || destroys[i].ShouldDestroy)
                            {
                                continue;
                            }
                            destroys[i] = new DestroyableComponentData()
                            {
                                ShouldDestroy = true
                            };
                            foreach (var velocitiesChunk in velocitiesChunks)
                            {
                                var teamTags          = velocitiesChunk.GetNativeArray(typeTeamTag);
                                var physicsVelocities = velocitiesChunk.GetNativeArray(typePhysicsVelocity);
                                for (var j = 0; j < teamTags.Length; j++)
                                {
                                    if (teamTags[j].Id != commandTeamTags[i].Id)
                                    {
                                        continue;
                                    }
                                    physicsVelocities[j] = moveCommands[i].Value;
                                }
                            }
                        }
                    }
                }
        }