3 Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 inline u32 time_to_daynight_ratio(float time_of_day, bool smooth)
24 float t = time_of_day;
26 t += ((int)(-t) / 24000) * 24000.0f;
28 t -= ((int)(t) / 24000) * 24000.0f;
32 const float values[9][2] = {
33 {4250.0f + 125.0f, 150.0f},
34 {4500.0f + 125.0f, 150.0f},
35 {4750.0f + 125.0f, 250.0f},
36 {5000.0f + 125.0f, 350.0f},
37 {5250.0f + 125.0f, 500.0f},
38 {5500.0f + 125.0f, 675.0f},
39 {5750.0f + 125.0f, 875.0f},
40 {6000.0f + 125.0f, 1000.0f},
41 {6250.0f + 125.0f, 1000.0f},
45 float lastt = values[0][0];
46 for (u32 i = 1; i < 9; i++) {
47 float t0 = values[i][0];
48 float switch_t = (t0 + lastt) / 2.0f;
58 if (t <= 4625.0f) // 4500 + 125
60 else if (t >= 6125.0f) // 6000 + 125
63 for (u32 i = 0; i < 9; i++) {
64 if (values[i][0] <= t)
67 float td0 = values[i][0] - values[i - 1][0];
68 float f = (t - values[i - 1][0]) / td0;
69 return f * values[i][1] + (1.0f - f) * values[i - 1][1];