-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
70 lines (55 loc) · 1.83 KB
/
main.cpp
File metadata and controls
70 lines (55 loc) · 1.83 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
63
64
65
66
67
68
69
70
#include "PositionEstimation/position_estimation.h"
#include "navigation_detection.h"
#include "utils.h"
#include "AR/ar.h"
#include <thread>
int main() {
ScreenCapture* capture = new ScreenCapture(
std::bind(
utils::find_window,
std::wstring(L"Truck Simulator"),
std::vector<std::wstring>{L"Discord"}
),
CaptureMode::BackgroundThread
);
capture->initialize();
navigation_detection::initialize(capture);
std::thread ar_thread([]() {
AR ar(
std::bind(
utils::find_window,
std::wstring(L"Truck Simulator"),
std::vector<std::wstring>{L"Discord"}
)
);
while (true) {
auto start = utils::get_time_seconds();
ar.draw_wheel_trajectory({1.0f, 0.75f, 0.0f, 1.0f});
ar.run();
auto end = utils::get_time_seconds();
double elapsed = end - start;
// target 120FPS because its twice the game telemetry update rate
if (elapsed < 0.0083) {
std::this_thread::sleep_for(std::chrono::milliseconds(static_cast<int>((0.0083 - elapsed) * 1000)));
}
}
});
ar_thread.detach();
std::thread position_estimation_thread([capture]() {
PositionEstimation position_estimation(capture);
while (true) {
position_estimation.run();
}
});
position_estimation_thread.detach();
while (true) {
auto start = utils::get_time_seconds();
navigation_detection::run();
auto end = utils::get_time_seconds();
double elapsed = end - start;
if (elapsed < 0.050) {
std::this_thread::sleep_for(std::chrono::milliseconds(static_cast<int>((0.050 - elapsed) * 1000)));
}
}
return 0;
}