Repository navigation
Expand file tree
/
Copy pathRealTimeModCore.cpp
More file actions
62 lines (48 loc) · 1.8 KB
/
Copy pathRealTimeModCore.cpp
File metadata and controls
62 lines (48 loc) · 1.8 KB
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
#include "UnionAfx.h"
#include "RealTimeModCore.h"
namespace GOTHIC_ENGINE {
bool RealTimeModCore::clockEnabled = true;
void RealTimeModCore::Init() {
ReadOptions();
SyncGameTimeWithSystem();
}
void RealTimeModCore::Update() {
if (!IsWorldReady()) return;
ScaleGameTimeToRealTime();
static int lastSyncMinute = -1;
int currentHour, currentMinute;
ogame->wldTimer->GetTime(currentHour, currentMinute);
if (currentMinute != lastSyncMinute && currentMinute % 5 == 0) {
SyncGameTimeWithSystem();
lastSyncMinute = currentMinute;
}
}
void RealTimeModCore::SyncGameTimeWithSystem() {
SYSTEMTIME sysTime;
GetLocalTime(&sysTime);
int minute = (sysTime.wMinute + 1) % 60;
int hour = sysTime.wHour;
if (minute == 0) {
hour = (hour + 1) % 24;
}
ogame->wldTimer->SetTime(hour, minute);
}
void RealTimeModCore::ScaleGameTimeToRealTime() {
if (!ogame || !ogame->wldTimer) return;
float frameTime = ztimer->frameTimeFloat;
float acceleration = (float)gameScaleToRealScaleApprox / 100000000.0f;
float worldTime = frameTime * (acceleration - 1.0f);
ogame->wldTimer->worldTime += worldTime;
if (clockEnabled && !ogame->game_showtime) {
ogame->game_showtime = TRUE;
}
}
void RealTimeModCore::ReadOptions() {
if (!zoptions) return;
clockEnabled = zoptions->ReadBool("RealTimeMod", "showClock", true);
}
bool RealTimeModCore::IsWorldReady() {
return ogame && ogame->GetWorld() && player && !ogame->inScriptStartup &&
!ogame->inLoadSaveGame && !ogame->inLevelChange;
}
}