I wanted to play a bit with particle systems, also the new (for me) java.util.concurrent classes. So I made a little multithreaded fireworks demo.

On my notebook drawing semi-transparent images is really slow. I suspect that with other graphics hardware it will be better. The other thing that bugs me is that despite threading, I could not get to 100% CPU, so my threads sleep/wait too often.

The demo will try to move as many particles as possible while retaining 30 FPS. On my notebook the screen looks a bit empty, but maybe you can get more out of it (33kb executable jar file).

23-24k particles here, around 37.5% CPU usage (100% on 3 cores I guess). If you're interested, I've made a few particle engines using different techniques (all using LWJGL though). If you search around the forum you can check them out if you want. One of my first ones used all available cores in your computer to update particles and can render 2 million particles at 60 FPS with 95-100% load on my hyperthreaded quad core (8 threads). It's actually RAM bandwidth limited, so that number would probably bump up a bit if I got some faster RAM for $40 or so.

If you're interested, I've made a few particle engines using different techniques (all using LWJGL though). If you search around the forum you can check them out if you want. One of my first ones used all available cores in your computer to update particles and can render 2 million particles at 60 FPS with 95-100% load on my hyperthreaded quad core (8 threads). It's actually RAM bandwidth limited.

Memory accesses are quite expensive indeed. I assume my own demo makes very bad use of cache and memory, many scattered reads and writes.

There are truly amazing particle engines, but in this case it's less the particle management but the drawing which is the bottleneck. I could use BufferedImages and write directly into the buffer like my raytracing demo does, but I wanted to use Java2D functions this time.

At the moment I'm trying to get a feeling what is slow and what is fast, and what are good ways to display graphics with Java if one doesn't want to bundle extra libs.

I have a demo which might look a bit better and might have better frame rate control, but it's hard to guesstimate if this code will adapt well to other machines:

Not too bad! You should consider more complex effects... like a particle effect that shoots up and has a particle trail and when it reaches the end it explodes. You could also have the particles that shoot out of that explode as well (much like actual fireworks).

The fountains are fun particle effects, but they're way too slow for compared to actual fireworks.

I've been trying to have it going smooth rather than fast. But it's alright, it's been an experiment and I'll let it rest now. I've learned a bit again, and want to work on a different project next, which was on hold for more than a year ... oh well. I just have too many ideas. I really must convince myself not to try to make an action RPG in low-graphics style in addition to all the other projects.

And I must look into music, what tools are nowadays used. I want to make a new raycasting demo with music and movements choreographed together - but the last time I tried to compose something was in the early 1990's when MOD files were popular and trackers were the tool of the trade ( http://en.wikipedia.org/wiki/Soundtracker#1990s_and_the_PC )

I've been trying to replace painting semi-transparent images for the glow effects with direct data buffer accesses and my own blending methods. I'd have expected that the standard Java implementation (which can use low level C libraries) is at least as efficient as my pure Java solution, but for some strange reason it isn't.

Latest version with above mentioned changes, and an upped particle limit (should max out at 26k particles, and still be more CPU efficient than before):

Edit: seems I have a race condition in the threading code which shows up more frequently now that the painting got more efficient. If the demo doesn't start or locks up, just kill it and start it again ...

Edit: Now also with less Math.sqrt ... (don't ask, I just had a brain fail when I coded that)

I've been finetuning my blending routines, and tried to balance the threading better. It should consume less CPU time now while showing a bit more particles than before. No big change in particle numbers though.

java-gaming.org is not responsible for the content posted by its members, including references to external websites,
and other references that may or may not have a relation with our primarily
gaming and game production oriented community.
inquiries and complaints can be sent via email to the info‑account of the
company managing the website of java‑gaming.org