Difference between revisions of "Selection Manager"

From Second Life Wiki
Jump to navigation Jump to search
 
Line 1: Line 1:
LLHandle<Type>
== Selection Objects ==
Groups of in-world items (e.g. objects and plots of land) that are referenced by the second life UI must be accessed through a selection object.  Selection objects are returned by all selection modification functions, such as selectObject() or selectParcelAt().  These selection objects wrap a collection of selected items with simple container-style queries, iterators, and functors.  Higher level operations are exposed via the appropriate selection manager object which may either operate on the current default selection, or take a handle to a selection object as a parameter.


LLObjectSelection
=== Selection Handles ===
LLParcelSelection
Selection objects are always accessed through an LLHandle.  LLHandles have the semantics of handles and the syntax of pointers.  Specifically, LLHandle is a reference counting pointer that can never be NULL.  Whenever NULL is assigned to an LLHandle, the handle will instead point to a default empty instance of the referenced object (in this case, an empty selection object).  It is up to the referenced object to expose an API to query for validity.  There is usually an existing mechanism for this, such as LLObjectSelection::isEmpty(). 


LLHandle is a special kind of reference counting pointer that can never be NULL.  Whenever assigning NULL to an LLHandle, it will point to a default empty instance of the referenced object.  For example:
For example:


LLHandle<LLObjectSelection> object_selection = gSelectMgr->getSelection();
LLHandle<LLObjectSelection> object_selection = gSelectMgr->getSelection();
llinfos << object_selection->getNumObjects() << llendl;
llinfos << object_selection->getNumObjects() << llendl;


Prints "n" where n is the number of objects currently selected.
Prints the number of objects currently selected.


object_selection = NULL;
object_selection = NULL;
llinfos << object_selection->getNumObjects() << llendl;


llinfos << object_selection->getNumObjects() << llendl;
Prints "0", as object_selection now points to an empty selection.  Notice that it is always safe to dereference an LLHandle.


Prints "0", as object_selection now points to an empty selection.
'''Note: the following code samples refer to a forthcoming selection manager API'''


Notice that selections can only be modified and created via LLSelectMgr.  
Any time you modify a given selection, you need to update your handle to point to a potentially new selection. For example:


Once the number of references for a given selection drops to 1 (the only handle being the one maintained by the selection manager), the selection manager is free to deselect the corresponding objects and clean up or reuse the selection instance.
LLHandle<LLObjectSelection> selected_objects = gSelectMgr->getSelection();
 
selected_objects = gSelectMgr->addObject(selected_objects, object_ptr);
Any time you modify a given selection, you need to update your handle to point to a potentially new selection.  For example:


LLHandle<LLObjectSelection> selected_objects = gSelectMgr->getSelection();
Generally, a selection will be built once (or modified by an LLTool instance) and the handle will be passed to the selection manager to perform various operations:
Selected_objects = gSelectMgr->addObject(selected_objects, object_ptr);


Usually, a selection will be built once (or modified by an LLTool instance) and the handle will be passed to the selection manager to perform various operations:
gSelectMgr->selectionDelete(selected_objects);


=== Selection Lifetime ===
Selections will persist as long as one object selection handle remains in use.  As soon as the last UI element loses its selection object handle, the selection manager is free to deselect the corresponding items, and to reuse the referenced selection object.  This is normally triggered through a per-frame call to deselectUnused();


gSelectMgr->selectionDelete(selected_objects);
Selection managers are also free to invalidate an open selection at any time by clearing its contents.  For example, when teleporting away from a set of selected objects, the object selection manager can invalidate all open selections on those objects.  As long as the appropriate UI elements reference the selection via a selection object and not direct object pointers, the UI can clean up gracefully.  This is also more efficient and easier to code than referencing objects via UUID.

Revision as of 15:25, 7 February 2007

Selection Objects

Groups of in-world items (e.g. objects and plots of land) that are referenced by the second life UI must be accessed through a selection object. Selection objects are returned by all selection modification functions, such as selectObject() or selectParcelAt(). These selection objects wrap a collection of selected items with simple container-style queries, iterators, and functors. Higher level operations are exposed via the appropriate selection manager object which may either operate on the current default selection, or take a handle to a selection object as a parameter.

Selection Handles

Selection objects are always accessed through an LLHandle. LLHandles have the semantics of handles and the syntax of pointers. Specifically, LLHandle is a reference counting pointer that can never be NULL. Whenever NULL is assigned to an LLHandle, the handle will instead point to a default empty instance of the referenced object (in this case, an empty selection object). It is up to the referenced object to expose an API to query for validity. There is usually an existing mechanism for this, such as LLObjectSelection::isEmpty().

For example:

LLHandle<LLObjectSelection> object_selection = gSelectMgr->getSelection();
llinfos << object_selection->getNumObjects() << llendl;

Prints the number of objects currently selected.

object_selection = NULL;
llinfos << object_selection->getNumObjects() << llendl;

Prints "0", as object_selection now points to an empty selection. Notice that it is always safe to dereference an LLHandle.

Note: the following code samples refer to a forthcoming selection manager API

Any time you modify a given selection, you need to update your handle to point to a potentially new selection. For example:

LLHandle<LLObjectSelection> selected_objects = gSelectMgr->getSelection();
selected_objects = gSelectMgr->addObject(selected_objects, object_ptr);

Generally, a selection will be built once (or modified by an LLTool instance) and the handle will be passed to the selection manager to perform various operations:

gSelectMgr->selectionDelete(selected_objects);

Selection Lifetime

Selections will persist as long as one object selection handle remains in use. As soon as the last UI element loses its selection object handle, the selection manager is free to deselect the corresponding items, and to reuse the referenced selection object. This is normally triggered through a per-frame call to deselectUnused();

Selection managers are also free to invalidate an open selection at any time by clearing its contents. For example, when teleporting away from a set of selected objects, the object selection manager can invalidate all open selections on those objects. As long as the appropriate UI elements reference the selection via a selection object and not direct object pointers, the UI can clean up gracefully. This is also more efficient and easier to code than referencing objects via UUID.