|Anonymous | Login | Signup for a new account||May 25, 2013 1:32 am|
|Main | My View | View Issues | Vote Tallies | FAQ|
|View Issue Details|
|ID||Project||Category||Date Submitted||Last Update|
|0006873||AI War||[All Projects] Bug - Gameplay||Mar 26, 2012 4:34 pm||Mar 27, 2012 3:02 pm|
|Fixed in Version|
|Summary||0006873: Beam weapons vs large stacks of units causes massive performance loss and stuttering.|
|Description||Beam 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.
|Tags||No tags attached.|
|Internal Weight||Fix Before Major Release|
|Attached Files|| test.sav [^] (594,287 bytes) Mar 26, 2012 4:34 pm|
test Beam cannon.sav [^] (586,811 bytes) Mar 26, 2012 4:35 pm
test Beam Frigates.sav [^] (607,015 bytes) Mar 26, 2012 4:35 pm
test spire.sav [^] (585,479 bytes) Mar 26, 2012 4:35 pm
test CPU Melter.sav [^] (607,863 bytes) Mar 26, 2012 4:36 pm
test everything long distance.sav [^] (604,063 bytes) Mar 26, 2012 4:36 pm
Mar 27, 2012 11:43 am
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.
Mar 27, 2012 12:34 pm
edited on: Mar 27, 2012 12: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:
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)
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.
Mar 27, 2012 3:02 pm
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.
|Only registered users can voice their support. Click here to register, or here to log in.|
|Supporters:||No one explicitly supports this issue yet.|
|Opponents:||No one explicitly opposes this issue yet.|
|Mar 26, 2012 4:34 pm||Lemon||New Issue|
|Mar 26, 2012 4:34 pm||Lemon||File Added: test.sav|
|Mar 26, 2012 4:35 pm||Lemon||File Added: test Beam cannon.sav|
|Mar 26, 2012 4:35 pm||Lemon||File Added: test Beam Frigates.sav|
|Mar 26, 2012 4:35 pm||Lemon||File Added: test spire.sav|
|Mar 26, 2012 4:36 pm||Lemon||File Added: test CPU Melter.sav|
|Mar 26, 2012 4:36 pm||Lemon||File Added: test everything long distance.sav|
|Mar 26, 2012 4:39 pm||Lemon||Note Added: 0021389|
|Mar 26, 2012 4:39 pm||Lemon||Note Edited: 0021389||View Revisions|
|Mar 26, 2012 4:39 pm||Lemon||Note Deleted: 0021389|
|Mar 26, 2012 4:40 pm||Lemon||Description Updated||View Revisions|
|Mar 27, 2012 9:36 am||tigersfan||Internal Weight||=> Fix Before Major Release|
|Mar 27, 2012 9:36 am||tigersfan||Assigned To||=> keith.lamothe|
|Mar 27, 2012 9:36 am||tigersfan||Status||new => assigned|
|Mar 27, 2012 11:43 am||keith.lamothe||Note Added: 0021428|
|Mar 27, 2012 12:34 pm||Hearteater||Note Added: 0021434|
|Mar 27, 2012 12:55 pm||Hearteater||Note Edited: 0021434||View Revisions|
|Mar 27, 2012 3:02 pm||Lemon||Note Added: 0021443|
|Copyright © 2000 - 2011 MantisBT Group|