/
main.cpp
80 lines (67 loc) · 1.91 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
#include "misc.h"
#include "gfx.h"
#include "palette.h"
#include "input.h"
#include "plotter.h"
Gfx gfx;
Input input;
Plotter plotter;
Palette palette;
const unsigned FPS = 20;
int frame_time;
double zoom_factor = 2;
int main(int argc, char *argv[]) {
FILE* fp = fopen("config.txt", "r");
if (fp) {
int a, b;
if (fscanf(fp," cores %d", &a) == 1) plotter.n_threads = a;
if (fscanf(fp," def_res %d %d", &a, &b) == 2) {
gfx.screen_w_default = a;
gfx.screen_h_default = b;
}
if (fscanf(fp," max_iter %d", &a) == 1) plotter.max_iter = a;
}
if (SDL_Init(SDL_INIT_EVERYTHING) == -1 || !gfx.init()) return 1;
plotter.init();
plotter.resize(gfx.get_screen_w(), gfx.get_screen_h());
plotter.plot();
while (true) {
frame_time = SDL_GetTicks();
input.update();
if (input.key_pressed(SDLK_ESCAPE) || input.is_quitting())
break;
if (input.key_down( SDLK_LCTRL ) &&
input.mouse_pressed(SDL_BUTTON_LEFT)) {
plotter.center();
} else if (input.mouse_pressed(SDL_BUTTON_LEFT)) {
if (input.key_down(SDLK_LSHIFT)) {
plotter.zoom(zoom_factor * 5);
} else {
plotter.zoom(zoom_factor);
}
} else if (input.mouse_pressed(SDL_BUTTON_RIGHT)) {
if (input.key_down(SDLK_LSHIFT)) {
plotter.zoom(1/(zoom_factor * 5));
} else {
plotter.zoom(1/zoom_factor);
}
}
if (input.key_pressed(SDLK_f)) {
plotter.end_plotting();
gfx.toggle_fullscreen();
plotter.resize(gfx.get_screen_w(), gfx.get_screen_h());
plotter.plot();
//zoom_on();
}
if (input.key_pressed(SDLK_p)) {
plotter.print_pos();
}
gfx.update();
int time_rem = 1000 / FPS - (SDL_GetTicks() - frame_time);
if (time_rem >= 5)
SDL_Delay(time_rem);
}
plotter.end_plotting();
SDL_Quit();
return 0;
}