danbuis / ArmadaAIEngineNew

Revisit of an old project to create an AI for Star Wars Armada
1 stars 0 forks source link

Speed up squadron creation #52

Closed danbuis closed 3 years ago

danbuis commented 3 years ago

Requirements

In the current implementation of squadron rendering we load all 41 squadrons and it takes a noticable amount of time to load them all and arrange them on the field.

Potential Solutions

Static versions of the base's game items. Likely easier once we decouple the view and the object. We can likely make at least one of the polygons non interactive. Since they are circles we can look at radii when dealing with squadron things, rather than checking on them. Not sure we can make the cardboard non interactive since we need that for determining LOS/arc etc.

Potential Tasks

What does it take to call this issue complete?

danbuis commented 3 years ago

Testing load is 410 squadrons, which is looping through the current squadron set 10 times.

Test Result
Baseline 27.255 seconds
Remove the print logging statement 25.069 seconds
Set the shapeInteracts flag to false 24.893 seconds
Removing one of the 2 circular Meshes from construction 20.291 seconds

For some reason also removing the creation of the actual circle polygon adds time, even though that is removing 200 trig operations per squadron, it adds ~30% time back.

danbuis commented 3 years ago

Nixing the relocate for the 400 squads did not change anything.

Its also likely worth exploring the fact that we are making 3 shader programs with each new squadron. I bet if we can make those static shader programs somewhere then we can speed up a bit by not needing to do the bits behind the scenes in OpenGl to set up 1200 new shaders

danbuis commented 3 years ago

Ok, so removing the shader creation, which was creating redundant shaders anyway, creates a run time of ~12 seconds, which is a speed up of ~50% alone.

danbuis commented 3 years ago

I think the bulk of the remaining issue is that we are making a bunch of identical mesh objects with slightly different location data.

We need to be able to make copies quickly. A static var won't work here because static means there is only one instance ever, and I'm not sure we can use the same mesh instance over and over.

I'm going to look at mesh instancing in lwjgl.

That might mean this one is on hold for a bit while I spend some time over in BBDLibrary land.

danbuis commented 3 years ago

Ok, i was able to trim some more time off by preprocessing the data for the Mesh and making it a static var to be used in Mesh creation. The code is a bit ickier, but the runtime is a lot better.

Runtime on my machine is settling it at ~10.3 seconds, which is more than twice as fast as the baseline. (measured across 3 separate runs)

I'm pretty sure that could be sped up quite a bit with some instanced rendering so that each mesh is only made 1 time ever and then rendered in several different spots.

That will require a significant rework of the BBDLibrary and/or shaders, both of which are outside the scope of this issue.