-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
74 lines (59 loc) · 1.32 KB
/
main.cpp
File metadata and controls
74 lines (59 loc) · 1.32 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
71
72
73
74
#include<iostream>
#include <steam/steamnetworkingsockets.h>
#include <steam/isteamnetworkingutils.h>
#include"UserInput.cpp"
#include <future>
std::mutex mutexUserInputQueue;
std::queue< std::string > queueUserInput;
std::thread *s_pThreadUserInput = nullptr;
SteamNetworkingMicroseconds g_logTimeZero;
bool av = true;
void LocalUserInput_Init()
{
s_pThreadUserInput = new std::thread( []()
{
while ( av )
{
char szLine[ 4000 ];
if ( !fgets( szLine, sizeof(szLine), stdin ) )
{
if ( av )
return;
av = false;
break;
}
mutexUserInputQueue.lock();
queueUserInput.push( std::string( szLine ) );
mutexUserInputQueue.unlock();
}
} );
}
bool LocalUserInput_GetNext( std::string &result )
{
bool got_input = false;
mutexUserInputQueue.lock();
while ( !queueUserInput.empty() && !got_input )
{
result = queueUserInput.front();
queueUserInput.pop();
got_input = !result.empty();
}
mutexUserInputQueue.unlock();
return got_input;
}
int main()
{
bool *active = &av;
std::string cmd;
LocalUserInput_Init();
while(*active)
{
while ( *active && LocalUserInput_GetNext( cmd ))
{
std::cout << "me: "<< cmd;
}
std::this_thread::sleep_for(std::chrono::milliseconds(10));
}
std::cout << "Bye Bye World" << std::endl;
return 0;
}