LightSourceManager Class Reference

Manages the users of OSG/OpenGL lights sources (which are limited to 8). More...

#include <LightSourceManager.h>

List of all members.

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 LightSourceUserCallbackgetUserCallback (const osg::Referenced *pUserObject) const
LightSourceUserCallbackgetUserCallback (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

UsergetUser (const osg::Referenced *pUserObject)
 Finds user data from the user object and also do some cleanup if possible.
const UsergetUser (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< UserusersQueue
 Potential users waiting for a source to be available.


Detailed Description

Manages the users of OSG/OpenGL lights sources (which are limited to 8).

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.

Author:
Sukender
Version:
0.2.2
Todo:
Think about a feature that could allow the lights to be smoothly faded. For instance, the lights that must be switched off could say (in onSourceTaken()) "wait a bit, I'll release the source in a minute!".

Definition at line 76 of file LightSourceManager.h.


Member Typedef Documentation

Definition at line 78 of file LightSourceManager.h.


Constructor & Destructor Documentation

LightSourceManager::LightSourceManager ( UINT  _firstManagedLight = 0,
UINT  _lastManagedLight = MAX_LIGHT 
) [inline]

Definition at line 81 of file LightSourceManager.h.


Member Function Documentation

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]

void LightSourceManager::doEnqueue ( osg::Referenced *  pNewUser,
Priority  priority,
LightSourceUserCallback pUserCB 
) [protected]

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]

Definition at line 158 of file LightSourceManager.h.

References ASSERT.

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.

Parameters:
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.
Returns:
The given light number, or UINT_MAX if no light is available at the moment.
Warning:
Enqueued users must have a LightSourceUserCallback in order to be valid. Else they'll be dropped. Note that it can be done after this call, but this is dangerous because it can be done only if this method does not enqueue direclty, and it needs to be done before any light source becomes available (Beware of multithreaded operations!).

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().

void LightSourceManager::setManagedLights ( UINT  _firstManagedLight,
UINT  _lastManagedLight 
)

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]

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().


Member Data Documentation

const UINT LightSourceManager::MAX_LIGHT = 8 [static]

Definition at line 79 of file LightSourceManager.h.

Referenced by setManagedLights().

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().


The documentation for this class was generated from the following files:

Generated on Sun Jan 17 11:39:28 2010 for PVLE (Pro-Vocation Light Engine) by  doxygen 1.5.9