public Array<Contact> getContactList () { // FIXME pool contacts org.jbox2d.dynamics.contacts.Contact contactList = world.getContactList(); contacts.clear(); while (contactList != null) { Contact contact = new Contact(this, contactList); contacts.add(contact); contactList = contactList.m_next; } return contacts; }
/** Construct a world object. * @param gravity the world gravity vector. * @param doSleep improve performance by not simulating inactive bodies. */ public World (Vector2 gravity, boolean doSleep) { addr = newWorld(gravity.x, gravity.y, doSleep); contacts.ensureCapacity(contactAddrs.length); freeContacts.ensureCapacity(contactAddrs.length); for (int i = 0; i < contactAddrs.length; i++) freeContacts.add(new Contact(this, 0)); }
/** Returns the list of {@link Contact} instances produced by the last call to {@link #step(float, int, int)}. Note that the * returned list will have O(1) access times when using indexing. contacts are created and destroyed in the middle of a time * step. Use {@link ContactListener} to avoid missing contacts * @return the contact list */ public Array<Contact> getContactList () { int numContacts = getContactCount(); if (numContacts > contactAddrs.length) { int newSize = 2 * numContacts; contactAddrs = new long[newSize]; contacts.ensureCapacity(newSize); freeContacts.ensureCapacity(newSize); } if (numContacts > freeContacts.size) { int freeConts = freeContacts.size; for (int i = 0; i < numContacts - freeConts; i++) freeContacts.add(new Contact(this, 0)); } jniGetContactList(addr, contactAddrs); contacts.clear(); for (int i = 0; i < numContacts; i++) { Contact contact = freeContacts.get(i); contact.addr = contactAddrs[i]; contacts.add(contact); } return contacts; }
/** Construct a world object. * @param gravity the world gravity vector. * @param doSleep improve performance by not simulating inactive bodies. */ public World (Vector2 gravity, boolean doSleep) { addr = newWorld(gravity.x, gravity.y, doSleep); contacts.ensureCapacity(contactAddrs.length); freeContacts.ensureCapacity(contactAddrs.length); for (int i = 0; i < contactAddrs.length; i++) freeContacts.add(new Contact(this, 0)); }
/** Returns the list of {@link Contact} instances produced by the last call to {@link #step(float, int, int)}. Note that the * returned list will have O(1) access times when using indexing. contacts are created and destroyed in the middle of a time * step. Use {@link ContactListener} to avoid missing contacts * @return the contact list */ public Array<Contact> getContactList () { int numContacts = getContactCount(); if (numContacts > contactAddrs.length) { int newSize = 2 * numContacts; contactAddrs = new long[newSize]; contacts.ensureCapacity(newSize); freeContacts.ensureCapacity(newSize); } if (numContacts > freeContacts.size) { int freeConts = freeContacts.size; for (int i = 0; i < numContacts - freeConts; i++) freeContacts.add(new Contact(this, 0)); } jniGetContactList(addr, contactAddrs); contacts.clear(); for (int i = 0; i < numContacts; i++) { Contact contact = freeContacts.get(i); contact.addr = contactAddrs[i]; contacts.add(contact); } return contacts; }