unsigned int GL::LightHandler::AddLight(const GL::Light& light) { if (light.GetTTL() == 0 || light.GetRadius() <= 0.0f) { return -1U; } if (light.GetIntensityWeight().SqLength() <= 0.01f) { return -1U; } if (lights.size() >= maxLights || lightIDs.empty()) { unsigned int minPriorityValue = light.GetPriority(); unsigned int minPriorityHandle = -1U; for (std::map<unsigned int, GL::Light>::const_iterator it = lights.begin(); it != lights.end(); ++it) { const GL::Light& lgt = it->second; if (lgt.GetPriority() < minPriorityValue) { minPriorityValue = lgt.GetPriority(); minPriorityHandle = it->first; } } if (minPriorityHandle != -1U) { lightIntensityWeight -= lights[minPriorityHandle].GetIntensityWeight(); lightIDs.push_back(lights[minPriorityHandle].GetID()); lights.erase(minPriorityHandle); } else { // no available light to replace return -1U; } } lights[lightHandle] = light; lights[lightHandle].SetID(lightIDs.front()); lights[lightHandle].SetRelativeTime(0); lights[lightHandle].SetAbsoluteTime(gs->frameNum); lightIntensityWeight += light.GetIntensityWeight(); lightIDs.pop_front(); return (lightHandle++); }