some (useful) remarks about particleemitter

Content and general development discussion, including maps, quests, and server code from the development team.
Post Reply
Posts: 3
Joined: 18 Aug 2008, 21:41

some (useful) remarks about particleemitter

Post by ManaTux » 19 Aug 2008, 03:13

in fact about randomness in general...
The use of rand() should be avoided. Not because of poor randomness, of course you don't need better quality, but because of performance. The overhead caused by repeated function calls can be significant for particles generation.

I would recommend to replace rand with a more efficient custom function.
you might use the glibc rand definition (according to ... _generator)

Code: Select all

unsigned int state=0x19082008;  //might be seeded somewhere

inline int myrand(){
  state = (state*1103515245)+12345;
  return state & RAND_MAX;
(putting this inside a class could be better)

this gives a 10x faster rand

This is really easy to do (mainly change only minmax.h) and can bring better performance for large particles systems.
It is also really clear and easy to use...
If you find some reason not to use this... I would be glad to hear them!
Post Reply