2012-03-16 07:34:30 -07:00
|
|
|
/*
|
2013-02-24 09:40:43 -08:00
|
|
|
Minetest
|
2013-02-24 10:38:45 -08:00
|
|
|
Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
|
2012-03-16 07:34:30 -07:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
2012-06-05 07:56:56 -07:00
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
2020-08-28 09:27:49 -07:00
|
|
|
the Free Software Foundation; either version 3.0 of the License, or
|
2012-03-16 07:34:30 -07:00
|
|
|
(at your option) 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
|
2012-06-05 07:56:56 -07:00
|
|
|
GNU Lesser General Public License for more details.
|
2012-03-16 07:34:30 -07:00
|
|
|
|
2012-06-05 07:56:56 -07:00
|
|
|
You should have received a copy of the GNU Lesser General Public License along
|
2012-03-16 07:34:30 -07:00
|
|
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
2017-08-17 13:19:39 -07:00
|
|
|
#pragma once
|
2012-03-16 07:34:30 -07:00
|
|
|
|
2012-12-02 08:02:04 -08:00
|
|
|
inline u32 time_to_daynight_ratio(float time_of_day, bool smooth)
|
2012-03-16 07:34:30 -07:00
|
|
|
{
|
2012-12-02 08:02:04 -08:00
|
|
|
float t = time_of_day;
|
2019-04-07 16:37:52 -07:00
|
|
|
if (t < 0.0f)
|
|
|
|
t += ((int)(-t) / 24000) * 24000.0f;
|
|
|
|
if (t >= 24000.0f)
|
|
|
|
t -= ((int)(t) / 24000) * 24000.0f;
|
|
|
|
if (t > 12000.0f)
|
|
|
|
t = 24000.0f - t;
|
|
|
|
|
|
|
|
const float values[9][2] = {
|
2019-10-18 13:54:44 -07:00
|
|
|
{4250.0f + 125.0f, 175.0f},
|
|
|
|
{4500.0f + 125.0f, 175.0f},
|
2019-04-07 16:37:52 -07:00
|
|
|
{4750.0f + 125.0f, 250.0f},
|
|
|
|
{5000.0f + 125.0f, 350.0f},
|
|
|
|
{5250.0f + 125.0f, 500.0f},
|
|
|
|
{5500.0f + 125.0f, 675.0f},
|
|
|
|
{5750.0f + 125.0f, 875.0f},
|
|
|
|
{6000.0f + 125.0f, 1000.0f},
|
|
|
|
{6250.0f + 125.0f, 1000.0f},
|
2012-12-02 08:02:04 -08:00
|
|
|
};
|
2019-04-07 16:37:52 -07:00
|
|
|
|
|
|
|
if (!smooth) {
|
2012-12-02 08:02:04 -08:00
|
|
|
float lastt = values[0][0];
|
2019-04-07 16:37:52 -07:00
|
|
|
for (u32 i = 1; i < 9; i++) {
|
2012-12-02 08:02:04 -08:00
|
|
|
float t0 = values[i][0];
|
2019-04-07 16:37:52 -07:00
|
|
|
float switch_t = (t0 + lastt) / 2.0f;
|
2012-12-02 08:02:04 -08:00
|
|
|
lastt = t0;
|
2019-04-07 16:37:52 -07:00
|
|
|
if (switch_t <= t)
|
2012-12-02 08:02:04 -08:00
|
|
|
continue;
|
2019-04-07 16:37:52 -07:00
|
|
|
|
2012-12-02 08:02:04 -08:00
|
|
|
return values[i][1];
|
|
|
|
}
|
2012-03-16 07:34:30 -07:00
|
|
|
return 1000;
|
2017-08-17 14:02:50 -07:00
|
|
|
}
|
|
|
|
|
2019-04-07 16:37:52 -07:00
|
|
|
if (t <= 4625.0f) // 4500 + 125
|
2019-04-04 15:30:10 -07:00
|
|
|
return values[0][1];
|
2019-04-07 16:37:52 -07:00
|
|
|
else if (t >= 6125.0f) // 6000 + 125
|
2019-04-04 15:30:10 -07:00
|
|
|
return 1000;
|
|
|
|
|
2019-04-07 16:37:52 -07:00
|
|
|
for (u32 i = 0; i < 9; i++) {
|
|
|
|
if (values[i][0] <= t)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
float td0 = values[i][0] - values[i - 1][0];
|
|
|
|
float f = (t - values[i - 1][0]) / td0;
|
|
|
|
return f * values[i][1] + (1.0f - f) * values[i - 1][1];
|
|
|
|
}
|
|
|
|
return 1000;
|
2012-03-16 07:34:30 -07:00
|
|
|
}
|