Skip to content

Commit

Permalink
performance fix
Browse files Browse the repository at this point in the history
  • Loading branch information
tpastor committed May 25, 2011
1 parent 8c8322f commit 7145666
Show file tree
Hide file tree
Showing 12 changed files with 41 additions and 23 deletions.
Binary file modified ArtemisTest/bin/Debug/ArtemisTest.dll
Binary file not shown.
Binary file modified ArtemisTest/bin/Debug/artemis.dll
Binary file not shown.
14 changes: 9 additions & 5 deletions DelayedEntityProcessingSystem.cs
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
namespace Artemis
{
public abstract class DelayedEntityProcessingSystem : DelayedEntitySystem {
Expand All @@ -16,11 +17,14 @@ public abstract class DelayedEntityProcessingSystem : DelayedEntitySystem {
* @param e the entity to process.
*/
public abstract void Process(Entity e, int accumulatedDelta);

public override void ProcessEntities(Bag<Entity> entities, int accumulatedDelta) {
for (int i = 0, s = entities.Size(); s > i; i++) {
Process(entities.Get(i), accumulatedDelta);
}

public override void ProcessEntities(Dictionary<int, Entity> entities, int accumulatedDelta)
{
foreach (var item in entities.Values)
{
Process(item, accumulatedDelta);
}

}
}
}
Expand Down
8 changes: 5 additions & 3 deletions DelayedEntitySystem.cs
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
namespace Artemis
{
public abstract class DelayedEntitySystem : EntitySystem {
Expand All @@ -8,8 +9,9 @@ public abstract class DelayedEntitySystem : EntitySystem {

public DelayedEntitySystem(params Type[] types) : base(types) {
}

public override void ProcessEntities(Bag<Entity> entities) {

public override void ProcessEntities(Dictionary<int, Entity> entities)
{
ProcessEntities(entities, acc);
Stop();
}
Expand All @@ -29,7 +31,7 @@ public abstract class DelayedEntitySystem : EntitySystem {
* The entities to process with accumulated delta.
* @param entities read-only bag of entities.
*/
public abstract void ProcessEntities(Bag<Entity> entities, int accumulatedDelta);
public abstract void ProcessEntities(Dictionary<int, Entity> entities, int accumulatedDelta);



Expand Down
13 changes: 8 additions & 5 deletions EntityProcessingSystem.cs
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
namespace Artemis
{
public abstract class EntityProcessingSystem : EntitySystem {
Expand All @@ -16,11 +17,13 @@ public abstract class EntityProcessingSystem : EntitySystem {
* @param e the entity to process.
*/
public abstract void Process(Entity e);

public override void ProcessEntities(Bag<Entity> entities) {
for (int i = 0, s = entities.Size(); s > i; i++) {
Process(entities.Get(i));
}

public override void ProcessEntities(Dictionary<int, Entity> entities)
{
foreach (var item in entities.Values)
{
Process(item);
}
}

public override bool CheckProcessing() {
Expand Down
11 changes: 6 additions & 5 deletions EntitySystem.cs
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
namespace Artemis
{
public abstract class EntitySystem {
Expand All @@ -8,13 +9,13 @@ public abstract class EntitySystem {

protected World world;

private Bag<Entity> actives;
private Dictionary<int,Entity> actives;

public EntitySystem() {
}

public EntitySystem(params Type[] types) {
actives = new Bag<Entity>();
actives = new Dictionary<int, Entity>();

foreach (Type type in types) {
ComponentType ct = ComponentTypeManager.GetTypeFor(type);
Expand Down Expand Up @@ -50,7 +51,7 @@ public abstract class EntitySystem {
*
* @param entities the entities this system contains.
*/
public virtual void ProcessEntities(Bag<Entity> entities) { }
public virtual void ProcessEntities(Dictionary<int,Entity> entities) { }

/**
*
Expand Down Expand Up @@ -79,7 +80,7 @@ public abstract class EntitySystem {
bool interest = (typeFlags & e.GetTypeBits()) == typeFlags;

if (interest && !contains && typeFlags > 0) {
actives.Add(e);
actives.Add(e.GetId(),e);
e.AddSystemBit(systemBit);
Added(e);
} else if (!interest && contains && typeFlags > 0) {
Expand All @@ -88,7 +89,7 @@ public abstract class EntitySystem {
}

private void Remove(Entity e) {
actives.Remove(e);
actives.Remove(e.GetId());
e.RemoveSystemBit(systemBit);
Removed(e);
}
Expand Down
10 changes: 6 additions & 4 deletions IntervalEntityProcessingSystem.cs
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
namespace Artemis
{
public abstract class IntervalEntityProcessingSystem : IntervalEntitySystem {
Expand All @@ -16,10 +17,11 @@ public abstract class IntervalEntityProcessingSystem : IntervalEntitySystem {
* @param e the entity to process.
*/
public abstract void Process(Entity e);

public override void ProcessEntities(Bag<Entity> entities) {
for (int i = 0, s = entities.Size(); s > i; i++) {
Process(entities.Get(i));

public override void ProcessEntities(Dictionary<int, Entity> entities)
{
for (int i = 0, s = entities.Count; s > i; i++) {
Process(entities[i]);
}
}

Expand Down
3 changes: 2 additions & 1 deletion Utils/Bag.cs
Expand Up @@ -20,7 +20,8 @@ public class Bag<E> where E : class
* @param capacity
* the initial capacity of Bag
*/
public Bag(int capacity) {
public Bag(int capacity)
{
data = new E[capacity];
}

Expand Down
Binary file modified artemis.suo
Binary file not shown.
5 changes: 5 additions & 0 deletions obj/x86/Debug/Artemis.csproj.FileListAbsolute.txt
Expand Up @@ -3,3 +3,8 @@ D:\artemis_CSharp\bin\Debug\artemis.exe
D:\artemis_CSharp\bin\Debug\artemis.pdb
D:\artemis_CSharp\obj\x86\Debug\artemis.exe
D:\artemis_CSharp\obj\x86\Debug\artemis.pdb
C:\Users\tpastor\Desktop\artemis\artemis_CSharp\bin\Debug\artemis.dll
C:\Users\tpastor\Desktop\artemis\artemis_CSharp\bin\Debug\artemis.pdb
C:\Users\tpastor\Desktop\artemis\artemis_CSharp\obj\x86\Debug\ResolveAssemblyReference.cache
C:\Users\tpastor\Desktop\artemis\artemis_CSharp\obj\x86\Debug\artemis.dll
C:\Users\tpastor\Desktop\artemis\artemis_CSharp\obj\x86\Debug\artemis.pdb
Binary file modified obj/x86/Debug/artemis.pdb
Binary file not shown.
Binary file modified obj/x86/Release/artemis.dll
Binary file not shown.

0 comments on commit 7145666

Please sign in to comment.