Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Solving Merge issues

  • Loading branch information...
commit d6646ded3d1a8dd66fa3378ab9f9bd33aa980cc4 1 parent a725109
@tpastor tpastor authored
View
387 ArtemisXBOX_PHONE7/Entity.cs
@@ -10,87 +10,102 @@
namespace Artemis
{
- public sealed class Entity {
- private int id;
- private long uniqueId;
- private BigInteger typeBits = 0;
- private BigInteger systemBits = 0;
-
- private EntityWorld world;
- private EntityManager entityManager;
+ public sealed class Entity
+ {
+ private int id;
+ private long uniqueId;
+ private BigInteger typeBits = 0;
+ private BigInteger systemBits = 0;
+
+ private EntityWorld world;
+ private EntityManager entityManager;
private bool enabled = true;
- private bool refreshingState = false;
- private bool deletingState = false;
-
- internal Entity(EntityWorld world, int id) {
- this.world = world;
- this.entityManager = world.EntityManager;
- this.id = id;
- }
-
- /**
- * The internal id for this entity within the framework. No other entity will have the same ID, but
- * ID's are however reused so another entity may acquire this ID if the previous entity was deleted.
- *
- * @return id of the entity.
- */
- internal int Id {
- get { return id;}
- }
-
- public long UniqueId {
- get { return uniqueId; }
- internal set {
+ private bool refreshingState = false;
+ private bool deletingState = false;
+
+ internal Entity(EntityWorld world, int id)
+ {
+ this.world = world;
+ this.entityManager = world.EntityManager;
+ this.id = id;
+ }
+
+ /**
+ * The internal id for this entity within the framework. No other entity will have the same ID, but
+ * ID's are however reused so another entity may acquire this ID if the previous entity was deleted.
+ *
+ * @return id of the entity.
+ */
+ internal int Id
+ {
+ get { return id; }
+ }
+
+ public long UniqueId
+ {
+ get { return uniqueId; }
+ internal set
+ {
System.Diagnostics.Debug.Assert(uniqueId >= 0);
uniqueId = value;
}
- }
-
- internal BigInteger TypeBits {
- get { return typeBits; }
- set { typeBits = value; }
- }
-
- internal void AddTypeBit(BigInteger bit) {
- typeBits |= bit;
- }
-
- internal void RemoveTypeBit(BigInteger bit) {
- typeBits &= ~bit;
- }
-
- public bool RefreshingState {
- get { return refreshingState; }
- set { refreshingState = value; }
- }
-
- public bool DeletingState {
- get { return deletingState; }
- set { deletingState = value; }
- }
-
- internal BigInteger SystemBits {
- get { return systemBits;}
- set { systemBits = value; }
- }
-
- internal void AddSystemBit(BigInteger bit) {
- systemBits |= bit;
- }
-
- internal void RemoveSystemBit(BigInteger bit) {
- systemBits &= ~bit;
- }
-
- public void Reset() {
- systemBits = 0;
- typeBits = 0;
- enabled = true;
- }
-
- public override String ToString() {
- return "Entity["+id+"]";
- }
+ }
+
+ internal BigInteger TypeBits
+ {
+ get { return typeBits; }
+ set { typeBits = value; }
+ }
+
+ internal void AddTypeBit(BigInteger bit)
+ {
+ typeBits |= bit;
+ }
+
+ internal void RemoveTypeBit(BigInteger bit)
+ {
+ typeBits &= ~bit;
+ }
+
+ public bool RefreshingState
+ {
+ get { return refreshingState; }
+ set { refreshingState = value; }
+ }
+
+ public bool DeletingState
+ {
+ get { return deletingState; }
+ set { deletingState = value; }
+ }
+
+ internal BigInteger SystemBits
+ {
+ get { return systemBits; }
+ set { systemBits = value; }
+ }
+
+ internal void AddSystemBit(BigInteger bit)
+ {
+ systemBits |= bit;
+ }
+
+ internal void RemoveSystemBit(BigInteger bit)
+ {
+ systemBits &= ~bit;
+ }
+
+ public void Reset()
+ {
+ systemBits = 0;
+ typeBits = 0;
+ enabled = true;
+ }
+
+ public override String ToString()
+ {
+ return "Entity[" + id + "]";
+ }
public bool Enabled
{
@@ -101,116 +116,134 @@ public bool Enabled
set
{
enabled = value;
- }
+ }
}
- /**
- * Add a component to this entity.
- * @param component to add to this entity
- */
- public void AddComponent(Component component){
+ /**
+ * Add a component to this entity.
+ * @param component to add to this entity
+ */
+ public void AddComponent(Component component)
+ {
System.Diagnostics.Debug.Assert(component != null);
- entityManager.AddComponent(this, component);
- }
-
- public void AddComponent<T>(Component component) where T : Component {
+ entityManager.AddComponent(this, component);
+ }
+
+ public void AddComponent<T>(Component component) where T : Component
+ {
System.Diagnostics.Debug.Assert(component != null);
- entityManager.AddComponent<T>(this, component);
- }
-
- /**
- * Removes the component from this entity.
- * @param component to remove from this entity.
- */
- public void RemoveComponent<T>(Component component) where T : Component{
+ entityManager.AddComponent<T>(this, component);
+ }
+
+ /**
+ * Removes the component from this entity.
+ * @param component to remove from this entity.
+ */
+ public void RemoveComponent<T>(Component component) where T : Component
+ {
System.Diagnostics.Debug.Assert(component != null);
- entityManager.RemoveComponent<T>(this, component);
- }
-
- /**
- * Faster removal of components from a entity.
- * @param component to remove from this entity.
- */
- public void RemoveComponent(ComponentType type){
+ entityManager.RemoveComponent<T>(this, component);
+ }
+
+ /**
+ * Faster removal of components from a entity.
+ * @param component to remove from this entity.
+ */
+ public void RemoveComponent(ComponentType type)
+ {
System.Diagnostics.Debug.Assert(type != null);
- entityManager.RemoveComponent(this, type);
- }
-
- /**
- * Checks if the entity has been deleted from somewhere.
- * @return if it's active.
- */
- public bool isActive{
+ entityManager.RemoveComponent(this, type);
+ }
+
+ /**
+ * Checks if the entity has been deleted from somewhere.
+ * @return if it's active.
+ */
+ public bool isActive
+ {
get
{
return entityManager.IsActive(id);
}
- }
-
- /**
- * This is the preferred method to use when retrieving a component from a entity. It will provide good performance.
- *
- * @param type in order to retrieve the component fast you must provide a ComponentType instance for the expected component.
- * @return
- */
- public Component GetComponent(ComponentType type) {
+ }
+
+ /**
+ * This is the preferred method to use when retrieving a component from a entity. It will provide good performance.
+ *
+ * @param type in order to retrieve the component fast you must provide a ComponentType instance for the expected component.
+ * @return
+ */
+ public Component GetComponent(ComponentType type)
+ {
System.Diagnostics.Debug.Assert(type != null);
- return entityManager.GetComponent(this, type);
- }
-
- /**
- * 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>());
- }
-
- /**
- * Get all components belonging to this entity.
- * WARNING. Use only for debugging purposes, it is dead slow.
- * WARNING. The returned bag is only valid until this method is called again, then it is overwritten.
- * @return all components of this entity.
- */
- public Bag<Component> Components {
+ return entityManager.GetComponent(this, type);
+ }
+
+ /**
+ * 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 bool HasComponent<T>() where T : Component
+ {
+ return (T)GetComponent(ComponentTypeManager.GetTypeFor<T>()) != null;
+ }
+
+
+ /**
+ * Get all components belonging to this entity.
+ * WARNING. Use only for debugging purposes, it is dead slow.
+ * WARNING. The returned bag is only valid until this method is called again, then it is overwritten.
+ * @return all components of this entity.
+ */
+ public Bag<Component> Components
+ {
get
{
return entityManager.GetComponents(this);
}
- }
-
- /**
- * Refresh all changes to components for this entity. After adding or removing components, you must call
- * this method. It will update all relevant systems.
- * It is typical to call this after adding components to a newly created entity.
- */
- public void Refresh() {
- if(refreshingState == true) {
- return;
- }
- world.RefreshEntity(this);
- refreshingState = true;
- }
-
- /**
- * Delete this entity from the world.
- */
- public void Delete() {
- if(deletingState == true) {
- return;
- }
- world.DeleteEntity(this);
- deletingState = true;
- }
-
- /**
- * Set the group of the entity. Same as World.setGroup().
- * @param group of the entity.
- */
+ }
+
+ /**
+ * Refresh all changes to components for this entity. After adding or removing components, you must call
+ * this method. It will update all relevant systems.
+ * It is typical to call this after adding components to a newly created entity.
+ */
+ public void Refresh()
+ {
+ if (refreshingState == true)
+ {
+ return;
+ }
+ world.RefreshEntity(this);
+ refreshingState = true;
+ }
+
+ /**
+ * Delete this entity from the world.
+ */
+ public void Delete()
+ {
+ if (deletingState == true)
+ {
+ return;
+ }
+ world.DeleteEntity(this);
+ deletingState = true;
+ }
+
+ /**
+ * Set the group of the entity. Same as World.setGroup().
+ * @param group of the entity.
+ */
public String Group
{
get
@@ -223,11 +256,11 @@ public String Group
}
}
-
- /**
- * Assign a tag to this entity. Same as World.setTag().
- * @param tag of the entity.
- */
+
+ /**
+ * Assign a tag to this entity. Same as World.setTag().
+ * @param tag of the entity.
+ */
public String Tag
{
get
@@ -239,6 +272,6 @@ public String Tag
world.TagManager.Register(value, this);
}
}
- }
+ }
}
View
5 Artemis_XNA_INDEPENDENT/Entity.cs
@@ -169,6 +169,11 @@ public bool Enabled
public T GetComponent<T>() where T : Component {
return (T)GetComponent(ComponentTypeManager.GetTypeFor<T>());
}
+
+ public bool HasComponent<T>() where T : Component {
+ return (T)GetComponent(ComponentTypeManager.GetTypeFor<T>()) != null;
+ }
+
/**
* Get all components belonging to this entity.
View
BIN  artemis.suo
Binary file not shown

3 comments on commit d6646de

@tpastor
Collaborator

Tem que pegar este ultimo commit e verificar se a versao MonoTouch quebra.
Testei no wp7/xbox e pc

->Overview de tudo q foi alterado nos ultimos commits
More c# Like
Adicionei VARIOS asserts no codigo (so rodam em modo debug, em release eles "somem")
deixei internal todos os metodos redundandes e todos aqueles que o usuario NAO deve chamar
botei inumerable na bag

@tpastor
Collaborator

tenta botar essa versao no starwarrior e ver oq acontece =P

@thelinuxlich

podeixar

Please sign in to comment.
Something went wrong with that request. Please try again.