8

This is more of a question as to request some advice on which pattern/approach I should use. I have done some investigations into this problem - with poor results.

Essentially I have an idea for a game, in which the key gameplay mechanic is based around falling snow - or, in the case of this idea game - falling particles.

The snow/particles need to fall down the screen - but accumulate in piles. The issue is, I need to snow to 'trickle down' the sides of the piles, when they are certain angle, and continue to accumulate. It is possible that holes open underneath piles of snow, and the snow has to fall out - think like sand falling through an hourglass.

I have tried this is Box2d - it is clear that Box2d isn't the right choice for 10,000's of tiny particles - that last for long periods of time. Box 2D chugged to death pretty quickly.

I tried drawing 1px bitmaps onto the screen, but processing 10,000's of collisions every update proved to be poorly performing too.

Any ideas would be appreciated.

Cheers

Dave Bish
  • 19,263
  • 7
  • 46
  • 63
  • You're probably going to end up with a 3dMark competitor... 10000s of persistent particles sound like a job for CUDA anyway – Alex Feb 25 '13 at 15:39
  • can you clarify - is it 2d or 3d, does the snow only accumualte by falling from above and what size if you play area? – Stuart Feb 25 '13 at 17:33
  • I'm making a tile-based 2d platformer game, and when I draw 200'000 sprites at full hd it gives me 60 frames per second on 2008 mediocre desktop, so I don't think that 10'000 sprites should be of concern. The collision logic might be flawed which gives poor results, like for example the OP may be running checks between all snowflakes, when some of them are too far away to qualify for checks. – user1306322 Feb 25 '13 at 21:25
  • Can you post a link to your project? It sounds interesting =) – Kevin Feb 26 '13 at 00:23
  • @Stuart The play area would idealy be full-screen - but the Gameplay would still work with larger 'snow' to lower the number of sprites... – Dave Bish Feb 27 '13 at 09:59

3 Answers3

1

Well, just like you discovered, no existing library will help you unless it's geared very specifically toward your scenario. With XNA unfortunately there aren't many things to choose from, and it looks like none of the existing particle system libraries support particle physics.

So you'll need to do a lot of work yourself. First and foremost you need to think of all the optimizations you can possibly do. Like a comment said, you shouldn't run checks between all particles every frame. You should use a point-based collision check instead of the fancier stuff usually used by physics engines. You should make sure the particles are always the same size, in this case (relative to a reference coordinate system that is, that doesn't mean you couldn't have zoom). And of course you need to skip as many collision checks as possible - the particles you know are at rest should never be checked, like the ones that have adjacent particles on all sides - which leads me to think of grids. Perhaps you could represent the entire 'world' as a grid, and simplify the logic from this point of view - pretty much the same as Minecraft does, wouldn't you agree?

Anyway, I realize I'm rambling a bit but it's such an open subject... :)

Alex Paven
  • 5,539
  • 2
  • 21
  • 35
1

Take a lot at this Cool Effects (for XNA & MonoGame) http://www.int6.org/development/cool-effects-for-xna-monogame/

There's no snow effect, but there are some interest effect you can use o modify.

Vackup
  • 652
  • 4
  • 11
1

Is it possibly to monitor which particles are actually being processed by the physics engine? If so, is there a way whereby you can stop processing their physics, or severely limit what is processed, if their velocity is less than 0.01 or something of the like?

If you only process the particles that need processing, then you can have as many as you like, assuming that they are not all moving at once!

If this is still a problem, it sounds like a fluid dynamics solution may be more fitting, as fluid dynamics is basically a whole lot of small, moving particles.

Here is some interesting information on 2D fluid dynamics:

http://www.ibiblio.org/e-notes/webgl/gpu/fluid.htm

Your physics engine may already contain what you need.

rhughes
  • 9,257
  • 11
  • 59
  • 87