An example, say there are 25 possible targets around the caller and the target limit is 12. In that case, the first array would have all 25 targets added to it and the second array would have all their distances to the caller added to it. I've managed to accomplish all this without issues. The problem is when it comes to populating the third and final array. The third array should only be composed of the 12 nearest targets disregarding the rest and this is where I am stuck. I created a function that is supposed to sort targets into the third array by using the data from the first two arrays but GZDoom just hard freezes whenever it is called.
Here is the sorting function:
- Code: Select all • Expand view
Void SortBeamTargetsRange(Int MaxTargets)
{
Array<Double> Ranges;
Double ClosestRange;
Bool Sort;
For (Int I = 0; I < InitialTargets.Size(); I++)
{
Ranges.Push(Distance3D(InitialTargets[I]));
}
ClosestRange = -1.0;
Sort = False;
For (Int I = 0; 0 < InitialTargets.Size(); I++)
{
If (I > -1)
{
If (!Sort)
{
If (I >= InitialTargets.Size())
{
Sort = True;
I = -1;
}
Else If (ClosestRange == -1.0 || ClosestRange > Ranges[I])
{
ClosestRange = Ranges[I];
}
}
Else
{
If (ClosestRange >= Ranges[I])
{
BeamTargets.Push(InitialTargets[I]);
InitialTargets.Delete(I,1);
Ranges.Delete(I,1);
ClosestRange = -1.0;
Sort = False;
I = -1;
If (BeamTargets.Size() >= MaxTargets)
{
Return;
}
}
}
}
}
}
Any ideas why it hard freezes?
EDIT:
I've changed the function a bit and it now works correctly without freezing, performance could be a bit better. Any tips on how to rewrite it to improve performance or is this the best I'm gonna get?