Forum

> > CS2D > General > Why does CS2D lag with many objects?
Forums overviewCS2D overviewGeneral overviewLog in to reply

English Why does CS2D lag with many objects?

6 replies
To the start Previous 1 Next To the start

old Why does CS2D lag with many objects?

AtomKuh
User Off Offline

Quote
Why does CS2D lag so much when spawning a large number of objects? For example, 500 Zombie NPCs or Turrets...

Can this be prevented when hosting on a powerful machine? I mean CS2D is such a "tiny" game...
edited 2×, last 07.04.20 04:05:00 am

old Re: Why does CS2D lag with many objects?

DC
Admin Off Offline

Quote
A lot of objects cost a lot of performance. No matter what game it is. CS2D can't magically work without consuming any CPU or bandwidth

Especially "complicated" objects like the ones you mentioned are expensive. Both turrets and NPCs have to check the environment in short intervals to detect if there's an enemy nearby. That costs CPU performance.

Also, when creating these objects the data has to be sent to all clients. This costs a lot of bandwidth and causes a lot of traffic.

CS2D also isn't optimized to handle such a large number of objects. There probably would still be a lot of room for further optimizations but I didn't see a reason to do so because it works okay with "normal" numbers of objects.

So yes, if you want to spawn big amounts of objects that cost a lot of CPU power then you have to do it on a decent server with a good bandwidth. You should check the CPU and bandwidth usage of the server (e.g. CPU with top or htop) to see what's the limiting factor.

The alternative would be to try to spawn less objects. 500 turrets/NPCs sounds like an insane amount and way too much to me. Also note that Lua will cause further slow downs if it is involved and uses hooks triggered by these objects.

old Re: Why does CS2D lag with many objects?

AtomKuh
User Off Offline

Quote
I had the idea of saving buildings coordinates in a table and when a player is out of their range, these buildings will get destroyed. After they are near the coordinates these buildings could spawn again.

btw is there a way to disable the explosion after destroying turrets, dispensers...?
To the start Previous 1 Next To the start
Log in to replyGeneral overviewCS2D overviewForums overview