当前位置: 首页>>代码示例>>Java>>正文


Java ImmutableArray.size方法代码示例

本文整理汇总了Java中com.badlogic.ashley.utils.ImmutableArray.size方法的典型用法代码示例。如果您正苦于以下问题:Java ImmutableArray.size方法的具体用法?Java ImmutableArray.size怎么用?Java ImmutableArray.size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.badlogic.ashley.utils.ImmutableArray的用法示例。


在下文中一共展示了ImmutableArray.size方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: update

import com.badlogic.ashley.utils.ImmutableArray; //导入方法依赖的package包/类
/**
 * Updates all the systems in this Engine.
 * @param deltaTime The time passed since the last frame.
 */
public void update(float deltaTime){
	if (updating) {
		throw new IllegalStateException("Cannot call update() on an Engine that is already updating.");
	}
	
	updating = true;
	ImmutableArray<EntitySystem> systems = systemManager.getSystems();
	for (int i = 0; i < systems.size(); ++i) {
		EntitySystem system = systems.get(i);
		
		if (system.checkProcessing()) {
			system.update(deltaTime);
		}

		componentOperationHandler.processOperations();
		entityManager.processPendingOperations();
	}
	updating = false;
}
 
开发者ID:DevelopersGuild,项目名称:Planetbase,代码行数:24,代码来源:Engine.java

示例2: intervalSystem

import com.badlogic.ashley.utils.ImmutableArray; //导入方法依赖的package包/类
@Test
public void intervalSystem () {
	Engine engine = new Engine();
	IntervalIteratingSystemSpy intervalSystemSpy = new IntervalIteratingSystemSpy();
	ImmutableArray<Entity> entities = engine.getEntitiesFor(Family.all(IntervalComponentSpy.class).get());
	ComponentMapper<IntervalComponentSpy> im = ComponentMapper.getFor(IntervalComponentSpy.class);

	engine.addSystem(intervalSystemSpy);

	for (int i = 0; i < 10; ++i) {
		Entity entity = new Entity();
		entity.add(new IntervalComponentSpy());
		engine.addEntity(entity);
	}

	for (int i = 1; i <= 10; ++i) {
		engine.update(deltaTime);

		for (int j = 0; j < entities.size(); ++j) {
			assertEquals(i / 2, im.get(entities.get(j)).numUpdates);
		}
	}
}
 
开发者ID:DevelopersGuild,项目名称:Planetbase,代码行数:24,代码来源:IntervalIteratingTest.java

示例3: entitySystemRemovalWhileIterating

import com.badlogic.ashley.utils.ImmutableArray; //导入方法依赖的package包/类
@Test
public void entitySystemRemovalWhileIterating () {
	Engine engine = new Engine();

	engine.addSystem(new CounterSystem());

	for (int i = 0; i < 20; ++i) {
		Entity entity = new Entity();
		entity.add(new CounterComponent());
		engine.addEntity(entity);
	}

	ImmutableArray<Entity> entities = engine.getEntitiesFor(Family.all(CounterComponent.class).get());

	for (int i = 0; i < entities.size(); ++i) {
		assertEquals(0, entities.get(i).getComponent(CounterComponent.class).counter);
	}

	engine.update(deltaTime);

	for (int i = 0; i < entities.size(); ++i) {
		assertEquals(1, entities.get(i).getComponent(CounterComponent.class).counter);
	}
}
 
开发者ID:DevelopersGuild,项目名称:Planetbase,代码行数:25,代码来源:EngineTests.java

示例4: closestEntity

import com.badlogic.ashley.utils.ImmutableArray; //导入方法依赖的package包/类
public static Entity closestEntity(Vector3 position, ImmutableArray<Entity> entities) {
	if (entities == null || entities.size() == 0)
		return null;
	
	Entity targetEntity = entities.first();
	float targetDist = MyMath.distance(position, Mappers.transform.get(targetEntity).pos);
	for (Entity searchEnt : entities) {
		float dist = MyMath.distance(Mappers.transform.get(searchEnt).pos, position);
		if (dist < targetDist) {
			targetDist = dist;
			targetEntity = searchEnt;
		}
	}

	return targetEntity;
}
 
开发者ID:0XDE57,项目名称:SpaceProject,代码行数:17,代码来源:Misc.java

示例5: intervalSystem

import com.badlogic.ashley.utils.ImmutableArray; //导入方法依赖的package包/类
@Test
public void intervalSystem() {
    Engine engine = new Engine();
    IntervalIteratingSystemSpy intervalSystemSpy = new IntervalIteratingSystemSpy();
    ImmutableArray<Entity> entities = engine.getEntitiesFor(Family.getFor(IntervalComponentSpy.class));
    ComponentMapper<IntervalComponentSpy> im = ComponentMapper.getFor(IntervalComponentSpy.class);

    engine.addSystem(intervalSystemSpy);

    for (int i = 0; i < 10; ++i) {
        Entity entity = new Entity();
        entity.add(new IntervalComponentSpy());
        engine.addEntity(entity);
    }

    for (int i = 1; i <= 10; ++i) {
        engine.update(deltaTime);

        for (int j = 0; j < entities.size(); ++j) {
            assertEquals(i / 2, im.get(entities.get(j)).numUpdates);
        }
    }
}
 
开发者ID:grum,项目名称:Ashley,代码行数:24,代码来源:IntervalIteratingTest.java

示例6: entitySystemRemovalWhileIterating

import com.badlogic.ashley.utils.ImmutableArray; //导入方法依赖的package包/类
@Test
public void entitySystemRemovalWhileIterating() {
    Engine engine = new Engine();

    engine.addSystem(new CounterSystem());

    for (int i = 0; i < 20; ++i) {
        Entity entity = new Entity();
        entity.add(new CounterComponent());
        engine.addEntity(entity);
    }

    ImmutableArray<Entity> entities = engine.getEntitiesFor(Family.getFor(CounterComponent.class));

    for (int i = 0; i < entities.size(); ++i) {
        assertEquals(0, entities.get(i).getComponent(CounterComponent.class).counter);
    }

    engine.update(deltaTime);

    for (int i = 0; i < entities.size(); ++i) {
        assertEquals(1, entities.get(i).getComponent(CounterComponent.class).counter);
    }
}
 
开发者ID:grum,项目名称:Ashley,代码行数:25,代码来源:EngineTests.java

示例7: removeAllEntities

import com.badlogic.ashley.utils.ImmutableArray; //导入方法依赖的package包/类
public void removeAllEntities(ImmutableArray<Entity> entities, boolean delayed) {
	if (delayed) {
		for(Entity entity: entities) {
			entity.scheduledForRemoval = true;
		}
		EntityOperation operation = entityOperationPool.obtain();
		operation.type = EntityOperation.Type.RemoveAll;
		operation.entities = entities;
		pendingOperations.add(operation);
	}
	else {
		while(entities.size() > 0) {
			removeEntity(entities.first(), false);
		}
	}
}
 
开发者ID:libgdx,项目名称:ashley,代码行数:17,代码来源:EntityManager.java

示例8: update

import com.badlogic.ashley.utils.ImmutableArray; //导入方法依赖的package包/类
/**
 * Updates all the systems in this Engine.
 * @param deltaTime The time passed since the last frame.
 */
public void update(float deltaTime){
	if (updating) {
		throw new IllegalStateException("Cannot call update() on an Engine that is already updating.");
	}
	
	updating = true;
	ImmutableArray<EntitySystem> systems = systemManager.getSystems();
	try {
		for (int i = 0; i < systems.size(); ++i) {
			EntitySystem system = systems.get(i);
			
			if (system.checkProcessing()) {
				system.update(deltaTime);
			}

			while(componentOperationHandler.hasOperationsToProcess() || entityManager.hasPendingOperations()) {
				componentOperationHandler.processOperations();
				entityManager.processPendingOperations();
			}
		}
	}
	finally {
		updating = false;
	}	
}
 
开发者ID:libgdx,项目名称:ashley,代码行数:30,代码来源:Engine.java

示例9: debug

import com.badlogic.ashley.utils.ImmutableArray; //导入方法依赖的package包/类
public static void debug() {
	if (Gdx.input.isKeyJustPressed(Input.Keys.B)) {
		ImmutableArray<Entity> projectiles = getAshleyEngine().getEntitiesFor(Families.PROJECTILE);
		if (projectiles == null) {
			return;
		}
		for (int i = 0; i < projectiles.size(); i++) {
			System.out.println(projectiles.get(i).getComponent(DestinationComponent.class));
		}
	}
}
 
开发者ID:JoakimRW,项目名称:ExamensArbeteTD,代码行数:12,代码来源:InputHandler.java

示例10: entityRemoved

import com.badlogic.ashley.utils.ImmutableArray; //导入方法依赖的package包/类
@Override
public void entityRemoved(Entity entity) {
	SplashComponent splash = Mappers.SPLASH_M.get(entity);
	
	DamageComponent dmgComp = Mappers.DAMAGE_M.get(entity);
	Entity targetedEnemy = Mappers.DESTINATION_M.get(entity).getDestinationEntity();
	PositionComponent splashPos = Mappers.POSITION_M.get(targetedEnemy);		
	
	if(splash != null && splashPos != null){
		ImmutableArray<Entity> enemies = getEngine().getEntitiesFor(Families.ENEMY);
		final ArrayList<Entity> enemiesToDamage = new ArrayList<>();
		for(int i = 0; i < enemies.size() ; i++){
			if(enemies.get(i).equals(targetedEnemy)) continue;
			PositionComponent enemyPos = Mappers.POSITION_M.get(enemies.get(i));
			if(enemiesToDamage.contains(enemies.get(i))) continue;
				if(enemyPos.position.dst(splashPos.position) < splash.radius){
					// todo 
					enemiesToDamage.add(enemies.get(i));
				}
		}
		
		
		
		for(Entity enemy : enemiesToDamage){
			HealthComponent enemyHp = Mappers.HEALTH_M.get(enemy);
			enemyHp.takeDamage(dmgComp.getDamage());
		}	
	}
}
 
开发者ID:JoakimRW,项目名称:ExamensArbeteTD,代码行数:30,代码来源:SplashDamageSystem.java

示例11: findNearestEnemy

import com.badlogic.ashley.utils.ImmutableArray; //导入方法依赖的package包/类
private Entity findNearestEnemy(Entity towerEntity) {
	Vector2 towerPosition = towerEntity.getComponent(PositionComponent.class).position;

	if (getEngine().getEntitiesFor(Families.ENEMY) == null) {
		return null;
	}
	ImmutableArray<Entity> enemies = getEngine().getEntitiesFor(Families.ENEMY);
	HashMap<Double, Entity> distanceMap = new HashMap<>();
	for (int i = 0; i < enemies.size(); i++) {
		Vector2 enemyPosition = enemies.get(i).getComponent(PositionComponent.class).position;

		double distance = towerPosition.dst(enemyPosition);
		distanceMap.put(distance, enemies.get(i));
	}
	if (distanceMap.isEmpty()) {
		return null;
	}

	Double minKey = Collections.min(distanceMap.keySet());
	RangeComponent component = towerEntity.getComponent(RangeComponent.class);
	if (component == null) {
		return null;
	}
	Double range = component.getRange();
	if (range < minKey) {
		return null;
	}
	return distanceMap.get(minKey);

}
 
开发者ID:JoakimRW,项目名称:ExamensArbeteTD,代码行数:31,代码来源:AimingSystem.java

示例12: addedToEngine

import com.badlogic.ashley.utils.ImmutableArray; //导入方法依赖的package包/类
@Override
public void addedToEngine (Engine engine) {
	ImmutableArray<Entity> newEntities = engine.getEntitiesFor(family);
	sortedEntities.clear();
	if (newEntities.size() > 0) {
		for (int i = 0; i < newEntities.size(); ++i) {
			sortedEntities.add(newEntities.get(i));
		}
		sortedEntities.sort(comparator);
	}
	shouldSort = false;
	engine.addEntityListener(family, this);
}
 
开发者ID:DevelopersGuild,项目名称:Planetbase,代码行数:14,代码来源:SortedIteratingSystem.java

示例13: getPointerPosition

import com.badlogic.ashley.utils.ImmutableArray; //导入方法依赖的package包/类
private PointerPositionComponent getPointerPosition() {
	ImmutableArray<Entity> entities = gameLoop.getEntitiesFor(Family
			.all(PointerPositionComponent.class).get());
	Entity entity = null;
	if (entities.size() == 0) {
		entity = new Entity();
		gameLoop.addEntity(entity);
	} else {
		entity = entities.first();
	}
	return gameLoop.addAndGetComponent(entity,
			PointerPositionComponent.class);
}
 
开发者ID:e-ucm,项目名称:ead,代码行数:14,代码来源:DefaultGameView.java

示例14: getGameComponent

import com.badlogic.ashley.utils.ImmutableArray; //导入方法依赖的package包/类
public static <T extends Component> T getGameComponent(Class<T> clazz,
		GameLoop gameLoop) {
	ImmutableArray<Entity> entities = gameLoop.getEntitiesFor(Family.all(
			clazz).get());
	if (entities.size() > 0) {
		return entities.first().getComponent(clazz);
	}
	return null;
}
 
开发者ID:e-ucm,项目名称:ead,代码行数:10,代码来源:GameEntitySystem.java

示例15: findNearestEnemies

import com.badlogic.ashley.utils.ImmutableArray; //导入方法依赖的package包/类
private ArrayList<Entity> findNearestEnemies(Entity towerEntity) {

		Vector2 towerPosition = towerEntity.getComponent(PositionComponent.class).position;
		TargetComponent targetComp = Mappers.TARGET_M.get(towerEntity);

		if (getEngine().getEntitiesFor(Families.ENEMY) == null) {
			return null;
		}

		RangeComponent component = towerEntity.getComponent(RangeComponent.class);
		if (component == null) {
			return null;
		}
		Double range = component.getRange();

		ImmutableArray<Entity> enemies = getEngine().getEntitiesFor(Families.ENEMY);
		HashMap<Double, Entity> distanceMap = new HashMap<>();
		for (int i  = 0; i < enemies.size(); i++) {
			Vector2 enemyPosition = enemies.get(i).getComponent(PositionComponent.class).position;

			double distance = towerPosition.dst(enemyPosition);

			if (distance < range) {
				distanceMap.put(distance, enemies.get(i));
			}
		}
		if (distanceMap.isEmpty() || distanceMap.keySet().isEmpty()) {
			return null;
		}

		Map<Double, Entity> multiDistanceList = new HashMap<>();

		for (int i = 0; i < targetComp.getMaxTargets(); i++) {
			if (distanceMap.isEmpty() || distanceMap.keySet().isEmpty()) {
				break;
			}
			Double min = Collections.min(distanceMap.keySet());
			multiDistanceList.put(min, distanceMap.get(min));
			distanceMap.remove(min);
		}
		return new ArrayList<Entity>(multiDistanceList.values());

	}
 
开发者ID:JoakimRW,项目名称:ExamensArbeteTD,代码行数:44,代码来源:AimingSystem.java


注:本文中的com.badlogic.ashley.utils.ImmutableArray.size方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。