Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags
0
Members

Mitigating lag from high numbers of actors

A topic by soozesayer created Jan 21, 2016 Views: 437 Replies: 2
Viewing posts 1 to 2

My current project is a shmup, leaning more towards the 'bullet hell' type - i.e. emphasis on dense patterns of bullets. Naturally, this leads to issues with processing demands, though this seemed to happen sooner than I would've hoped - in my test build thus far, the lag becomes noticeable as early as spawning two moderately sized enemies. I've tried to shift some code around to avoid calling functions constantly when I don't need to (i.e. get/setVelocity() on a bullet that's not going to be changing in velocity) but I don't know how much simpler I can make the scripts. Any general tips/advice for cutting the lag further? If it's this bad here, then where I'm going with it would end up being a nightmare...

Moderator (1 edit) (+3)

Hey!

I'd recommend that you use the dev tools (F12 while your game is running, or F6 when launching your game) to grab a CPU profile and look where most of your game's time is spent. See https://developers.google.com/web/tools/chrome-dev... and/or https://developer.chrome.com/devtools/docs/cpu-pro....

Here are some ideas of what MIGHT be performance bottlenecks:

  1. Does each one of your bullets have a behavior? You might want to add them to a list instead and have a single bullet manager that takes care of moving them around by looping over them. Less work for the engine.
  2. Are you creating / deleting bullets all the time? You could create a pool of hidden / unused bullets when the game starts. Make them invisible and add them to a list that you can pick from when you need to spawn a new bullet. Once a bullet goes offscreen, remove it from the live bullet list and add it back to the available bullets pool. Less work allocating, creating, destroying and garbage collecting bullets for the engine.

But don't do any of that until you have profiled and located where most of your game actually spends its CPU time or you might end up optimizing the 5% instead of the 95%.

(+1)

Thanks for the advice! These tips (along with plugging a couple memory leaks I found w/ the dev tools) help set me on the right track, and things are looking better already.