com.badlogic.ashley.core.Component Java Examples
The following examples show how to use
com.badlogic.ashley.core.Component.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GameSaver.java From StockSimulator with GNU General Public License v2.0 | 6 votes |
public String saveToJson() { gameState.stopThread(); try { ImmutableArray<Entity> entities = gameState.getEntityEngine().getEntities(); SavedGame savedGame = new SavedGame(); for (Entity entity : entities) { List<ComponentContainer> componentContainers = new ArrayList<ComponentContainer>(); for (Component c : entity.getComponents()) { componentContainers.add(new ComponentContainer(c)); } EntityContainer entityContainer = new EntityContainer(entity.getId(), entity.getClass().getName(), componentContainers); savedGame.entitiesContainers.add(entityContainer); } return new GsonBuilder().enableComplexMapKeySerialization().create().toJson(savedGame); } catch (Exception e) { e.printStackTrace(); } gameState.startThread(); return "Failed"; }
Example #2
Source File: EntityManglerSystem.java From entity-system-benchmarks with Apache License 2.0 | 6 votes |
@Override public void addedToEngine(Engine engine) { for (int i = 0; permutations.length > i; i++) { Array<Class<? extends Component>> components = new Array<Class<? extends Component>>(); for (int classIndex = 0, s = (int)(rng.nextFloat() * 7) + 3; s > classIndex; classIndex++) { components.add(types.get((int)(rng.nextFloat() * types.size))); } permutations[i] = components; } this.engine = engine; entities = engine.getEntitiesFor(Family.all().get()); for (int i = 0; ENTITY_COUNT > i; i++) createEntity(); }
Example #3
Source File: EntityDeleterSystem.java From entity-system-benchmarks with Apache License 2.0 | 5 votes |
public EntityDeleterSystem(long seed, int entityCount, Class<? extends Component> c1, Class<? extends Component> c2) { this.c1 = c1; this.c2 = c2; ENTITY_COUNT = entityCount; ids = new long[ENTITY_COUNT]; // ashley is backed up am IntMap, hence we only need to track ids // for (int i = 0; ids.length > i; i++) }
Example #4
Source File: EntityManglerSystem.java From entity-system-benchmarks with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") private final void createEntity() { Entity e = new Entity(); Array<Class<? extends Component>> components = permutations[cmp[cmpIndex++]]; if (cmpIndex == cmp.length) cmpIndex = 0; Object[] data = components.items; for (int i = 0, s = components.size; s > i; i++) { e.add(newInstance(data[i])); } engine.addEntity(e); }
Example #5
Source File: PooledEntityDeleterSystem.java From entity-system-benchmarks with Apache License 2.0 | 5 votes |
public PooledEntityDeleterSystem(long seed, int entityCount, Class<? extends Component> c1, Class<? extends Component> c2) { this.c1 = c1; this.c2 = c2; ENTITY_COUNT = entityCount; ids = new long[ENTITY_COUNT]; }
Example #6
Source File: GameSaver.java From StockSimulator with GNU General Public License v2.0 | 4 votes |
public ComponentContainer(Component c) { clazz = c.getClass().getName(); value = c; }
Example #7
Source File: EntityManglerSystem.java From entity-system-benchmarks with Apache License 2.0 | 4 votes |
@SuppressWarnings("unchecked") public EntityManglerSystem(long seed, int entityCount) { // 4096 entities = 256 compositions, 262144 = 2048 super(0); int entityPermutations = (int)Math.sqrt(entityCount * 16); rng = new Random(seed); ENTITY_COUNT = entityCount; RENEW = ENTITY_COUNT / 4; ArrayList<Integer> idsList = new ArrayList<Integer>(); for (int i = 0; ENTITY_COUNT > i; i++) idsList.add(i); Collections.shuffle(idsList); ids = new int[ENTITY_COUNT]; for (int i = 0; ids.length > i; i++) ids[i] = idsList.get(i); types = new Array<Class<? extends Component>>(); types.add(Comp1.class); types.add(Comp2.class); types.add(Comp3.class); types.add(Comp4.class); types.add(Comp5.class); types.add(Comp6.class); types.add(Comp7.class); types.add(Comp8.class); types.add(Comp9.class); types.add(Comp10.class); types.add(Comp11.class); types.add(Comp12.class); permutations = new Array[entityPermutations]; for (int i = 0; permutations.length > i; i++) { Array<Class<? extends Component>> components = new Array<Class<? extends Component>>(); for (int classIndex = 0, s = (int)(rng.nextFloat() * 7) + 3; s > classIndex; classIndex++) { components.add(types.get((int)(rng.nextFloat() * types.size))); } permutations[i] = components; } cmp = new int[ENTITY_COUNT * 4]; for (int i = 0; cmp.length > i; i++) cmp[i] = (int)(rng.nextFloat() * permutations.length); }