#include <LightSourceManager.h>
Classes | |
class | User |
Data about a light source user (object, priority and callback). More... | |
Public Types | |
typedef float | Priority |
Public Member Functions | |
LightSourceManager (UINT _firstManagedLight=0, UINT _lastManagedLight=MAX_LIGHT) | |
UINT | request (osg::Referenced *pNewUser, Priority priority, LightSourceUserCallback *pUserCB=NULL, bool enqueue=false) |
Request for a light source. | |
void | remove (osg::Referenced *pUserObject) |
Removes an user (enqueued or not). | |
void | clear () |
Removes all users (enqueued or not). | |
const LightSourceUserCallback * | getUserCallback (const osg::Referenced *pUserObject) const |
LightSourceUserCallback * | getUserCallback (osg::Referenced *pUserObject) |
void | setUserCallback (osg::Referenced *pUserObject, LightSourceUserCallback *pUserCB) |
void | updatePriority (osg::Referenced *pUserObject, Priority newPriority) |
Changes the priority of an user (enqueued or not). | |
void | checkForAvailableLights () |
Checks if some user object has been dealocated and thus leaves an available light source. | |
void | setManagedLights (UINT _firstManagedLight, UINT _lastManagedLight) |
Static Public Attributes | |
static const UINT | MAX_LIGHT = 8 |
Protected Member Functions | |
User * | getUser (const osg::Referenced *pUserObject) |
Finds user data from the user object and also do some cleanup if possible. | |
const User * | getUser (const osg::Referenced *pUserObject) const |
Finds user data from the user object. | |
void | lightAvailable (UINT lightNumber) |
Processes enqueued potential users for the newly available light. | |
void | lightAvailable (UINT lightNumber, std::vector< User >::iterator &itBestCandidate) |
void | lightAvailable (User *pEmptyUser) |
void | cleanQueue () |
Removes all empty entries in the queue. | |
void | doEnqueue (osg::Referenced *pNewUser, Priority priority, LightSourceUserCallback *pUserCB) |
void | doEnqueue (User *pUserObject) |
void | unManage (UINT i, bool canEnqueue) |
Deletes a user. | |
std::vector< User >::iterator | getBestEnqueuedCandidate () |
Get an iterator on the enqueued user with the highest priority. | |
Protected Attributes | |
UINT | firstManagedLight |
UINT | lastManagedLight |
User | users [MAX_LIGHT] |
std::vector< User > | usersQueue |
Potential users waiting for a source to be available. |
This class manages a range of lights ([0; 7] is the default) by giving one to classes that ask for it, if possible. Light sources users are stored with a priority, so that request for sources can be rejected, and some low-priority user can be deprived of their current light. One manager can be used per render stage.
Definition at line 76 of file LightSourceManager.h.
typedef float LightSourceManager::Priority |
Definition at line 78 of file LightSourceManager.h.
LightSourceManager::LightSourceManager | ( | UINT | _firstManagedLight = 0 , |
|
UINT | _lastManagedLight = MAX_LIGHT | |||
) | [inline] |
Definition at line 81 of file LightSourceManager.h.
void LightSourceManager::checkForAvailableLights | ( | ) |
Checks if some user object has been dealocated and thus leaves an available light source.
This should be called on every frame in order to be clean.
Definition at line 131 of file LightSourceManager.cpp.
References LightSourceManager::User::check(), firstManagedLight, getBestEnqueuedCandidate(), lastManagedLight, lightAvailable(), LightSourceManager::User::priority, unManage(), users, and usersQueue.
void LightSourceManager::cleanQueue | ( | ) | [protected] |
Removes all empty entries in the queue.
Definition at line 160 of file LightSourceManager.cpp.
References usersQueue.
Referenced by doEnqueue(), and getUser().
void LightSourceManager::clear | ( | ) |
Removes all users (enqueued or not).
Definition at line 120 of file LightSourceManager.cpp.
References firstManagedLight, lastManagedLight, unManage(), users, and usersQueue.
void LightSourceManager::doEnqueue | ( | User * | pUserObject | ) | [inline, protected] |
Definition at line 171 of file LightSourceManager.h.
References doEnqueue(), LightSourceManager::User::priority, LightSourceManager::User::pUserCB, and LightSourceManager::User::pUserObject.
Referenced by doEnqueue().
void LightSourceManager::doEnqueue | ( | osg::Referenced * | pNewUser, | |
Priority | priority, | |||
LightSourceUserCallback * | pUserCB | |||
) | [protected] |
Definition at line 76 of file LightSourceManager.cpp.
References ASSERT, cleanQueue(), LightSourceManager::User::priority, LightSourceManager::User::pUserCB, LightSourceManager::User::pUserObject, and usersQueue.
Referenced by request(), and unManage().
std::vector< LightSourceManager::User >::iterator LightSourceManager::getBestEnqueuedCandidate | ( | ) | [protected] |
Get an iterator on the enqueued user with the highest priority.
Definition at line 229 of file LightSourceManager.cpp.
References ASSERT, MIN_PRIORITY, and usersQueue.
Referenced by checkForAvailableLights(), and lightAvailable().
const LightSourceManager::User * LightSourceManager::getUser | ( | const osg::Referenced * | pUserObject | ) | const [protected] |
Finds user data from the user object.
Definition at line 186 of file LightSourceManager.cpp.
References ASSERT, firstManagedLight, lastManagedLight, LightSourceManager::User::pUserObject, THROW_TRACED_EXCEPTION, users, and usersQueue.
LightSourceManager::User * LightSourceManager::getUser | ( | const osg::Referenced * | pUserObject | ) | [protected] |
Finds user data from the user object and also do some cleanup if possible.
Definition at line 167 of file LightSourceManager.cpp.
References ASSERT, LightSourceManager::User::check(), cleanQueue(), firstManagedLight, lastManagedLight, lightAvailable(), LightSourceManager::User::pUserObject, THROW_TRACED_EXCEPTION, users, and usersQueue.
LightSourceUserCallback* LightSourceManager::getUserCallback | ( | osg::Referenced * | pUserObject | ) | [inline] |
Definition at line 106 of file LightSourceManager.h.
const LightSourceUserCallback* LightSourceManager::getUserCallback | ( | const osg::Referenced * | pUserObject | ) | const [inline] |
Definition at line 105 of file LightSourceManager.h.
void LightSourceManager::lightAvailable | ( | User * | pEmptyUser | ) | [inline, protected] |
void LightSourceManager::lightAvailable | ( | UINT | lightNumber, | |
std::vector< User >::iterator & | itBestCandidate | |||
) | [protected] |
Definition at line 210 of file LightSourceManager.cpp.
References ASSERT, lightAvailable(), users, and usersQueue.
void LightSourceManager::lightAvailable | ( | UINT | lightNumber | ) | [protected] |
Processes enqueued potential users for the newly available light.
Definition at line 204 of file LightSourceManager.cpp.
References getBestEnqueuedCandidate(), and usersQueue.
Referenced by checkForAvailableLights(), getUser(), lightAvailable(), remove(), and setManagedLights().
void LightSourceManager::remove | ( | osg::Referenced * | pUserObject | ) |
Removes an user (enqueued or not).
If it was an active user, then the used light source becomes available.
Definition at line 89 of file LightSourceManager.cpp.
References LightSourceManager::User::check(), firstManagedLight, lastManagedLight, lightAvailable(), LightSourceManager::User::pUserObject, THROW_TRACED_EXCEPTION, unManage(), users, and usersQueue.
Referenced by Explosion::~Explosion().
UINT LightSourceManager::request | ( | osg::Referenced * | pNewUser, | |
Priority | priority, | |||
LightSourceUserCallback * | pUserCB = NULL , |
|||
bool | enqueue = false | |||
) |
Request for a light source.
pNewUser | User asking for the light source (=user object). | |
priority | Arbitrary value that indicates how much the user object's light source is important. | |
pUserCB | Optional LightSourceUserCallback that goes with the user object. | |
enqueue | Tells the manager if the user object should be enqueued and warned when a source is available. |
Definition at line 37 of file LightSourceManager.cpp.
References LightSourceManager::User::check(), clampu(), doEnqueue(), firstManagedLight, lastManagedLight, LightSourceManager::User::priority, LightSourceManager::User::pUserCB, LightSourceManager::User::pUserObject, unManage(), and users.
Referenced by Explosion::init().
Definition at line 256 of file LightSourceManager.cpp.
References ASSERT, firstManagedLight, lastManagedLight, lightAvailable(), MAX_LIGHT, LightSourceManager::User::reset(), unManage(), users, and usersQueue.
void LightSourceManager::setUserCallback | ( | osg::Referenced * | pUserObject, | |
LightSourceUserCallback * | pUserCB | |||
) | [inline] |
Definition at line 107 of file LightSourceManager.h.
void LightSourceManager::unManage | ( | UINT | i, | |
bool | canEnqueue | |||
) | [protected] |
Deletes a user.
Definition at line 282 of file LightSourceManager.cpp.
References LightSourceManager::User::check(), doEnqueue(), LightSourceManager::User::pUserCB, LightSourceManager::User::pUserObject, LightSourceManager::User::reset(), and users.
Referenced by checkForAvailableLights(), clear(), remove(), request(), and setManagedLights().
void LightSourceManager::updatePriority | ( | osg::Referenced * | pUserObject, | |
Priority | newPriority | |||
) | [inline] |
Changes the priority of an user (enqueued or not).
For example, you can call this when the distance between light source and the camera changes, or when intensity changes.
Definition at line 111 of file LightSourceManager.h.
Referenced by Explosion::step().
UINT LightSourceManager::firstManagedLight [protected] |
Definition at line 120 of file LightSourceManager.h.
Referenced by checkForAvailableLights(), clear(), getUser(), remove(), request(), and setManagedLights().
UINT LightSourceManager::lastManagedLight [protected] |
Definition at line 121 of file LightSourceManager.h.
Referenced by checkForAvailableLights(), clear(), getUser(), remove(), request(), and setManagedLights().
const UINT LightSourceManager::MAX_LIGHT = 8 [static] |
User LightSourceManager::users[MAX_LIGHT] [protected] |
Definition at line 147 of file LightSourceManager.h.
Referenced by checkForAvailableLights(), clear(), getUser(), lightAvailable(), remove(), request(), setManagedLights(), and unManage().
std::vector<User> LightSourceManager::usersQueue [protected] |
Potential users waiting for a source to be available.
Definition at line 176 of file LightSourceManager.h.
Referenced by checkForAvailableLights(), cleanQueue(), clear(), doEnqueue(), getBestEnqueuedCandidate(), getUser(), lightAvailable(), remove(), and setManagedLights().