Jump to content

game.physics.p2.setImpactEvents(false); leads to weird error


valueerror
 Share

Recommended Posts

firefox says:

   TypeError: c[a] is undefined

and chromium says:

Uncaught TypeError: Cannot read property 'indexOf' of undefined phaser.js:71135c.off phaser.js:71135Phaser.Physics.P2.setImpactEvents phaser.js:77354setupPhysics (index):527states.(anonymous function).create (index):361b.StateManager.loadComplete phaser.js:16585b.StateManager.preUpdate phaser.js:16358b.Game.update phaser.js:23088b.RequestAnimationFrame.updateRAF phaser.js:41421window.requestAnimationFrame.forceSetTimeOut._onLoop

in my game i am only using onBeginContact events..  so disabling impactEvents should be save or even recommended to gain performance ? 

Link to comment
Share on other sites

i removed EVERYTHING for my testcase. . so i do nothing else than this:

game.physics.startSystem(Phaser.Physics.P2JS);game.physics.p2.setImpactEvents(false); 

and still get the error..   i should probably file a bug report ? ! (or did i misinterpet the whole thing and you can not use it this way to disable the expensive impactEvents..)

 

until a day ago i thought NOT enabling impactEvents is enough..    (but actually couldn't make out ANY difference with or without those impact events..  i made heavy use of groupcollisioncallbacks and so on and it took a while to change the whole code to onBeginContact events.. but now that it's done and i see no difference at all i started to wonder if those calculations are really disabled - thats why i tried to definitely disable them..  and it doesn't work.

Link to comment
Share on other sites

This is only a small p2 error in the implementation of the event bus. That line causes you headache. The listeners array is accessed with an unknown key.

 var index = listeners[ type ].indexOf( listener );

https://github.com/schteppe/p2.js/blob/d1c7a340c42e4d5d1d939fba5fd13c5e49d6abd2/src/events/EventEmitter.js#L72

 

You won't get an error if you enable it beforehand (so that the listener type is available). See here:

http://jsfiddle.net/76Lzbofp/1/

 

You could fix it in phaser's implementation of 'setImpactEvents' or in p2's EventEmitter.

 

Regarding your performance question. 'setImpactEvents' is really disabled by default as there is no listener attached at the beginning. You can easily test if you enable or disable it and watch the events being received. As long as no event listener is attached to the p2 world there are no further calculations being made. While we are browsing through the source code have a look at the part where the specific impact event is build and dispatched:

 

https://github.com/schteppe/p2.js/blob/d1c7a340c42e4d5d1d939fba5fd13c5e49d6abd2/src/world/World.js#L800

 

See it? There are no extra calculations, it's just a convenient way to get the first collisions between two objects. You should look for other parts in your code to optimise performance. The "impact" attempt looks like a dead end to me.

 

Good luck!

Regards George

Link to comment
Share on other sites

as for other parts of the code that drain performance..  i made a test with a slow machine to actually see a difference and nothing i removed gave me more than 1 or 2 fps back..  i'm actually quite sure that there is not much i can do to boost performance further without sacrificing important gameplay features..   i use p2 with springs, revoluteconstraints, emitters, sounds - lets say everything you need for an interesting game :)  on my desktop i have 60 fps straight.. even on my nexus7 2013 in chrome i have 60fps most of the time...  but i am still concerned about slower devices.

 

one thing i noticed though is that the game needs 5 to 20 seconds on slower devices until it can run at 60fps ... the first time i trigger an emitter might also cause a frame drop down to 35 fps but the second time doesn't...

 

any idea if there is something i can do to address these occasional framedrops? 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...