PixelLightAPI  .
SceneContext.h
Go to the documentation of this file.
00001 /*********************************************************\
00002  *  File: SceneContext.h                                 *
00003  *
00004  *  Copyright (C) 2002-2012 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         *  @param[in] bRespectPause
00165         *    Respect pause? ("PLCore::Timing::GetInstance()->IsPaused()")
00166         *
00167         *  @remarks
00168         *    You can use this method to do work you have to to within each frame. It's
00169         *    recommended to keep the work done within the implementation as compact as possible.
00170         *    Don't use this method to perform 'polling'-everything, use events or if required
00171         *    for example timers instead.
00172         */
00173         PLS_API void Update(bool bRespectPause = true);
00174 
00175         /**
00176         *  @brief
00177         *    Returns the scene renderer manager
00178         *
00179         *  @return
00180         *    The scene renderer manager
00181         */
00182         PLS_API SceneRendererManager &GetSceneRendererManager();
00183 
00184         /**
00185         *  @brief
00186         *    Returns the visibility manager
00187         *
00188         *  @return
00189         *    The visibility manager
00190         */
00191         PLS_API VisManager &GetVisManager();
00192 
00193 
00194         //[-------------------------------------------------------]
00195         //[ Processing                                            ]
00196         //[-------------------------------------------------------]
00197         /**
00198         *  @brief
00199         *    Starts a scene process
00200         *
00201         *  @remarks
00202         *    During scene traversal using for instance the hierarchy of a scene container, a scene node can
00203         *    be processed multiple times. If this is NOT desired, a scene node must be 'marked' as already
00204         *    processed so it isn't touched multiple times. The scene graph class offers 3 functions for this
00205         *    purpose: StartProcess(), TouchNode() and EndProcess(). If a scene process starts, StartProcess()
00206         *    is called with internally increases a counter. If a node should be processes TouchNode() is called,
00207         *    if 'true' is returned the node was already processed. After the whole scene process is finished, call
00208         *    EndProcess(). This is NOT 'multi threading save' and only ONE scene process can be performed at the
00209         *    same time, but this technique is incredible fast because internally only counters are compared!
00210         *
00211         *  @return
00212         *    'true' if all went fine, else 'false' (there's already a process running)
00213         */
00214         PLS_API bool StartProcess();
00215 
00216         /**
00217         *  @brief
00218         *    Checks whether a scene node was touched
00219         *
00220         *  @param[in] cSceneNode
00221         *    Scene node to check
00222         *
00223         *  @return
00224         *    'true' if the scene node was touched, else 'false'
00225         *
00226         *  @see
00227         *    - StartProcess()
00228         */
00229         PLS_API bool IsNodeTouched(SceneNode &cSceneNode) const;
00230 
00231         /**
00232         *  @brief
00233         *    Touches a scene node
00234         *
00235         *  @param[in] cSceneNode
00236         *    Scene node to touch
00237         *
00238         *  @return
00239         *    'true' if all went fine and the scene node was touched the first time during the
00240         *    current process, else 'false' if the scene node was already touched during the current
00241         *    process or there's currently no active process or the given scene node is invalid
00242         *
00243         *  @see
00244         *    - StartProcess()
00245         */
00246         PLS_API bool TouchNode(SceneNode &cSceneNode);
00247 
00248         /**
00249         *  @brief
00250         *    Ends a scene process
00251         *
00252         *  @see
00253         *    - StartProcess()
00254         *
00255         *  @return
00256         *    'true' if all went fine, else 'false' (there's currently no process running)
00257         */
00258         PLS_API bool EndProcess();
00259 
00260 
00261     //[-------------------------------------------------------]
00262     //[ Private data                                          ]
00263     //[-------------------------------------------------------]
00264     private:
00265         PLRenderer::RendererContext  *m_pRendererContext;       /**< The used renderer context, not destroyed by the scene context (always valid!) */
00266         PLMesh::MeshManager          *m_pMeshManager;           /**< The mesh manager, can be a null pointer */
00267         PLMath::GraphPathManager     *m_pGraphPathManager;      /**< The graph path manager, can be a null pointer */
00268         SceneNodeHandler             *m_pRoot;                  /**< The root of the scene graph (always valid!) */
00269         PLCore::Array<SceneNode*>     m_lstDeleteNodes;         /**< List of scene nodes to delete */
00270         SceneRendererManager         *m_pSceneRendererManager;  /**< Scene renderer manager, can be a null pointer */
00271         VisManager                   *m_pVisManager;            /**< Visibility manager, can be a null pointer */
00272         bool                          m_bProcessActive;         /**< Is there currently an active process? */
00273         PLCore::uint32                m_nProcessCounter;        /**< Internal process counter */
00274 
00275 
00276 };
00277 
00278 
00279 //[-------------------------------------------------------]
00280 //[ Namespace                                             ]
00281 //[-------------------------------------------------------]
00282 } // PLScene
00283 
00284 
00285 #endif // __PLSCENE_SCENECONTEXT_H__


PixelLight PixelLight 0.9.11-R1
Copyright (C) 2002-2012 by The PixelLight Team
Last modified Thu Feb 23 2012 14:08:59
The content of this PixelLight document is published under the
Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported