Exemple #1
0
    protected override void OnUpdate()
    {
        // TODO (mogensh) put this check into its own system. Can we enable/disable systems depending on configvars ?
        if (CharacterModule.PredictionCheck.IntValue > 0)
        {
            var timeQuery = EntityManager.CreateEntityQuery(ComponentType.ReadOnly <GlobalGameTime>());
            var time      = timeQuery.GetSingleton <GlobalGameTime>().gameTime;

            var query = EntityManager.CreateEntityQuery(typeof(Character.PredictedData), typeof(PredictedGhostComponent));
            var predictedDataArray = query.ToComponentDataArray <Character.PredictedData>(Allocator.TempJob);
            var entityArray        = query.ToEntityArray(Allocator.TempJob);
            for (int i = 0; i < predictedDataArray.Length; i++)
            {
                if (!GhostPredictionSystemGroup.ShouldPredict(World.GetExistingSystem <GhostPredictionSystemGroup>().PredictingTick, EntityManager.GetComponentData <PredictedGhostComponent>(entityArray[i])))
                {
                    continue;
                }
                var predictedData = predictedDataArray[i];

                if (predictedData.tick > 0 && time.tick != predictedData.tick + 1)
                {
                    GameDebug.Log("Update tick invalid. Game tick:" + time.tick + " but current state is at tick:" + predictedData.tick);
                }

                predictedData.tick = time.tick;
                EntityManager.SetComponentData(entityArray[i], predictedData);
            }

            entityArray.Dispose();
            predictedDataArray.Dispose();
            timeQuery.Dispose();
            query.Dispose();
        }

        base.OnUpdate();
    }
Exemple #2
0
 /// <summary>
 /// Gets a BufferFromEntity&lt;T&gt; object that can access a <seealso cref="DynamicBuffer{T}"/>.
 /// </summary>
 /// <remarks>Assign the returned object to a field of your Job struct so that you can access the
 /// contents of the buffer in a Job.</remarks>
 /// <param name="isReadOnly">Whether the buffer data is only read or is also written. Access data in
 /// a read-only fashion whenever possible.</param>
 /// <typeparam name="T">The type of <see cref="IBufferElementData"/> stored in the buffer.</typeparam>
 /// <returns>An array-like object that provides access to buffers, indexed by <see cref="Entity"/>.</returns>
 /// <seealso cref="ComponentDataFromEntity{T}"/>
 public BufferFromEntity <T> GetBufferFromEntity <T>(bool isReadOnly = false) where T : struct, IBufferElementData
 {
     AddReaderWriter(isReadOnly ? ComponentType.ReadOnly <T>() : ComponentType.ReadWrite <T>());
     return(EntityManager.GetBufferFromEntity <T>(isReadOnly));
 }
 public FixedArrayFromEntity <T> GetFixedArrayFromEntity <T>(bool isReadOnly = false) where T : struct
 {
     AddReaderWriter(isReadOnly ? ComponentType.ReadOnly <T>() : ComponentType.Create <T>());
     return(EntityManager.GetFixedArrayFromEntity <T>(TypeManager.GetTypeIndex <T>(), isReadOnly));
 }
Exemple #4
0
 /// <summary>
 /// Gets the run-time type information required to access an array of component data in a chunk.
 /// </summary>
 /// <param name="isReadOnly">Whether the component data is only read, not written. Access components as
 /// read-only whenever possible.</param>
 /// <typeparam name="T">A struct that implements <see cref="IComponentData"/>.</typeparam>
 /// <returns>An object representing the type information required to safely access component data stored in a
 /// chunk.</returns>
 /// <remarks>Pass an <see cref="ArchetypeChunkComponentType"/> instance to a job that has access to chunk data,
 /// such as an <see cref="IJobChunk"/> job, to access that type of component inside the job.</remarks>
 public ArchetypeChunkComponentType <T> GetArchetypeChunkComponentType <T>(bool isReadOnly = false) where T : struct, IComponentData
 {
     AddReaderWriter(isReadOnly ? ComponentType.ReadOnly <T>() : ComponentType.ReadWrite <T>());
     return(EntityManager.GetArchetypeChunkComponentType <T>(isReadOnly));
 }
Exemple #5
0
 public ComponentDataFromEntity <T> GetComponentDataFromEntity <T>(bool isReadOnly = false)
     where T : struct, IComponentData
 {
     AddReaderWriter(isReadOnly ? ComponentType.ReadOnly <T>() : ComponentType.Create <T>());
     return(EntityManager.GetComponentDataFromEntity <T>(isReadOnly));
 }
Exemple #6
0
 public ArchetypeChunkEntityType GetArchetypeChunkEntityType()
 {
     AddReaderWriter(ComponentType.ReadOnly <Entity>());
     return(EntityManager.GetArchetypeChunkEntityType());
 }
Exemple #7
0
 public ArchetypeChunkSharedComponentType <T> GetArchetypeChunkSharedComponentType <T>()
     where T : struct, ISharedComponentData
 {
     AddReaderWriter(ComponentType.ReadOnly <T>());
     return(EntityManager.GetArchetypeChunkSharedComponentType <T>());
 }
Exemple #8
0
        ArchetypeQuery *CreateQuery(ref UnsafeScratchAllocator unsafeScratchAllocator, EntityQueryDesc[] queryDesc)
        {
            var outQuery = (ArchetypeQuery *)unsafeScratchAllocator.Allocate(sizeof(ArchetypeQuery) * queryDesc.Length, UnsafeUtility.AlignOf <ArchetypeQuery>());

            for (int q = 0; q != queryDesc.Length; q++)
            {
                // Validate the queryDesc has components declared in a consistent way
                queryDesc[q].Validate();

                var typesNone = queryDesc[q].None;
                var typesAll  = queryDesc[q].All;
                var typesAny  = queryDesc[q].Any;

                // None forced to read only
                {
                    for (int i = 0; i < typesNone.Length; i++)
                    {
                        if (typesNone[i].AccessModeType != ComponentType.AccessMode.ReadOnly)
                        {
                            typesNone[i] = ComponentType.ReadOnly(typesNone[i].TypeIndex);
                        }
                    }
                }

                var isFilterWriteGroup = (queryDesc[q].Options & EntityQueryOptions.FilterWriteGroup) != 0;
                if (isFilterWriteGroup)
                {
                    // Each ReadOnly<type> in any or all
                    //   if has WriteGroup types,
                    //   - Recursively add to any (if not explictly mentioned)

                    var explicitList = CreateExplicitTypeList(typesNone, typesAll, typesAny);

                    for (int i = 0; i < typesAny.Length; i++)
                    {
                        IncludeDependentWriteGroups(typesAny[i], explicitList);
                    }
                    for (int i = 0; i < typesAll.Length; i++)
                    {
                        IncludeDependentWriteGroups(typesAll[i], explicitList);
                    }

                    // Each ReadWrite<type> in any or all
                    //   if has WriteGroup types,
                    //     Add to none (if not exist in any or all or none)
                    var noneList = new NativeList <ComponentType>(typesNone.Length, Allocator.Temp);
                    for (int i = 0; i < typesNone.Length; i++)
                    {
                        noneList.Add(typesNone[i]);
                    }
                    for (int i = 0; i < typesAny.Length; i++)
                    {
                        ExcludeWriteGroups(typesAny[i], noneList, explicitList);
                    }
                    for (int i = 0; i < typesAll.Length; i++)
                    {
                        ExcludeWriteGroups(typesAll[i], noneList, explicitList);
                    }
                    typesNone = new ComponentType[noneList.Length];
                    for (int i = 0; i < noneList.Length; i++)
                    {
                        typesNone[i] = noneList[i];
                    }
                    noneList.Dispose();
                    explicitList.Dispose();
                }

                ConstructTypeArray(ref unsafeScratchAllocator, typesNone, out outQuery[q].None, out outQuery[q].NoneAccessMode, out outQuery[q].NoneCount);
                ConstructTypeArray(ref unsafeScratchAllocator, typesAll, out outQuery[q].All, out outQuery[q].AllAccessMode, out outQuery[q].AllCount);
                ConstructTypeArray(ref unsafeScratchAllocator, typesAny, out outQuery[q].Any, out outQuery[q].AnyAccessMode, out outQuery[q].AnyCount);
                outQuery[q].Options = queryDesc[q].Options;
            }

            return(outQuery);
        }