@@ -22,47 +22,51 @@ with this program; if not, write to the Free Software Foundation, Inc.,
22
22
inline u32 time_to_daynight_ratio (float time_of_day , bool smooth )
23
23
{
24
24
float t = time_of_day ;
25
- if (t < 0 )
26
- t += ((int )(- t )/24000 )* 24000 ;
27
- if (t >= 24000 )
28
- t -= ((int )(t )/24000 )* 24000 ;
29
- if (t > 12000 )
30
- t = 24000 - t ;
31
- float values [][2 ] = {
32
- {4250 + 125 , 150 },
33
- {4500 + 125 , 150 },
34
- {4750 + 125 , 250 },
35
- {5000 + 125 , 350 },
36
- {5250 + 125 , 500 },
37
- {5500 + 125 , 675 },
38
- {5750 + 125 , 875 },
39
- {6000 + 125 , 1000 },
40
- {6250 + 125 , 1000 },
25
+ if (t < 0.0f )
26
+ t += ((int )(- t ) / 24000 ) * 24000.0f ;
27
+ if (t >= 24000.0f )
28
+ t -= ((int )(t ) / 24000 ) * 24000.0f ;
29
+ if (t > 12000.0f )
30
+ t = 24000.0f - t ;
31
+
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 },
41
42
};
42
- if (!smooth ){
43
+
44
+ if (!smooth ) {
43
45
float lastt = values [0 ][0 ];
44
- for (u32 i = 1 ; i < sizeof ( values )/ sizeof ( * values ) ; i ++ ){
46
+ for (u32 i = 1 ; i < 9 ; i ++ ) {
45
47
float t0 = values [i ][0 ];
46
- float switch_t = (t0 + lastt ) / 2 ;
48
+ float switch_t = (t0 + lastt ) / 2.0f ;
47
49
lastt = t0 ;
48
- if (switch_t <= t )
50
+ if (switch_t <= t )
49
51
continue ;
52
+
50
53
return values [i ][1 ];
51
54
}
52
55
return 1000 ;
53
56
}
54
57
55
- if (t <= 4625 ) // 4500 + 125
58
+ if (t <= 4625.0f ) // 4500 + 125
56
59
return values [0 ][1 ];
57
- else if (t >= 6125 ) // 6000 + 125
60
+ else if (t >= 6125.0f ) // 6000 + 125
58
61
return 1000 ;
59
- for (u32 i = 0 ; i < sizeof (values ) / sizeof (* values ); i ++ ) {
60
- if (values [i ][0 ] <= t )
61
- continue ;
62
62
63
- float td0 = values [i ][0 ] - values [i - 1 ][0 ];
64
- float f = (t - values [i - 1 ][0 ]) / td0 ;
65
- return f * values [i ][1 ] + (1.0 - f ) * values [i - 1 ][1 ];
66
- }
67
- return 1000 ;
63
+ for (u32 i = 0 ; i < 9 ; i ++ ) {
64
+ if (values [i ][0 ] <= t )
65
+ continue ;
66
+
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 ];
70
+ }
71
+ return 1000 ;
68
72
}
0 commit comments