PixelLightAPI  .
SceneContext.h
Go to the documentation of this file.
00001 /*********************************************************\
00002  *  File: SceneContext.h                                 *
00003  *
00004  *  Copyright (C) 2002-2011 The PixelLight Team (http://www.pixellight.org/)
00005  *
00006  *  This file is part of PixelLight.
00007  *
00008  *  PixelLight is free software: you can redistribute it and/or modify
00009  *  it under the terms of the GNU Lesser General Public License as published by
00010  *  the Free Software Foundation, either version 3 of the License, or
00011  *  (at your option) any later version.
00012  *
00013  *  PixelLight is distributed in the hope that it will be useful,
00014  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00016  *  GNU Lesser General Public License for more details.
00017  *
00018  *  You should have received a copy of the GNU Lesser General Public License
00019  *  along with PixelLight. If not, see <http://www.gnu.org/licenses/>.
00020 \*********************************************************/
00021 
00022 
00023 #ifndef __PLSCENE_SCENECONTEXT_H__
00024 #define __PLSCENE_SCENECONTEXT_H__
00025 #pragma once
00026 
00027 
00028 //[-------------------------------------------------------]
00029 //[ Includes                                              ]
00030 //[-------------------------------------------------------]
00031 #include <PLCore/Container/Array.h>
00032 #include <PLCore/Base/Event/Event.h>
00033 #include <PLCore/Core/AbstractContext.h>
00034 #include "PLScene/PLScene.h"
00035 
00036 
00037 //[-------------------------------------------------------]
00038 //[ Forward declarations                                  ]
00039 //[-------------------------------------------------------]
00040 namespace PLMath {
00041     class GraphPathManager;
00042 }
00043 namespace PLRenderer {
00044     class RendererContext;
00045 }
00046 namespace PLMesh {
00047     class MeshManager;
00048 }
00049 namespace PLScene {
00050     class SceneNode;
00051     class VisManager;
00052     class SceneContainer;
00053     class SceneNodeHandler;
00054     class SceneRendererManager;
00055 }
00056 
00057 
00058 //[-------------------------------------------------------]
00059 //[ Namespace                                             ]
00060 //[-------------------------------------------------------]
00061 namespace PLScene {
00062 
00063 
00064 //[-------------------------------------------------------]
00065 //[ Classes                                               ]
00066 //[-------------------------------------------------------]
00067 /**
00068 *  @brief
00069 *    Scene context
00070 *
00071 *  @note
00072 *    - There should be only one scene context instance per application
00073 */
00074 class SceneContext : public PLCore::AbstractContext {
00075 
00076 
00077     //[-------------------------------------------------------]
00078     //[ Friends                                               ]
00079     //[-------------------------------------------------------]
00080     friend class SceneNode;
00081 
00082 
00083     //[-------------------------------------------------------]
00084     //[ Public events                                         ]
00085     //[-------------------------------------------------------]
00086     public:
00087         PLCore::Event<> EventUpdate;    /**< Scene context update event */
00088 
00089 
00090     //[-------------------------------------------------------]
00091     //[ Public functions                                      ]
00092     //[-------------------------------------------------------]
00093     public:
00094         /**
00095         *  @brief
00096         *    Constructor
00097         *
00098         *  @param[in] cRendererContext
00099         *    Renderer context to use
00100         */
00101         PLS_API SceneContext(PLRenderer::RendererContext &cRendererContext);
00102 
00103         /**
00104         *  @brief
00105         *    Destructor
00106         */
00107         PLS_API ~SceneContext();
00108 
00109         /**
00110         *  @brief
00111         *    Returns the used renderer context
00112         *
00113         *  @return
00114         *    The used renderer context
00115         */
00116         PLS_API PLRenderer::RendererContext &GetRendererContext() const;
00117 
00118         /**
00119         *  @brief
00120         *    Returns the mesh manager
00121         *
00122         *  @return
00123         *    The mesh manager
00124         */
00125         PLS_API PLMesh::MeshManager &GetMeshManager();
00126 
00127         /**
00128         *  @brief
00129         *    Returns the graph path manager
00130         *
00131         *  @return
00132         *    The graph path manager
00133         */
00134         PLS_API PLMath::GraphPathManager &GetGraphPathManager();
00135 
00136         /**
00137         *  @brief
00138         *    Returns the root of the scene graph
00139         *
00140         *  @return
00141         *    The root of the scene graph, a null pointer on (terrible) error
00142         *
00143         *  @see
00144         *    - SceneNode and SceneContainer for more information
00145         */
00146         PLS_API SceneContainer *GetRoot();
00147 
00148         /**
00149         *  @brief
00150         *    Performs a cleanup-operation (garbage collection)
00151         *
00152         *  @remarks
00153         *    If SceneNode::Delete() is called, scene nodes are not destroyed immediately,
00154         *    instead they register them self into a 'to delete' list of the scene graph. As
00155         *    soon this function is called, the scene nodes are destroyed. Normally this function
00156         *    is called once per frame automatically.
00157         */
00158         PLS_API void Cleanup();
00159 
00160         /**
00161         *  @brief
00162         *    Method that is called once per update loop
00163         *
00164         *  @remarks
00165         *    You can use this method to do work you have to to within each frame. It's
00166         *    recommended to keep the work done within the implementation as compact as possible.
00167         *    Don't use this method to perform 'polling'-everything, use events or if required
00168         *    for example timers instead.
00169         */
00170         PLS_API void Update();
00171 
00172         /**
00173         *  @brief
00174         *    Returns the scene renderer manager
00175         *
00176         *  @return
00177         *    The scene renderer manager
00178         */
00179         PLS_API SceneRendererManager &GetSceneRendererManager();
00180 
00181         /**
00182         *  @brief
00183         *    Returns the visibility manager
00184         *
00185         *  @return
00186         *    The visibility manager
00187         */
00188         PLS_API VisManager &GetVisManager();
00189 
00190 
00191         //[-------------------------------------------------------]
00192         //[ Processing                                            ]
00193         //[-------------------------------------------------------]
00194         /**
00195         *  @brief
00196         *    Starts a scene process
00197         *
00198         *  @remarks
00199         *    During scene traversal using for instance the hierarchy of a scene container, a scene node can
00200         *    be processed multiple times. If this is NOT desired, a scene node must be 'marked' as already
00201         *    processed so it isn't touched multiple times. The scene graph class offers 3 functions for this
00202         *    purpose: StartProcess(), TouchNode() and EndProcess(). If a scene process starts, StartProcess()
00203         *    is called with internally increases a counter. If a node should be processes TouchNode() is called,
00204         *    if 'true' is returned the node was already processed. After the whole scene process is finished, call
00205         *    EndProcess(). This is NOT 'multi threading save' and only ONE scene process can be performed at the
00206         *    same time, but this technique is incredible fast because internally only counters are compared!
00207         *
00208         *  @return
00209         *    'true' if all went fine, else 'false' (there's already a process running)
00210         */
00211         PLS_API bool StartProcess();
00212 
00213         /**
00214         *  @brief
00215         *    Checks whether a scene node was touched
00216         *
00217         *  @param[in] cSceneNode
00218         *    Scene node to check
00219         *
00220         *  @return
00221         *    'true' if the scene node was touched, else 'false'
00222         *
00223         *  @see
00224         *    - StartProcess()
00225         */
00226         PLS_API bool IsNodeTouched(SceneNode &cSceneNode) const;
00227 
00228         /**
00229         *  @brief
00230         *    Touches a scene node
00231         *
00232         *  @param[in] cSceneNode
00233         *    Scene node to touch
00234         *
00235         *  @return
00236         *    'true' if all went fine and the scene node was touched the first time during the
00237         *    current process, else 'false' if the scene node was already touched during the current
00238         *    process or there's currently no active process or the given scene node is invalid
00239         *
00240         *  @see
00241         *    - StartProcess()
00242         */
00243         PLS_API bool TouchNode(SceneNode &cSceneNode);
00244 
00245         /**
00246         *  @brief
00247         *    Ends a scene process
00248         *
00249         *  @see
00250         *    - StartProcess()
00251         *
00252         *  @return
00253         *    'true' if all went fine, else 'false' (there's currently no process running)
00254         */
00255         PLS_API bool EndProcess();
00256 
00257 
00258     //[-------------------------------------------------------]
00259     //[ Private data                                          ]
00260     //[-------------------------------------------------------]
00261     private:
00262         PLRenderer::RendererContext  *m_pRendererContext;       /**< The used renderer context, not destroyed by the scene context (always valid!) */
00263         PLMesh::MeshManager          *m_pMeshManager;           /**< The mesh manager, can be a null pointer */
00264         PLMath::GraphPathManager     *m_pGraphPathManager;      /**< The graph path manager, can be a null pointer */
00265         SceneNodeHandler             *m_pRoot;                  /**< The root of the scene graph (always valid!) */
00266         PLCore::Array<SceneNode*>     m_lstDeleteNodes;         /**< List of scene nodes to delete */
00267         SceneRendererManager         *m_pSceneRendererManager;  /**< Scene renderer manager, can be a null pointer */
00268         VisManager                   *m_pVisManager;            /**< Visibility manager, can be a null pointer */
00269         bool                          m_bProcessActive;         /**< Is there currently an active process? */
00270         PLCore::uint32                m_nProcessCounter;        /**< Internal process counter */
00271 
00272 
00273 };
00274 
00275 
00276 //[-------------------------------------------------------]
00277 //[ Namespace                                             ]
00278 //[-------------------------------------------------------]
00279 } // PLScene
00280 
00281 
00282 #endif // __PLSCENE_SCENECONTEXT_H__


PixelLight PixelLight 0.9.10-R1
Copyright (C) 2002-2011 by The PixelLight Team
Last modified Fri Dec 23 2011 15:51:00
The content of this PixelLight document is published under the
Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported