glest / glest-source

Glest is a network multi-player cross-platform 3D real-time strategy (RTS) game, where you create armies of units and battle different factions.
https://glest.io
GNU General Public License v3.0
57 stars 39 forks source link

game lags when there are a lot of units #142

Open andy5995 opened 6 years ago

andy5995 commented 6 years ago

A problem in other RTS games... playing with @MirceaKitsune I noticed that even when the units were reduced from ~1000 to 400, the lag only got slightly better. It was still horrible. Normally I wouldn't notice any lag at 400 units.

That was on a 128x256 map with many resources. The game started fine.

Every item on a map uses computer resources.

But it seems to me that once gold and other resources have been harvested from the map, and units die off, then the lag should decrease, not stay the same. In fact, there should be performance improvement if 80% of the gold on a map has been harvested 40 minutes into a game, for instance.

Note that lag seems significantly less for people using higher-powered GPUs, such as those used @Jammyjamjamman and david123.

MirceaKitsune commented 6 years ago

I can report that I was experiencing between 0.5 and 1 FPS at best. I could barely keep scrolling the view and clicking on things, it was pretty much unplayable.

The lag was triggered once a certain number of overall units was reached, after roughly 1 hour of gameplay. However even after most of them died off the lag persisted. Perhaps the engine was struggling to catch up with delays induced by computing so many units?

It only stopped after you told me you were leaving. At first I thought you disconnected, but since you were running the server and I waited to finish the game that couldn't have been the case. Perhaps it had to do with you no longer giving commands to units after a certain amount of time?

andy5995 commented 6 years ago

Posted in Discord:

@Jammyjamjamman - Today at 7:34 PM: @andy5995 yeah, I'm just working on the basic idea that more objects -> more lag. Also, certain objects are more demanding e.g. player units are more demanding than inanimate objects (gold, trees etc.) Another thing, objects which hold resources (wood, stone, gold) cause more lag than plain objects (rocks, shrubs, mountains).

andy5995: I have to wonder though... what happens when the map is filled with buildings? I mean.. we always look at the lag as happening with high unit counts, but the other thing that's happening at that time is there are more buildings occupying map space. And that would explain why the lag usually never improves when mobile, fighting units are killed off: because there are a lot of buildings still on the map. If not the enemies (from being destroyed at the end), then buildings that the winning team has still standing.

Notice how lag often happens maps with a lot of trees? So if the trees are already occupying a lot of map space, then buildings are added before many of the trees are harvested... lag!

Most maps don't have a ton of gold or stone, but are more likely to contain a ton of trees, like Paraiso, Land O Plenty, and Forest Path.

This theory will need more testing though.

andy5995 commented 6 years ago

For an initial test, I removed a lot of trees from the Forest Path map.. Lag started happening around 600 units, about 15 - 20 minutes in.

The Doodleville map is 128x64. a 6 player map instead of 8. (for the game above, 2 slots were empty, so a total of 6.) This game ran fine:

image

So did this one:

image

Why should there be such a difference between these 2 maps?

Jammyjamjamman commented 6 years ago

Well, there's a couple of other possibilities.

  1. Maybe the AI is getting its knickers in a twist and using up computing resources on particular maps. (This would be easy to test, with a human vs human game performance against human vs AI performance).

  2. Maybe the pathfinder gets its knickers in a twist on maps with complex cramped paths.

andy5995 commented 6 years ago

Maybe the pathfinder gets its knickers in a twist on maps with complex cramped paths.

Jammy - Yesterday at 7:39 PM One thing that concerns me about the AI is, it creates a list of commands and executes the oldest command in the list (FIFO queue), but I don't think there's a mechanism to control the size of the list.

On cramped maps, that command list has to be processed a lot more when units are told to attack or move, but takes them a long time because of terrain bottlenecks and trying to get around units that are in front.

As a result, that would mean the command list gets much longer. Right?

Jammyjamjamman commented 6 years ago

As a result, that would mean the command list gets much longer. Right?

That's certainly a plausible theory.