-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprinter.hpp
61 lines (53 loc) · 1.38 KB
/
printer.hpp
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
#pragma once
#include "base.hpp"
class Printer : public Outer {
private:
Timer* timer;
int not_clear;
public:
LL clk;
Printer(LL clk, int _not_clear, int _debug = 0) : not_clear(_not_clear), Outer(_debug) {
timer = new Timer(clk);
timer->slp(debug ? 3 : 1);
printf(not_clear ? "\n" : "\x1b[256F\x1b[0J");
fflush(stdout);
timer->bg();
}
inline void print_a_frame(char* buffer, int print_size) {
printf(not_clear ? "\n" : "\x1b[256F");
fwrite(buffer, 1, print_size, stdout);
fflush(stdout);
timer->wait();
}
};
class Preloader : public Outer {
private:
FILE* fp;
inline void pt(int c) {
fputc(c, fp);
}
void w(int x) {
if (x >= 10) w(x / 10);
pt(x % 10 + '0');
}
public:
Preloader(std::string output, int x, int y, int clk, int _debug = 0) : Outer(_debug) {
fp = fopen(output.c_str(), "w");
if (!fp) {
throws("Open output file failed.");
return;
}
w(x);
pt(32);
w(y >> 1);
pt(32);
w(clk);
// pt(32);
// pt(10);
pt(10);
}
inline void print_a_frame(char* buffer, int print_size) {
fwrite(buffer, 1, print_size + 1, fp);
}
inline void cls() { fclose(fp); }
};