A small trick for everybody, if i think right? (About Bullet Collision Performance)


(Bora Kasap) #1

eBullet means Enemy Bullet, so pBullet is Player Bullet

This functions are in a static class(GLOBALS) and works only when i want:

CHECKeBulletPlayerCollisions();
CHECKpBulletEnemyCollisions();

And this functions are in World class’ Update function:

if (classFirst(pBullet) != null && classFirst(Enemy) != null)
			{
				GLOBALS.CHECKpBulletEnemyCollisions();
			}

if (classFirst(eBullet) != null && classFirst(Player) != null)
			{
				GLOBALS.CHECKeBulletPlayerCollisions();
			}

Now my game performance unbelievable for my netbook!

Other way, all the bullets checking collision for enemy instances. Now it is looking like the same thing with a small difference, but i think i got it now, it is not a small difference.

When bullets checking collision they own, each bullet creating an array of enemy instances inside each one of them. But when it is a single collision function, only there are 2 arrays for 2 entity types.


(Jacob Albano) #2

I obviously don’t have the code to test it myself, but I’m not sure why this would make a difference. Flashpunk’s collision functions already exit early if the type to be collided against doesn’t exist in the world.


(Bora Kasap) #3

you’re so right, i mean it is not about that. it is about each one of bullets creating an array of enemy instances to check their own collision. but thats not neccessary… all arrays are the same


(Bora Kasap) #4

maybe you are right, maybe it is about something other… because now i realized that: bullets not creating “array of enemy insances”, they are using an array of types created by flashpunk and updated continuously inside FP.world… right?


(Jacob Albano) #5

That’s right. Again, I don’t have your specific code so it very well may be that this is an optimization that works for you.