Browse files

Updating the XBOX/WP7 version

  • Loading branch information...
1 parent 4a7d8a5 commit d0f74cb8823a01ca0d761df49cd598b5dc8d5a81 @thelinuxlich committed Apr 20, 2012
View
9 ArtemisXBOX_PHONE7/BlackBoard/BlackBoard.cs
@@ -24,7 +24,8 @@ public void SetEntry<T>(String name, T intel)
{
foreach (var item in triggers[name])
{
- item.Fire(TriggerState);
+ if(item.fired ==false)
+ item.Fire(TriggerState);
}
}
}
@@ -50,7 +51,8 @@ public void RemoveEntry(String name)
{
foreach (var item in triggers[name])
{
- item.Fire(TriggerState.VALUE_REMOVED);
+ if (item.fired == false)
+ item.Fire(TriggerState.VALUE_REMOVED);
}
}
}
@@ -90,7 +92,8 @@ public void AddTrigger(Trigger Trigger, bool evaluateNow = false)
}
if (evaluateNow)
{
- Trigger.Fire(TriggerState.TRIGGER_ADDED);
+ if (Trigger.fired == false)
+ Trigger.Fire(TriggerState.TRIGGER_ADDED);
}
}
}
View
3 ArtemisXBOX_PHONE7/BlackBoard/Trigger.cs
@@ -39,15 +39,18 @@ public void RemoveThisTrigger()
BlackBoard.RemoveTrigger(this);
}
+ internal bool fired = false;
internal void Fire(TriggerState TriggerState)
{
+ fired = true;
this.TriggerState = TriggerState;
if (CheckConditionToFire())
{
CalledOnFire(TriggerState);
if (OnFire != null)
OnFire(this);
}
+ fired = false;
}
public event Action<Trigger> OnFire;
View
15 ArtemisXBOX_PHONE7/ComponentMapper.cs
@@ -5,34 +5,29 @@ public sealed class ComponentMapper<T> where T : Component {
private ComponentType type;
private EntityManager em;
-
/// <summary>
/// Allows you to interact with components that are mapped to entities
/// </summary>
public ComponentMapper() { }
-
/// <summary>
/// Creates a component mapper within the given Entity World
/// </summary>
/// <param name="world">EntityWorld</param>
public ComponentMapper(EntityWorld world) {
- this.em = world.GetEntityManager();
- this.type = ComponentTypeManager.GetTypeFor<T>();
+ em = world.EntityManager;
+ type = ComponentTypeManager.GetTypeFor<T>();
}
-
-
/// <summary>
/// Sets the entity manager for this component mapper
/// </summary>
/// <param name="em">Entity Manager that manages the component</param>
- public void SetEntityManager(EntityManager em)
+ public EntityManager EntityManager
{
- this.em = em;
+ set { em = value; }
}
-
-
+
/// <summary>
/// Gets the component for the given entity/component type combo
/// </summary>
View
13 ArtemisXBOX_PHONE7/ComponentType.cs
@@ -1,11 +1,12 @@
using System;
+using System.Numerics;
namespace Artemis
{
public sealed class ComponentType {
- private static long nextBit = 1;
+ private static BigInteger nextBit = 1;
private static int nextId = 0;
- private long bit;
+ private BigInteger bit;
private int id;
public ComponentType() {
@@ -18,12 +19,12 @@ public sealed class ComponentType {
id = nextId++;
}
- public long GetBit() {
- return bit;
+ public BigInteger Bit {
+ get { return bit;}
}
- public int GetId() {
- return id;
+ public int Id {
+ get { return id; }
}
}
}
View
12 ArtemisXBOX_PHONE7/ComponentTypeManager.cs
@@ -1,10 +1,11 @@
using System;
using System.Collections.Generic;
+using System.Numerics;
namespace Artemis
{
public static class ComponentTypeManager {
private static Dictionary<Type, ComponentType> componentTypes = new Dictionary<Type, ComponentType>();
-
+
/// <summary>
/// Get the component type for the given component instance
/// </summary>
@@ -20,7 +21,6 @@ public static class ComponentTypeManager {
}
return type;
}
-
/// <summary>
/// Ensure the given component type [tag] is an "official" component type for your solution
@@ -39,16 +39,14 @@ public static ComponentType GetTypeFor(Type component)
return type;
}
-
-
- public static long GetBit<T>() where T : Component
+ public static BigInteger GetBit<T>() where T : Component
{
- return GetTypeFor<T>().GetBit();
+ return GetTypeFor<T>().Bit;
}
public static int GetId<T>() where T : Component
{
- return GetTypeFor<T>().GetId();
+ return GetTypeFor<T>().Id;
}
}
}
View
5 ArtemisXBOX_PHONE7/DelayedEntityProcessingSystem.cs
@@ -4,6 +4,7 @@ namespace Artemis
{
public abstract class DelayedEntityProcessingSystem : DelayedEntitySystem {
+
/// <summary>
/// Create a new DelayedEntityProcessingSystem. It requires at least one component.
/// </summary>
@@ -12,8 +13,6 @@ public abstract class DelayedEntityProcessingSystem : DelayedEntitySystem {
public DelayedEntityProcessingSystem(Type requiredType,params Type[] otherTypes) : base(GetMergedTypes(requiredType, otherTypes)){
}
-
-
/// <summary>
/// Process an entity this system is interested in.
/// </summary>
@@ -22,8 +21,6 @@ public abstract class DelayedEntityProcessingSystem : DelayedEntitySystem {
public abstract void Process(Entity e, int accumulatedDelta);
-
-
/// <summary>
/// Process all entities with the delayed Entity processing system
/// </summary>
View
12 ArtemisXBOX_PHONE7/DelayedEntitySystem.cs
@@ -19,7 +19,7 @@ protected override void ProcessEntities(Dictionary<int, Entity> entities)
protected override bool CheckProcessing()
{
if(running) {
- acc += world.GetDelta();
+ acc += world.Delta;
if(acc >= delay) {
return enabled;
@@ -46,7 +46,7 @@ protected override bool CheckProcessing()
*/
public void StartDelayedRun(int delay) {
this.delay = delay;
- this.acc = 0;
+ acc = 0;
running = true;
}
@@ -55,8 +55,8 @@ protected override bool CheckProcessing()
*
* @return the originally set delay.
*/
- public int GetInitialTimeDelay() {
- return delay;
+ public int InitialTimeDelay {
+ get { return delay;}
}
public int GetRemainingTimeUntilProcessing() {
@@ -79,8 +79,8 @@ protected override bool CheckProcessing()
* Aborts running the system in the future and stops it. Call delayedRun() to start it again.
*/
public void Stop() {
- this.running = false;
- this.acc = 0;
+ running = false;
+ acc = 0;
}
}
View
88 ArtemisXBOX_PHONE7/Entity.cs
@@ -1,21 +1,24 @@
using System;
+using System.Numerics;
namespace Artemis
{
public sealed class Entity {
private int id;
private long uniqueId;
- private long typeBits = 0;
- private long systemBits = 0;
+ private BigInteger typeBits = 0;
+ private BigInteger systemBits = 0;
private EntityWorld world;
private EntityManager entityManager;
+ private string staticKey = "";
+ private bool enabled = true;
public Entity() {
}
public Entity(EntityWorld world, int id) {
this.world = world;
- this.entityManager = world.GetEntityManager();
+ this.entityManager = world.EntityManager;
this.id = id;
}
@@ -25,54 +28,41 @@ public sealed class Entity {
*
* @return id of the entity.
*/
- public int GetId() {
- return id;
+ public int Id {
+ get { return id;}
}
- public void SetUniqueId(long uniqueId) {
- this.uniqueId = uniqueId;
+ public long UniqueId {
+ get { return uniqueId; }
+ set { uniqueId = value;}
}
- /**
- * Get the unique ID of this entity. Because entity instances are reused internally use this to identify between different instances.
- * @return the unique id of this entity.
- */
- public long GetUniqueId() {
- return uniqueId;
+ public BigInteger TypeBits {
+ get { return typeBits; }
+ set { typeBits = value; }
}
- public long GetTypeBits() {
- return typeBits;
- }
-
- public void AddTypeBit(long bit) {
+ public void AddTypeBit(BigInteger bit) {
typeBits |= bit;
}
- public void RemoveTypeBit(long bit) {
+ public void RemoveTypeBit(BigInteger bit) {
typeBits &= ~bit;
}
- public long GetSystemBits() {
- return systemBits;
+ public BigInteger SystemBits {
+ get { return systemBits;}
+ set { systemBits = value; }
}
- public void AddSystemBit(long bit) {
+ public void AddSystemBit(BigInteger bit) {
systemBits |= bit;
}
- public void RemoveSystemBit(long bit) {
+ public void RemoveSystemBit(BigInteger bit) {
systemBits &= ~bit;
}
- public void SetSystemBits(long systemBits) {
- this.systemBits = systemBits;
- }
-
- public void SetTypeBits(long typeBits) {
- this.typeBits = typeBits;
- }
-
public void Reset() {
systemBits = 0;
typeBits = 0;
@@ -81,7 +71,23 @@ public sealed class Entity {
public override String ToString() {
return "Entity["+id+"]";
}
-
+
+ public string StaticKey
+ {
+ get { return staticKey; }
+ set { staticKey = value;}
+ }
+
+ public void Enable()
+ {
+ this.enabled = true;
+ }
+
+ public void Disable()
+ {
+ this.enabled = false;
+ }
+
/**
* Add a component to this entity.
* @param component to add to this entity
@@ -117,7 +123,12 @@ public sealed class Entity {
public bool IsActive(){
return entityManager.IsActive(id);
}
-
+
+ public bool IsEnabled()
+ {
+ return enabled;
+ }
+
/**
* This is the preferred method to use when retrieving a component from a entity. It will provide good performance.
*
@@ -164,25 +175,30 @@ public sealed class Entity {
public void Delete() {
world.DeleteEntity(this);
}
+
+ public void Suspend()
+ {
+ world.SuspendEntity(this);
+ }
/**
* Set the group of the entity. Same as World.setGroup().
* @param group of the entity.
*/
public void SetGroup(String group) {
- world.GetGroupManager().Set(group, this);
+ world.GroupManager.Set(group, this);
}
/**
* Assign a tag to this entity. Same as World.setTag().
* @param tag of the entity.
*/
public void SetTag(String tag) {
- world.GetTagManager().Register(tag, this);
+ world.TagManager.Register(tag, this);
}
public String GetTag() {
- return world.GetTagManager().GetTagOfEntity(this);
+ return world.TagManager.GetTagOfEntity(this);
}
}
}
View
104 ArtemisXBOX_PHONE7/EntityManager.cs
@@ -27,7 +27,7 @@ public sealed class EntityManager {
public EntityManager(EntityWorld world) {
this.world = world;
}
-
+
/// <summary>
/// Create a new, "blank" entity
@@ -40,24 +40,25 @@ public sealed class EntityManager {
} else {
e.Reset();
}
- e.SetUniqueId(uniqueEntityId++);
- activeEntities.Set(e.GetId(),e);
+ e.UniqueId = uniqueEntityId++;
+ activeEntities.Set(e.Id,e);
count++;
totalCreated++;
if(AddedEntityEvent != null) {
AddedEntityEvent(e);
}
return e;
}
-
+
+
/// <summary>
/// Remove an entity from the world
/// </summary>
/// <param name="e">Entity you want to remove</param>
public void Remove(Entity e) {
- activeEntities.Set(e.GetId(), null);
+ activeEntities.Set(e.Id, null);
- e.SetTypeBits(0);
+ e.TypeBits = 0;
Refresh(e);
@@ -71,14 +72,14 @@ public sealed class EntityManager {
RemovedEntityEvent(e);
}
}
-
+
/// <summary>
/// Strips all components from the given entity
/// </summary>
/// <param name="e">Entity for which you want to remove all components</param>
private void RemoveComponentsOfEntity(Entity e) {
- int entityId = e.GetId();
+ int entityId = e.Id;
for(int a = 0,b = componentsByType.Size(); b > a; a++) {
Bag<Component> components = componentsByType.Get(a);
if(components != null && entityId < components.Size()) {
@@ -89,7 +90,7 @@ public sealed class EntityManager {
}
}
}
-
+
/// <summary>
/// Check if this entity is active, or has been deleted, within the framework.
/// </summary>
@@ -98,8 +99,7 @@ public sealed class EntityManager {
public bool IsActive(int entityId) {
return activeEntities.Get(entityId) != null;
}
-
-
+
/// <summary>
/// Add the given component to the given entity
@@ -109,23 +109,24 @@ public sealed class EntityManager {
public void AddComponent(Entity e, Component component) {
ComponentType type = ComponentTypeManager.GetTypeFor(component.GetType());
- if(type.GetId() >= componentsByType.GetCapacity()) {
- componentsByType.Set(type.GetId(), null);
+ if(type.Id >= componentsByType.GetCapacity()) {
+ componentsByType.Set(type.Id, null);
}
- Bag<Component> components = componentsByType.Get(type.GetId());
+ Bag<Component> components = componentsByType.Get(type.Id);
if(components == null) {
components = new Bag<Component>();
- componentsByType.Set(type.GetId(), components);
+ componentsByType.Set(type.Id, components);
}
- components.Set(e.GetId(), component);
+ components.Set(e.Id, component);
- e.AddTypeBit(type.GetBit());
+ e.AddTypeBit(type.Bit);
if(AddedComponentEvent != null) {
AddedComponentEvent(e,component);
}
}
+
/// <summary>
@@ -138,37 +139,38 @@ public sealed class EntityManager {
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);
+ if(type.Id >= componentsByType.GetCapacity()) {
+ componentsByType.Set(type.Id, null);
}
- Bag<Component> components = componentsByType.Get(type.GetId());
+ Bag<Component> components = componentsByType.Get(type.Id);
if(components == null) {
components = new Bag<Component>();
- componentsByType.Set(type.GetId(), components);
+ componentsByType.Set(type.Id, components);
}
- components.Set(e.GetId(), component);
+ components.Set(e.Id, component);
- e.AddTypeBit(type.GetBit());
+ e.AddTypeBit(type.Bit);
if(AddedComponentEvent != null) {
AddedComponentEvent(e,component);
}
}
-
+
/// <summary>
/// Ensure the any changes to components are synced up with the entity - ensure systems "see" all components
/// </summary>
/// <param name="e">The entity whose components you want to refresh</param>
public void Refresh(Entity e) {
- SystemManager systemManager = world.GetSystemManager();
- Bag<EntitySystem> systems = systemManager.GetSystems();
+ SystemManager systemManager = world.SystemManager;
+ Bag<EntitySystem> systems = systemManager.Systems;
for(int i = 0, s=systems.Size(); s > i; i++) {
systems.Get(i).Change(e);
}
}
-
+
+
/// <summary>
/// Removes the given component from the given entity
@@ -180,7 +182,7 @@ public sealed class EntityManager {
ComponentType type = ComponentTypeManager.GetTypeFor<T>();
RemoveComponent(e, type);
}
-
+
/// <summary>
@@ -189,15 +191,15 @@ public sealed class EntityManager {
/// <param name="e">The entity for which you want to remove the component</param>
/// <param name="type">The component type you want to remove</param>
public void RemoveComponent(Entity e, ComponentType type) {
- int entityId = e.GetId();
- Bag<Component> components = componentsByType.Get(type.GetId());
+ int entityId = e.Id;
+ Bag<Component> components = componentsByType.Get(type.Id);
if(RemovedComponentEvent != null) {
RemovedComponentEvent(e,components.Get(entityId));
}
components.Set(entityId, null);
- e.RemoveTypeBit(type.GetBit());
+ e.RemoveTypeBit(type.Bit);
}
-
+
/// <summary>
/// Get the component instance of the given component type for the given entity
@@ -206,14 +208,13 @@ public sealed class EntityManager {
/// <param name="type">The desired component type</param>
/// <returns>Component instance</returns>
public Component GetComponent(Entity e, ComponentType type) {
- int entityId = e.GetId();
- Bag<Component> bag = componentsByType.Get(type.GetId());
+ int entityId = e.Id;
+ Bag<Component> bag = componentsByType.Get(type.Id);
if(bag != null && entityId < bag.GetCapacity())
return bag.Get(entityId);
return null;
}
-
-
+
/// <summary>
/// Get the entity for the given entityId
@@ -223,41 +224,39 @@ public sealed class EntityManager {
public Entity GetEntity(int entityId) {
return activeEntities.Get(entityId);
}
-
+
/// <summary>
/// Get how many entities are currently active
/// </summary>
/// <returns>How many entities are currently active</returns>
- public int GetEntityCount() {
- return count;
+ public int EntityCount {
+ get { return count;}
}
-
+
/// <summary>
/// Get how many entities have been created since start.
/// </summary>
/// <returns>The total number of entities created</returns>
- public long GetTotalCreated() {
- return totalCreated;
+ public long TotalCreated {
+ get { return totalCreated;}
}
-
+
/// <summary>
/// Gets how many entities have been removed since start.
/// </summary>
/// <returns>The total number of removed entities</returns>
- public long GetTotalRemoved() {
- return totalRemoved;
+ public long TotalRemoved {
+ get { return totalRemoved;}
}
-
-
-
+
/// <summary>
/// Get all components assigned to an entity
/// </summary>
/// <param name="e">Entity for which you want the components</param>
/// <returns>Bag of components</returns>
public Bag<Component> GetComponents(Entity e) {
entityComponents.Clear();
- int entityId = e.GetId();
+ int entityId = e.Id;
for(int a = 0,b = componentsByType.Size(); b > a; a++) {
Bag<Component> components = componentsByType.Get(a);
if(components != null && entityId < components.Size()) {
@@ -269,14 +268,13 @@ public sealed class EntityManager {
}
return entityComponents;
}
-
-
+
/// <summary>
/// Get all active Entities
/// </summary>
/// <returns>Bag of active entities</returns>
- public Bag<Entity> GetActiveEntities() {
- return activeEntities;
+ public Bag<Entity> ActiveEntities {
+ get { return activeEntities;}
}
}
}
View
5 ArtemisXBOX_PHONE7/EntityProcessingSystem.cs
@@ -22,7 +22,10 @@ protected override void ProcessEntities(Dictionary<int, Entity> entities)
{
foreach (Entity item in entities.Values)
{
- Process(item);
+ if (item.IsEnabled())
+ {
+ Process(item);
+ }
}
}
}
View
26 ArtemisXBOX_PHONE7/EntitySystem.cs
@@ -32,12 +32,12 @@ public static BlackBoard BlackBoard
for (int i = 0, j = types.Length; i < j; i++) {
Type type = types[i];
ComponentType ct = ComponentTypeManager.GetTypeFor(type);
- typeFlags |= ct.GetBit();
+ typeFlags |= ct.Bit;
}
}
- public void SetSystemBit(BigInteger bit) {
- this.systemBit = bit;
+ public BigInteger SystemBit {
+ set { systemBit = value; }
}
/**
@@ -89,26 +89,32 @@ public static BlackBoard BlackBoard
public virtual void Removed(Entity e) { }
public virtual void Change(Entity e) {
- bool contains = (systemBit & e.GetSystemBits()) == systemBit;
- bool interest = (typeFlags & e.GetTypeBits()) == typeFlags;
+ bool contains = (systemBit & e.SystemBits) == systemBit;
+ bool interest = (typeFlags & e.TypeBits) == typeFlags;
if (interest && !contains && typeFlags > 0) {
- actives.Add(e.GetId(),e);
+ actives.Add(e.Id,e);
e.AddSystemBit(systemBit);
Added(e);
} else if (!interest && contains && typeFlags > 0) {
Remove(e);
}
}
+
+ protected void Add(Entity e) {
+ actives.Add(e.Id,e);
+ e.AddSystemBit(systemBit);
+ Added(e);
+ }
- private void Remove(Entity e) {
- actives.Remove(e.GetId());
+ protected void Remove(Entity e) {
+ actives.Remove(e.Id);
e.RemoveSystemBit(systemBit);
Removed(e);
}
- public void SetWorld(EntityWorld world) {
- this.world = world;
+ public EntityWorld World {
+ set { world = value; }
}
public void Toggle() {
View
112 ArtemisXBOX_PHONE7/EntityWorld.cs
@@ -7,10 +7,11 @@ public sealed class EntityWorld {
private EntityManager entityManager;
private TagManager tagManager;
private GroupManager groupManager;
- private Bag<Entity> refreshed = new Bag<Entity>();
- private Bag<Entity> deleted = new Bag<Entity>();
- private ArtemisPool pool;
- private Dictionary<Type,Manager> managers = new Dictionary<Type, Manager>();
+ private Bag<Entity> refreshed = new Bag<Entity>();
+ private Bag<Entity> deleted = new Bag<Entity>();
+ private Bag<Entity> suspended = new Bag<Entity>();
+ private ArtemisPool pool;
+ private Dictionary<String,Stack<int>> cached = new Dictionary<String, Stack<int>>();
private int delta;
@@ -20,50 +21,33 @@ public sealed class EntityWorld {
tagManager = new TagManager(this);
groupManager = new GroupManager(this);
}
- public void SetManager(Manager manager) {
- managers.Add(manager.GetType(), manager);
- }
- public T GetManager<T>() where T : Manager {
- Manager m;
- managers.TryGetValue(typeof(T), out m);
- return (T)m;
- }
-
- public GroupManager GetGroupManager() {
- return groupManager;
+ public GroupManager GroupManager {
+ get { return groupManager; }
}
- public SystemManager GetSystemManager() {
- return systemManager;
+ public SystemManager SystemManager {
+ get { return systemManager; }
}
- public EntityManager GetEntityManager() {
- return entityManager;
+ public EntityManager EntityManager {
+ get { return entityManager; }
}
- public TagManager GetTagManager() {
- return tagManager;
+ public TagManager TagManager {
+ get { return tagManager; }
}
/**
* Time since last game loop.
* @return delta in milliseconds.
*/
- public int GetDelta() {
- return delta;
+ public int Delta {
+ get { return delta; }
+ set { delta = value; }
}
/**
- * You must specify the delta for the game here.
- *
- * @param delta time since last game loop.
- */
- public void SetDelta(int delta) {
- this.delta = delta;
- }
-
- /**
* Delete the provided entity from the world.
* @param e entity
*/
@@ -82,6 +66,12 @@ public sealed class EntityWorld {
public void RefreshEntity(Entity e) {
refreshed.Add(e);
}
+
+ public void SuspendEntity(Entity e)
+ {
+ groupManager.Remove(e);
+ suspended.Add(e);
+ }
/**
* Create and return a new or reused entity instance.
@@ -106,14 +96,43 @@ public sealed class EntityWorld {
return entityManager.GetEntity(entityId);
}
- public void SetPool(ArtemisPool gamePool)
+ public void RegisterStaticEntity(String tag,Entity e)
{
- pool = gamePool;
+ e.Disable();
+ e.StaticKey = tag;
+ entityManager.Refresh(e);
+ if (cached.ContainsKey(tag))
+ {
+ Stack<int> entities;
+ cached.TryGetValue(tag,out entities);
+ entities.Push(e.Id);
+ } else {
+ Stack<int> entities = new Stack<int>();
+ entities.Push(e.Id);
+ cached.Add(tag, entities);
+ }
}
- public ArtemisPool GetPool()
+ public Entity LoadStaticEntity(String tag)
{
- return pool;
+ if (cached.ContainsKey(tag))
+ {
+ Stack<int> entities;
+ cached.TryGetValue(tag, out entities);
+ Entity e = entityManager.GetEntity(entities.Pop());
+ e.Enable();
+ return e;
+ }
+ else
+ {
+ throw new Exception("no more static entities in cache!");
+ }
+ }
+
+ public ArtemisPool Pool
+ {
+ get { return pool; }
+ set { pool = value; }
}
public void LoopStart()
@@ -136,10 +155,23 @@ public void LoopStart()
}
deleted.Clear();
}
+
+ if (!suspended.IsEmpty())
+ {
+ for (int i = 0, j = suspended.Size(); j > i; i++)
+ {
+ Entity e = suspended.Get(i);
+ e.Disable();
+ Stack<int> entities;
+ cached.TryGetValue(e.StaticKey, out entities);
+ entities.Push(e.Id);
+ }
+ suspended.Clear();
+ }
}
public Dictionary<Entity,Bag<Component>> GetCurrentState() {
- Bag<Entity> entities = entityManager.GetActiveEntities();
+ Bag<Entity> entities = entityManager.ActiveEntities;
Dictionary<Entity,Bag<Component>> currentState = new Dictionary<Entity, Bag<Component>>();
for(int i = 0,j = entities.Size(); i < j; i++) {
Entity e = entities.Get(i);
@@ -152,12 +184,12 @@ public void LoopStart()
public void LoadEntityState(String tag,String groupName,Bag<Component> components) {
Entity e;
if(tag != null) {
- e = this.CreateEntity(tag);
+ e = CreateEntity(tag);
} else {
- e = this.CreateEntity();
+ e = CreateEntity();
}
if(groupName != null) {
- this.groupManager.Set(groupName,e);
+ groupManager.Set(groupName,e);
}
for(int i = 0, j = components.Size(); i < j; i++) {
e.AddComponent(components.Get(i));
View
9 ArtemisXBOX_PHONE7/GroupManager.cs
@@ -28,7 +28,7 @@ public sealed class GroupManager {
}
entities.Add(e);
- groupByEntity.Set(e.GetId(), group);
+ groupByEntity.Set(e.Id, group);
}
/**
@@ -42,14 +42,13 @@ public sealed class GroupManager {
return EMPTY_BAG;
return bag;
}
-
-
+
/// <summary>
/// Removes an entity from the group it is assigned to, if any.
/// </summary>
/// <param name="e">The entity to be removed</param>
public void Remove(Entity e) {
- int entityId = e.GetId();
+ int entityId = e.Id;
if(entityId < groupByEntity.GetCapacity()) {
String group = groupByEntity.Get(entityId);
if(group != null) {
@@ -68,7 +67,7 @@ public sealed class GroupManager {
* @return the name of the group that this entity belongs to, null if none.
*/
public String GetGroupOf(Entity e) {
- int entityId = e.GetId();
+ int entityId = e.Id;
if(entityId < groupByEntity.GetCapacity()) {
return groupByEntity.Get(entityId);
}
View
2 ArtemisXBOX_PHONE7/IntervalEntitySystem.cs
@@ -11,7 +11,7 @@ public abstract class IntervalEntitySystem : EntitySystem {
protected override bool CheckProcessing()
{
- acc += world.GetDelta();
+ acc += world.Delta;
if(acc >= interval) {
acc -= interval;
return enabled;
View
2 ArtemisXBOX_PHONE7/IntervalTagSystem.cs
@@ -13,7 +13,7 @@ public abstract class IntervalTagSystem : TagSystem
protected override bool CheckProcessing()
{
- acc += world.GetDelta();
+ acc += world.Delta;
if(acc >= interval) {
acc -= interval;
return enabled;
View
26 ArtemisXBOX_PHONE7/LICENSE.txt
@@ -0,0 +1,26 @@
+Copyright 2011 GAMADU.COM. All rights reserved.
+
+Redistribution and use in source and binary forms, with or without modification, are
+permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice, this list of
+ conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ of conditions and the following disclaimer in the documentation and/or other materials
+ provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED BY GAMADU.COM ``AS IS'' AND ANY EXPRESS OR IMPLIED
+WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GAMADU.COM OR
+CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+The views and conclusions contained in the software and documentation are those of the
+authors and should not be interpreted as representing official policies, either expressed
+or implied, of GAMADU.COM.
+
View
45 ArtemisXBOX_PHONE7/OneShotSystem.cs
@@ -0,0 +1,45 @@
+using System;
+using System.Collections.Generic;
+
+namespace Artemis
+{
+ public abstract class OneShotSystem : EntitySystem
+ {
+ public OneShotSystem () : base()
+ {
+ }
+
+ public override void Change(Entity e)
+ {
+ }
+
+ public override void Initialize() {
+ Enable();
+ }
+
+ public override void Added(Entity e)
+ {
+ Enable();
+ }
+
+ protected override void End()
+ {
+ Disable();
+ }
+
+ public abstract void Process(Entity e);
+
+ protected override void ProcessEntities(Dictionary<int, Entity> entities)
+ {
+ foreach (Entity item in entities.Values)
+ {
+ if (item.IsEnabled())
+ {
+ Process(item);
+ Remove (item);
+ }
+ }
+ }
+ }
+}
+
View
2 ArtemisXBOX_PHONE7/QueueSystemProcessingThreadSafe.cs
@@ -16,7 +16,7 @@ public QueueManager()
this.ReleaseLock();
}
- public void AquireLock()
+ public void AquireLock()
{
Monitor.Enter(lockobj);
}
View
5 ArtemisXBOX_PHONE7/README
@@ -0,0 +1,5 @@
+This is a port of the awesome Entity System framework Artemis by Arni Arent and Tiago Costa - http://gamadu.com/artemis
+
+Currently, we lack documentation and the project is beginning to receive new features(and fix some bugs), but we will not change the Artemis way of using Entities/Components/Systems, rest assured :)
+
+Development discussion can be found here: http://www.ploobs.com.br/forum/viewtopic.php?f=39&t=95
View
7 ArtemisXBOX_PHONE7/SystemBitManager.cs
@@ -1,13 +1,14 @@
using System;
using System.Collections.Generic;
+using System.Numerics;
namespace Artemis
{
public static class SystemBitManager {
private static int POS = 0;
- private static Dictionary<EntitySystem, long> systemBits = new Dictionary<EntitySystem, long>();
+ private static Dictionary<EntitySystem, BigInteger> systemBits = new Dictionary<EntitySystem, BigInteger>();
- public static long GetBitFor(EntitySystem es){
- long bit;
+ public static BigInteger GetBitFor(EntitySystem es){
+ BigInteger bit;
bool hasBit = systemBits.TryGetValue(es, out bit);
if(!hasBit){
bit = 1L << POS;
View
2 ArtemisXBOX_PHONE7/SystemManager.cs
@@ -60,7 +60,7 @@ public sealed class SystemManager {
}
if(!mergedBag.Contains((EntitySystem)system))
mergedBag.Add((EntitySystem)system);
- system.SetSystemBit(SystemBitManager.GetBitFor(system));
+ system.SystemBit = SystemBitManager.GetBitFor(system);
return (T)system;
}
View
2 ArtemisXBOX_PHONE7/TagSystem.cs
@@ -20,7 +20,7 @@ public abstract class TagSystem : EntitySystem
protected override void ProcessEntities(Dictionary<int, Entity> entities)
{
- Entity e = this.world.GetTagManager().GetEntity(tag);
+ Entity e = world.TagManager.GetEntity(tag);
if (e != null)
{
Process(e);
View
BIN Artemis_XNA_INDEPENDENT/Artemis.pidb
Binary file not shown.
View
BIN Artemis_XNA_INDEPENDENT/ArtemisTest/ArtemisTest.pidb
Binary file not shown.
View
42 artemis.userprefs
@@ -1,32 +1,46 @@
<Properties>
<MonoDevelop.Ide.Workspace ActiveConfiguration="Release" />
- <MonoDevelop.Ide.Workbench ActiveDocument="Artemis_XNA_INDEPENDENT/OneShotSystem.cs">
+ <MonoDevelop.Ide.Workbench ActiveDocument="Artemis_XNA_INDEPENDENT/EntityManager.cs">
<Files>
- <File FileName="Artemis_XNA_INDEPENDENT/ComponentMapper.cs" Line="1" Column="1" />
- <File FileName="Artemis_XNA_INDEPENDENT/ComponentType.cs" Line="1" Column="1" />
+ <File FileName="Artemis_XNA_INDEPENDENT/ComponentMapper.cs" Line="26" Column="44" />
+ <File FileName="Artemis_XNA_INDEPENDENT/ComponentType.cs" Line="21" Column="3" />
<File FileName="Artemis_XNA_INDEPENDENT/Component.cs" Line="1" Column="1" />
- <File FileName="Artemis_XNA_INDEPENDENT/ComponentTypeManager.cs" Line="1" Column="1" />
+ <File FileName="Artemis_XNA_INDEPENDENT/ComponentTypeManager.cs" Line="49" Column="29" />
<File FileName="Artemis_XNA_INDEPENDENT/DelayedEntityProcessingSystem.cs" Line="1" Column="1" />
- <File FileName="Artemis_XNA_INDEPENDENT/Entity.cs" Line="1" Column="1" />
- <File FileName="Artemis_XNA_INDEPENDENT/EntityManager.cs" Line="1" Column="1" />
+ <File FileName="Artemis_XNA_INDEPENDENT/Entity.cs" Line="32" Column="21" />
+ <File FileName="Artemis_XNA_INDEPENDENT/EntityManager.cs" Line="264" Column="17" />
<File FileName="Artemis_XNA_INDEPENDENT/EntityProcessingSystem.cs" Line="30" Column="4" />
- <File FileName="Artemis_XNA_INDEPENDENT/EntitySystem.cs" Line="114" Column="4" />
- <File FileName="Artemis_XNA_INDEPENDENT/EntityWorld.cs" Line="1" Column="1" />
- <File FileName="Artemis_XNA_INDEPENDENT/GroupSystem.cs" Line="1" Column="1" />
- <File FileName="Artemis_XNA_INDEPENDENT/GroupManager.cs" Line="1" Column="1" />
+ <File FileName="Artemis_XNA_INDEPENDENT/EntitySystem.cs" Line="46" Column="8" />
+ <File FileName="Artemis_XNA_INDEPENDENT/EntityWorld.cs" Line="175" Column="55" />
+ <File FileName="Artemis_XNA_INDEPENDENT/GroupManager.cs" Line="70" Column="23" />
<File FileName="Artemis_XNA_INDEPENDENT/SystemBitManager.cs" Line="1" Column="1" />
- <File FileName="Artemis_XNA_INDEPENDENT/SystemManager.cs" Line="141" Column="32" />
+ <File FileName="Artemis_XNA_INDEPENDENT/SystemManager.cs" Line="27" Column="24" />
<File FileName="Artemis_XNA_INDEPENDENT/ArtemisTest/SingleHealthBarRenderSystem.cs" Line="1" Column="1" />
- <File FileName="Artemis_XNA_INDEPENDENT/ArtemisTest/Test.cs" Line="111" Column="30" />
+ <File FileName="Artemis_XNA_INDEPENDENT/ArtemisTest/Test.cs" Line="274" Column="19" />
<File FileName="Artemis_XNA_INDEPENDENT/ArtemisTest/MultHealthBarRenderSystem.cs" Line="1" Column="1" />
<File FileName="Artemis_XNA_INDEPENDENT/ArtemisTest/SingleHEAVYHealthBarRenderSystem.cs" Line="1" Column="1" />
- <File FileName="Artemis_XNA_INDEPENDENT/DelayedEntitySystem.cs" Line="1" Column="1" />
<File FileName="Artemis_XNA_INDEPENDENT/ArtemisTest/DummySystem.cs" Line="1" Column="1" />
<File FileName="Artemis_XNA_INDEPENDENT/ArtemisTest/DummySystem2.cs" Line="1" Column="1" />
<File FileName="Artemis_XNA_INDEPENDENT/ArtemisTest/Health.cs" Line="1" Column="1" />
<File FileName="Artemis_XNA_INDEPENDENT/ArtemisTest/DummySystem3.cs" Line="1" Column="1" />
- <File FileName="Artemis_XNA_INDEPENDENT/OneShotSystem.cs" Line="20" Column="10" />
+ <File FileName="Artemis_XNA_INDEPENDENT/OneShotSystem.cs" Line="32" Column="53" />
<File FileName="Artemis_XNA_INDEPENDENT/QueueSystemProcessing.cs" Line="70" Column="10" />
+ <File FileName="Artemis_XNA_INDEPENDENT/HybridQueueSystemProcessing.cs" Line="1" Column="1" />
+ <File FileName="Artemis_XNA_INDEPENDENT/IntervalEntityProcessingSystem.cs" Line="1" Column="1" />
+ <File FileName="Artemis_XNA_INDEPENDENT/IntervalEntitySystem.cs" Line="14" Column="22" />
+ <File FileName="Artemis_XNA_INDEPENDENT/IntervalTagSystem.cs" Line="16" Column="22" />
+ <File FileName="Artemis_XNA_INDEPENDENT/ParallelEntityProcessingSystem.cs" Line="1" Column="1" />
+ <File FileName="Artemis_XNA_INDEPENDENT/Pool.cs" Line="1" Column="1" />
+ <File FileName="Artemis_XNA_INDEPENDENT/QueueSystemProcessingThreadSafe.cs" Line="1" Column="1" />
+ <File FileName="Artemis_XNA_INDEPENDENT/TagManager.cs" Line="1" Column="1" />
+ <File FileName="Artemis_XNA_INDEPENDENT/TagSystem.cs" Line="23" Column="24" />
+ <File FileName="Artemis_XNA_INDEPENDENT/BlackBoard/BlackBoard.cs" Line="1" Column="1" />
+ <File FileName="Artemis_XNA_INDEPENDENT/BlackBoard/SimpleTrigger.cs" Line="1" Column="1" />
+ <File FileName="Artemis_XNA_INDEPENDENT/ArtemisTest/DummyCommunicationSystem.cs" Line="1" Column="1" />
+ <File FileName="Artemis_XNA_INDEPENDENT/ArtemisTest/HybridQueueSystemTest.cs" Line="1" Column="1" />
+ <File FileName="Artemis_XNA_INDEPENDENT/ArtemisTest/QueueSystemProcessingThreadSafe.cs" Line="122" Column="28" />
+ <File FileName="Artemis_XNA_INDEPENDENT/ArtemisTest/QueueSystemTest.cs" Line="1" Column="1" />
+ <File FileName="Artemis_XNA_INDEPENDENT/ArtemisTest/QueueSystemTest2.cs" Line="1" Column="1" />
</Files>
</MonoDevelop.Ide.Workbench>
<MonoDevelop.Ide.DebuggingService.Breakpoints>

0 comments on commit d0f74cb

Please sign in to comment.