Jump to content

P2JS - Low performance with 3000 object (serious game project)


Hadik
 Share

Recommended Posts

I create a lot of game in Phaser.IO (for example very popular IO game mudwars.io - about 20k visitors per day) and I am now prepareing for next project, when I need some kind of P2JS system, where I can simulate huge number of blocks.

 

But when I place about 3000 blocks, game performace is poor, on my (i5-4460 and AMD R9 270X) I got only 16 FPS.. So phaser is unusable, and I planning use much more counts, like 50 000 blocks.

Then I try same thing in the Unity engine (2D), and with same numbers of blocks, I got full FPS(without vsync around 120 FPS).

 

So is there any option how I can optimalizte phaser, or is unusable for this kind of project ? Thank you for reply

Link to comment
Share on other sites

Unity exports to WebGL only whereas Phaser works with both Canvas and Webgl - make sure rendering it's set to AUTO - WebGL it's much faster than canvas.

P2 it's slow but if you're in need of simple physics Arcade it's better in terms of performance. 

50k blocks - that's a lot of game objects to be updated even without physics. Are they all going to be on the screen (visible section) simultaneously? 

There are lots of tricks for handling such a large number of objects but they do depend on how those objects are going to be spawned and used. 

And as a final solution you could roll your own simplified physics system - though it will involve lots of math and physics and not sure if it will be very optimized.

Link to comment
Share on other sites

With both method I got almost same FPS.

Can arcade hold physics like this (video bellow), I need simple physics, when I will simulate "blocks" in zero gravity space, unfortunetly I will also need joints for connect these blocks together, and make complex strucutres. On the other hand, in game will be around 50 000 blocks, but on the view, will be only about 500 maybe less, but I trying in P2JS disable physics out of camere view but withou success.

 

Also only few block require full P2JS, rest of block will be out of screen, I want make complex strucutres from these blocks, but on the other hand every block should be object, because I need detect collision (hit), on block level, not full strucuter, because every block will be destroyable. So only few count of blocks requre complex physics, other will be only dummy for other network players.

 

(test with 100 blocks... with 3000 I got 16 FPS)

)

Link to comment
Share on other sites

3000 full physics bodies sounds like quite a lot for P2 to handle at once, especially with no sleeping or culling going on.

You could rule out Phaser entirely by just using p2 (it has a Pixi renderer available) and see what happens. My guess is it won't be able to handle it. Perhaps try Matter.js instead, or use Unity.

Link to comment
Share on other sites

I think 50.000 bodies will be very difficult to manage, even if you use techniques to manage your physics (within your viewport). If you really want to simplify the physics, maybe you can make your own deterministic model.Here is an example of how to mimic the colliding boxes (144 boxes):

 

Here you are only adding physical bodies to objects that are close enought to the main object and you only use it to set the velocity of the small cubes. It is an oversimplified model, since it does not even rotate the bodies unlike in the video and there is no interaction (collision checking) between the small boxes . However, If you do not care about the realism, just the visual effect, then it could be useful. For example if your main object is traveling fast troughout the scene then you might be able to procedurally generate those boxes.

Here for example, is the exact same scene, but without using any built in physics system (you are just checking collision manually based upon relative position):

 

You could have scenes in which you use the arcade physics where necessary and make everything else deterministic using your own system. Another idea might be to see if you can use particlesystems to visualize the boxes moving around in space?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

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