-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
67 lines (54 loc) · 1.38 KB
/
main.cpp
File metadata and controls
67 lines (54 loc) · 1.38 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
#include <expected>
#include <iostream>
#include <stdbool.h>
#include <stdio.h>
#include <time.h>
#include <unistd.h>
#include <vector>
#include <SdlMedia.h>
#include <Game.h>
#include "util.h"
using tetra::Game;
using tetra::get_time_millis;
using tetra::MS_PER_SECOND;
using tetra::NS_PER_MS;
using std::cout;
using std::cerr;
using std::vector;
namespace tetra {
vector<long unsigned> get_minos_table();
}
constexpr int WINW = 480;
constexpr int WINH = 640;
void loop(Game& game) {
long previous = get_time_millis();
long lag = 0;
int error = 0;
while (!game.quit()) {
long current = get_time_millis();
lag += current - previous;
previous = current;
//todo: extract update from within readInput
game.readInput();
for (;!game.quit() && lag >= game.slice; lag -= game.slice){
//todo: this is tick
game.update();
}
error = game.render();
if (error) {
cerr << "An error ocurred rendering game. Exiting\n";
}
SDL_Delay(70);
}
}
int main() {
std::expected<Game,int> maybe_play = Game::withDimensions(WINW, WINH);
if (!maybe_play.has_value()) {
cerr << "An error ocurred :/: "<< maybe_play.error() <<"\n";
} else {
loop(*maybe_play);
}
for (auto n:tetra::get_minos_table()) {
cout << n << '\n';
}
}