Skip to content

Commit

Permalink
Ashley depends on gdx-core (1.2.0)
Browse files Browse the repository at this point in the history
ImmutableArray and ImmutableIntMap are wrappers of gdx's Array and IntMap
  • Loading branch information
dsaltares committed Jul 12, 2014
1 parent 8b48cca commit 81d9a2e
Show file tree
Hide file tree
Showing 32 changed files with 317 additions and 4,949 deletions.
15 changes: 8 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ allprojects {
}
}

ext.projectGroup = "ashley"
ext {
projectGroup = "ashley"
gdxVersion = '1.2.0'
}

/** needed to disable Java 8 doclint which throws errors **/
allprojects {
Expand All @@ -29,17 +32,15 @@ allprojects {

project(":core") {
apply from : '../publish.gradle'

dependencies {
compile "com.badlogicgames.gdx:gdx:$gdxVersion"
}
}

project(":tests") {

ext {
gdxVersion = '1.2.0'
}

dependencies {
compile project(":core")
compile "com.badlogicgames.gdx:gdx:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-backend-lwjgl:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
}
Expand Down
5 changes: 3 additions & 2 deletions core/src/com/badlogic/ashley/core/ComponentType.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@

package com.badlogic.ashley.core;

import com.badlogic.ashley.utils.Bits;
import com.badlogic.ashley.utils.ObjectMap;
import com.badlogic.gdx.utils.Bits;
import com.badlogic.gdx.utils.ObjectMap;


/**
* A {@link ComponentType} is used to uniquely identify a Component sub-class by assigning them an index. This is used
Expand Down
17 changes: 11 additions & 6 deletions core/src/com/badlogic/ashley/core/Engine.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@

import com.badlogic.ashley.signals.Listener;
import com.badlogic.ashley.signals.Signal;
import com.badlogic.ashley.utils.Array;
import com.badlogic.ashley.utils.ImmutableIntMap;
import com.badlogic.ashley.utils.IntMap;
import com.badlogic.ashley.utils.ObjectMap;
import com.badlogic.ashley.utils.ObjectMap.Entries;
import com.badlogic.ashley.utils.ObjectMap.Entry;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.IntMap;
import com.badlogic.gdx.utils.ObjectMap;
import com.badlogic.gdx.utils.ObjectMap.Entries;
import com.badlogic.gdx.utils.ObjectMap.Entry;

/**
* The Engine class is the heart of the Entity framework. It is responsible for keeping track of entities and
Expand Down Expand Up @@ -53,6 +53,8 @@ public class Engine {
private ObjectMap<Class<?>, EntitySystem> systemsByClass;
/** A hashmap that organises all entities into family buckets */
private ObjectMap<Family, IntMap<Entity>> families;
/** A hashmap that organises all entities into immutable family buckets */
private ObjectMap<Family, ImmutableIntMap<Entity>> immutableFamilies;
/** A collection of entity added/removed event listeners */
private Array<EntityListener> listeners;
/** EntityListeners that await removal */
Expand All @@ -70,6 +72,7 @@ public Engine(){
systems = new Array<EntitySystem>();
systemsByClass = new ObjectMap<Class<?>, EntitySystem>();
families = new ObjectMap<Family, IntMap<Entity>>();
immutableFamilies = new ObjectMap<Family, ImmutableIntMap<Entity>>();
listeners = new Array<EntityListener>();
removalPendingListeners = new Array<EntityListener>();
notifying = false;
Expand Down Expand Up @@ -206,8 +209,10 @@ public ImmutableIntMap<Entity> getEntitiesFor(Family family){
}
}
families.put(family, entities);
immutableFamilies.put(family, new ImmutableIntMap<Entity>(entities));
}
return families.get(family);

return immutableFamilies.get(family);
}

/**
Expand Down
13 changes: 8 additions & 5 deletions core/src/com/badlogic/ashley/core/Entity.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
package com.badlogic.ashley.core;

import com.badlogic.ashley.signals.Signal;
import com.badlogic.ashley.utils.Array;
import com.badlogic.ashley.utils.Bits;
import com.badlogic.ashley.utils.ImmutableArray;
import com.badlogic.ashley.utils.ObjectMap;
import com.badlogic.ashley.utils.ObjectMap.Keys;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.Bits;
import com.badlogic.gdx.utils.ObjectMap;
import com.badlogic.gdx.utils.ObjectMap.Keys;

/**
* Entities are simple containers. They can hold components that give them "data". The component's data
Expand All @@ -42,6 +42,8 @@ public class Entity {
private ObjectMap<Class<? extends Component>, Component> components;
/** An auxiliary array for quick access to all the components of an entity */
private Array<Component> componentsArray;
/** A wrapper around componentsArray so users cannot modify it */
private ImmutableArray<Component> immutableComponentsArray;
/** A Bits describing all the components in this entity. For quick matching. */
private Bits componentBits;
/** A Bits describing all the systems this entity was matched with. */
Expand All @@ -60,6 +62,7 @@ public class Entity {
public Entity(){
components = new ObjectMap<Class<? extends Component>, Component>();
componentsArray = new Array<Component>();
immutableComponentsArray = new ImmutableArray<Component>(componentsArray);
componentBits = new Bits();
familyBits = new Bits();
flags = 0;
Expand Down Expand Up @@ -159,7 +162,7 @@ public Bits getComponentBits(){
* @return immutable array with all the entity components
*/
public ImmutableArray<Component> getComponents() {
return componentsArray;
return immutableComponentsArray;
}

/**
Expand Down
22 changes: 17 additions & 5 deletions core/src/com/badlogic/ashley/core/Family.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@

package com.badlogic.ashley.core;

import com.badlogic.ashley.utils.Bits;
import com.badlogic.ashley.utils.ObjectMap;
import com.badlogic.gdx.utils.Bits;
import com.badlogic.gdx.utils.ObjectMap;


/**
* A family represents a group of components. It is used to describe what entities a system
Expand Down Expand Up @@ -160,11 +161,22 @@ public boolean equals(Object obj) {
private static String getFamilyHash(Bits all, Bits one, Bits exclude) {
StringBuilder builder = new StringBuilder();
builder.append("all:");
builder.append(all.toString());
builder.append(getBitsString(all));
builder.append(",one:");
builder.append(one.toString());
builder.append(getBitsString(one));
builder.append(",exclude:");
builder.append(exclude.toString());
builder.append(getBitsString(exclude));
return builder.toString();
}

private static String getBitsString(Bits bits) {
StringBuilder builder = new StringBuilder();

int numBits = bits.length();
for (int i = 0; i < numBits; ++i) {
builder.append(bits.get(i) ? "1" : "0");
}

return builder.toString();
}
}
13 changes: 6 additions & 7 deletions core/src/com/badlogic/ashley/core/PooledEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@

package com.badlogic.ashley.core;

import com.badlogic.ashley.utils.Pool;
import com.badlogic.ashley.utils.Pools;
import com.badlogic.ashley.utils.Pool.Poolable;
import com.badlogic.gdx.utils.Pool;
import com.badlogic.gdx.utils.Pool.Poolable;
import com.badlogic.gdx.utils.Pools;


/**
* Engine derived class adding Entity and Component pooling. This improves performance in environments
Expand All @@ -33,13 +34,11 @@
public class PooledEngine extends Engine {

private EntityPool entityPool;
private Pools componentPools;

public PooledEngine() {
super();

entityPool = new EntityPool();
componentPools = new Pools();
}

/**
Expand Down Expand Up @@ -74,15 +73,15 @@ public void removeEntity(Entity entity){
* @return obtains an available pooled component of the required type
*/
public <T extends Component> T createComponent(Class<T> componentType) {
return componentPools.obtain(componentType);
return Pools.obtain(componentType);
}

private class PooledEntity extends Entity implements Poolable {

@Override
public Component remove(Class<? extends Component> componentType){
Component component = super.remove(componentType);
componentPools.free(component);
Pools.free(component);
return component;
}

Expand Down
3 changes: 2 additions & 1 deletion core/src/com/badlogic/ashley/signals/Signal.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@

package com.badlogic.ashley.signals;

import com.badlogic.ashley.utils.Array;
import com.badlogic.gdx.utils.Array;


/**
* A Signal is a basic event class then can dispatch an event to multiple listeners. It uses
Expand Down
8 changes: 3 additions & 5 deletions core/src/com/badlogic/ashley/systems/IteratingSystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import com.badlogic.ashley.core.EntitySystem;
import com.badlogic.ashley.core.Family;
import com.badlogic.ashley.utils.ImmutableIntMap;
import com.badlogic.ashley.utils.ImmutableIntMap.Keys;
import com.badlogic.gdx.utils.IntMap.Entry;

/**
* A simple EntitySystem that iterates over each entity and calls processEntity() for each entity every time
Expand Down Expand Up @@ -68,10 +68,8 @@ public void removedFromEngine(Engine engine) {

@Override
public void update(float deltaTime) {
Keys keys = entities.immutableKeys();

while(keys.hasNext()){
processEntity(entities.get(keys.next()), deltaTime);
for (Entry<Entity> entry : entities) {
processEntity(entry.value, deltaTime);
}
}

Expand Down
Loading

0 comments on commit 81d9a2e

Please sign in to comment.