@Override public void addSystem(EntitySystem system) { super.addSystem(system); if (EntityListener.class.isInstance(system)) { this.addEntityListener((EntityListener) system); } if (InputProcessor.class.isInstance(system)) { inputs.addProcessor((InputProcessor) system); } if (ContactListener.class.isInstance(system)) { contactSystems.add((ContactListener) system); } }
@Override protected void inserted(Entity e) { World b2World; // Adding to box2D world if( universe.containsKey(transformMapper.get(e).mapId) ) { b2World = universe.get(transformMapper.get(e).mapId); } else { b2World = newWorld(e); b2World.setContactListener(this); universe.put( transformMapper.get(e).mapId, b2World ); } // Adding contact listeners if( !contactListeners.containsKey(transformMapper.get(e).mapId) ) { contactListeners.put( transformMapper.get(e).mapId, new ArrayList<ContactListener>() ); } // Body initialization bodyMapper.get(e).physicsBody.initialize( b2World ); bodyMapper.get(e).getBody().setUserData(e); previousMap.put(e, transformMapper.get(e).mapId); updateBody(e); }
public void remove(ContactListener listener) { for (ObjectMap<Short, ContactListener> listenerMap : listeners.values()) { ObjectMap.Entries<Short, ContactListener> entries = listenerMap.entries(); while (entries.hasNext()) { ObjectMap.Entry<Short, ContactListener> entry = entries.next(); if (entry.value == listener) { entries.remove(); } } } }
@Override public void beginContact(Contact contact) { Fixture fixtureA = contact.getFixtureA(); Fixture fixtureB = contact.getFixtureB(); ContactListener listener = get( fixtureA.getFilterData().categoryBits, fixtureB.getFilterData().categoryBits ); if (listener != null) { listener.beginContact(contact); } }
@Override public void endContact(Contact contact) { Fixture fixtureA = contact.getFixtureA(); Fixture fixtureB = contact.getFixtureB(); ContactListener listener = get( fixtureA.getFilterData().categoryBits, fixtureB.getFilterData().categoryBits ); if (listener != null) { listener.endContact(contact); } }
@Override public void preSolve(Contact contact, Manifold oldManifold) { Fixture fixtureA = contact.getFixtureA(); Fixture fixtureB = contact.getFixtureB(); ContactListener listener = get( fixtureA.getFilterData().categoryBits, fixtureB.getFilterData().categoryBits ); if (listener != null) { listener.preSolve(contact, oldManifold); } }
@Override public void postSolve(Contact contact, ContactImpulse impulse) { Fixture fixtureA = contact.getFixtureA(); Fixture fixtureB = contact.getFixtureB(); ContactListener listener = get( fixtureA.getFilterData().categoryBits, fixtureB.getFilterData().categoryBits ); if (listener != null) { listener.postSolve(contact, impulse); } }
private void addInternal(short categoryA, short categoryB, ContactListener listener) { ObjectMap<Short, ContactListener> listenerMap = listeners.get(categoryA); if (listenerMap == null) { listenerMap = new ObjectMap<Short, ContactListener>(); listeners.put(categoryA, listenerMap); } listenerMap.put(categoryB, listener); }
private ContactListener get(short categoryA, short categoryB) { ObjectMap<Short, ContactListener> listenersMap = listeners.get(categoryA); if (listenersMap == null) { return null; } return listenersMap.get(categoryB); }
@Override public void beginContact(Contact contact) { Fixture fixtureA = contact.getFixtureA(); Fixture fixtureB = contact.getFixtureB(); ContactListener listener = getListener(fixtureA.getFilterData().categoryBits, fixtureB.getFilterData().categoryBits); if (listener != null) { listener.beginContact(contact); } }
@Override public void endContact(Contact contact) { Fixture fixtureA = contact.getFixtureA(); Fixture fixtureB = contact.getFixtureB(); ContactListener listener = getListener(fixtureA.getFilterData().categoryBits, fixtureB.getFilterData().categoryBits); if (listener != null) { listener.endContact(contact); } }
@Override public void preSolve(Contact contact, Manifold oldManifold) { Fixture fixtureA = contact.getFixtureA(); Fixture fixtureB = contact.getFixtureB(); ContactListener listener = getListener(fixtureA.getFilterData().categoryBits, fixtureB.getFilterData().categoryBits); if (listener != null) { listener.preSolve(contact, oldManifold); } }
@Override public void postSolve(Contact contact, ContactImpulse impulse) { Fixture fixtureA = contact.getFixtureA(); Fixture fixtureB = contact.getFixtureB(); ContactListener listener = getListener(fixtureA.getFilterData().categoryBits, fixtureB.getFilterData().categoryBits); if (listener != null) { listener.postSolve(contact, impulse); } }
private void addListenerInternal(short categoryA, short categoryB, ContactListener listener) { ObjectMap<Short, ContactListener> listenerCollection = listeners.get(categoryA); if (listenerCollection == null) { listenerCollection = new ObjectMap<Short, ContactListener>(); listeners.put(categoryA, listenerCollection); } listenerCollection.put(categoryB, listener); }
private ContactListener getListener(short categoryA, short categoryB) { ObjectMap<Short, ContactListener> listenerCollection = listeners.get(categoryA); if (listenerCollection == null) { return null; } return listenerCollection.get(categoryB); }
@Override public void beginContact(Contact contact) { mContacts.add(new StableContact(contact)); Actor aa = (Actor) contact.getFixtureA().getBody().getUserData(); Actor ab = (Actor) contact.getFixtureB().getBody().getUserData(); if (aa instanceof Knocked) { ((Knocked) aa).knocked(ab); } else if (ab instanceof Knocked) { ((Knocked) ab).knocked(aa); } for (ContactListener l : mListeners) { l.beginContact(contact); } }
@Override public void endContact(Contact contact) { for (int i = 0; i < mContacts.size(); i++) { StableContact c = mContacts.get(i); if (c.getFixtureA() == contact.getFixtureA() && c.getFixtureB() == contact.getFixtureB()) { mContacts.remove(i); } } for (ContactListener l : mListeners) { l.endContact(contact); } }
@SuppressWarnings("unchecked") public ScaledBox2DSystem() { super( Aspect.getAspectForAll(Transform.class, PhysicsBodyComponent.class) ); universe = new Hashtable<Integer,World>(); contactListeners= new Hashtable<Integer, List<ContactListener>>(); globalListeners = new ArrayList<ContactListener>(); previousMap = new Hashtable<Entity, Integer>(); }
public void add(short categoryA, short categoryB, ContactListener listener) { addInternal(categoryA, categoryB, listener); addInternal(categoryB, categoryA, listener); }
public void addContactListener(ContactListener contactListener) { contactListeners.add(contactListener); }
public void removeContactListener(ContactListener contactListener) { contactListeners.remove(contactListener); }
@Override public void beginContact(Contact contact) { for (ContactListener contactListener : contactListeners) { contactListener.beginContact(contact); } }
@Override public void endContact(Contact contact) { for (ContactListener contactListener : contactListeners) { contactListener.endContact(contact); } }
@Override public void preSolve(Contact contact, Manifold oldManifold) { for (ContactListener contactListener : contactListeners) { contactListener.preSolve(contact, oldManifold); } }
@Override public void postSolve(Contact contact, ContactImpulse impulse) { for (ContactListener contactListener : contactListeners) { contactListener.postSolve(contact, impulse); } }
public void setContactListener(final ContactListener pListener) { this.mWorld.setContactListener(pListener); }
public ContactListener getContactListener() { return null; }
public CollisionHandler() { listeners = new ObjectMap<Short, ObjectMap<Short, ContactListener>>(); }
public void addListener(short categoryA, short categoryB, ContactListener listener) { addListenerInternal(categoryA, categoryB, listener); addListenerInternal(categoryB, categoryA, listener); }
public ContactListenerMultiplexer(final ContactListener... receivers) { super(receivers); }
public ContactListenerMultiplexer(final Array<ContactListener> receivers) { super(receivers); }
@Override public void beginContact(final Contact contact) { for (ContactListener listener : receivers) { listener.beginContact(contact); } }
@Override public void preSolve(final Contact contact, final Manifold oldManifold) { for (ContactListener listener : receivers) { listener.preSolve(contact, oldManifold); } }
@Override public void postSolve(final Contact contact, final ContactImpulse impulse) { for (ContactListener listener : receivers) { listener.postSolve(contact, impulse); } }
@Override public void endContact(final Contact contact) { for (ContactListener listener : receivers) { listener.endContact(contact); } }
public Array<ContactListener> getContactSystems() { return contactSystems; }
/** * Constructor */ public ContactHandler() { mContacts = new ArrayList<StableContact>(); mListeners = new ArrayList<ContactListener>(); }
@Override public void preSolve(Contact contact, Manifold oldManifold) { for (ContactListener l : mListeners) { l.preSolve(contact, oldManifold); } }
@Override public void postSolve(Contact contact, ContactImpulse impulse) { for (ContactListener l : mListeners) { l.postSolve(contact, impulse); } }
public void addListener(ContactListener listen) { mListeners.add(listen); }