-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainMaster.cpp
137 lines (108 loc) · 3.14 KB
/
mainMaster.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
126
127
128
129
130
131
132
133
134
135
136
137
#include <iostream>
#include <vector>
#include <SFML/Graphics.hpp>
#include "Fractal.h"
#include "QS_Julia.h"
#include "FractalViewConsole.h"
#include "FractalViewWindow.h"
#include "MasterSocket.h"
#include "SlaveSocket.h"
#define WINDOW
#define WINDOW_W 1280
#define WINDOW_H 720
FractalViewWindow* testJuliaLocalWindowed(sf::RenderWindow* window, double zoom)
{
const unsigned int W = WINDOW_W;
const unsigned int H = 720;
//const Quaternion C(-0.835, 0.232, 0, 0);
const Quaternion C(-0.756, 0.232, 0, 0); // fractus
//const Quaternion C(-0.756, 0.156, 0, 0); // fractus pas beau
//const Quaternion C(-0.756, 0.356, 0, 0); // rose
//const Quaternion C(0.42, 0.42, 0, 0); // stars
//const Quaternion C(0.005, 0.852, 0, 0); // lightning
sf::Uint32 id = 0;
SuiteCollection suites;
Fractal fractal;
FractalViewWindow* view = new FractalViewWindow(&fractal, window, W, H);
if(!view->Initialize()) // Unable to create the texture
{
return 0;
}
for(unsigned int y = 0; y < H; ++y)
{
for(unsigned int x = 0; x < W; ++x)
{
//Quaternion z0((x-W/2.)/300., (y-H/2.)/300., 0, 0);
Quaternion z0((x-W/2.-0.835)/zoom,(y-H/2.+0.232)/zoom, 0, 0);
//Quaternion z0((x-W/2.)/(100.*zoom), (y+H/2.)/(100.*zoom), 0, 0);
suites.push_back(new QS_Julia(id++, z0, C, 100., 100.));
}
}
fractal.CreatePart(suites);
MasterSocket ms(54000, fractal);
ms.AuthentificationRoutine();
while(fractal.GetParts()[0]->GetResults().size() == 0) {}
std::cout << "Building image..." << std::endl;
view->BuildImage();
std::cout << "Image built!" << std::endl;
return view;
}
int main(void)
{
#ifndef WINDOW
MasterSocket ms(54000);
std::cout << "Fractals. Here." << std::endl;
testJuliaLocal();
ms.AuthentificationRoutine();
//*******For testing purpose*********
//SlaveSocket ss("localhost", 54000);
//ss.Run();
#else
//std::vector<sf::VideoMode> modes = sf::VideoMode::getFullscreenModes();
//sf::RenderWindow window(modes[0], "Fractalou", sf::Style::Fullscreen);
sf::RenderWindow window(sf::VideoMode(WINDOW_W,WINDOW_H), "Fractalou", sf::Style::Default);
double zoom = 500;
FractalViewWindow* view = 0;
window.setVerticalSyncEnabled(true);
window.setFramerateLimit(60);
view = testJuliaLocalWindowed(&window, zoom);
view->Display();
window.display();
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
switch( event.type )
{
case sf::Event::KeyPressed:
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Escape))
{
window.close();
}
else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Add)
|| sf::Keyboard::isKeyPressed(sf::Keyboard::Subtract))
{
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Add))
zoom*=2.;
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Subtract))
zoom/=2.;
delete view;
view = testJuliaLocalWindowed(&window, zoom);
window.clear();
view->Display();
window.display();
}
break;
case sf::Event::Closed:
window.close();
break;
default:
break;
}
}
}
delete view;
#endif
return 0;
}