Otclient  14/8/2020
particletype.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010-2020 OTClient <https://github.com/edubart/otclient>
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to deal
6  * in the Software without restriction, including without limitation the rights
7  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8  * copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20  * THE SOFTWARE.
21  */
22 
23 #include "particletype.h"
25 
27 {
28  // particles default configuration. (make them reasonable for user detect missing properties on scripts)
32  pMaxPositionAngle = 360;
33  pStartSize = Size(32, 32);
34  pFinalSize = Size(32, 32);
35  pMinDuration = 0;
36  pMaxDuration = 10;
38  pMinVelocity = 32;
39  pMaxVelocity = 64;
41  pMaxVelocityAngle = 360;
42  pMinAcceleration = 32;
43  pMaxAcceleration = 64;
46 }
47 
49 {
50  for(const OTMLNodePtr& childNode : node->children()) {
51  if(childNode->tag() == "name")
52  pName = childNode->value();
53  else if(childNode->tag() == "position-radius") {
54  pMinPositionRadius = childNode->value<float>();
55  pMaxPositionRadius = childNode->value<float>();
56  }
57  else if(childNode->tag() == "min-position-radius")
58  pMinPositionRadius = childNode->value<float>();
59  else if(childNode->tag() == "max-position-radius")
60  pMaxPositionRadius = childNode->value<float>();
61  else if(childNode->tag() == "position-angle") {
62  pMinPositionAngle = childNode->value<float>() * DEG_TO_RAD;
63  pMaxPositionAngle = childNode->value<float>() * DEG_TO_RAD;
64  }
65  else if(childNode->tag() == "min-position-angle")
66  pMinPositionAngle = childNode->value<float>() * DEG_TO_RAD;
67  else if(childNode->tag() == "max-position-angle")
68  pMaxPositionAngle = childNode->value<float>() * DEG_TO_RAD;
69 
70  // velocity
71  else if(childNode->tag() == "velocity") {
72  pMinVelocity = childNode->value<float>();
73  pMaxVelocity = childNode->value<float>();
74  }
75  else if(childNode->tag() == "min-velocity")
76  pMinVelocity = childNode->value<float>();
77  else if(childNode->tag() == "max-velocity")
78  pMaxVelocity = childNode->value<float>();
79  else if(childNode->tag() == "velocity-angle") {
80  pMinVelocityAngle = childNode->value<float>() * DEG_TO_RAD;
81  pMaxVelocityAngle = childNode->value<float>() * DEG_TO_RAD;
82  }
83  else if(childNode->tag() == "min-velocity-angle")
84  pMinVelocityAngle = childNode->value<float>() * DEG_TO_RAD;
85  else if(childNode->tag() == "max-velocity-angle")
86  pMaxVelocityAngle = childNode->value<float>() * DEG_TO_RAD;
87  else if(childNode->tag() == "acceleration") {
88  pMinAcceleration = childNode->value<float>();
89  pMaxAcceleration = childNode->value<float>();
90  }
91 
92  // acceleration
93  else if(childNode->tag() == "min-acceleration")
94  pMinAcceleration = childNode->value<float>();
95  else if(childNode->tag() == "max-acceleration")
96  pMaxAcceleration = childNode->value<float>();
97  else if(childNode->tag() == "acceleration-angle") {
98  pMinAccelerationAngle = childNode->value<float>() * DEG_TO_RAD;
99  pMaxAccelerationAngle = childNode->value<float>() * DEG_TO_RAD;
100  }
101  else if(childNode->tag() == "min-acceleration-angle")
102  pMinAccelerationAngle = childNode->value<float>() * DEG_TO_RAD;
103  else if(childNode->tag() == "max-acceleration-angle")
104  pMaxAccelerationAngle = childNode->value<float>() * DEG_TO_RAD;
105 
106  // duration
107  else if(childNode->tag() == "duration") {
108  pMinDuration = childNode->value<float>();
109  pMaxDuration = childNode->value<float>();
110  }
111  else if(childNode->tag() == "min-duration")
112  pMinDuration = childNode->value<float>();
113  else if(childNode->tag() == "max-duration")
114  pMaxDuration = childNode->value<float>();
115  else if(childNode->tag() == "ignore-physics-after")
116  pIgnorePhysicsAfter = childNode->value<float>();
117 
118  // visual
119  else if(childNode->tag() == "size") {
120  pStartSize = childNode->value<Size>();
121  pFinalSize = childNode->value<Size>();
122  }
123  else if(childNode->tag() == "start-size")
124  pStartSize = childNode->value<Size>();
125  else if(childNode->tag() == "final-size")
126  pFinalSize = childNode->value<Size>();
127 
128  else if(childNode->tag() == "colors")
129  pColors = stdext::split<Color>(childNode->value());
130  else if(childNode->tag() == "colors-stops")
131  pColorsStops = stdext::split<float>(childNode->value());
132  else if(childNode->tag() == "texture")
133  pTexture = g_textures.getTexture(childNode->value());
134  else if(childNode->tag() == "composition-mode") {
135  if(childNode->value() == "normal")
137  else if(childNode->value() == "multiply")
139  else if(childNode->value() == "addition")
141  }
142  }
143 
144  if(pColors.empty())
145  pColors.emplace_back(255, 255, 255, 128);
146  if(pColorsStops.empty())
147  pColorsStops.push_back(0);
148 
149  if(pColors.size() != pColorsStops.size())
150  stdext::throw_exception("particle colors must be equal to colorstops-1");
151 
152  pTexture->setSmooth(true);
154 }
ParticleType::pMaxVelocity
float pMaxVelocity
Definition: particletype.h:52
ParticleType::pStartSize
Size pStartSize
Definition: particletype.h:45
ParticleType::pTexture
TexturePtr pTexture
Definition: particletype.h:65
ParticleType::pMinDuration
float pMinDuration
Definition: particletype.h:60
Painter::CompositionMode_Normal
@ CompositionMode_Normal
Definition: painter.h:39
Painter::CompositionMode_Add
@ CompositionMode_Add
Definition: painter.h:41
ParticleType::pMaxDuration
float pMaxDuration
Definition: particletype.h:60
ParticleType::load
void load(const OTMLNodePtr &node)
Definition: particletype.cpp:48
ParticleType::pMaxVelocityAngle
float pMaxVelocityAngle
Definition: particletype.h:53
ParticleType::ParticleType
ParticleType()
Definition: particletype.cpp:26
ParticleType::pMinVelocityAngle
float pMinVelocityAngle
Definition: particletype.h:53
texturemanager.h
ParticleType::pColorsStops
std::vector< float > pColorsStops
Definition: particletype.h:64
OTMLNode::children
OTMLNodeList children()
Definition: otmlnode.cpp:170
ParticleType::pMaxAcceleration
float pMaxAcceleration
Definition: particletype.h:56
ParticleType::pColors
std::vector< Color > pColors
Definition: particletype.h:63
ParticleType::pMaxAccelerationAngle
float pMaxAccelerationAngle
Definition: particletype.h:57
ParticleType::pMinVelocity
float pMinVelocity
Definition: particletype.h:52
ParticleType::pMinPositionAngle
float pMinPositionAngle
Definition: particletype.h:49
DEG_TO_RAD
#define DEG_TO_RAD
Definition: const.h:28
ParticleType::pMinAccelerationAngle
float pMinAccelerationAngle
Definition: particletype.h:57
ParticleType::pMinAcceleration
float pMinAcceleration
Definition: particletype.h:56
ParticleType::pFinalSize
Size pFinalSize
Definition: particletype.h:45
Size
TSize< int > Size
Definition: size.h:107
particletype.h
ParticleType::pMaxPositionAngle
float pMaxPositionAngle
Definition: particletype.h:49
TextureManager::getTexture
TexturePtr getTexture(const std::string &fileName)
Definition: texturemanager.cpp:90
stdext::throw_exception
void throw_exception(const std::string &what)
Throws a generic exception.
Definition: exception.h:43
Texture::buildHardwareMipmaps
virtual bool buildHardwareMipmaps()
Definition: texture.cpp:111
ParticleType::pCompositionMode
Painter::CompositionMode pCompositionMode
Definition: particletype.h:67
ParticleType::pIgnorePhysicsAfter
float pIgnorePhysicsAfter
Definition: particletype.h:60
ParticleType::pName
std::string pName
Definition: particletype.h:42
stdext::shared_object_ptr< OTMLNode >
Texture::setSmooth
virtual void setSmooth(bool smooth)
Definition: texture.cpp:127
ParticleType::pMaxPositionRadius
float pMaxPositionRadius
Definition: particletype.h:48
Painter::CompositionMode_Multiply
@ CompositionMode_Multiply
Definition: painter.h:40
g_textures
TextureManager g_textures
Definition: texturemanager.cpp:33
TSize< int >
ParticleType::pMinPositionRadius
float pMinPositionRadius
Definition: particletype.h:48