-
-
Notifications
You must be signed in to change notification settings - Fork 113
/
Copy pathsunlight_info.cpp
73 lines (65 loc) · 1.77 KB
/
sunlight_info.cpp
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
#include "stdafx.h"
#include "sunlight_info.h"
#include "t_string.h"
TStringId SunlightInfo::getText() const {
return getText(state);
}
TStringId SunlightInfo::getText(SunlightState state) {
switch (state) {
case SunlightState::NIGHT: return TStringId("NIGHT");
case SunlightState::DAY: return TStringId("DAY");
}
}
const auto dayLength = 1500_visible;
const auto nightLength = 1500_visible;
const auto duskLength = 180_visible;
void SunlightInfo::update(GlobalTime currentTime) {
GlobalTime d;
while (1) {
d += dayLength;
if (d > currentTime) {
lightAmount = 1;
timeRemaining = d - currentTime;
state = SunlightState::DAY;
break;
}
d += duskLength;
if (d > currentTime) {
lightAmount = (d - currentTime).getDouble() / duskLength.getDouble();
timeRemaining = d + nightLength - duskLength - currentTime;
state = SunlightState::NIGHT;
break;
}
d += nightLength - duskLength * 2;
if (d > currentTime) {
lightAmount = 0;
timeRemaining = d + duskLength - currentTime;
state = SunlightState::NIGHT;
break;
}
d += duskLength;
if (d > currentTime) {
lightAmount = 1 - (d - currentTime).getDouble() / duskLength.getDouble();
timeRemaining = d - currentTime;
state = SunlightState::NIGHT;
break;
}
}
}
SunlightState SunlightInfo::getState() const {
return state;
}
double SunlightInfo::getLightAmount() const {
return lightAmount;
}
TimeInterval SunlightInfo::getTimeRemaining() const {
return timeRemaining;
}
TimeInterval SunlightInfo::getTimeSinceDawn() const {
switch (state) {
case SunlightState::DAY:
return dayLength - timeRemaining;
case SunlightState::NIGHT:
return dayLength + nightLength - timeRemaining;
}
}