-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
44 lines (38 loc) · 807 Bytes
/
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
#include <iostream>
#include <unistd.h>
#include <thread>
#include "Game.h"
using namespace std;
//helper function, calls window update in a loop
void updateWindow(Game& game)
{
while(game.isRunning())
{
game.updateWindow();
usleep(1667); //run updates at 60hz
}
}
void handleIO(Game& game)
{
while(game.isRunning())
{
game.playSounds();
game.pollKeyboard();
usleep(1667); //run updates at 60hz
}
}
int main(int argc, char* args[])
{
//instantiate game and window update thread
Game game;
thread renderThread(updateWindow, ref(game));
thread IOThread(handleIO, ref(game));
while (game.isRunning())
{
game.runCPU();
usleep(1000);
}
renderThread.join();
IOThread.join();
return 0;
}