some (useful) remarks about particleemitter

Content and general development discussion, including quest scripts and server code. TMW Classic is a project comprising the Legacy tmwAthena server & the designated improved engine server based on evolHercules.


Forum rules

This forum houses many years of development, tracing back to some of the earliest posts that exist on the board.

Its current use is for the continued development of the server and game it has always served: TMW Classic.

Post Reply
ManaTux
Peon
Peon
Posts: 3
Joined: 18 Aug 2008, 20:41

some (useful) remarks about particleemitter

Post by ManaTux »

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 http://en.wikipedia.org/wiki/Linear_con ... _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