Exemple #1
0
 /// <summary>Creates an enumerable from a <c>BigIntger</c> which holds type bits.</summary>
 /// <param name="bits">The BigInteger which holds the type bits.</param>
 /// <returns>An Enumerable of each type the bits has.</returns>
 internal static IEnumerable <Type> GetTypesFromBits(BigInteger bits)
 {
     foreach (KeyValuePair <Type, ComponentType> keyValuePair in ComponentTypes)
     {
         if ((keyValuePair.Value.Bit & bits) != 0)
         {
             yield return(keyValuePair.Key);
         }
     }
 }
        /// <summary>Gets the one.</summary>
        /// <param name="types">The types.</param>
        /// <returns>The specified Aspect.</returns>
        public Aspect GetOne(params Type[] types)
        {
            Debug.Assert(types != null, "Types must not be null.");

            foreach (ComponentType componentType in types.Select(ComponentTypeManager.GetTypeFor))
            {
                this.OneTypesMap |= componentType.Bit;
            }

            return(this);
        }
 /// <summary>Appends the types.</summary>
 /// <param name="builder">The builder.</param>
 /// <param name="headerMessage">The header message.</param>
 /// <param name="typeBits">The type bits.</param>
 private static void AppendTypes(StringBuilder builder, string headerMessage, BigInteger typeBits)
 {
     if (typeBits != 0)
     {
         builder.AppendLine(headerMessage);
         foreach (Type type in ComponentTypeManager.GetTypesFromBits(typeBits))
         {
             builder.Append(", ");
             builder.AppendLine(type.Name);
         }
     }
 }
Exemple #4
0
        /// <summary>Initializes a new instance of the <see cref="ComponentType"/> class.</summary>
        internal ComponentType()
        {
#if XBOX || WINDOWS_PHONE || PORTABLE || FORCEINT32
            if (nextId == 32)
            {
                // nextBit has overflown and is 0 now
                throw new InvalidOperationException("Distinct ComponentType limit reached: number of ComponentType types is restricted to 32 in the current Artemis build.");
            }
#endif

            this.Id  = nextId;
            this.Bit = nextBit;

            nextId++;
            nextBit <<= 1;
        }
        /// <summary>Gets the bit-register for the specified entity system.</summary>
        /// <param name="entitySystem">The entity system.</param>
        /// <returns>The bit flag register for the specified system.</returns>
        public BigInteger GetBitFor(EntitySystem entitySystem)
        {
            BigInteger bit;
            if (this.systemBits.TryGetValue(entitySystem, out bit) == false)
            {
#if WINDOWS_PHONE || XBOX || PORTABLE || FORCEINT32
                if (this.position == 32)
                {
                    // bit is going to overflow and become 1 again
                    throw new InvalidOperationException("EntitySystem instances limit reached: number of EntitySystem instances is restricted to 32 in the current Artemis build.");
                }

                bit = 1 << this.position;
#else
                bit = new BigInteger(1) << this.position;
#endif
                this.position++;
                this.systemBits.Add(entitySystem, bit);
            }

            return bit;
        }
        /// <summary>Gets the bit-register for the specified entity system.</summary>
        /// <param name="entitySystem">The entity system.</param>
        /// <returns>The bit flag register for the specified system.</returns>
        public BigInteger GetBitFor(EntitySystem entitySystem)
        {
            BigInteger bit;

            if (this.systemBits.TryGetValue(entitySystem, out bit) == false)
            {
#if WINDOWS_PHONE || XBOX || PORTABLE || FORCEINT32
                if (this.position == 32)
                {
                    // bit is going to overflow and become 1 again
                    throw new InvalidOperationException("EntitySystem instances limit reached: number of EntitySystem instances is restricted to 32 in the current Artemis build.");
                }

                bit = 1 << this.position;
#else
                bit = new BigInteger(1) << this.position;
#endif
                this.position++;
                this.systemBits.Add(entitySystem, bit);
            }

            return(bit);
        }
 /// <summary>Appends the types.</summary>
 /// <param name="builder">The builder.</param>
 /// <param name="headerMessage">The header message.</param>
 /// <param name="typeBits">The type bits.</param>
 private static void AppendTypes(StringBuilder builder, string headerMessage, BigInteger typeBits)
 {
     if (typeBits != 0)
     {
         builder.AppendLine(headerMessage);
         foreach (Type type in ComponentTypeManager.GetTypesFromBits(typeBits))
         {
             builder.Append(", ");
             builder.AppendLine(type.Name);
         }
     }
 }
        /// <summary>Gets the one.</summary>
        /// <param name="types">The types.</param>
        /// <returns>The specified Aspect.</returns>
        public Aspect GetOne(params Type[] types)
        {
            Debug.Assert(types != null, "Types must not be null.");

            foreach (ComponentType componentType in types.Select(ComponentTypeManager.GetTypeFor))
            {
                this.OneTypesMap |= componentType.Bit;
            }

            return this;
        }
Exemple #9
0
        /// <summary>Initializes a new instance of the <see cref="ComponentType"/> class.</summary>
        internal ComponentType()
        {
            #if XBOX || WINDOWS_PHONE || PORTABLE || FORCEINT32
            if (nextId == 32)
            {
                // nextBit has overflown and is 0 now
                throw new InvalidOperationException("Distinct ComponentType limit reached: number of ComponentType types is restricted to 32 in the current Artemis build.");
            }
            #endif

            this.Id = nextId;
            this.Bit = nextBit;

            nextId++;
            nextBit <<= 1;
        }
Exemple #10
0
 /// <summary>Initializes static members of the <see cref="ComponentType"/> class.</summary>
 static ComponentType()
 {
     nextBit = 1;
     nextId = 0;
 }
Exemple #11
0
 /// <summary>Initializes static members of the <see cref="ComponentType"/> class.</summary>
 static ComponentType()
 {
     nextBit = 1;
     nextId  = 0;
 }
Exemple #12
0
        /// <summary>Gets the one.</summary>
        /// <param name="types">The types.</param>
        /// <returns>The specified Aspect.</returns>
        public Aspect GetOne(params Type[] types)
        {
            Debug.Assert(types != null, "Types must not be null.");
            for(int i = 0; i < types.Length; ++i)
            {
                ComponentType componentType = ComponentTypeManager.GetTypeFor(types[i]);
                this.OneTypesMap |= componentType.Bit;
            }

            return this;
        }