-
Notifications
You must be signed in to change notification settings - Fork 1
/
guihandler.cpp
96 lines (76 loc) · 3.69 KB
/
guihandler.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
#include "guihandler.h"
#include "numbers.h"
#include <QThread>
#include <QDebug>
#include <QTime>
GuiHandler::GuiHandler(const BackendDataDto& dto){
m_fpsTimer = new QTimer(this);
connect(m_fpsTimer, &QTimer::timeout,this, &GuiHandler::updateCanvas);
m_fps = dto.m_fps;
m_collapser = new Collapser(dto);
collapserThread = new QThread(this);
m_collapser->moveToThread(collapserThread);
m_tileMap = QVector<int>(dto.m_dimensionsWidth* dto.m_dimensionsHeight,-1).toList();
connect(collapserThread, &QThread::finished, collapserThread, &QThread::deleteLater);
connect(collapserThread,&QThread::started,m_collapser,&Collapser::startCollapsing);
connect(m_collapser, &Collapser::tileMapChanged,this,[&](int index, int newTile){
m_tileMap.replace(index, newTile);
});
m_secondsTimer = new QTimer(this);
connect(m_secondsTimer, &QTimer::timeout, this, &GuiHandler::onSecondsTimerTimeout );
connect(m_collapser, &Collapser::updateCanvas, this, &GuiHandler::updateCanvas);
m_numbers = new Numbers(dto.m_dimensionsWidth, dto.m_dimensionsHeight);
//QTimer::singleShot(10, this, &GuiHandler::startCollapsing);
}
void GuiHandler::drawGrid(){
emit updateCanvas();
}
QList<MapConstructor::constructParameters> GuiHandler::getCurrentTimeConstructParameters(const QTime& currentTime){
QList<MapConstructor::constructParameters> disadvantageWeightmapConstructionInstructions;
qDebug() << (currentTime.hour()/10)%10 << currentTime.hour()%10 << (currentTime.minute()/10)%10 << currentTime.minute()%10;
disadvantageWeightmapConstructionInstructions << m_numbers->getNumberConstructParameters(1,(currentTime.hour()/10)%10,3)
<< m_numbers->getNumberConstructParameters(2,currentTime.hour()%10,3)
<< m_numbers->getNumberConstructParameters(3,(currentTime.minute()/10)%10,3)
<< m_numbers->getNumberConstructParameters(4,(currentTime.minute()%10),3);//numberWeightmapOne;//numberWeightmapTwo;
return disadvantageWeightmapConstructionInstructions;
}
void GuiHandler::startCollapsing(){
qDebug() << "Starting Collapse Algorithm";
QTime currentTime(QTime::currentTime());
m_collapser->setNewWeightMap(this->getCurrentTimeConstructParameters(currentTime));
emit tilesToHighlightChanged(m_collapser->getTilesToBeColouredDifferently());
m_fpsTimer->start(1000/m_fps);
collapserThread->start();
m_secondsTimer->start(1000);
// int currentHour = -1;
}
int GuiHandler::calculateTilePixelWidthHeight(){
int horizontalPixels = m_collapser->getWindowSizeHorizontalInPixels();
int horizontalTiles = m_collapser->getDimensionsWidth();
//CURRENTLY WIDTH MUST BE GREATER THAN HEIGHT
if(horizontalTiles < m_collapser->getDimensionsWidth()){
//Sorry
qFatal("Width must have more or equal number of tiles as height");
return -1;
}
while((horizontalPixels%horizontalTiles) != 0){
horizontalPixels--;
}
qDebug() << "Pixels in horizontal direction: " << horizontalPixels;
return horizontalPixels/horizontalTiles;
}
void GuiHandler::onSecondsTimerTimeout(){
QTime currentTime(QTime::currentTime());
if(m_lastTime == currentTime.minute())
return;
m_collapser->resetTileMap();
m_collapser->setNewWeightMap(this->getCurrentTimeConstructParameters(currentTime));
emit tilesToHighlightChanged(m_collapser->getTilesToBeColouredDifferently());
//m_collapser->restart();
m_lastTime = currentTime.minute();
}
GuiHandler::~GuiHandler(){
delete m_fpsTimer;
delete m_collapser;
delete m_numbers;
}