Exemple #1
0
        /// <summary>
        /// Unsafe method for getting a <see cref="ParticleFieldAccessor"/>.
        /// If the field doesn't exist an invalid accessor is returned to the user.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="fieldDesc"></param>
        /// <returns></returns>
        public ParticleFieldAccessor <T> GetField <T>(ParticleFieldDescription <T> fieldDesc) where T : struct
        {
            ParticleField field;

            return(fields.TryGetValue(fieldDesc, out field) ?
                   new ParticleFieldAccessor <T>(field) :
                   ParticleFieldAccessor <T> .Invalid());
        }
Exemple #2
0
        /// <summary>
        /// Sets the particle's field to a value. However, you should try to use the indexer wherever possible.
        /// </summary>
        /// <typeparam name="T">The field type.</typeparam>
        /// <param name="accessor">The field accessor</param>
        /// <param name="value">The value to set</param>
        public void Set <T>(ParticleFieldAccessor <T> accessor, T value) where T : struct
        {
#if PARTICLES_SOA
            Utilities.Write(accessor[Index], ref value);
#else
            Utilities.Write(Pointer + accessor, ref value);
#endif
        }
Exemple #3
0
        /// <summary>
        /// Gets the particle's field value. However, you should try to use the indexer wherever possible.
        /// </summary>
        /// <typeparam name="T">The field type.</typeparam>
        /// <param name="accessor">The field accessor</param>
        /// <returns>The field value.</returns>
        public T Get <T>(ParticleFieldAccessor <T> accessor) where T : struct
        {
#if PARTICLES_SOA
            return(Utilities.Read <T>(accessor[Index]));
#else
            return(Utilities.Read <T>(Pointer + accessor));
#endif
        }
Exemple #4
0
        /// <summary>
        /// Gets the particle field with the specified description if the field exists in this pool
        /// </summary>
        /// <typeparam name="T">Type data for the field</typeparam>
        /// <param name="fieldDesc">Field's decription</param>
        /// <param name="accessor">Accessor for the field</param>
        /// <returns></returns>
        public bool TryGetField <T>(ParticleFieldDescription <T> fieldDesc, out ParticleFieldAccessor <T> accessor) where T : struct
        {
            ParticleField field;

            if (!fields.TryGetValue(fieldDesc, out field))
            {
                accessor = ParticleFieldAccessor <T> .Invalid();

                return(false);
            }

            accessor = new ParticleFieldAccessor <T>(field);
            return(true);
        }
Exemple #5
0
        /// <summary>
        /// Copy data from one particle index to another
        /// </summary>
        /// <param name="dst">Index of the destination particle</param>
        /// <param name="src">Index of the source particle</param>
        private void CopyParticleData(int dst, int src)
        {
            var dstParticle = FromIndex(dst);
            var srcParticle = FromIndex(src);

#if PARTICLES_SOA
            foreach (var field in fields.Values)
            {
                var accessor = new ParticleFieldAccessor(field);
                Utilities.CopyMemory(dstParticle[accessor], srcParticle[accessor], field.Size);
            }
#else
            Utilities.CopyMemory(dstParticle, srcParticle, ParticleSize);
#endif
        }
Exemple #6
0
 public                 IntPtr this[ParticleFieldAccessor accessor] => Pointer + accessor;
Exemple #7
0
 public                 IntPtr this[ParticleFieldAccessor accessor] => accessor[Index];