MezzanineEngine 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
particleemitter.cpp
1 // © Copyright 2010 - 2014 BlackTopp Studios Inc.
2 /* This file is part of The Mezzanine Engine.
3 
4  The Mezzanine Engine is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  The Mezzanine Engine is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with The Mezzanine Engine. If not, see <http://www.gnu.org/licenses/>.
16 */
17 /* The original authors have included a copy of the license specified above in the
18  'Docs' folder. See 'gpl.txt'
19 */
20 /* We welcome the use of the Mezzanine engine to anyone, including companies who wish to
21  Build professional software and charge for their product.
22 
23  However there are some practical restrictions, so if your project involves
24  any of the following you should contact us and we will try to work something
25  out:
26  - DRM or Copy Protection of any kind(except Copyrights)
27  - Software Patents You Do Not Wish to Freely License
28  - Any Kind of Linking to Non-GPL licensed Works
29  - Are Currently In Violation of Another Copyright Holder's GPL License
30  - If You want to change our code and not add a few hundred MB of stuff to
31  your distribution
32 
33  These and other limitations could cause serious legal problems if you ignore
34  them, so it is best to simply contact us or the Free Software Foundation, if
35  you have any questions.
36 
37  Joseph Toppi - toppij@gmail.com
38  John Blackwood - makoenergy02@gmail.com
39 */
40 
41 #ifndef _graphicsparticleemitter_cpp
42 #define _graphicsparticleemitter_cpp
43 
44 #include "Graphics/particleemitter.h"
45 
46 #include "exception.h"
47 #include "serialization.h"
48 #include "stringtool.h"
49 
50 #include <Ogre.h>
51 
52 namespace Mezzanine
53 {
54  namespace Graphics
55  {
56  ParticleEmitter::ParticleEmitter(Ogre::ParticleEmitter* InternalEmitter, ParticleSystemProxy* Creator) :
57  GraphicsEmitter(InternalEmitter),
58  ParentSystem(Creator)
59  { }
60 
62  { }
63 
64  ///////////////////////////////////////////////////////////////////////////////
65  // Utility
66 
67  void ParticleEmitter::SetCustomParam(const String& Name, const String& Value)
68  {
69  this->GraphicsEmitter->setParameter(Name,Value);
70  this->CustomEmitterParameters[Name] = Value;
71  }
72 
74  {
75  return this->GraphicsEmitter->getParameter(Name);
76  }
77 
78  ///////////////////////////////////////////////////////////////////////////////
79  // Serialization
80 
82  {
83  XML::Node SelfRoot = ParentNode.AppendChild(this->GetDerivedSerializableName());
84 
85  this->ProtoSerializeCustomParameters(SelfRoot);
86  }
87 
88  /*void ParticleEmitter::ProtoSerializeProperties(XML::Node& SelfRoot) const
89  {
90 
91  }*/
92 
94  {
95  XML::Node CustomParametersNode = SelfRoot.AppendChild( ParticleEmitter::GetSerializableName() + "CustomParameters" );
96 
97  if( CustomParametersNode.AppendAttribute("Version").SetValue("1") )
98  {
99  for( NameValuePairMap::const_iterator ParamIt = this->CustomEmitterParameters.begin() ; ParamIt != this->CustomEmitterParameters.end() ; ++ParamIt )
100  {
101  XML::Node CustomParamNode = CustomParametersNode.AppendChild( "CustomParam" );
102  if( CustomParamNode.AppendAttribute("Version").SetValue("1") &&
103  CustomParamNode.AppendAttribute("ParamName").SetValue( (*ParamIt).first ) &&
104  CustomParamNode.AppendAttribute("ParamValue").SetValue( (*ParamIt).second ) )
105  {
106  return;
107  }else{
108  SerializeError("Create XML Attribute Values",ParticleEmitter::GetSerializableName() + "CustomParameters",true);
109  }
110  }
111  }else{
112  SerializeError("Create XML Attribute Values",ParticleEmitter::GetSerializableName() + "CustomParameters",true);
113  }
114  }
115 
117  {
118  this->ProtoDeSerializeCustomParameters(SelfRoot);
119  }
120 
121  /*void ParticleEmitter::ProtoDeSerializeProperties(const XML::Node& SelfRoot)
122  {
123 
124  }*/
125 
127  {
128  XML::Attribute CurrAttrib;
129  XML::Node CustomParametersNode = SelfRoot.GetChild( ParticleEmitter::GetSerializableName() + "CustomParameters" );
130 
131  if( !CustomParametersNode.Empty() ) {
132  if(CustomParametersNode.GetAttribute("Version").AsInt() == 1) {
133  String ParamName, ParamValue;
134 
135  for( XML::NodeIterator ParamIt = CustomParametersNode.begin() ; ParamIt != CustomParametersNode.end() ; ++ParamIt )
136  {
137  if( !(*ParamIt).Empty() ) {
138  if((*ParamIt).GetAttribute("Version").AsInt() == 1) {
139  CurrAttrib = (*ParamIt).GetAttribute("ParamName");
140  if( !CurrAttrib.Empty() )
141  ParamName = CurrAttrib.AsString();
142 
143  CurrAttrib = (*ParamIt).GetAttribute("ParamValue");
144  if( !CurrAttrib.Empty() )
145  ParamValue = CurrAttrib.AsString();
146 
147  if( !ParamName.empty() && !ParamValue.empty() ) {
148  this->SetCustomParam(ParamName,ParamValue);
149  }
150  }
151  }
152  }
153  }else{
154  MEZZ_EXCEPTION(Exception::INVALID_VERSION_EXCEPTION,"Incompatible XML Version for " + (ParticleEmitter::GetSerializableName() + "CustomParameters" ) + ": Not Version 1.");
155  }
156  }else{
157  MEZZ_EXCEPTION(Exception::II_IDENTITY_NOT_FOUND_EXCEPTION,ParticleEmitter::GetSerializableName() + "CustomParameters" + " was not found in the provided XML node, which was expected.");
158  }
159  }
160 
163 
165  { return "ParticleEmitter"; }
166 
167  ///////////////////////////////////////////////////////////////////////////////
168  // Internal Methods
169 
170  Ogre::ParticleEmitter* ParticleEmitter::_GetGraphicsEmitter() const
171  { return this->GraphicsEmitter; }
172  }//Graphics
173 }//Mezzanine
174 
175 #endif