2012-03-16 15:34:30 +01:00
|
|
|
/*
|
2013-02-24 18:40:43 +01:00
|
|
|
Minetest
|
2013-02-24 19:38:45 +01:00
|
|
|
Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
|
2012-03-16 15:34:30 +01:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
2012-06-05 16:56:56 +02:00
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2.1 of the License, or
|
2012-03-16 15:34:30 +01: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 16:56:56 +02:00
|
|
|
GNU Lesser General Public License for more details.
|
2012-03-16 15:34:30 +01:00
|
|
|
|
2012-06-05 16:56:56 +02:00
|
|
|
You should have received a copy of the GNU Lesser General Public License along
|
2012-03-16 15:34:30 +01: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 22:19:39 +02:00
|
|
|
#pragma once
|
2012-03-16 15:34:30 +01:00
|
|
|
|
2012-12-02 17:02:04 +01:00
|
|
|
inline u32 time_to_daynight_ratio(float time_of_day, bool smooth)
|
2012-03-16 15:34:30 +01:00
|
|
|
{
|
2012-12-02 17:02:04 +01:00
|
|
|
float t = time_of_day;
|
2019-04-08 01:37:52 +02: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 22:54:44 +02:00
|
|
|
{4250.0f + 125.0f, 175.0f},
|
|
|
|
{4500.0f + 125.0f, 175.0f},
|
2019-04-08 01:37:52 +02: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 17:02:04 +01:00
|
|
|
};
|
2019-04-08 01:37:52 +02:00
|
|
|
|
|
|
|
if (!smooth) {
|
2012-12-02 17:02:04 +01:00
|
|
|
float lastt = values[0][0];
|
2019-04-08 01:37:52 +02:00
|
|
|
for (u32 i = 1; i < 9; i++) {
|
2012-12-02 17:02:04 +01:00
|
|
|
float t0 = values[i][0];
|
2019-04-08 01:37:52 +02:00
|
|
|
float switch_t = (t0 + lastt) / 2.0f;
|
2012-12-02 17:02:04 +01:00
|
|
|
lastt = t0;
|
2019-04-08 01:37:52 +02:00
|
|
|
if (switch_t <= t)
|
2012-12-02 17:02:04 +01:00
|
|
|
continue;
|
2019-04-08 01:37:52 +02:00
|
|
|
|
2012-12-02 17:02:04 +01:00
|
|
|
return values[i][1];
|
|
|
|
}
|
2012-03-16 15:34:30 +01:00
|
|
|
return 1000;
|
2017-08-17 23:02:50 +02:00
|
|
|
}
|
|
|
|
|
2019-04-08 01:37:52 +02:00
|
|
|
if (t <= 4625.0f) // 4500 + 125
|
2019-04-05 00:30:10 +02:00
|
|
|
return values[0][1];
|
2019-04-08 01:37:52 +02:00
|
|
|
else if (t >= 6125.0f) // 6000 + 125
|
2019-04-05 00:30:10 +02:00
|
|
|
return 1000;
|
|
|
|
|
2019-04-08 01:37:52 +02: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 15:34:30 +01:00
|
|
|
}
|