LoD calculation time, fps wise.

why would you not use a kdtree I don’t understand :confused:

it’s waaaay faster

once we get a octree in native code that should be even better.

listSmall = []
for (co, index, dist) in kd.find_range(vector, 30):
     listSmall.append(index)
    #if these don't have physics giv'em physics
    if 'Phys' not in own['MasterList'][index]:
         own['MasterList'][index]['Phys']=True
         own['MasterList'][index].suspendPhysics= False

listBigl = []
for (co, index, dist) in kd.find_range(vector, 35):
    if index not in listSmall:
         if 'Phys' in own['MasterList'][index]:
               own['MasterList'][index].suspendPhysics=True
               del own['MasterList'][index]['Phys']



sorry for the lag reply :o

It is better to do it like this? dont you call the function twice now(before and in the loop)?

yes, but the loop run more times ,
is pretty common assign some variable before that starts a loop when possible

this probably is more obvious:


for number in numbers:
    if number > (a+b):
        big_numbers.append(number)


res = a+b
for number in numbers:
    if number > res:
        big_numbers.append(number)

since (a+b) is ever the same , is better do the calculation only once, creating a variable out of loop.
the advantage depend from the amount of items contained in the list numbers.

more big is the list more has sense do also little optimizations .

sayd that …also punctations are operations ,
in the same way:


for obj in objects:
    dist = own.getDistanceTo(obj)


getDistanceTo = own.getDistanceTo
for obj in objects:
    dist = getDistanceTo(obj)

since -> own.getDistanceTo is costant

the second code is more performant.(tested :cool:)
dirty ? yes sure a bit dirty is. (not rarely optimization is dirty)

a code more fast mantaining 3 distances for each object , require a code yet more dirty afaik :o.

Also you are using this, doesn’t it mean it set it to True or False even if it is already True or False?
so this is more performance eating?

can be that internally do already the check and do nothing if the new value is the same as the current .
the fact is that we not know what is the current lod because we have not write it.
ideally each lod can be an integer .

so if integer is the same integer -> nothing to do(decisely the case more recurrent)

this more over should be the lod.
what should be, and what is the current lod …

good will be use kdtree(very fast if used in certain way)
but im almost sure is not usable with more than one distance

I agree performing the (a+b) calculation outside of the loop. Both the efficiency and the readability benefit from it.

But stripping an object method away decreases readability. It seams to be fine in this very narrow context (the code is very close to each other so a reader can immediately see the relation). The achieved efficiency increase is really minor and nearly not noticeable. When you notice such a difference it is much more efficient to reduce the number of iterations especially at the context of LOD processing.