All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.artemis.ComponentType Maven / Gradle / Ivy

There is a newer version: 2.3.0
Show newest version
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 type; /** True if component type is a {@link PackedComponent} */ private final Taxonomy taxonomy; boolean packedHasWorldConstructor = false; private final int index; ComponentType(Class 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 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 getType() { return type; } @Override public String toString() { return "ComponentType["+ ClassReflection.getSimpleName(type) +"] ("+index+")"; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy