DayZ 1.30
DayZ Explorer by KGB
 
Загрузка...
Поиск...
Не найдено
WorldTimeTracker.c
См. документацию.
2{
3 private const float POLL_INTERVAL = 10.0;
4
5 // Last sampled total minutes from calendar
6 protected int m_LastTotalMinutes = -1;
7 protected float m_PollAccumulated = 0.0;
8
9 bool TryPollDelta(float timeSlice, out int outDeltaMinutes)
10 {
11 outDeltaMinutes = 0;
12
13 m_PollAccumulated += timeSlice;
15 return false;
16
18
19 int year, month, day, hour, minute;
20 g_Game.GetWorld().GetDate(year, month, day, hour, minute);
21 int total = ToTotalMinutes(year, month, day, hour, minute);
22
23 if (m_LastTotalMinutes >= 0)
24 {
25 int delta = total - m_LastTotalMinutes;
26 if (delta < 0)
27 delta = 0;
28
29 outDeltaMinutes = delta;
30 }
31
32 m_LastTotalMinutes = total;
33
34 return true;
35 }
36
37 // Convert calendar to monotonically increasing minutes.
38 // Handles varying month lengths and leap years in a simple Gregorian manner
39 protected int ToTotalMinutes(int year, int month, int day, int hour, int minute)
40 {
41 int days = DaysSinceYearZero(year) + DaysBeforeMonthInYear(year, month) + (day - 1);
42 return days * 24 * 60 + hour * 60 + minute;
43 }
44
45 protected int DaysSinceYearZero(int year)
46 {
47 // Count days from year 0 to the start of 'year'
48 // Gregorian leap year rules: leap if divisible by 4, not by 100 unless divisible by 400
49 int y = year; // assuming year >= 0
50 int leapDays = y / 4 - y / 100 + y / 400;
51 return y * 365 + leapDays;
52 }
53
54 protected bool IsLeapYear(int year)
55 {
56 return ((year % 4) == 0 && (year % 100) != 0) || ((year % 400) == 0);
57 }
58
59 protected int DaysBeforeMonthInYear(int year, int month)
60 {
61 static const int daysInMonthNormal[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
62 static const int daysInMonthLeap[12] = {31,29,31,30,31,30,31,31,30,31,30,31};
63
64 int days = 0;
65 int i = 0;
66 if (IsLeapYear(year))
67 {
68 for (i = 0; i < month - 1; ++i)
69 days += daysInMonthLeap[i];
70 }
71 else
72 {
73 for (i = 0; i < month - 1; ++i)
74 days += daysInMonthNormal[i];
75 }
76
77 return days;
78 }
79}
DayZGame g_Game
Определения DayZGame.c:4074
Icon y
const float POLL_INTERVAL
Определения WorldTimeTracker.c:3
int m_LastTotalMinutes
Определения WorldTimeTracker.c:6
int DaysBeforeMonthInYear(int year, int month)
Определения WorldTimeTracker.c:59
bool TryPollDelta(float timeSlice, out int outDeltaMinutes)
Определения WorldTimeTracker.c:9
int DaysSinceYearZero(int year)
Определения WorldTimeTracker.c:45
float m_PollAccumulated
Определения WorldTimeTracker.c:7
int ToTotalMinutes(int year, int month, int day, int hour, int minute)
Определения WorldTimeTracker.c:39
bool IsLeapYear(int year)
Определения WorldTimeTracker.c:54