本文整理了Java中com.artemis.utils.Bag
类的一些代码示例,展示了Bag
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Bag
类的具体详情如下:
包路径:com.artemis.utils.Bag
类名称:Bag
[英]Collection type a bit like ArrayList but does not preserve the order of its entities, speedwise it is very good, especially suited for games.
[中]
代码示例来源:origin: net.mostlyoriginal.artemis-odb/contrib-components-libgdx
/** Safely delete all entities from bag, regardless if the bag changes. */
public static void safeDeleteAll(final ImmutableBag<Entity> entities1) {
final Bag<Entity> entities = new Bag<>();
entities.addAll(entities1);
for (int i = 0, s = entities.size(); i < s; i++) {
entities.get(i).deleteFromWorld();
}
}
}
代码示例来源:origin: junkdog/artemis-odb
ComponentIdentityResolver() {
compositionBits = new Bag(BitVector.class);
compositionBits.add(new BitVector());
compositionMappers = new Bag<Bag<ComponentMapper>>();
compositionMappers.add(new Bag(ComponentMapper.class));
}
代码示例来源:origin: junkdog/artemis-odb
private TransmuteOperation operation(int entityId, int compositionId) {
TransmuteOperation operation = operations.safeGet(compositionId);
if (operation == null) {
operation = factory.createOperation(entityId);
operations.set(compositionId, operation);
}
return operation;
}
代码示例来源:origin: stackoverflow.com
Bag myBag = new HashBag();
myBag.add("Orange");
myBag.add("Apple", 4);
myBag.add("Apple");
myBag.remove("Apple", 2);
int apples = myBag.getCount("Apple"); // Should be 3.
int kumquats = myBag.getCount("Kumquat"); // Should be 0.
代码示例来源:origin: net.mostlyoriginal.artemis-odb/contrib-core
/**
* Sort bag.
* Entities must implement Sortable.
*
* Be aware that bags require a resort when you
* remove entries.
*/
public static void sort(Bag bag) {
if ( !bag.isEmpty() ) {
Arrays.sort(bag.getData(), 0, bag.size());
}
}
代码示例来源:origin: junkdog/artemis-odb
void processComponentIdentity(int id, BitVector componentBits) {
for (int i = 0, s = subscriptions.size(); s > i; i++) {
subscriptions.get(i).processComponentIdentity(id, componentBits);
}
}
代码示例来源:origin: junkdog/artemis-odb
@Override
public void validate(int sourceId, Bag<Entity> entities, LinkListener listener) {
for (int i = 0; entities.size() > i; i++) {
Entity e = entities.get(i);
if (!all.getActiveEntityIds().unsafeGet(e.getId())) {
entities.remove(i--);
if (listener != null)
listener.onTargetDead(sourceId, e.getId());
}
}
}
代码示例来源:origin: junkdog/artemis-odb
/** Fetch unique identity for passed composition. */
int getIdentity(BitVector components) {
Object[] bitsets = compositionBits.getData();
int size = compositionBits.size();
for (int i = NO_COMPONENTS; size > i; i++) { // want to start from 1 so that 0 can mean null
if (components.equals(bitsets[i]))
return i;
}
return -1;
}
代码示例来源:origin: junkdog/artemis-odb
int allocateIdentity(BitVector componentBits, ComponentManager cm) {
Bag<ComponentMapper> mappers =
new Bag<ComponentMapper>(ComponentMapper.class, componentBits.cardinality());
ComponentTypeFactory tf = cm.getTypeFactory();
for (int i = componentBits.nextSetBit(0); i >= 0; i = componentBits.nextSetBit(i + 1)) {
mappers.add(cm.getMapper(tf.getTypeFor(i).getType()));
}
compositionMappers.add(mappers);
compositionBits.add(new BitVector(componentBits));
return compositionBits.size() - 1;
}
}
代码示例来源:origin: net.mostlyoriginal.artemis-odb/contrib-eventbus
@Override
public void process() {
Object[] eventsToDispatch = eventQueue.getData();
int i = 0;
int s = eventQueue.size();
while (i < s) {
for (; i < s; i++) {
Event event = (Event) eventsToDispatch[i];
super.dispatch(event);
}
// we may end up having more events to dispatch at this point
// - some event handlers could dispatch more events
s = eventQueue.size();
}
eventQueue.clear();
}
代码示例来源:origin: junkdog/artemis-odb
@Override
public void onCreated(ComponentType type) {
Bag<LinkSite> links = linkFactory.create(type);
if (links.isEmpty())
return;
for (int i = 0, s = links.size(); s > i; i++) {
elm.linkSites.add(links.get(i));
}
}
}
代码示例来源:origin: junkdog/artemis-odb
void translate(Component c, Field field, Bag<Entity> translatedIds) {
try {
Bag bag = (Bag) field.get(c);
for (int i = 0, s = bag.size(); s > i; i++) {
Object o = bag.get(i);
if (o instanceof Entity) {
bag.set(i, translatedIds.get(((Entity)o).getId()));
} else {
return;
}
}
} catch (ReflectionException e) {
throw new RuntimeException(e);
}
}
};
代码示例来源:origin: junkdog/artemis-odb
/**
* Add listener interested in changes to the subscription.
*
* @param listener listener to add.
*/
public void addSubscriptionListener(SubscriptionListener listener) {
extra.listeners.add(listener);
}
代码示例来源:origin: junkdog/artemis-odb
private void growEntityStores() {
int newSize = 2 * entities.getCapacity();
entities.ensureCapacity(newSize);
ComponentManager cm = world.getComponentManager();
cm.ensureCapacity(newSize);
for (int i = 0, s = entityBitVectors.size(); s > i; i++) {
entityBitVectors.get(i).ensureCapacity(newSize);
}
}
代码示例来源:origin: junkdog/artemis-odb
private Builder() {
allTypes = new Bag<Class<? extends Component>>();
exclusionTypes = new Bag<Class<? extends Component>>();
oneTypes = new Bag<Class<? extends Component>>();
}
代码示例来源:origin: junkdog/artemis-odb
public ArchetypeMapper(World world, IntBag toSave) {
int[] ids = toSave.getData();
Bag<Component> components = new Bag<Component>();
Bag<Class<? extends Component>> types = new Bag<Class<? extends Component>>();
for (int i = 0, s = toSave.size(); s > i; i++) {
int compositionId = world.getEntity(ids[i]).getCompositionId();
if (!compositionIdMapper.containsKey(compositionId)) {
components.clear();
types.clear();
world.getComponentManager().getComponentsFor(ids[i], components);
compositionIdMapper.put(compositionId,
new TransmuterEntry(toClasses(components, types)));
}
}
}
代码示例来源:origin: net.mostlyoriginal.artemis-odb/contrib-core
/**
* Remove this id from the tree
*/
public void remove (int id) {
Container c = idToContainer.get(id);
if (c == null)
return;
if (c.parent != null) {
c.parent.containers.remove(c);
}
cPool.free(c);
}
代码示例来源:origin: junkdog/artemis-odb
/**
* Gets component type by index.
* <p>
* @param index maps to {@link ComponentType}
* @return the component's {@link ComponentType}
*/
public ComponentType getTypeFor(int index) {
return types.get(index);
}
代码示例来源:origin: net.mostlyoriginal.artemis-odb/contrib-eventbus
/**
* 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;
}
代码示例来源:origin: DaanVanYperen/artemis-odb-contrib
/**
* Clears entire pool.
*/
public void clear() {
pool.clear();
}
内容来源于网络,如有侵权,请联系作者删除!