diff options
author | Andrei Karas <akaras@inbox.ru> | 2015-12-31 21:40:07 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2015-12-31 21:40:07 +0300 |
commit | a1b0ccfbb80cf2e0dc80a52971a0f50261b8b7d6 (patch) | |
tree | fa91fbd708dfce9baef9b33bd60455c7756dd55b | |
parent | 627e8fbd919f346e4e45ef192b516faf8b11d4ac (diff) | |
download | manaverse-a1b0ccfbb80cf2e0dc80a52971a0f50261b8b7d6.tar.gz manaverse-a1b0ccfbb80cf2e0dc80a52971a0f50261b8b7d6.tar.bz2 manaverse-a1b0ccfbb80cf2e0dc80a52971a0f50261b8b7d6.tar.xz manaverse-a1b0ccfbb80cf2e0dc80a52971a0f50261b8b7d6.zip |
Move particlechangefunc into enums directory.
-rw-r--r-- | src/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/Makefile.am | 1 | ||||
-rw-r--r-- | src/enums/particle/particlechangefunc.h | 38 | ||||
-rw-r--r-- | src/particle/particleemitter.cpp | 20 | ||||
-rw-r--r-- | src/particle/particleemitterprop.h | 42 |
5 files changed, 74 insertions, 28 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 04eca3c0e..6ba5429fa 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1067,6 +1067,7 @@ SET(SRCS render/rendererslistsdl.h render/rendererslistsdl2.h enums/particle/alivestatus.h + enums/particle/particlechangefunc.h enums/render/rendertype.h particle/particle.cpp particle/particle.h diff --git a/src/Makefile.am b/src/Makefile.am index 050713de4..d2ce140a5 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -564,6 +564,7 @@ SRC += events/actionevent.h \ render/rendererslistsdl.h \ render/rendererslistsdl2.h \ enums/particle/alivestatus.h \ + enums/particle/particlechangefunc.h \ enums/render/blitmode.h \ enums/render/rendertype.h \ being/playerignorestrategy.h \ diff --git a/src/enums/particle/particlechangefunc.h b/src/enums/particle/particlechangefunc.h new file mode 100644 index 000000000..fba22245c --- /dev/null +++ b/src/enums/particle/particlechangefunc.h @@ -0,0 +1,38 @@ +/* + * The ManaPlus Client + * Copyright (C) 2006-2009 The Mana World Development Team + * Copyright (C) 2009-2010 The Mana Developers + * Copyright (C) 2011-2015 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef ENUMS_PARTICLE_PARTICLECHANGEFUNC_H +#define ENUMS_PARTICLE_PARTICLECHANGEFUNC_H + +#include "enums/simpletypes/enumdefines.h" + +enumStart(ParticleChangeFunc) +{ + FUNC_NONE = 0, + FUNC_SINE, + FUNC_SAW, + FUNC_TRIANGLE, + FUNC_SQUARE +} +enumEnd(ParticleChangeFunc); + +#endif // ENUMS_PARTICLE_PARTICLECHANGEFUNC_H diff --git a/src/particle/particleemitter.cpp b/src/particle/particleemitter.cpp index b8ae200ce..855c62fa1 100644 --- a/src/particle/particleemitter.cpp +++ b/src/particle/particleemitter.cpp @@ -473,13 +473,25 @@ ParticleEmitter::readParticleEmitterProp(XmlNodePtrConst propertyNode, T def) const int period = XML::getProperty(propertyNode, "change-period", 0); const int phase = XML::getProperty(propertyNode, "change-phase", 0); if (change == "saw" || change == "sawtooth") - retval.setFunction(FUNC_SAW, amplitude, period, phase); + { + retval.setFunction(ParticleChangeFunc::FUNC_SAW, + amplitude, period, phase); + } else if (change == "sine" || change == "sinewave") - retval.setFunction(FUNC_SINE, amplitude, period, phase); + { + retval.setFunction(ParticleChangeFunc::FUNC_SINE, + amplitude, period, phase); + } else if (change == "triangle") - retval.setFunction(FUNC_TRIANGLE, amplitude, period, phase); + { + retval.setFunction(ParticleChangeFunc::FUNC_TRIANGLE, + amplitude, period, phase); + } else if (change == "square") - retval.setFunction(FUNC_SQUARE, amplitude, period, phase); + { + retval.setFunction(ParticleChangeFunc::FUNC_SQUARE, + amplitude, period, phase); + } return retval; } diff --git a/src/particle/particleemitterprop.h b/src/particle/particleemitterprop.h index 8e0716f2e..ecbaa3aec 100644 --- a/src/particle/particleemitterprop.h +++ b/src/particle/particleemitterprop.h @@ -25,27 +25,19 @@ #include <cmath> -#include "localconsts.h" - -/** - * Returns a random numeric value that is larger than or equal min and smaller - * than max - */ +#include "enums/particle/particlechangefunc.h" -enum ChangeFunc -{ - FUNC_NONE = 0, - FUNC_SINE, - FUNC_SAW, - FUNC_TRIANGLE, - FUNC_SQUARE -}; +#include "localconsts.h" template <typename T> struct ParticleEmitterProp final { ParticleEmitterProp() : - minVal(0), maxVal(0), changeFunc(FUNC_NONE), - changeAmplitude(0), changePeriod(0), changePhase(0) + minVal(0), + maxVal(0), + changeFunc(ParticleChangeFunc::FUNC_NONE), + changeAmplitude(0), + changePeriod(0), + changePhase(0) { } @@ -60,8 +52,10 @@ template <typename T> struct ParticleEmitterProp final set(val, val); } - void setFunction(ChangeFunc func, T amplitude, - const int period, const int phase) + void setFunction(ParticleChangeFuncT func, + T amplitude, + const int period, + const int phase) { changeFunc = func; changeAmplitude = amplitude; @@ -79,17 +73,17 @@ template <typename T> struct ParticleEmitterProp final switch (changeFunc) { - case FUNC_SINE: + case ParticleChangeFunc::FUNC_SINE: val += static_cast<T>(std::sin(M_PI * 2 * (static_cast<double>( tick % changePeriod) / static_cast<double>( changePeriod)))) * changeAmplitude; break; - case FUNC_SAW: + case ParticleChangeFunc::FUNC_SAW: val += static_cast<T>(changeAmplitude * (static_cast<double>( tick % changePeriod) / static_cast<double>( changePeriod))) * 2 - changeAmplitude; break; - case FUNC_TRIANGLE: + case ParticleChangeFunc::FUNC_TRIANGLE: if ((tick % changePeriod) * 2 < changePeriod) { val += changeAmplitude - static_cast<T>(( @@ -104,13 +98,13 @@ template <typename T> struct ParticleEmitterProp final // I have no idea why this works but it does } break; - case FUNC_SQUARE: + case ParticleChangeFunc::FUNC_SQUARE: if ((tick % changePeriod) * 2 < changePeriod) val += changeAmplitude; else val -= changeAmplitude; break; - case FUNC_NONE: + case ParticleChangeFunc::FUNC_NONE: default: // nothing break; @@ -122,7 +116,7 @@ template <typename T> struct ParticleEmitterProp final T minVal; T maxVal; - ChangeFunc changeFunc; + ParticleChangeFuncT changeFunc; T changeAmplitude; int changePeriod; int changePhase; |