Original Post
I have a program that i ran in a profiler and 50% of the entire code is in one function. It is really slowing down the program and thought maybe there is a much better way to code this. The program is in XNA but its really more of standard code question so I put it in general game programming. I am running collision detection using spacial hashing and this update function is from updating the grid.
There are a lot of uses of elementAt(), would that cause the slowdown to happen? the function it calls inside of itself (handlecollide) isnt spending any time in it so it is all just in the for statements. There has to be a better way to code this. Bucketlist count is usually around 3 or 4 and count is around 200-300.
thanks guys,
[Edited by - EdBoon on November 29, 2010 9:02:32 PM]
public void Update() { int bucketListCount; int count = occupiedBucket.Count(); for (int i = 0; i < count; i++) { bucketListCount = bucketList[occupiedBucket.ElementAt(i)].Count(); for (int j = 0; j < bucketListCount; j++) { for (int k = j + 1; k < bucketListCount; k++) { bucketList[occupiedBucket.ElementAt(i)].ElementAt(j).handleCollide(bucketList[occupiedBucket.ElementAt(i)].ElementAt(k)); } } } }There are a lot of uses of elementAt(), would that cause the slowdown to happen? the function it calls inside of itself (handlecollide) isnt spending any time in it so it is all just in the for statements. There has to be a better way to code this. Bucketlist count is usually around 3 or 4 and count is around 200-300.
thanks guys,
[Edited by - EdBoon on November 29, 2010 9:02:32 PM]