English Why does CS2D lag with many objects?

6 replies
Goto Page
To the start Previous 1 Next To the start
Up
AtomKuh
User
Offline Off
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
07.04.20 06:08:26 pm
Up
DC
Admin
Online On
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.
www.UnrealSoftware.de | www.CS2D.com | www.CarnageContest.com | Use the forum & avoid PMs!
07.04.20 06:52:45 pm
Up
Mami Tomoe
User
Offline Off
tl;dr

CS2D is single threaded and (mostly) every task is too slow for such a massive amount of AI to exist in a stable manner.
08.04.20 12:49:13 am
Up
AtomKuh
User
Offline Off
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...?
08.04.20 12:51:21 am
Up
Cure Pikachu
User
Offline Off
Has been answered elsewhere but no, at the moment you can't remove turrets/dispensers/supplies and such w/o the explosion effect.
IMG:https://i.imgur.com/uUrye71.png
IMG:https://i.imgur.com/xpsyQRX.png
08.04.20 12:52:46 am
Up
AtomKuh
User
Offline Off
too bad...

Another question: is it possible to change the creator of a building while it stays "alive"?
08.04.20 01:30:57 am
Up
Cure Pikachu
User
Offline Off
Also no, at least not that I know of. You want to "change ownership" of a building, closest I can think of is blow up building then immediately spawn another in its place.
IMG:https://i.imgur.com/uUrye71.png
IMG:https://i.imgur.com/xpsyQRX.png
To the start Previous 1 Next To the start