PixelLightAPI  .
SceneLoaderPL.h
Go to the documentation of this file.
00001 /*********************************************************\
00002  *  File: SceneLoaderPL.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_SCENELOADER_PL_H__
00024 #define __PLSCENE_SCENELOADER_PL_H__
00025 #pragma once
00026 
00027 
00028 //[-------------------------------------------------------]
00029 //[ Includes                                              ]
00030 //[-------------------------------------------------------]
00031 #include "PLScene/Scene/SceneLoader/SceneLoader.h"
00032 
00033 
00034 //[-------------------------------------------------------]
00035 //[ Forward declarations                                  ]
00036 //[-------------------------------------------------------]
00037 namespace PLCore {
00038     class XmlElement;
00039 }
00040 namespace PLScene {
00041     class SceneNode;
00042     class SceneNodeModifier;
00043 }
00044 
00045 
00046 //[-------------------------------------------------------]
00047 //[ Namespace                                             ]
00048 //[-------------------------------------------------------]
00049 namespace PLScene {
00050 
00051 
00052 //[-------------------------------------------------------]
00053 //[ Classes                                               ]
00054 //[-------------------------------------------------------]
00055 /**
00056 *  @brief
00057 *    Scene loader implementation for the PixelLight scene XML file format
00058 *
00059 *  @note
00060 *    - If the save function receives a boolean 'NoDefault'-parameter with 'true', (default setting)
00061 *      variables with default values are not saved
00062 */
00063 class SceneLoaderPL : public SceneLoader {
00064 
00065 
00066     //[-------------------------------------------------------]
00067     //[ RTTI interface                                        ]
00068     //[-------------------------------------------------------]
00069     pl_class(PLS_RTTI_EXPORT, SceneLoaderPL, "PLScene", PLScene::SceneLoader, "Scene loader implementation for the PixelLight scene XML file format")
00070         // Properties
00071         pl_properties
00072             pl_property("Formats",  "scene,SCENE")
00073             pl_property("Load",     "1")
00074             pl_property("Save",     "1")
00075         pl_properties_end
00076         // Constructors
00077         pl_constructor_0(DefaultConstructor,    "Default constructor",  "")
00078         // Methods
00079         pl_method_2(Load,       pl_ret_type(bool),  SceneContainer&,    PLCore::File&,          "Load method",                                              "")
00080         pl_method_2(Save,       pl_ret_type(bool),  SceneContainer&,    PLCore::File&,          "Save method",                                              "")
00081         pl_method_3(SaveParams, pl_ret_type(bool),  SceneContainer&,    PLCore::File&,  bool,   "Save method. Parameters: No default values as 'bool'.",    "")
00082     pl_class_end
00083 
00084 
00085     //[-------------------------------------------------------]
00086     //[ Public RTTI methods                                   ]
00087     //[-------------------------------------------------------]
00088     public:
00089         PLS_API bool Load(SceneContainer &cContainer, PLCore::File &cFile);
00090         PLS_API bool Save(SceneContainer &cContainer, PLCore::File &cFile);
00091         PLS_API bool SaveParams(SceneContainer &cContainer, PLCore::File &cFile, bool bNoDefault);
00092 
00093 
00094     //[-------------------------------------------------------]
00095     //[ Private structures                                    ]
00096     //[-------------------------------------------------------]
00097     private:
00098         /**
00099         *  @brief
00100         *    Internal per instance data
00101         */
00102         struct SInstance {
00103             SceneContainer *pContainer;             /**< Scene root container (the one we currently 'load in', always valid) */
00104             // Statistics
00105             PLCore::uint32  nTotalNumOfContainers;  /**< Total number of containers within the scene (without the root container itself) */
00106             PLCore::uint32  nTotalNumOfNodes;       /**< Total number of nodes (without containers) within the scene */
00107             PLCore::uint32  nTotalNumOfModifiers;   /**< Total number of modifiers within the scene */
00108         };
00109 
00110 
00111     //[-------------------------------------------------------]
00112     //[ Public functions                                      ]
00113     //[-------------------------------------------------------]
00114     public:
00115         /**
00116         *  @brief
00117         *    Default constructor
00118         */
00119         PLS_API SceneLoaderPL();
00120 
00121         /**
00122         *  @brief
00123         *    Destructor
00124         */
00125         PLS_API virtual ~SceneLoaderPL();
00126 
00127 
00128     //[-------------------------------------------------------]
00129     //[ Private functions                                     ]
00130     //[-------------------------------------------------------]
00131     private:
00132         /**
00133         *  @brief
00134         *    Loader implementation for format version 1
00135         *
00136         *  @param[in] cContainer
00137         *    Scene container to load into
00138         *  @param[in] cSceneElement
00139         *    Scene XML element to read the data from
00140         *  @param[in] cFile
00141         *    File to load from
00142         *
00143         *  @return
00144         *    'true' if all went fine, else 'false'
00145         */
00146         bool LoadV1(SceneContainer &cContainer, const PLCore::XmlElement &cSceneElement, PLCore::File &cFile) const;
00147 
00148         /**
00149         *  @brief
00150         *    Recursive part of the load function
00151         *
00152         *  @param[in] sInstance
00153         *    Per instance data
00154         *  @param[in] cContainer
00155         *    Scene container object
00156         *  @param[in] cParent
00157         *    Parent XML element
00158         *  @param[in] nFirstSceneRow
00159         *    First scene Row
00160         *  @param[in] nLastSceneRow
00161         *    Last scene Row
00162         *
00163         *  @return
00164         *    'true' if all went fine, else 'false'
00165         */
00166         bool LoadRec(SInstance &sInstance, SceneContainer &cContainer, const PLCore::XmlElement &cParent, PLCore::uint32 nFirstSceneRow, PLCore::uint32 nLastSceneRow) const;
00167 
00168         /**
00169         *  @brief
00170         *    Loads a scene node and returns it
00171         *
00172         *  @param[in] sInstance
00173         *    Per instance data
00174         *  @param[in] cContainer
00175         *    Scene container object
00176         *  @param[in] cNode
00177         *    XML node
00178         *  @param[in] bContainer
00179         *    Is this a scene container?
00180         *
00181         *  @return
00182         *    The created scene node, a null pointer on error (maybe XML element has no class attribute?)
00183         */
00184         SceneNode *LoadNode(SInstance &sInstance, SceneContainer &cContainer, const PLCore::XmlElement &cNode, bool bContainer) const;
00185 
00186         /**
00187         *  @brief
00188         *    Loads a scene node modifier and returns it
00189         *
00190         *  @param[in] sInstance
00191         *    Per instance data
00192         *  @param[in] cNode
00193         *    XML node
00194         *  @param[in] cSceneNode
00195         *    Scene node where to add the modifier
00196         *
00197         *  @return
00198         *    The created scene node modifier, a null pointer on error (maybe XML element has no class attribute?)
00199         */
00200         SceneNodeModifier *LoadModifier(SInstance &sInstance, const PLCore::XmlElement &cNode, SceneNode &cSceneNode) const;
00201 
00202         /**
00203         *  @brief
00204         *    Recursive part of the save function
00205         *
00206         *  @param[in] sInstance
00207         *    Per instance data
00208         *  @param[in] cContainer
00209         *    Scene container object
00210         *  @param[in] cParent
00211         *    Parent XML element
00212         *  @param[in] bNoDefault
00213         *    If 'true', variables with default values will be ignored
00214         *
00215         *  @return
00216         *    'true' if all went fine, else 'false'
00217         */
00218         bool SaveRec(SInstance &sInstance, const SceneContainer &cContainer, PLCore::XmlElement &cParent, bool bNoDefault = true) const;
00219 
00220         /**
00221         *  @brief
00222         *    Modifiers part of the save function
00223         *
00224         *  @param[in] sInstance
00225         *    Per instance data
00226         *  @param[in] cParent
00227         *    Parent XML element
00228         *  @param[in] cSceneNode
00229         *    Node to save the modifiers from
00230         *  @param[in] bNoDefault
00231         *    If 'true', variables with default values will be ignored
00232         *
00233         *  @return
00234         *    'true' if all went fine, else 'false'
00235         */
00236         bool SaveModifiers(SInstance &sInstance, PLCore::XmlElement &cParent, const SceneNode &cSceneNode, bool bNoDefault = true) const;
00237 
00238 
00239 };
00240 
00241 
00242 //[-------------------------------------------------------]
00243 //[ Namespace                                             ]
00244 //[-------------------------------------------------------]
00245 } // PLScene
00246 
00247 
00248 #endif // __PLSCENE_SCENELOADER_PL_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