forked from EasyRPG/Player
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflash.h
77 lines (70 loc) · 2.09 KB
/
flash.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*
* This file is part of EasyRPG Player.
*
* EasyRPG Player 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 3 of the License, or
* (at your option) any later version.
*
* EasyRPG Player 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 EasyRPG Player. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef EP_FLASH_H
#define EP_FLASH_H
#include <cstdint>
#include "color.h"
/** Contains helper functions for flash effect */
namespace Flash {
/**
* Perform one time step of flash data animation
*
* @param current_level flash level
* @param time_left amount of flash time left
* @param continuous true if continuous flash
* @param period original flash period
* @param sat original flash saturation
*/
inline void Update(double& current_level, int32_t& time_left, bool continuous, int32_t period, int32_t sat)
{
if (current_level > 0 || continuous) {
if (time_left > 0) {
current_level = current_level - (current_level / time_left);
--time_left;
}
if (time_left <= 0) {
time_left = 0;
current_level = 0;
if (continuous) {
time_left = period;
current_level = sat;
}
}
}
}
/**
* Perform one time step of flash data animation
*
* @param current_level flash level
* @param time_left amount of flash time left
*/
inline void Update(double& current_level, int32_t& time_left) {
Update(current_level, time_left, false, 0, 0);
}
/**
* Create a Color object from RPG_RT flash values [0,31]
*
* @param r red color
* @param g green color
* @param b blue color
* @param current_level strength of flash
*/
constexpr Color MakeColor(int r, int g, int b, double current_level) {
return current_level > 0.0 ? Color(r * 8, g * 8, b * 8, current_level * 8) : Color();
}
} //namespace Flash
#endif