View Issue Details

IDProjectCategoryLast Update
0006873AI War 1 / ClassicBug - GameplayMar 27, 2012 4:02 pm
ReporterLemon Assigned Tokeith.lamothe  
Status assignedResolutionopen 
Product Version5.031 
Summary0006873: Beam weapons vs large stacks of units causes massive performance loss and stuttering.
DescriptionBeam weapons positioned so that they hit large numbers of units cause some really ugly performance loss.

For me, 4k enemy units arriving out of a wormhole starts stuttering as soon as more than 30 beam weapon units are in place to fire on it. More than 50 beam weapons will make it basically unplayable. I'm on an i7-2600, so I'm sure that plenty of other players will encounter stuttering at significantly lower numbers.

My guess is that there is something in the targeting code that isn't scaling up well. Something like with all the enemies being so close together its scanning all 4000 enemies 4000 times to determine the best shot to take, which is an ugly 16M loop. Might want to see if there is some way to optimize that or otherwise have some quicker less comprehensive algorithm to fall back on in extreme situations.

I'll upload a few test saves, but its a rather extreme game so anyone with a markedly different PC setup might not be able to handle the numbers of units I'm playing with in the first place.

This first save has a wave about to come in 0000001:0000001.5 mins, so you can prepare for it with the units you like.

Saves 2-4 all show fairly bad stuttering with various beam weapons. Test 1 can be shown to cause stuttering on my system with as little as 30 beam cannons.

Test 5 is aptly named the CPU melter, the battle will take less than 10s game time to complete but spend several minutes real time.

The final test has the entire fleet at a distance. Giving enemies a bit of time to spread out and then engaging removes the stutter problem, showing that it is purely the huge stacks of units being fired on that cause this issue.
TagsNo tags attached.
Internal WeightFix Before Major Release

Activities

Lemon

Mar 26, 2012 5:34 pm

reporter  

test.sav (594,287 bytes)

Lemon

Mar 26, 2012 5:35 pm

reporter  

test Beam cannon.sav (586,811 bytes)

Lemon

Mar 26, 2012 5:35 pm

reporter  

test Beam Frigates.sav (607,015 bytes)

Lemon

Mar 26, 2012 5:35 pm

reporter  

test spire.sav (585,479 bytes)

Lemon

Mar 26, 2012 5:36 pm

reporter  

test CPU Melter.sav (607,863 bytes)

Lemon

Mar 26, 2012 5:36 pm

reporter  

keith.lamothe

Mar 27, 2012 12:43 pm

administrator   ~0021428

Thanks for the thoroughness of report and saves :)

It doesn't actually check for best shot at all; that would indeed be ugly performance-wise.

In this case I think it's just that each of those beams has to do a "does line segment x1,y1:x2,y2 intersect circle of center x3,y3 with radius a" 4000 times, and when the enemy units are more spread out it is easier for that check to early-out with an "obviously not, the circle is nowhere near that line segment".

Further, the continuous beam weapons on the spire ships are way worse: they have to do that check every single sim-frame. Other beam weapons only check once.

Anyway, I'll see if there's some improvement I can do, but ultimately the math of "what is happening here?" (not "what should I do?", which can afford to degrade) is just that much.

Hearteater

Mar 27, 2012 1:34 pm

reporter   ~0021434

Last edited: Mar 27, 2012 1:55 pm

Have you tried using a rotation so you can just check against the x-axis?

Let x and y be the location of the firing ship
Let a be the angle of the beam attack with 0 degrees being along the positive x-axis
Let d be the length of the attack

Let tx and ty be the target ship's location
Let tr be the target ship's radius

Really rough pseudo-code:

Calculate a
Set C = cos(-a)
Set S = sin(-a)
For Each Enemy Ship in Roughly in Target Area:
{
Set tmptx = tx - x
Set tmpty = ty - y
Set TY = Abs(tmptx * S + tmpty * C)
if (TY <= tr)
{
Set TX = tmptx * C - tmpty * S
if (TX >= 0 && TX <= d + tr)
{
ShipHit()
}
}
}

That's only two multiplications, three additions/substraction, one Abs (compare + mult basically), and one compare per ship for most misses. Four, five, one and three respectively for near misses and hits.

EDIT: Forgot the translation. Also added the target's radius to the end of the beam.

Lemon

Mar 27, 2012 4:02 pm

reporter   ~0021443

Yuck, I hate trignometry.

So its just the hit detection? I supposed I should be ashamed of trying to (ab)use my beam weapons to their maximum effect. :P

Alternatively, if you can't find a way to circumvent or fudge the math, just have the huge waves stream in over the course of a few seconds and have their first order be a move command to get x distance away.

Issue History

Date Modified Username Field Change
Mar 26, 2012 5:34 pm Lemon New Issue
Mar 26, 2012 5:34 pm Lemon File Added: test.sav
Mar 26, 2012 5:35 pm Lemon File Added: test Beam cannon.sav
Mar 26, 2012 5:35 pm Lemon File Added: test Beam Frigates.sav
Mar 26, 2012 5:35 pm Lemon File Added: test spire.sav
Mar 26, 2012 5:36 pm Lemon File Added: test CPU Melter.sav
Mar 26, 2012 5:36 pm Lemon File Added: test everything long distance.sav
Mar 26, 2012 5:40 pm Lemon Description Updated
Mar 27, 2012 10:36 am tigersfan Internal Weight => Fix Before Major Release
Mar 27, 2012 10:36 am tigersfan Assigned To => keith.lamothe
Mar 27, 2012 10:36 am tigersfan Status new => assigned
Mar 27, 2012 12:43 pm keith.lamothe Note Added: 0021428
Mar 27, 2012 1:34 pm Hearteater Note Added: 0021434
Mar 27, 2012 1:55 pm Hearteater Note Edited: 0021434
Mar 27, 2012 4:02 pm Lemon Note Added: 0021443