public void AddComponent <T>(Entity e, Component component) where T : Component { ComponentType type = ComponentTypeManager.GetTypeFor <T>(); if (type.GetId() >= componentsByType.GetCapacity()) { componentsByType.Set(type.GetId(), null); } Bag <Component> components = componentsByType.Get(type.GetId()); if (components == null) { components = new Bag <Component>(); componentsByType.Set(type.GetId(), components); } components.Set(e.GetId(), component); e.AddTypeBit(type.GetBit()); if (AddedComponentEvent != null) { AddedComponentEvent(e, component); } }
/// <summary> /// Add a component to the given entity /// If the component's type does not already exist, add it to the bag of availalbe component types /// </summary> /// <typeparam name="T">Component type you want to add</typeparam> /// <param name="e">The entity to which you want to add the component</param> /// <param name="component">The component instance you want to add</param> internal void AddComponent <T>(Entity e, Component component) where T : Component { System.Diagnostics.Debug.Assert(component != null); System.Diagnostics.Debug.Assert(e != null); ComponentType type = ComponentTypeManager.GetTypeFor <T>(); if (type.Id >= componentsByType.Capacity) { componentsByType.Set(type.Id, null); } Bag <Component> components = componentsByType.Get(type.Id); if (components == null) { components = new Bag <Component>(); componentsByType.Set(type.Id, components); } components.Set(e.Id, component); e.AddTypeBit(type.Bit); if (AddedComponentEvent != null) { AddedComponentEvent(e, component); } }
/// <summary>Initializes a new instance of the <see cref="ComponentMapper{T}"/> class.</summary> /// <param name="entityWorld">The entity world.</param> public ComponentMapper(EntityWorld entityWorld) { Debug.Assert(entityWorld != null, "Entity world must not be null."); this.entityManager = entityWorld.EntityManager; this.componentType = ComponentTypeManager.GetTypeFor <T>(); }
/// <summary> /// Removes the given component from the given entity /// </summary> /// <typeparam name="T">The type of the component you want to remove</typeparam> /// <param name="e">The entity for which you are removing the component</param> /// <param name="component">The specific component instance you want removed</param> internal void RemoveComponent <T>(Entity e, Component component) where T : Component { System.Diagnostics.Debug.Assert(component != null); System.Diagnostics.Debug.Assert(e != null); ComponentType type = ComponentTypeManager.GetTypeFor <T>(); RemoveComponent(e, type); }
public HybridQueueSystemProcessing(Type requiredType, params Type[] otherTypes) : base(requiredType, otherTypes) { foreach (var item in GetMergedTypes(requiredType, otherTypes)) { compTypes.Add(ComponentTypeManager.GetTypeFor(item)); } }
public EntitySystem(params Type[] types) { for (int i = 0, j = types.Length; i < j; i++) { Type type = types[i]; ComponentType ct = ComponentTypeManager.GetTypeFor(type); typeFlags |= ct.GetBit(); } }
/// <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>Marks the component to remove. The actual removal is deferred and will happen in the next EntityWorld update.</summary> /// <typeparam name="T">Component Type.</typeparam> public void RemoveComponent <T>() where T : IComponent { this.entityManager.RemoveComponent(this, ComponentTypeManager.GetTypeFor <T>()); }
public bool HasComponent <T>() where T : Component { return((T)GetComponent(ComponentTypeManager.GetTypeFor <T>()) != null); }
/** * Slower retrieval of components from this entity. Minimize usage of this, but is fine to use e.g. when creating new entities * and setting data in components. * @param <T> the expected return component type. * @param type the expected return component type. * @return component that matches, or null if none is found. */ public T GetComponent <T>() where T : Component { return((T)GetComponent(ComponentTypeManager.GetTypeFor <T>())); }
public ComponentMapper(EntityWorld world) { this.em = world.GetEntityManager(); this.type = ComponentTypeManager.GetTypeFor <T>(); }
public void RemoveComponent <T>(Entity e, Component component) where T : Component { ComponentType type = ComponentTypeManager.GetTypeFor <T>(); RemoveComponent(e, type); }
/// <summary> /// Creates a component mapper within the given Entity World /// </summary> /// <param name="world">EntityWorld</param> public ComponentMapper(EntityWorld world) { System.Diagnostics.Debug.Assert(world != null); em = world.EntityManager; type = ComponentTypeManager.GetTypeFor <T>(); }