Spinning Topp Logo BlackTopp Studios
inc
particleaffector.cpp
1 // © Copyright 2010 - 2016 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 _graphicsparticleaffector_cpp
42 #define _graphicsparticleaffector_cpp
43 
44 #include "Graphics/particleaffector.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  ParticleAffector::ParticleAffector(Ogre::ParticleAffector* InternalAffector, ParticleSystemProxy* Creator) :
57  GraphicsAffector(InternalAffector),
58  ParentSystem(Creator)
59  { }
60 
62  { }
63 
64  ///////////////////////////////////////////////////////////////////////////////
65  // Utility
66 
67  void ParticleAffector::SetCustomParam(const String& Name, const String& Value)
68  {
69  this->GraphicsAffector->setParameter(Name,Value);
70  this->CustomAffectorParameters[Name] = Value;
71  }
72 
74  {
75  return this->GraphicsAffector->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 ParticleAffector::ProtoSerializeProperties(XML::Node& SelfRoot) const
89  {
90 
91  }*/
92 
94  {
95  XML::Node CustomParametersNode = SelfRoot.AppendChild( "CustomParameters" );
96 
97  if( CustomParametersNode.AppendAttribute("Version").SetValue("1") )
98  {
99  for( NameValuePairMap::const_iterator ParamIt = this->CustomAffectorParameters.begin() ; ParamIt != this->CustomAffectorParameters.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",ParticleAffector::GetSerializableName() + "CustomParameters",true);
109  }
110  }
111  }else{
112  SerializeError("Create XML Attribute Values",ParticleAffector::GetSerializableName() + "CustomParameters",true);
113  }
114  }
115 
117  {
118  this->ProtoDeSerializeCustomParameters(SelfRoot);
119  }
120 
121  /*void ParticleAffector::ProtoDeSerializeProperties(const XML::Node& SelfRoot)
122  {
123 
124  }*/
125 
127  {
128  XML::Attribute CurrAttrib;
129  XML::Node CustomParametersNode = SelfRoot.GetChild( ParticleAffector::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(ExceptionBase::INVALID_VERSION_EXCEPTION,"Incompatible XML Version for " + (ParticleAffector::GetSerializableName() + "CustomParameters" ) + ": Not Version 1.");
155  }
156  }else{
157  MEZZ_EXCEPTION(ExceptionBase::II_IDENTITY_NOT_FOUND_EXCEPTION,ParticleAffector::GetSerializableName() + "CustomParameters" + " was not found in the provided XML node, which was expected.");
158  }
159  }
160 
163 
165  { return "ParticleAffector"; }
166 
167  ///////////////////////////////////////////////////////////////////////////////
168  // Internal Methods
169 
170  Ogre::ParticleAffector* ParticleAffector::_GetGraphicsAffector() const
171  { return this->GraphicsAffector; }
172  }//Graphics
173 }//Mezzanine
174 
175 #endif
Attribute AppendAttribute(const Char8 *Name)
Creates an Attribute and puts it at the end of this Nodes attributes.
A light-weight handle for manipulating attributes in DOM tree.
Definition: attribute.h:74
Ogre::ParticleAffector * GraphicsAffector
The internal affector class this class get's it functionality from.
virtual void ProtoDeSerialize(const XML::Node &SelfRoot)
Take the data stored in an XML Node and overwrite this object with it.
String GetCustomParam(const String &Name) const
Gets a custom parameter of a particle affector.
Thrown when the requested identity could not be found.
Definition: exception.h:94
#define MEZZ_EXCEPTION(num, desc)
An easy way to throw exceptions with rich information.
Definition: exception.h:3048
static String GetSerializableName()
Get the name of the the XML tag the proxy class will leave behind as its instances are serialized...
Thrown when a version is accessed/parsed/required and it cannot work correctly or is missing...
Definition: exception.h:112
const Char8 * AsString(const Char8 *def="") const
Attempts to convert the value of the attribute to a String and returns the results.
bool Empty() const
Is this storing anything at all?
This implements the exception hiearchy for Mezzanine.
The interface for serialization.
bool SetValue(const Char8 *rhs)
Set the value of this.
virtual void ProtoSerialize(XML::Node &ParentNode) const
Convert this class to an XML::Node ready for serialization.
ParticleAffector(Ogre::ParticleAffector *InternalAffector, ParticleSystemProxy *Creator)
Internal Class constructor.
Child node iterator (a bidirectional iterator over a collection of Node)
Definition: nodeiterator.h:77
A light-weight handle for manipulating nodes in DOM tree.
Definition: node.h:89
iterator begin() const
Get a Child node iterator that references the first child Node.
int AsInt(int def=0) const
Attempts to convert the value of the attribute to an int and returns the results. ...
iterator end() const
Get a Child node iterator that references one past the last child Node.
bool Empty() const
Is this storing anything at all?
virtual void ProtoDeSerializeCustomParameters(const XML::Node &SelfRoot)
Take the data stored in an XML Node and overwrite the custom altered parameters of this object with i...
virtual void ProtoSerializeCustomParameters(XML::Node &SelfRoot) const
Convert the custom altered parameters of this class to an XML::Node ready for serialization.
virtual String GetDerivedSerializableName() const
Gets the most derived serializable name of this WorldProxy.
NameValuePairMap CustomAffectorParameters
A cache containing all of the custom altered parameters of this particle affector.
virtual ~ParticleAffector()
Class destructor.
void SetCustomParam(const String &Name, const String &Value)
Sets a custom parameter of a particle affector.
This is the proxy class for placing and manipulating particles in the scene.
The bulk of the engine components go in this namspace.
Definition: actor.cpp:56
virtual Ogre::ParticleAffector * _GetGraphicsAffector() const
Accessor for the internal particle affector.
void SerializeError(const String &FailedTo, const String &ClassName, Boole SOrD)
Simply does some string concatenation, then throws an Exception.
Node AppendChild(NodeType Type=NodeElement)
Creates a Node and makes it a child of this one.
std::string String
A datatype used to a series of characters.
Definition: datatypes.h:159
Attribute GetAttribute(const Char8 *Name) const
Attempt to get an Attribute on this Node with a given name.
Node GetChild(const Char8 *Name) const
Attempt to get a child Node with a given name.