3
* Copyright (C) 2006-2009 The Mana World Development Team
4
* Copyright (C) 2009-2010 The Mana Developers
5
* Copyright (C) 2011-2013 The ManaPlus Developers
7
* This file is part of The ManaPlus Client.
9
* This program is free software; you can redistribute it and/or modify
10
* it under the terms of the GNU General Public License as published by
11
* the Free Software Foundation; either version 2 of the License, or
14
* This program is distributed in the hope that it will be useful,
15
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
* GNU General Public License for more details.
19
* You should have received a copy of the GNU General Public License
20
* along with this program. If not, see <http://www.gnu.org/licenses/>.
23
#ifndef PARTICLE_PARTICLEEMITTERPROP_H
24
#define PARTICLE_PARTICLEEMITTERPROP_H
29
#include "localconsts.h"
32
* Returns a random numeric value that is larger than or equal min and smaller
45
template <typename T> struct ParticleEmitterProp final
47
ParticleEmitterProp():
48
minVal(0), maxVal(0), changeFunc(FUNC_NONE),
49
changeAmplitude(0), changePeriod(0), changePhase(0)
53
void set(const T min, const T max)
64
void setFunction(ChangeFunc func, T amplitude,
65
const int period, const int phase)
68
changeAmplitude = amplitude;
69
changePeriod = period;
75
T value(int tick) const
78
T val = static_cast<T>(minVal + (maxVal - minVal)
79
* (rand() / (static_cast<double>(RAND_MAX) + 1)));
84
val += static_cast<T>(std::sin(M_PI * 2 * (static_cast<double>(
85
tick % changePeriod) / static_cast<double>(
86
changePeriod)))) * changeAmplitude;
89
val += static_cast<T>(changeAmplitude * (static_cast<double>(
90
tick % changePeriod) / static_cast<double>(
91
changePeriod))) * 2 - changeAmplitude;
94
if ((tick % changePeriod) * 2 < changePeriod)
96
val += changeAmplitude - static_cast<T>((
97
tick % changePeriod) / static_cast<double>(
98
changePeriod)) * changeAmplitude * 4;
102
val += changeAmplitude * -3 + static_cast<T>((
103
tick % changePeriod) / static_cast<double>(
104
changePeriod)) * changeAmplitude * 4;
105
// I have no idea why this works but it does
109
if ((tick % changePeriod) * 2 < changePeriod)
110
val += changeAmplitude;
112
val -= changeAmplitude;
126
ChangeFunc changeFunc;
132
#endif // PARTICLE_PARTICLEEMITTERPROP_H