PixelLightAPI  .
EngineApplication.h
Go to the documentation of this file.
00001 /*********************************************************\
00002  *  File: EngineApplication.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 __PLENGINE_ENGINEAPPLICATION_H__
00024 #define __PLENGINE_ENGINEAPPLICATION_H__
00025 #pragma once
00026 
00027 
00028 //[-------------------------------------------------------]
00029 //[ Includes                                              ]
00030 //[-------------------------------------------------------]
00031 #include <PLRenderer/Renderer/TextureBuffer.h>
00032 #include <PLScene/Scene/SceneNodeHandler.h>
00033 #include <PLScene/Application/SceneApplication.h>
00034 #include "PLEngine/Tools/Screenshot.h"
00035 #include "PLEngine/Tools/SceneRendererTool.h"
00036 
00037 
00038 //[-------------------------------------------------------]
00039 //[ Forward declarations                                  ]
00040 //[-------------------------------------------------------]
00041 namespace PLInput {
00042     class Controller;
00043     class VirtualController;
00044 }
00045 namespace PLScene {
00046     class SNCamera;
00047     class SNKeyValue;
00048     class SceneQuery;
00049 }
00050 namespace PLEngine {
00051     class ConsoleCommand;
00052 }
00053 
00054 
00055 //[-------------------------------------------------------]
00056 //[ Namespace                                             ]
00057 //[-------------------------------------------------------]
00058 namespace PLEngine {
00059 
00060 
00061 //[-------------------------------------------------------]
00062 //[ Classes                                               ]
00063 //[-------------------------------------------------------]
00064 /**
00065 *  @brief
00066 *    Basic scene application class
00067 *
00068 *  @remarks
00069 *    An application class that provides a standard scene graph for usual 3D applications and offers functionality
00070 *    to load in whole scenes at once as well as load screen handling and screenshot capturing.
00071 */
00072 class EngineApplication : public PLScene::SceneApplication {
00073 
00074 
00075     //[-------------------------------------------------------]
00076     //[ RTTI interface                                        ]
00077     //[-------------------------------------------------------]
00078     pl_class(PL_RTTI_EXPORT, EngineApplication, "PLEngine", PLScene::SceneApplication, "Basic scene application class")
00079         #ifdef PLENGINE_EXPORTS // The following is only required when compiling PLEngine
00080             // Constructors
00081             pl_constructor_1(ParameterConstructor,  PLCore::Frontend&,  "Parameter constructor. Frontend this application instance is running in as first parameter.",  "")
00082             // Methods
00083             pl_method_0(GetScene,               pl_ret_type(PLScene::SceneContainer*),                                      "Returns the scene container (the 'concrete scene'), can be a null pointer.",                                                                                               "")
00084             pl_method_1(SetScene,               pl_ret_type(void),                          PLScene::SceneContainer*,       "Sets the scene container (the 'concrete scene'). New scene container as first parameter (can be a null pointer).",                                                         "")
00085             pl_method_0(ClearScene,             pl_ret_type(void),                                                          "Clears the scene, after calling this method the scene is empty.",                                                                                                          "")
00086             pl_method_1(LoadScene,              pl_ret_type(bool),                          const PLCore::String&,          "Loads a scene. Filename of the scene to load as first argument. Returns 'true' if all went fine, else 'false'. This method will completely replace the current scene.",    "")
00087             pl_method_0(GetCamera,              pl_ret_type(PLScene::SNCamera*),                                            "Get the scene camera, can be a null pointer.",                                                                                                                             "")
00088             pl_method_1(SetCamera,              pl_ret_type(void),                          PLScene::SNCamera*,             "Sets the scene camera. New scene camera as first parameter (can be a null pointer).",                                                                                      "")
00089             pl_method_0(GetInputController,     pl_ret_type(PLInput::VirtualController*),                                   "Get the virtual input controller (can be a null pointer).",                                                                                                                "")
00090             pl_method_1(SetInputController,     pl_ret_type(void),                          PLInput::VirtualController*,    "Set the virtual input controller. Virtual input controller (can be a null pointer) as first parameter.",                                                                   "")
00091             pl_method_0(GetSceneRendererTool,   pl_ret_type(SceneRendererTool&),                                            "Returns the scene renderer tool.",                                                                                                                                         "")
00092             pl_method_0(GetScreenshotTool,      pl_ret_type(Screenshot&),                                                   "Returns the screenshot tool.",                                                                                                                                             "")
00093         #endif
00094         // Signals
00095         pl_signal_0(SignalCameraSet,            "A new camera has been set",                    "")
00096         pl_signal_0(SignalSceneLoadingFinished, "Scene loading has been finished successfully", "")
00097     pl_class_end
00098 
00099 
00100     //[-------------------------------------------------------]
00101     //[ Public static data                                    ]
00102     //[-------------------------------------------------------]
00103     public:
00104         PL_API static const PLCore::String DefaultSceneRenderer;    /**< The used default (and very basic) scene renderer */
00105 
00106 
00107     //[-------------------------------------------------------]
00108     //[ Public functions                                      ]
00109     //[-------------------------------------------------------]
00110     public:
00111         /**
00112         *  @brief
00113         *    Constructor
00114         *
00115         *  @param[in] cFrontend
00116         *    Frontend this application instance is running in
00117         *  @param[in] sSceneFilename
00118         *    Filename of the scene to load
00119         */
00120         PL_API EngineApplication(PLCore::Frontend &cFrontend, const PLCore::String &sSceneFilename = "");
00121 
00122         /**
00123         *  @brief
00124         *    Destructor
00125         */
00126         PL_API virtual ~EngineApplication();
00127 
00128         /**
00129         *  @brief
00130         *    Returns the scene container (the 'concrete scene')
00131         *
00132         *  @return
00133         *    Scene container, can be a null pointer
00134         */
00135         PL_API PLScene::SceneContainer *GetScene() const;
00136 
00137         /**
00138         *  @brief
00139         *    Sets the scene container (the 'concrete scene')
00140         *
00141         *  @param[in] pContainer
00142         *    New scene container, can be a null pointer
00143         */
00144         PL_API void SetScene(PLScene::SceneContainer *pContainer);
00145 
00146         /**
00147         *  @brief
00148         *    Clears the scene, after calling this method the scene is empty
00149         */
00150         PL_API void ClearScene();
00151 
00152         /**
00153         *  @brief
00154         *    Get scene camera
00155         *
00156         *  @return
00157         *    Scene camera, can be a null pointer
00158         */
00159         PL_API PLScene::SNCamera *GetCamera() const;
00160 
00161         /**
00162         *  @brief
00163         *    Get virtual input controller
00164         *
00165         *  @return
00166         *    Virtual input controller (can be a null pointer)
00167         */
00168         PL_API PLInput::VirtualController *GetInputController() const;
00169 
00170         /**
00171         *  @brief
00172         *    Set virtual input controller
00173         *
00174         *  @param[in] pInputController
00175         *    Virtual input controller (can be a null pointer)
00176         */
00177         PL_API void SetInputController(PLInput::VirtualController *pInputController);
00178 
00179         /**
00180         *  @brief
00181         *    Get scene renderer tool
00182         *
00183         *  @return
00184         *    Scene renderer tool instance
00185         *
00186         *  @remarks
00187         *    Use "GetSceneRendererTool()" for a simplified interface to the scene renderer. By writing for example
00188         *    "GetSceneRendererTool().SetPassAttribute("BackgroundBitmap", "Material", "Data/Textures/Background.dds");"
00189         *    one can usually (on standard scene renderer configurations) set directly a background bitmap.
00190         *
00191         *    This component is initialized within the application framework initialization function "OnStart()" that is called prior to "Main()".
00192         *    As a result, using the returned component instance prior to the application-specific initialization routine "OnInit()" will not
00193         *    work.
00194         */
00195         PL_API SceneRendererTool &GetSceneRendererTool();
00196 
00197         /**
00198         *  @brief
00199         *    Get scene renderer tool
00200         *
00201         *  @return
00202         *    Scene renderer tool instance
00203         *
00204         *  @see
00205         *    - Non-constant GetSceneRendererTool()
00206         */
00207         PL_API const SceneRendererTool &GetSceneRendererTool() const;
00208 
00209         /**
00210         *  @brief
00211         *    Get screenshot tool
00212         *
00213         *  @return
00214         *    Screenshot tool instance
00215         *
00216         *  @remarks
00217         *    This component is initialized within the application framework initialization function "OnStart()" that is called prior to "Main()".
00218         *    As a result, using the returned component instance prior to the application-specific initialization routine "OnInit()" will not
00219         *    work.
00220         */
00221         PL_API Screenshot &GetScreenshotTool();
00222 
00223         //[-------------------------------------------------------]
00224         //[ Edit functions                                        ]
00225         //[-------------------------------------------------------]
00226         /**
00227         *  @brief
00228         *    Returns whether or not edit mode is enabled
00229         *
00230         *  @return
00231         *    'true' if edit mode is enabled, else 'false'
00232         *
00233         *  @remarks
00234         *    This class introduces some generic edit features which are enabled by default. For public release
00235         *    versions you may disable the edit mode so users can't for example use edit features to chat.
00236         */
00237         PL_API bool IsEditModeEnabled() const;
00238 
00239         /**
00240         *  @brief
00241         *    Sets whether or not edit mode is enabled
00242         *
00243         *  @param[in] bEnabled
00244         *    'true' if edit mode is enabled, else 'false'
00245         *
00246         *  @remarks
00247         *    Also the scene nodes 'SNEngineInformation0' and 'SNConsole0' from the root scene are enabled/disabled.
00248         *    By default, edit mode is enabled.
00249         *
00250         *  @see
00251         *    - IsEditModeEnabled()
00252         */
00253         PL_API void SetEditModeEnabled(bool bEnabled = true);
00254 
00255         //[-------------------------------------------------------]
00256         //[ Console functions                                     ]
00257         //[-------------------------------------------------------]
00258         /**
00259         *  @brief
00260         *    Quit the engine
00261         *
00262         *  @param[in] cCommand
00263         *    Calling command
00264         */
00265         PL_API void ConsoleCommandQuit(ConsoleCommand &cCommand);
00266 
00267 
00268     //[-------------------------------------------------------]
00269     //[ Public virtual EngineApplication functions            ]
00270     //[-------------------------------------------------------]
00271     public:
00272         /**
00273         *  @brief
00274         *    Sets the scene camera
00275         *
00276         *  @param[in] pCamera
00277         *    New scene camera, can be a null pointer
00278         *
00279         *  @note
00280         *    - Deactivates automatically the current set camera and activates the new camera
00281         *    - Sets this camera also within the 'SPScene' surface painter instance
00282         *    - Emits the "SignalCameraSet"-signal
00283         */
00284         PL_API virtual void SetCamera(PLScene::SNCamera *pCamera);
00285 
00286         /**
00287         *  @brief
00288         *    Loads a scene
00289         *
00290         *  @param[in] sFilename
00291         *    Filename of the scene to load
00292         *
00293         *  @return
00294         *    'true' if all went fine, else 'false'
00295         *
00296         *  @remarks
00297         *    This function will use the current set scene container (the 'concrete scene') to load
00298         *    in given scene data. It will temporarily add a new base path so all scene data can be found
00299         *    even if the scene to load is not within the application directory.
00300         *    Supported 'SNKeyValue' information:
00301         *      Key                       Value
00302         *      'SceneRenderer'           'Class name of the scene renderer to use'
00303         *      'SceneRendererVariables'  '<Variable>=<Value>'
00304         *      'ClearColor'              '<red> <green> <blue> <alpha>' (all floating point values from 0-1)
00305         *      'StartCamera'             '<name of the start camera scene node>' (name is relative to the loaded scene container)
00306         *
00307         *  @note
00308         *    - If currently the edit dialog is opened, it will be closed automatically to avoid update problems
00309         *    - Emits the "SignalSceneLoadingFinished"-signal when the scene loading has been finished successfully
00310         */
00311         PL_API virtual bool LoadScene(const PLCore::String &sFilename);
00312 
00313 
00314     //[-------------------------------------------------------]
00315     //[ Protected virtual PLCore::AbstractLifecycle functions ]
00316     //[-------------------------------------------------------]
00317     protected:
00318         /**
00319         *  @brief
00320         *    Initialization function that is called prior to OnInit()
00321         *
00322         *  @return
00323         *    'true' if all went fine, else 'false' which will stop the application
00324         *
00325         *  @remarks
00326         *    The default implementation does the following tasks:
00327         *    - Everything that PLRenderer::RendererApplication::OnStart() does (we reimplement the PLScene::SceneApplication::OnStart() order)
00328         *    - Initialize input system
00329         *    - Call OnCreateInputController()
00330         *    - Initialize scene renderer tool
00331         *    - Initialize screenshot tool
00332         *    - Create scene context
00333         *    - Call OnCreateRootScene()
00334         *    - Return and go on with OnInit()
00335         */
00336         PL_API virtual bool OnStart() override;
00337 
00338         /**
00339         *  @brief
00340         *    Called when the object has the focus (keep the implementation lightweight)
00341         *
00342         *  @remarks
00343         *    The default implementation does the following tasks:
00344         *    - Everything that PLScene::SceneApplication::OnResume() does
00345         *    - Activate the input controller
00346         */
00347         PL_API virtual void OnResume() override;
00348 
00349         /**
00350         *  @brief
00351         *    Called when the object has no longer the focus (keep the implementation lightweight)
00352         *
00353         *  @remarks
00354         *    The default implementation does the following tasks:
00355         *    - Everything that PLScene::SceneApplication::OnPause() does
00356         *    - Deactivate the input controller
00357         */
00358         PL_API virtual void OnPause() override;
00359 
00360         /**
00361         *  @brief
00362         *    De-initialization function that is called after OnDeInit()
00363         *
00364         *  @remarks
00365         *    The default implementation does the following tasks:
00366         *    - Destroy input controller
00367         *    - Everything that PLScene::SceneApplication::OnStop() does
00368         */
00369         PL_API virtual void OnStop() override;
00370 
00371 
00372     //[-------------------------------------------------------]
00373     //[ Protected virtual PLCore::AbstractFrontend functions  ]
00374     //[-------------------------------------------------------]
00375     protected:
00376         /**
00377         *  @brief
00378         *    Called to let the frontend update it's states
00379         *
00380         *  @remarks
00381         *    The default implementation does the following tasks:
00382         *    - Everything that PLScene::SceneApplication::OnUpdate() does
00383         *    - Update input manager
00384         */
00385         PL_API virtual void OnUpdate() override;
00386 
00387 
00388     //[-------------------------------------------------------]
00389     //[ Protected virtual PLScene::SceneApplication functions ]
00390     //[-------------------------------------------------------]
00391     protected:
00392         PL_API virtual void OnCreateRootScene() override;
00393 
00394 
00395     //[-------------------------------------------------------]
00396     //[ Protected virtual EngineApplication functions         ]
00397     //[-------------------------------------------------------]
00398     protected:
00399         /**
00400         *  @brief
00401         *    Function that is called to create the application's scene container
00402         *
00403         *  @param[in] cContainer
00404         *    Scene container where the 'concrete scene' should be created in
00405         *
00406         *  @note
00407         *    - Part of the application framework initialization function "OnStart()"
00408         *    - The default implementation creates an controllable camera and a simple mesh scene node
00409         *    - Called from within "PLScene::SceneApplication::OnCreateRootScene()"
00410         */
00411         PL_API virtual void OnCreateScene(PLScene::SceneContainer &cContainer);
00412 
00413         /**
00414         *  @brief
00415         *    Function that is called to initialize the application's virtual input controller
00416         *
00417         *  @note
00418         *    - Part of the application framework initialization function "OnStart()"
00419         *    - In the default implementation, an instance of VirtualStandardController is created
00420         */
00421         PL_API virtual void OnCreateInputController();
00422 
00423         /**
00424         *  @brief
00425         *    Function that is called when an input controller has been found
00426         *
00427         *  @param[in] pInputController
00428         *    Found input controller, always valid
00429         *  @param[in] sInputSemantic
00430         *    Purpose of this input controller
00431         *
00432         *  @remarks
00433         *    Use this virtual method for instance to connect the input controller to real input devices.
00434         *
00435         *  @note
00436         *    - Connected to the "PLInput::InputManager::EventInputControllerFound"-event
00437         *    - The default implementation tries to connect all controls automatically with the virtual standard controller
00438         */
00439         PL_API virtual void OnInputControllerFound(PLInput::Controller *pInputController, PLCore::String sInputSemantic);
00440 
00441 
00442     //[-------------------------------------------------------]
00443     //[ Protected data                                        ]
00444     //[-------------------------------------------------------]
00445     protected:
00446         PLScene::SceneNodeHandler                  m_cSceneContainerHandler;    /**< Scene node handler for the scene container */
00447         PLScene::SceneNodeHandler                  m_cCameraHandler;            /**< Scene node handler for the camera */
00448         PLCore::String                             m_sDefaultSceneRenderer;     /**< Default scene renderer */
00449         PLCore::String                             m_sClearColor;               /**< Clear color */
00450         PLCore::String                             m_sStartCamera;              /**< Name of the given start camera */
00451         PLScene::SceneNode                        *m_pFirstFoundCamera;         /**< First found camera, can be a null pointer */
00452         PLCore::Array<const PLScene::SNKeyValue*>  m_lstPostKeys;               /**< Keys to process AFTER all other */
00453         bool                                       m_bHasLoadScreen;            /**< Is there a load screen? */
00454         PLInput::VirtualController                *m_pInputController;          /**< Virtual input controller, can be a null pointer */
00455         SceneRendererTool                          m_cSceneRendererTool;        /**< Scene renderer tool */
00456         Screenshot                                 m_cScreenshot;               /**< Screenshot tool */
00457         bool                                       m_bEditModeEnabled;          /**< Edit mode enabled? */
00458 
00459 
00460     //[-------------------------------------------------------]
00461     //[ Private functions                                     ]
00462     //[-------------------------------------------------------]
00463     private:
00464         /**
00465         *  @brief
00466         *    Called when a scene node was found
00467         *
00468         *  @param[in] cQuery
00469         *    Query found the scene node
00470         *  @param[in] cSceneNode
00471         *    Found scene node
00472         */
00473         void OnSceneNode(PLScene::SceneQuery &cQuery, PLScene::SceneNode &cSceneNode);
00474 
00475         /**
00476         *  @brief
00477         *    Called on load progress
00478         *
00479         *  @param[in] fLoadProgress
00480         *    Load progress (0.0-1.0)
00481         */
00482         void OnLoadProgress(float fLoadProgress);
00483 
00484 
00485     //[-------------------------------------------------------]
00486     //[ Private event handlers                                ]
00487     //[-------------------------------------------------------]
00488     private:
00489         PLCore::EventHandler<PLScene::SceneQuery &, PLScene::SceneNode &>   EventHandlerSceneNode;
00490         PLCore::EventHandler<float>                                         EventHandlerLoadProgress;
00491         PLCore::EventHandler<PLInput::Controller*, PLCore::String>          EventHandlerInputControllerFound;
00492 
00493 
00494 };
00495 
00496 
00497 //[-------------------------------------------------------]
00498 //[ Namespace                                             ]
00499 //[-------------------------------------------------------]
00500 } // PLEngine
00501 
00502 
00503 #endif // __PLENGINE_ENGINEAPPLICATION_H__


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