-
Notifications
You must be signed in to change notification settings - Fork 0
/
Properties.cpp
74 lines (57 loc) · 2.41 KB
/
Properties.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
#include "Properties.hpp"
Properties prop;
Properties::Properties() :
INTERFACECOLOR ({ 70, 70, 70 }),
UPSCALING (1),
BACKGROUNDCOLOR ({0.2, 0.2, 0.8}),
MAXGEN (8),
FOV (90),
FOCUS (10),
BLURRADIUS (100)
{
loadProperties();
}
void Properties::loadProperties() {
std::string line = "", word = "";
std::ifstream file(getExeDir() + "\\properties.txt");
if (!file) {
printf("properties.txt does not exist!");
return;
}
else while(getline(file, line)) {
std::istringstream iss(line, std::istringstream::in);
std::vector<std::string> wordsVector;
while (iss >> word) {
wordsVector.push_back(word);
}
if (wordsVector[0] == "UPSCALING") UPSCALING = std::stod(wordsVector[1]);
else if (wordsVector[0] == "BACKGROUNDCOLOR") BACKGROUNDCOLOR = {std::stod(wordsVector[1]),
std::stod(wordsVector[2]),
std::stod(wordsVector[3])};
else if (wordsVector[0] == "MAXGEN") MAXGEN = std::stod(wordsVector[1]);
else if (wordsVector[0] == "FOV") FOV = std::stod(wordsVector[1]);
else if (wordsVector[0] == "FOCAL") FOCUS = std::stod(wordsVector[1]);
else if (wordsVector[0] == "BLURRADIUS") BLURRADIUS = std::stod(wordsVector[1]);
}
file.close();
}
void Properties::saveProperties() {
std::ofstream file(getExeDir() + "\\properties.txt");
if (!file) {
printf("properties.txt does not exist!");
return;
}
file << "UPSCALING " << UPSCALING << std::endl;
file << "BACKGROUNDCOLOR " << BACKGROUNDCOLOR.x_ << " " << BACKGROUNDCOLOR.y_ << " " << BACKGROUNDCOLOR.z_ << std::endl;
file << "MAXGEN " << MAXGEN << std::endl;
file << "FOV " << FOV << std::endl;
file << "FOCAL " << FOCUS << std::endl;
file << "BLURRADIUS " << BLURRADIUS << std::endl;
file.close();
}
std::string getExeDir() {
char buffer[MAX_PATH];
GetModuleFileNameA( NULL, buffer, MAX_PATH );
std::string f = buffer;
return f.substr(0, f.find_last_of("\\/"));
}