本文整理汇总了Java中com.artemis.utils.Bag类的典型用法代码示例。如果您正苦于以下问题:Java Bag类的具体用法?Java Bag怎么用?Java Bag使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Bag类属于com.artemis.utils包,在下文中一共展示了Bag类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: processSystem
import com.artemis.utils.Bag; //导入依赖的package包/类
@Override
protected void processSystem() {
Bag<Entity> entities = getEntities();
Sort sort = Sort.instance();
sort.sort(entities, new Comparator<Entity>() {
@Override
public int compare(Entity o1, Entity o2) {
Transform t1 = mTransform.get(o1);
Transform t2 = mTransform.get(o2);
if (t1.z < t2.z) {
return 1;
}
else if (t1.z > t2.z) {
return -1;
}
else {
return 0;
}
}
});
for (Entity e : entities) {
process(e);
}
}
示例2: getRelevantListeners
import com.artemis.utils.Bag; //导入依赖的package包/类
/** Get listeners that are subscribed to the event. */
protected ImmutableBag<EventListener> getRelevantListeners(Event event) {
final Bag<EventListener> relevantListeners = new Bag<>();
// resort listeners when we need to.
if (sortDirty) {
sortDirty=false;
BagUtils.sort(listeners);
}
// who needs efficiency! not us!
for(int i=0, s=listeners.size(); i<s; i++) {
final EventListener listener = listeners.get(i);
if ( listener != null ) {
if ( canHandle(listener, event))
{
relevantListeners.add(listener);
}
}
}
return relevantListeners;
}
示例3: getListenersForHierarchicalUncached
import com.artemis.utils.Bag; //导入依赖的package包/类
/**
* Get listeners for class, including all superclasses,
* sorted by priority.
*
* Not backed by cache.
*
* @param aClass Class to fetch listeners for.
* @return Bag of listeners, empty if none found.
*/
private Bag<EventListener> getListenersForHierarchicalUncached(Class<?> aClass) {
// get hierarchy for event.
final Class<?>[] classes = classHierarchy.of(aClass);
// step through hierarchy back to front, fetching the listeners for each step.
final Bag<EventListener> hierarchicalListeners = new Bag<>(4);
for (Class<?> c : classes) {
final Bag<EventListener> listeners = getListenersFor(c, false);
if (listeners != null) {
hierarchicalListeners.addAll(listeners);
}
}
// sort by priority.
BagUtils.sort(hierarchicalListeners);
return hierarchicalListeners;
}
示例4: dispatch
import com.artemis.utils.Bag; //导入依赖的package包/类
/**
* Dispatch event to registered listeners.
* Events are called on the call stack, avoid deeply nested or circular event calls.
*/
@Override
public void dispatch(Event event) {
if ( event == null ) throw new NullPointerException("Event required.");
final Bag<EventListener> listeners = getListenersForHierarchical(event.getClass());
/** Fetch hierarchical list of listeners. */
Object[] data = listeners.getData();
for (int i = 0, s = listeners.size(); i < s; i++) {
final EventListener listener = (EventListener) data[i];
if (listener != null) {
listener.handle(event);
}
}
}
示例5: setup
import com.artemis.utils.Bag; //导入依赖的package包/类
@Setup(Level.Iteration)
public void setup() {
quadTree = new QuadTree(0, 0, treeSize, treeSize);
testData = new Bag<>();
// fill = new IntBag();
Random random = new Random(0);
for (int id = 0; id < entities; id++) {
TestData data = new TestData();
data.id = id;
data.x = random.nextFloat() * (treeSize - 1);
data.y = random.nextFloat() * (treeSize - 1);
data.width = 0.025f + random.nextFloat() * 0.075f;
data.height = 0.025f + random.nextFloat() * 0.075f;
testData.add(data);
// quadTree.insert(data.id, data.x, data.y, data.width, data.height);
}
// for (int id = 0; id < size; id++) {
// TestData search = new TestData();
// search.x = random.nextFloat() * 14;
// search.y = random.nextFloat() * 14;
// search.width = 0.1f + random.nextFloat() * 1.9f;
// search.height = 0.1f + random.nextFloat() * 1.9f;
// searchData.add(search);
// }
}
示例6: unsubscribe
import com.artemis.utils.Bag; //导入依赖的package包/类
/**
* Unsubscribe T from entity.
*
* @param subscriber subscriber
* @param entityId entity to subscribe
*/
public void unsubscribe(T subscriber, int entityId) {
// unhook entity from subscriber
IntBag entities = subscriberEntities.get(subscriber);
if (entities != null) {
int index = entities.indexOf(entityId);
if ( index != -1 ) {
entities.remove(index);
}
}
// unhook subscriber from entity.
Bag<T> subscribers = entitySubscribers.get(entityId);
if (subscribers != null) {
subscribers.remove(subscriber);
}
}
示例7: getEntitiesWithLayer
import com.artemis.utils.Bag; //导入依赖的package包/类
public ImmutableBag<Entity> getEntitiesWithLayer (int layerId) {
Bag<Entity> entities = new Bag<Entity>();
IntBag bag = subscription.getEntities();
int[] data = bag.getData();
for (int i = 0; i < bag.size(); i++) {
int id = data[i];
Entity entity = world.getEntity(id);
Layer layer = layerCm.get(entity);
if (layer.layerId == layerId)
entities.add(entity);
}
return entities;
}
示例8: add
import com.artemis.utils.Bag; //导入依赖的package包/类
/**
* Set the group of the entity.
*
* @param group group to add the entity into.
* @param e entity to add into the group.
*/
public void add(Entity e, String group) {
Bag<Entity> entities = entitiesByGroup.get(group);
if(entities == null) {
entities = new Bag<Entity>();
entitiesByGroup.put(group, entities);
}
entities.add(e);
Bag<String> groups = groupsByEntity.get(e);
if(groups == null) {
groups = new Bag<String>();
groupsByEntity.put(e, groups);
}
groups.add(group);
}
示例9: World
import com.artemis.utils.Bag; //导入依赖的package包/类
public World() {
managers = new HashMap<Class<? extends Manager>, Manager>();
managersBag = new Bag<Manager>();
systems = new HashMap<Class<?>, EntitySystem>();
systemsBag = new Bag<EntitySystem>();
added = new Bag<Entity>();
changed = new Bag<Entity>();
deleted = new Bag<Entity>();
enable = new Bag<Entity>();
disable = new Bag<Entity>();
cm = new ComponentManager();
setManager(cm);
em = new EntityManager();
setManager(em);
}
示例10: add
import com.artemis.utils.Bag; //导入依赖的package包/类
/**
* Set the group of the entity.
*
* @param group group to add the entity into.
* @param e entity to add into the group.
*/
public void add(Entity e, String group) {
Bag<Entity> entities;
if (!entitiesByGroup.containsKey(group))
{
entities = new Bag<Entity>();
entitiesByGroup.put(group, entities);
}
else
{
entities = entitiesByGroup.get(group);
}
entities.add(e);
Bag<String> groups;
if (!groupsByEntity.containsKey(e))
{
groups = new Bag<String>();
groupsByEntity.put(e, groups);
}
else
{
groups = groupsByEntity.get(e);
}
groups.add(group);
}
示例11: getExclusiveEntities
import com.artemis.utils.Bag; //导入依赖的package包/类
/**
* Get all entities that only belong to the provided group
* @param group
* @return
*/
public ImmutableBag<Entity> getExclusiveEntities(String group) {
ImmutableBag<Entity> entities = getEntities(group);
Bag<Entity> bag = new Bag<Entity>();
//check for collisions
for (int i = 0; i < entities.size(); i++)
{
Entity e = entities.get(i);
if (getGroups(e).size() == 1){
bag.add(e);
}
}
return bag;
}
示例12: World
import com.artemis.utils.Bag; //导入依赖的package包/类
public World() {
managers = new ObjectMap<Class<? extends Manager>, Manager>();
managersBag = new Bag<Manager>();
systems = new ObjectMap<Class<?>, EntitySystem>();
systemsBag = new Bag<EntitySystem>();
added = new Bag<Entity>();
changed = new Bag<Entity>();
deleted = new Bag<Entity>();
enable = new Bag<Entity>();
disable = new Bag<Entity>();
cm = new ComponentManager();
setManager(cm);
em = new EntityManager();
setManager(em);
}
示例13: MdxWorld
import com.artemis.utils.Bag; //导入依赖的package包/类
/**
* Creates a new world
*
* @param configuration The configuration to be applied
*/
public MdxWorld(WorldConfiguration configuration) {
super(configuration);
interpolatingSystemsBag = new Bag<InterpolatingSystem>();
renderingSystemsBag = new Bag<RenderingSystem>();
mdxInvocationStrategy = new MdxInvocationStrategy();
for(BaseSystem system : configuration.systems) {
if(system instanceof InterpolatingSystem) {
interpolatingSystemsBag.add((InterpolatingSystem) system);
}
if(system instanceof RenderingSystem) {
renderingSystemsBag.add((RenderingSystem)system);
}
}
setInvocationStrategy(mdxInvocationStrategy);
}
示例14: initialize
import com.artemis.utils.Bag; //导入依赖的package包/类
@Override
public void initialize() {
collisionPairs = new Bag<CollisionPair>();
collisionPairs.add(new CollisionPair(Groups.PLAYER_BULLETS, Groups.ENEMY_SHIPS, new CollisionHandler() {
// TODO separate this out into a seperate collision handler so I can have both this and player/enemy collisions
@Override
public void handleCollision(Entity bullet, Entity enemy) {
Position enemyPosition = positionMapper.get(enemy);
EntityFactory.createEnemyExplosion(world, enemyPosition.pos.x, enemyPosition.pos.y).addToWorld();
EntityFactory.freeEntity(bullet);
EntityFactory.freeEntity(enemy);
bullet.deleteFromWorld();
enemy.deleteFromWorld();
}
}));
}
示例15: copyEntityFromOldWorld
import com.artemis.utils.Bag; //导入依赖的package包/类
/**
* Copy entity from old world into the new one.
*
* This assumes the old world is no longer in use, and is potentially unsafe if it isn't. (The components are not cloned, just reused!)
*/
public static Entity copyEntityFromOldWorld( Entity old )
{
Entity entity = Tox.world.createEntity();
Bag<Component> fillBag = new Bag<Component>();
old.getComponents(fillBag);
for ( Component comp : fillBag )
{
entity.addComponent(comp);
}
return entity;
}