LightList in-place sort - for PSSM shadows


09-05-2008 15:20:36

Hi folks,

wondering how to do an in-place custom sort on a list in python, as per the PSSM example in the ogre wiki. Everything seems to be working, but the technique requires an ogre.LightList to be sorted with a custom sort function, which seems to be impossible in pythonOgre ( unless someone knows of a way to do it ). Heres the C++ code I'm trying to translate:

struct lightsLess
bool operator()(const Light* l1, const Light* l2) const
if (l1 == l2)
return false;
return l1->tempSquareDist < l2->tempSquareDist;

bool PSSMShadowListener::sortLightsAffectingFrustum(Ogre::LightList& lightList)
lightList.begin(), lightList.end(),
return true;

Here's my python version:

def lightsLess(l1, l2):
if l1 == l2:
return False;
return l1.tempSquareDist < l2.tempSquareDist


# this is part of an ogre.ShadowListener

def sortLightsAffectingFrustum(self, lightList):
lights = sorted(lightList, lightsLess)
lightList = ogre.LightList()
for l in lights:
return True

Trouble is that by the end of the function lightList is a new lightList in the local scope, and not the same object that was passed into the function. Therefore the original lightList object passes through the function un-modified. Anyone know how to deal with this?

many thanks,


09-05-2008 15:26:12

Ha, never mind.

just noticed that ogre.LightList implements __setitem__, so its just

lightList = sortedLightList

when I finally get this working, will post the whole code somewhere.