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