com.artemis.ComponentType Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of artemis-odb Show documentation
Show all versions of artemis-odb Show documentation
Fork of Artemis Entity System Framework.
package com.artemis;
import com.artemis.utils.reflect.ClassReflection;
import com.artemis.utils.reflect.Constructor;
/**
* Identifies components in artemis without having to use classes.
*
* This class keeps a list of all generated component types for fast
* retrieval.
*
*
* @author Arni Arent
*/
public class ComponentType {
static enum Taxonomy {
BASIC, POOLED, PACKED;
}
/** The class type of the component type. */
private final Class extends Component> type;
/** True if component type is a {@link PackedComponent} */
private final Taxonomy taxonomy;
boolean packedHasWorldConstructor = false;
private final int index;
ComponentType(Class extends Component> type, int index) {
this.index = index;
this.type = type;
if (ClassReflection.isAssignableFrom(PackedComponent.class, type)) {
taxonomy = Taxonomy.PACKED;
packedHasWorldConstructor = hasWorldConstructor(type);
} else if (ClassReflection.isAssignableFrom(PooledComponent.class, type)) {
taxonomy = Taxonomy.POOLED;
} else {
taxonomy = Taxonomy.BASIC;
}
}
private static boolean hasWorldConstructor(Class extends Component> type) {
Constructor[] constructors = ClassReflection.getConstructors(type);
for (int i = 0; constructors.length > i; i++) {
@SuppressWarnings("rawtypes")
Class[] types = constructors[i].getParameterTypes();
if (types.length == 1 && types[0] == World.class)
return true;
}
return false;
}
/**
* Get the component type's index.
*
* @return the component types index
*/
public int getIndex() {
return index;
}
protected Taxonomy getTaxonomy() {
return taxonomy;
}
public boolean isPackedComponent() {
return taxonomy == Taxonomy.PACKED;
}
public Class extends Component> getType() {
return type;
}
@Override
public String toString() {
return "ComponentType["+ ClassReflection.getSimpleName(type) +"] ("+index+")";
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy