forked from imagina-gmin317-2015/TP4
/
gamewindow.cpp
836 lines (718 loc) · 21.2 KB
/
gamewindow.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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
#include "gamewindow.h"
#include "terrain.h"
#include "camera.h"
#include <QtGui/QGuiApplication>
#include <QtGui/QMatrix4x4>
#include <QtGui/QOpenGLShaderProgram>
#include <QtGui/QScreen>
#include <QtCore/qmath.h>
#include <QMouseEvent>
#include <QKeyEvent>
#include <time.h>
#include <sys/time.h>
#include <iostream>
#include <QtCore>
#include <QtGui>
#include <QTimer>
using namespace std;
static bool animate = true; //permet de savoir si on anime les terrain des différentes fenêtre GameWindow en les faisant tourner selon l'axe y
/**
* @brief GameWindow::GameWindow, constructeur de la classe GameWindow.
* @param refresh_rate, taux de rafraîchissement de la fenêtre
* @param c, paramètre facultatif qui permet d'avoir une caméra partagée par plusieurs fenêtres
*/
GameWindow::GameWindow(int refresh_rate, Camera* c) : carte(1), m_refresh_rate(refresh_rate), speed(0.5f)
{
srand(time(NULL));
if(c != 0){
share_cam = true;
m_camera = c;
}else{
share_cam = false;
m_camera = new Camera();
}
season = "NONE";
saison = Saison::NONE;
nb_vertex_width = nb_vertex_height = 0;
m_timer = new QTimer(this);
connect(m_timer,SIGNAL(timeout()),this, SLOT(renderNow()));
restartTimer();
doConnect();
}
/**
* @brief GameWindow::~GameWindow, destructeur de la classe GameWindow.
*/
GameWindow::~GameWindow(){
delete p;
if(!share_cam)
delete m_camera;
delete m_timer;
}
/**
* @brief GameWindow::initialize, initialise les fonctionnalités OpenGL et charge une heightmap.
*/
void GameWindow::initialize()
{
const qreal retinaScale = devicePixelRatio();
glViewport(0, 0, width() * retinaScale, height() * retinaScale);
glClearColor(0.0, 0.0, 0.0, 0.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-1.0, 1.0, -1.0, 1.0, -100.0, 100.0);
glEnable(GL_DEPTH_TEST); // Active le Z-Buffer
glShadeModel(GL_SMOOTH);
glEnable(GL_COLOR_MATERIAL);
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
//Add ambient light
GLfloat ambientColor[] = {0.8f, 0.8f, 0.8f, 1.0f};
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambientColor);
//Add directionnal light
GLfloat lightColor0[] = {1.f, 1.f, 1.f, 1.0f};
GLfloat lightPos0[] = {-1.0f, 0.5f, 0.5f, 0.0f};
glLightfv(GL_LIGHT0, GL_DIFFUSE, lightColor0);
glLightfv(GL_LIGHT0, GL_POSITION, lightPos0);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
Terrain* T = FileManager::Instance().getTerrain();
if(T->nb_vertex_width != 0)
{
season = T->saison;
updateEnumSaison();
nb_vertex_width = T->nb_vertex_width;
nb_vertex_height = T->nb_vertex_height;
p = new point[nb_vertex_width * nb_vertex_height];
for(int i = 0 ; i < nb_vertex_width * nb_vertex_height ; i++)
{
p[i].x = T->vertex[i].x();
p[i].y = T->vertex[i].y();
p[i].z = T->vertex[i].z();
}
initTrees(T->tree);
updateTitle();
}else{
loadMap(":/heightmap-2.png");
initTrees();
}
createParticles();
}
/**
* @brief GameWindow::loadMap, permet de charger une heightmap.
* @param localPath, chemin vers la heightmap
*/
void GameWindow::loadMap(QString localPath)
{
if (QFile::exists(localPath)) {
m_image = QImage(localPath);
}
uint id = 0;
nb_vertex_width = m_image.width();
nb_vertex_height = m_image.height();
p = new point[nb_vertex_width * nb_vertex_height];
QRgb pixel;
for(int i = 0; i < nb_vertex_width; i++)
{
for(int j = 0; j < nb_vertex_height; j++)
{
pixel = m_image.pixel(i,j);
id = i*nb_vertex_width +j;
p[id].x = (float)i/(nb_vertex_width) - ((float)nb_vertex_width/2.0)/nb_vertex_width;
p[id].y = (float)j/(nb_vertex_width) - ((float)nb_vertex_height/2.0)/nb_vertex_height;
p[id].z = 0.001f * (float)(qRed(pixel));
}
}
}
/**
* @brief GameWindow::render, fonction de rendu OpenGL contenant plusieurs type de rendu.
*/
void GameWindow::render()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glScalef(m_camera->ss,m_camera->ss,m_camera->ss);
glRotatef(m_camera->rotX,1.0f,0.0f,0.0f);
glRotatef(m_camera->rotY,0.0f,0.0f,1.0f);
switch(m_camera->etat)
{
case 0:
displayPoints();
break;
case 1:
displayLines();
break;
case 2:
displayTriangles();
break;
case 3:
displayTrianglesC();
break;
case 4:
displayTrianglesTexture();
break;
case 5:
displayTrianglesTexture();
displayLines();
break;
default:
displayPoints();
break;
}
displayParticles();
displayTree();
if(animate){
animWindow();
}
++m_frame;
}
/**
* @brief GameWindow::event, fonction permettant la gestion d'évenements.
* @param event, QEvent
* @return
*/
bool GameWindow::event(QEvent *event)
{
switch (event->type())
{
case QEvent::UpdateRequest:
renderNow();
return true;
default:
return QWindow::event(event);
}
}
/**
* @brief GameWindow::keyPressEvent, permet de gérer les évenements de type clavier.
* @param event, évenement de type clavier
*/
void GameWindow::keyPressEvent(QKeyEvent *event)
{
switch(event->key())
{
case 'Z':
m_camera->ss += 0.10f;
break;
case 'S':
m_camera->ss -= 0.10f;
break;
case 'A':
m_camera->rotX += 1.0f;
break;
case 'E':
m_camera->rotX -= 1.0f;
break;
case 'Q':
m_camera->rotY += 1.0f;
break;
case 'D':
m_camera->rotY -= 1.0f;
break;
case 'W':
m_camera->etat ++;
if(m_camera->etat > 5)
m_camera->etat = 0;
break;
case 'C':
animate = !animate;
break;
case 'P':
m_refresh_rate *= 2;
if(m_refresh_rate > 120)
m_refresh_rate = 120;
restartTimer();
break;
case 'M':
m_refresh_rate /= 2;
if(m_refresh_rate < 1)
m_refresh_rate = 1;
restartTimer();
break;
case 'X':
carte ++;
if(carte > 3)
carte = 1;
QString depth (":/heightmap-");
depth += QString::number(carte) ;
depth += ".png" ;
loadMap(depth);
break;
}
}
/**
* @brief GameWindow::displayPoints, fonction d'affichage du terrain avec des points.
*/
void GameWindow::displayPoints()
{
seasonColor();
glBegin(GL_POINTS);
uint id = 0;
#pragma omp for schedule(dynamic)
for(int i = 0; i < nb_vertex_width; i++)
{
for(int j = 0; j < nb_vertex_height; j++)
{
id = i*nb_vertex_width +j;
glVertex3f(
p[id].x,
p[id].y,
p[id].z);
}
}
glEnd();
}
/**
* @brief GameWindow::displayTriangles, fonction d'affichage du terrain avec des triangles.
*/
void GameWindow::displayTriangles()
{
seasonColor();
glBegin(GL_TRIANGLES);
uint id = 0;
#pragma omp for schedule(dynamic)
for(int i = 0; i < nb_vertex_width-1; i++)
{
for(int j = 0; j < nb_vertex_height-1; j++)
{
id = i*nb_vertex_width +j;
glVertex3f(
p[id].x,
p[id].y,
p[id].z);
id = i*nb_vertex_width +(j+1);
glVertex3f(
p[id].x,
p[id].y,
p[id].z);
id = (i+1)*nb_vertex_width +j;
glVertex3f(
p[id].x,
p[id].y,
p[id].z);
id = i*nb_vertex_width +(j+1);
glVertex3f(
p[id].x,
p[id].y,
p[id].z);
id = (i+1)*nb_vertex_width +j+1;
glVertex3f(
p[id].x,
p[id].y,
p[id].z);
id = (i+1)*nb_vertex_width +j;
glVertex3f(
p[id].x,
p[id].y,
p[id].z);
}
}
glEnd();
}
/**
* @brief GameWindow::displayTrianglesC, fonction d'affichage du terrain avec des triangles de couleurs différentes.
*/
void GameWindow::displayTrianglesC()
{
glColor3f(1.0f, 1.0f, 1.0f);
glBegin(GL_TRIANGLES);
uint id = 0;
#pragma omp for schedule(dynamic)
for(int i = 0; i < nb_vertex_width-1; i++)
{
for(int j = 0; j < nb_vertex_height-1; j++)
{
glColor3f(0.0f, 1.0f, 0.0f);
id = i*nb_vertex_width +j;
glVertex3f(
p[id].x,
p[id].y,
p[id].z);
id = i*nb_vertex_width +(j+1);
glVertex3f(
p[id].x,
p[id].y,
p[id].z);
id = (i+1)*nb_vertex_width +j;
glVertex3f(
p[id].x,
p[id].y,
p[id].z);
glColor3f(1.0f, 1.0f, 1.0f);
id = i*nb_vertex_width +(j+1);
glVertex3f(
p[id].x,
p[id].y,
p[id].z);
id = (i+1)*nb_vertex_width +j+1;
glVertex3f(
p[id].x,
p[id].y,
p[id].z);
id = (i+1)*nb_vertex_width +j;
glVertex3f(
p[id].x,
p[id].y,
p[id].z);
}
}
glEnd();
}
/**
* @brief GameWindow::displayLines, fonction d'affichage du terrain avec des lignes.
*/
void GameWindow::displayLines()
{
seasonColor();
glBegin(GL_LINES);
uint id = 0;
#pragma omp for schedule(dynamic)
for(int i = 0; i < nb_vertex_width-1; i++)
{
for(int j = 0; j < nb_vertex_height-1; j++)
{
id = i*nb_vertex_width +j;
glVertex3f(
p[id].x,
p[id].y,
p[id].z);
id = i*nb_vertex_width +(j+1);
glVertex3f(
p[id].x,
p[id].y,
p[id].z);
id = (i+1)*nb_vertex_width +j;
glVertex3f(
p[id].x,
p[id].y,
p[id].z);
id = i*nb_vertex_width +j;
glVertex3f(
p[id].x,
p[id].y,
p[id].z);
id = (i+1)*nb_vertex_width +j;
glVertex3f(
p[id].x,
p[id].y,
p[id].z);
id = i*nb_vertex_width +(j+1);
glVertex3f(
p[id].x,
p[id].y,
p[id].z);
id = i*nb_vertex_width +(j+1);
glVertex3f(
p[id].x,
p[id].y,
p[id].z);
id = (i+1)*nb_vertex_width +j+1;
glVertex3f(
p[id].x,
p[id].y,
p[id].z);
id = (i+1)*nb_vertex_width +j+1;
glVertex3f(
p[id].x,
p[id].y,
p[id].z);
id = (i+1)*nb_vertex_width +(j);
glVertex3f(
p[id].x,
p[id].y,
p[id].z);
}
}
glEnd();
}
/**
* @brief GameWindow::displayTrianglesTexture, fonction d'affichage du terrain avec des triangles texturés en fonction de la hauteur des vertices.
*/
void GameWindow::displayTrianglesTexture()
{
glColor3f(1.0f, 1.0f, 1.0f);
glBegin(GL_TRIANGLES);
uint id = 0;
#pragma omp for schedule(dynamic)
for(int i = 0; i < nb_vertex_width-1; i++)
{
for(int j = 0; j < nb_vertex_height-1; j++)
{
id = i*nb_vertex_width +j;
displayColor(p[id].z);
glVertex3f(
p[id].x,
p[id].y,
p[id].z);
id = i*nb_vertex_width +(j+1);
displayColor(p[id].z);
glVertex3f(
p[id].x,
p[id].y,
p[id].z);
id = (i+1)*nb_vertex_width +j;
displayColor(p[id].z);
glVertex3f(
p[id].x,
p[id].y,
p[id].z);
id = i*nb_vertex_width +(j+1);
displayColor(p[id].z);
glVertex3f(
p[id].x,
p[id].y,
p[id].z);
id = (i+1)*nb_vertex_width +j+1;
displayColor(p[id].z);
glVertex3f(
p[id].x,
p[id].y,
p[id].z);
id = (i+1)*nb_vertex_width +j;
displayColor(p[id].z);
glVertex3f(
p[id].x,
p[id].y,
p[id].z);
}
}
glEnd();
}
/**
* @brief GameWindow::displayColor, affiche une couleur sur les vertices en fonction de l'altitude de ceux-ci.
* @param alt, altitude en z
*/
void GameWindow::displayColor(float alt)
{
if (alt > 0.2)
{
glColor3f(1.0f, 1.0f, 1.0f);
}
else if (alt > 0.1)
{
glColor3f(alt, 1.0f, 1.0f);
}
else if (alt > 0.05f)
{
glColor3f(1.0f, alt, alt);
}
else
{
glColor3f(0.0f, 0.0f, 1.0f);
}
}
/**
* @brief GameWindow::animWindow, fonction permettant la rotation automatique du terrain selon l'axe y.
*/
void GameWindow::animWindow(){
m_camera->rotY += speed;
}
/**
* @brief GameWindow::restartTimer, permet de relancer le timer lorsque celui-ci change.
*/
void GameWindow::restartTimer(){
m_timer->stop();
m_timer->start(1000.f / m_refresh_rate);
updateTitle();
}
/**
* @brief GameWindow::updateTitle, Met à jour le titre de la fenêtre en fonction de la saison et du framerate de celle-ci.
*/
void GameWindow::updateTitle(){
QString fps = QString::number(m_refresh_rate);
QString title = fps + "FPS - " + season;
setTitle(title);
}
/**
* @brief GameWindow::seasonColor, Affiche le terrain d'une couleur différente en fonction de la saison.
*/
color GameWindow::seasonColor(){
if(saison == Saison::PRINTEMPS){
glColor3f(0.f, 0.7f, 0.2f);
return color{0.f, 0.7f, 0.2f};
}
else if(saison == Saison::ETE){
glColor3f(1.f, 1.f, 0.f);
return color{1.f, 1.f, 0.f};
}
else if(saison == Saison::AUTOMNE){
glColor3f(0.86f, 0.4f, 0.f);
return color{0.86f, 0.4f, 0.f};
}
else if(saison == Saison::HIVER){
glColor3f(0.8f, 0.8f, 0.8f);
return color{0.8f, 0.8f, 0.8f};
}
return color{0.f,0.f,0.f};
}
/**
* @brief GameWindow::createParticles, Initialise le tableau de particules.
*/
void GameWindow::createParticles(){
tab_particles = new particles[MAX_PARTICLES];
#pragma omp parallel for
for(unsigned int i = 0 ; i < MAX_PARTICLES ; i++){
tab_particles[i] = newParticle();
}
}
/**
* @brief GameWindow::newParticle, Créé et retourne une nouvelle particule à une position aléatoire.
* @return nouvelle particule
*/
particles GameWindow::newParticle(){
particles part;
int rand_x, rand_y, id;
rand_x = rand() % nb_vertex_width;
rand_y = rand() % nb_vertex_height;
id = rand_y * nb_vertex_width + rand_x;
part.x = p[id].x;
part.y = p[id].y;
part.z = (rand() % 5 + 3) / 10.f;
part.min_z = p[id].z;
part.falling_speed = (rand() % 10 + 1) / 1000.f;
return part;
}
/**
* @brief GameWindow::displayParticles, Affiche le système de particules lorsque c'est nécessaire.
*/
void GameWindow::displayParticles(){
if(season == "AUTOMNE"){
glColor3f(0.0f, 0.0f, 1.0f);
}else if(season == "HIVER"){
glColor3f(1.0f, 1.0f, 1.0f);
}else{
return;
}
glBegin(GL_POINTS);
#pragma omp for schedule(dynamic)
for(unsigned int i = 0 ; i < MAX_PARTICLES ; i++){
glVertex3f(tab_particles[i].x, tab_particles[i].y, tab_particles[i].z);
tab_particles[i].z -= tab_particles[i].falling_speed;
if(tab_particles[i].z < tab_particles[i].min_z){
tab_particles[i] = newParticle();
}
}
glEnd();
}
/**
* @brief GameWindow::displayTree, Affiche les différents arbres sur le terrain.
*/
void GameWindow::displayTree(){
if(saison == Saison::NONE){
return;
}
for(unsigned int i = 0 ; i < NB_ARBRES ; i++){
tree[saison][i]->display();
}
}
/**
* @brief GameWindow::doConnect, Connecte le client au serveur.
*/
void GameWindow::doConnect(){
socket = new QTcpSocket(this);
connect(socket, SIGNAL(connected()),this, SLOT(connected()));
connect(socket, SIGNAL(disconnected()),this, SLOT(disconnected()));
connect(socket, SIGNAL(bytesWritten(qint64)),this, SLOT(bytesWritten(qint64)));
connect(socket, SIGNAL(readyRead()),this, SLOT(readyRead()));
qDebug() << QString::number(m_refresh_rate) << "FPS window : connecting...";
// this is not blocking call
socket->connectToHost("127.0.0.1", 9999);
// we need to wait...
if(!socket->waitForConnected(5000))
{
qDebug() << "Error: " << socket->errorString();
}
}
/**
* @brief GameWindow::save, envoi le terrain de la fenêtre au FileManager pour le sauvegarder.
*/
void GameWindow::save(){
Terrain* T = new Terrain(season, seasonColor(), nb_vertex_width, nb_vertex_height, p, tree);
FileManager::Instance().saveCustomMap(T);
}
/**
* @brief GameWindow::updateEnumSaison, met à jour l'enum Saison en fonction de la saison courante.
*/
void GameWindow::updateEnumSaison()
{
if(season == "PRINTEMPS"){
saison = Saison::PRINTEMPS;
}else if(season == "ETE"){
saison = Saison::ETE;
}else if(season == "AUTOMNE"){
saison = Saison::AUTOMNE;
}else if(season == "HIVER"){
saison = Saison::HIVER;
}
}
/**
* @brief GameWindow::initTrees, Lorsque le fichier binaire est vide, initialise les arbres des différentes saisons pour la fenêtre.
*/
void GameWindow::initTrees()
{
tree = new GameObject**[FileManager::NB_TERRAIN];
tree[Saison::PRINTEMPS] = new GameObject*[NB_ARBRES];
tree[Saison::ETE] = new GameObject*[NB_ARBRES];
tree[Saison::AUTOMNE] = new GameObject*[NB_ARBRES];
tree[Saison::HIVER] = new GameObject*[NB_ARBRES];
for(unsigned int j = 0 ; j < FileManager::NB_TERRAIN ; j++){
for(unsigned int i = 0 ; i < NB_ARBRES ; i++){
QVector3D pos;
int rand_x, rand_y, id;
rand_x = rand() % nb_vertex_width;
rand_y = rand() % nb_vertex_height;
id = rand_y * nb_vertex_width + rand_x;
pos.setX(p[id].x); pos.setY(p[id].y); pos.setZ(p[id].z);
if(j == Saison::PRINTEMPS){
tree[j][i] = new GameObject(pos, QVector3D(0.f,0.f,0.f), QVector3D(0.1f,0.1f,0.1f), ":/island_tree.ply");
}else if(j == Saison::ETE){
tree[j][i] = new GameObject(pos, QVector3D(0.f,0.f,0.f), QVector3D(0.1f,0.1f,0.1f), ":/summertree.ply");
}else if(j == Saison::AUTOMNE){
tree[j][i] = new GameObject(pos, QVector3D(0.f,0.f,0.f), QVector3D(0.1f,0.1f,0.1f), ":/autumntree.ply");
}else if(j == Saison::HIVER){
tree[j][i] = new GameObject(pos, QVector3D(0.f,0.f,0.f), QVector3D(0.1f,0.1f,0.1f), ":/wintertree.ply");
}
}
}
}
/**
* @brief GameWindow::initTrees, Initialise les arbres de la fenêtre en fonction des données contenu dans le fichier binaire.
* @param t, tableau de GameObject contenant les différents arbres des différentes saisons
*/
void GameWindow::initTrees(GameObject ***t)
{
tree = new GameObject**[FileManager::NB_TERRAIN];
for(unsigned int j = 0 ; j < FileManager::NB_TERRAIN ; j++){
tree[j] = new GameObject*[NB_ARBRES];
for(unsigned int i = 0 ; i < NB_ARBRES ; i++){
tree[j][i] = t[j][i];
tree[j][i]->open(tree[j][i]->localPath);
}
}
}
/** SLOTS **/
/**
* @brief GameWindow::connected, s'execute lorsque le client se connecte à un serveur.
*/
void GameWindow::connected()
{
qDebug() << QString::number(m_refresh_rate) << "FPS window : connected...";
}
/**
* @brief GameWindow::disconnected, s'éxecute lorsque le client est déconnecté.
*/
void GameWindow::disconnected()
{
qDebug() << QString::number(m_refresh_rate) << "FPS window : disconnected...";
}
/**
* @brief GameWindow::readyRead, permet de recevoir les données envoyées par le serveur.
*/
void GameWindow::readyRead()
{
// read the data from the socket
QString str = QString(socket->readAll());
if(str == "SAVE"){
save();
}else{
season = str;
updateEnumSaison();
updateTitle();
}
}