-
Notifications
You must be signed in to change notification settings - Fork 1
/
newdialog.cpp
102 lines (84 loc) · 2.15 KB
/
newdialog.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
/*
* newdialog.cpp
* MazeGenerator
*
* Copyright 2018 Matthew T. Pandina. All rights reserved.
*
*/
#include "newdialog.h"
#include "ui_newdialog.h"
#include <QDebug>
#include "Maze.h"
#include "BitArray.h"
NewDialog::NewDialog(QWidget *parent, int width, int height) :
QDialog(parent),
ui(new Ui::NewDialog),
width(width),
height(height)
{
ui->setupUi(this);
ui->spinBoxWidth->setValue(width);
ui->spinBoxHeight->setValue(height);
ui->spinBoxWidth->setFocus();
updateMemoryDisplay();
}
NewDialog::~NewDialog()
{
delete ui;
}
void NewDialog::on_spinBoxWidth_valueChanged(int arg1)
{
width = arg1;
updateMemoryDisplay();
}
void NewDialog::on_spinBoxHeight_valueChanged(int arg1)
{
height = arg1;
updateMemoryDisplay();
}
void NewDialog::updateMemoryDisplay()
{
uint64_t memory = sizeof(Maze);
uint32_t dims[2] = { width, height };
uint32_t length = 2;
uint32_t totalPositions = 1;
uint32_t totalWalls = 0;
memory += sizeof(uint32_t) * length;
for (uint32_t i = 0; i < length; ++i)
totalPositions *= dims[i];
for (uint32_t i = 0; i < length; ++i) {
uint32_t subTotal = 1;
for (uint32_t j = 0; j < length; ++j)
if (j != i)
subTotal *= dims[j];
totalWalls += subTotal * (dims[i] - 1);
}
memory += sizeof(Wall) * totalWalls;
memory += sizeof(uint8_t) * totalPositions;
memory += sizeof(BitArrayRef) * length * 2;
memory += sizeof(int32_t) * totalPositions; // DisjSets_create
memory += sizeof(BitArray) * length * 2;
memory += (totalPositions / 8 + ((totalPositions % 8) ? 1 : 0)) * length * 2;
ui->labelMemory->setText(sizeHuman(memory));
}
QString NewDialog::sizeHuman(uint64_t size)
{
float num = size;
QStringList list;
list << "KiB" << "MiB" << "GiB" << "TiB";
QStringListIterator i(list);
QString unit("bytes");
while(num >= 1024.0 && i.hasNext()) {
unit = i.next();
num /= 1024.0;
}
return QString().setNum(num, 'f', 2) + " " + unit;
}
int NewDialog::getHeight() const
{
return height;
}
int NewDialog::getWidth() const
{
return width;
}