Particle engine...

Community Forums/Showcase/Particle engine...

Yahfree(Posted 2008) [#1]
Hey, just as a side experiment to help learn C++, I revamped my older 2d particle system with some C++ routines for extra speed, and extra functions.

The engine features:

-C++ routines for extra speed
-simple Emit particle function to drop a particle
-Particles can be automaticaly faded away/rotatated to their direction
-Can render multible layers of particles, by setting a Z parameter on a partical at creation.
-Can offset a particle/group of particles
-Can add a force to a particle, in otherwords, like the offset but it changes direction slowly (showing momentum ect.) this is what is used in this demo to create a gravity effect.
-Built in convince functions like ParticleExplosion, or ParticleCount.
-Can clear all the particles with a single call, or only certain layers.


Anyways, here's the module / a demonstration of it:

link

hold the LMB to do a rapid particle explosion, and the RMB to do a particle fountain.

Let me know what you guys think. I was going to go with arrays, but the complication is not worth the better preformance.


plash(Posted 2008) [#2]
Pretty good, there is a major slow-down when holding LMB though.

Sometimes complication is best :P

EDIT: Wow.. If I run the program in a separate desktop (using dapp) it runs at a constant 60-62 fps while holding RMB and LMB.


6(Posted 2008) [#3]
Hey, thats good work. Quite mesmerizing.


Abrexxes(Posted 2008) [#4]
Nice,no problems here. (IntelDualCore/Intel3100/XPsp3+Vista)


Moraldi(Posted 2008) [#5]
Good work!. Which lib did you use?


plash(Posted 2008) [#6]
Good work!. Which lib did you use?
His own?

Notice:
I revamped my older 2d particle system



Vilu(Posted 2008) [#7]
Very smooth. I'd love to see how many particles it could handle before slowing down. I'm getting no slowdown at all on my 5-year old IBM T40 lappy with both mouse buttons down and 1000+ particles on screen.


Yahfree(Posted 2008) [#8]
thanks for the feedback guys, the full module is up on the same link now, and the source/exe for that demo aswell.


MGE(Posted 2008) [#9]
Nornal rendering speed on my test boxes, once again, it's not the CPU speed, but the GPU speed that is always the bottleneck.


Yahfree(Posted 2008) [#10]
fixed a little bug with compiling the module, one of the source files was the wrong name...

JGOware, how do you give some of the processing job to the CPU? Are you just its all on the GPU? Because i've never messed with that stuff before, sounds interesting


plash(Posted 2008) [#11]
fixed a little bug with compiling the module, one of the source files was the wrong name...
I was going to mention that, but I couldn't remember if the main mod source had to be named the same as the module.

EDIT: I never tried to compile it :o


GW(Posted 2008) [#12]
I see the slowdown too. I wonder if its related to the creation/ destruction that happens in runtime.
Perhaps a better method is to create a large pool initially and simply turn them off rather than delete them. When creating a new particle, find the first one disabled and re-use it. Moving from a list to an array will speed thing up as well.


Craig H. Nisbet(Posted 2008) [#13]
I've been using C++ for a few months now. I really like it! I'd be very interested to learn how you got the c++ code into blitz. Can you explain the process required?


Yahfree(Posted 2008) [#14]
GW:

Thats the idea of arrays, and it won't be that hard to implement, I just have to figure out how, I did make an attempt, but it didnt agree with the C++ routines, causing some nasty pointer glitches.

Craig H. Nisbet:

This is the first time i've used C++ to help speed things up. With bmax its pretty straight forward, with B3D you have to do some DLL hattery.

Heres a 101:


You need to create your function in C++, in this case, it returns the int '2', for blitzmax to reconize it, you need to place a extern function around it, and name it "C" or anything i think :

extern "C" {
       
       
       int MyFunction() {
           return 2;
       }
       
       
       
}


Now in blitzmax you do the following:

1. import the C++ file
2. define the function(s) you want to use (use extern function)

Import "myfile.cpp"

'define function
Extern "C"
 Function MyFunction:Int()
End Extern

Print MyFunction()

End


should print '2'

that concludes the 101.


chwaga(Posted 2008) [#15]
nice, i had no slowdon whatsoever at over 1.2k particles!


Yahfree(Posted 2008) [#16]
Thanks, now back to work on the game that's actually using this