-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.cpp
94 lines (75 loc) · 2.3 KB
/
main.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// Standard Includes
#include <iostream>
#include <string>
#include <thread>
#include <vector>
#include <mutex>
// 3rd Party / Library Includes
#include <osvr/ClientKit/ClientKit.h>
#include <osvr/Common/ClientContext.h>
#include <osvr/Common/PathNode.h>
#include <osvr/Common/PathTreeFull.h>
#include <osvr/Common/ApplyPathNodeVisitor.h>
#include <osvr/ClientKit/Interface.h>
#include <osvr/Util/TreeTraversalVisitor.h>
#include <QtWidgets/QApplication>
// 1st Party Includes
#include "osvr_controller_viewer.h"
#include "path_tree_iterator.h"
#include "interface_element.h"
static std::mutex value_lock;
static std::vector<interface_element> interface_values;
OSVR_Controller_Viewer* w;
const char* app_id = "OSVR_Controller_Viewer";
osvr::clientkit::ClientContext ctx(app_id, 0);
std::mutex ctx_lock;
osvr::common::PathTree osvr_path_tree;
osvr::clientkit::Interface* current_interface = nullptr;
bool thread_close = false;
bool connected = false;
void update_path_values() {
std::vector<std::pair<std::string, bool>> temp_button_values;
osvr::common::clonePathTree(ctx.get()->getPathTree(), osvr_path_tree);
path_tree_iterator p_tree_iter;
osvr::util::traverseWith(osvr_path_tree.getRoot(),
[&p_tree_iter](osvr::common::PathNode &node) {
osvr::common::applyPathNodeVisitor(p_tree_iter, node);
});
value_lock.lock();
interface_values = p_tree_iter.interfaces;
value_lock.unlock();
}
void init_context() {
if (!ctx.checkStatus()) {
do {
std::this_thread::sleep_for(std::chrono::milliseconds(200));
ctx.update();
} while (!ctx.checkStatus());
}
}
void osvr_connect() {
while (!thread_close) {
ctx_lock.lock();
if (!ctx.checkStatus()) {
init_context();
}
ctx.update();
update_path_values();
ctx_lock.unlock();
std::this_thread::sleep_for(std::chrono::milliseconds(10));
}
}
int main(int argc, char *argv[])
{
std::thread osvr_connection_thread = std::thread(osvr_connect);
QApplication a(argc, argv);
w = new OSVR_Controller_Viewer();
Ui_OSVR_Controller_ViewerClass* ui = w->get_Ui();
ui->pathTree->set_path_ptr(&interface_values, &value_lock);
w->set_osvr_ctx_ptr(&ctx, &ctx_lock);
w->show();
int exec_res = a.exec();
thread_close = true;
osvr_connection_thread.join();
return exec_res;
}