-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
125 lines (103 loc) · 4.17 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#include "iocontroller.h"
#include "console.h"
#include "program.h"
#include "graphics.h"
#include <SDL2/SDL.h>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include "tests.cpp"
void tests() {
// bruteforceSpeed();
// symmetrySpeed();
// shapeSpeed();
// noShapeSpeed();
// borderCorrect();
// borderSpeed();
// multiThreads();
// multiSplits();
// multiSpeed(/*8, 7*/);
// allSpeeds();
// gmpBruteforceSpeed(/*64*/);
// gmpBordertraceSpeed(/*64*/);
// for(int t = 0; t < 25; t++) {
// gmpFractalSpeedAll(t);
// }
// gmpScaleSpeed();
// doublePrec();
}
void parseArgs(unsigned int argc, char* argv[], unsigned int& width, unsigned int& height) {
for(unsigned int i = 1; i < argc; i++) {
if((strcmp(argv[i], "-p") == 0 || strcmp(argv[i], "--precision") == 0) && argc > i + 1) {
// TODO: Start with given arbitrary precision
std::cout << "Setting precision on startup is not implemented yet!" << std::endl;
}
else if((strcmp(argv[i], "-r") == 0 || strcmp(argv[i], "--resolution") == 0) && argc > i + 2) {
width = atoi(argv[i + 1]);
height = atoi(argv[i + 2]);
if(height == 0 || width == 0) {
std::cout << "Incorrect value for width and/or height. Skipping " << argv[i] << ' ' << argv[i + 1] << ' ' << argv[i + 2] << '.' << std::endl;
width = DEFAULTWIDTH;
height = DEFAULTHEIGHT;
}
i += 2; // Advance 2 extra arguments
}
else if(strcmp(argv[i], "-t") == 0 || strcmp(argv[i], "--test") == 0) {
tests();
exit(EXIT_SUCCESS);
}
else {
if(strcmp(argv[i], "-h") != 0 && strcmp(argv[i], "--help") != 0)
std::cout << "Incorrect usage.\n" << std::endl;
std::cout << "---[ Fraccert ]---\n"
<< "An interactive fractal viewer\n"
<< "Author: Luc de Jonckheere\n"
<< "\n"
<< "Flags:\n"
<< " (-p | --precision) [p] - Sets precision to p bits\n"
<< " (-r | --resolution) [x] [y] - Run fraccert in x by y pixels\n"
<< " (-t | --tests) - Run tests\n"
<< " (-h | --help) - Prints help\n"
<< "\n"
<< "Usage:\n"
<< "Use scroll wheel or +/- keys to scale.\n"
<< "WASD or arrow keys to translate.\n"
<< "T to toggle between Mandelbrot and Julia.\n"
<< "G to toggle coloring method.\n"
<< "H to return to the starting location\n"
<< "IJKL to translate Julia c value.\n"
<< "[] to change NMAX.\n"
<< "Use escape ('esc') to remove any queued actions.\n" << std::endl;
exit(EXIT_SUCCESS);
}
}
}
int main(int argc, char* argv[]) {
// Delfault settings
unsigned int width = DEFAULTWIDTH;
unsigned int height = DEFAULTHEIGHT;
parseArgs(argc, argv, width, height);
if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) < 0) {
printf("SDL could not initialize!\nSDL Error: %s\n", SDL_GetError());
exit(EXIT_FAILURE);
}
// Julia window
Graphics* juliaGraphics = new Graphics();
Program* juliaWindow = new Program(juliaGraphics, DEFAULTWIDTH / 2, DEFAULTHEIGHT / 2, SDL_WINDOW_HIDDEN);
// Init model-view-controller
Graphics* graphics = new Graphics();
Program* program = new Program(graphics, width, height, SDL_WINDOW_SHOWN);
IOController* ioController = new IOController(program, juliaWindow, program->getWindowID(), juliaWindow->getWindowID());
program->setJuliaWindow(juliaWindow);
juliaWindow->setJuliaWindow(program); // So it can request c
program->redraw(); // Initial draw
ioController->mainLoop();
std::cout << std::endl;
delete juliaGraphics;
delete juliaWindow;
delete graphics;
delete program;
delete ioController;
SDL_Quit();
return EXIT_SUCCESS;
}