I haven't really worked with engines before, neither am I a pro in c++
but from the start of my game making obsession I've always optimized my games to the maximum
whether it was c# , java , actionscript or even blitz3D ( basic language ) there was always a way.
What makes me happy is the speed, the less CPU or memory it uses the better =)
So let me start with the ragdolls, I've noticed that it can get pretty nasty after you have a whole bunch of them
especially in the Bloody Massacre demo.
What you see there is a pile of bodies, now the problem is that those guys are still moving,
well not really moving but jiggling which is kind of creepy. makes me think that they'll come back to life or something.
I've also noticed some other problems I noticed once I have another ten or twenty bodies in
that same place the fps starts to decrease dramatically and even exponentially, it was kind of weird seeing
the fps drop from 60 to 10 after few kills, I also noticed that those bodies stayed active even if they were out of
the user's field of view.
Of course there are ways to prevent those stuff from happening, like making the ragdoll sleep after several seconds
after the it's parent's death, like for example npc dies , ragdoll gets activated and after several seconds it sets sleep(true)
Before posting I tried testing it out in the Blood Massacre Demo, everything ran better than I expected with a simple code such as :
Code:
if (time_after_death>50) ragdoll.sleep(true); else time_after_death++;
I honestly didn't expect for the bodies to wake up when they got in contact with another body
I managed to improve the game performance , fps stayed constant and the bodies didn't jiggle no more.
Later I tried making a pile of bodies to test it out the result was slow at first like last time but then after some time they all became inactive and everything got faster.
Now the problem, the reason why a body jiggles when you have to bodies one over another is because one ragdoll
pushes another which later pushes the one who pushed it which can kind of result in an infinite loop.
Imagine two ragdolls perfectly aligned over each other are dropped on a terrain, the result will be :
Ragdoll 1 who's under ragdoll 2 will touch the ground then it bounces a little off and pushes ragdoll 2 a bit up
then cause ragdoll 2 still hasn't touched the ground it will drop onto ragdoll 1 pushing it down, then since
ragdoll 1 obviously can't go though the floor, it will push itself up, pushing radoll 2 up again, and then everything repeats.
Now the solution, I thought only about one solution, it's a really simple one
making the ragdoll unable to push other ragdolls, it could be an option in the ragdoll class
that you can set on and off it'll come really handy in many situations.
I'd feel really stupid for writing all of this if there's already a way to do that