-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathengine.cc
More file actions
executable file
·109 lines (100 loc) · 3.97 KB
/
engine.cc
File metadata and controls
executable file
·109 lines (100 loc) · 3.97 KB
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
#include <fstream>
#include <iostream>
#include <stdexcept>
#include <string>
#include <list>
#include <cmath>
#include <stack>
#include <math.h>
#include "easy_image.h"
#include "handlers/2DLsystem.h"
#include "handlers/Intro.h"
#include "handlers/LightedZBuffering.h"
#include "handlers/Universal.h"
#include "handlers/WireFrame.h"
#include "handlers/ZBufferTriangle.h"
#include "ini_configuration.h"
img::EasyImage generate_image(const ini::Configuration& configuration) {
std::string t;
if (!configuration["General"]["type"].as_string_if_exists(t)) std::cout << "⛔️| Failed to fetch type" << std::endl;
std::cout << "🥱| Generating image of type '" + t + "'" << std::endl;
img::EasyImage result;
if (t == "IntroColorRectangle") result = colorRectangle(configuration);
if (t == "IntroBlocks") result = blocks(configuration);
if (t == "IntroLines") result = introLines(configuration);
if (t == "2DLSystem") result = LSystem(configuration);
if (t == "Wireframe") result = wireFrame(configuration);
if (t == "ZBufferedWireframe") result = wireFrame(configuration, true);
if (t == "ZBuffering") result = zBufferTriangle(configuration);
if (t == "LightedZBuffering") result = lightedZBuffering(configuration);
std::cout << "✅| Image generated" << std::endl;
return result;
}
// Provided by University of Antwerp
int main(int argc, char const* argv[]) {
int retVal = 0;
try {
std::vector<std::string> args =
std::vector<std::string>(argv + 1, argv + argc);
if (args.empty()) {
std::ifstream fileIn("filelist");
std::string filelistName;
while (std::getline(fileIn, filelistName)) {
args.push_back(filelistName);
}
}
for (std::string fileName : args) {
ini::Configuration conf;
try {
std::ifstream fin(fileName);
fin >> conf;
fin.close();
}
catch (ini::ParseException& ex) {
std::cerr << "Error parsing file: " << fileName << ": " << ex.what()
<< std::endl;
retVal = 1;
continue;
}
img::EasyImage image = generate_image(conf);
if (image.get_height() > 0 && image.get_width() > 0) {
std::string::size_type pos = fileName.rfind('.');
if (pos == std::string::npos) {
// filename does not contain a '.' --> append a '.bmp' suffix
fileName += ".bmp";
}
else {
fileName = fileName.substr(0, pos) + ".bmp";
}
try {
std::ofstream f_out(fileName.c_str(), std::ios::trunc |
std::ios::out |
std::ios::binary);
f_out << image;
}
catch (std::exception& ex) {
std::cerr << "Failed to write image to file: " << ex.what()
<< std::endl;
retVal = 1;
}
}
else {
std::cout << "Could not generate image for " << fileName << std::endl;
}
}
}
catch (const std::bad_alloc& exception) {
// When you run out of memory this exception is thrown. When this happens
// the return value of the program MUST be '100'. Basically this return
// value tells our automated test scripts to run your engine on a pc with
// more memory.
//(Unless of course you are already consuming the maximum allowed amount of
// memory)
// If your engine does NOT adhere to this requirement you risk losing points
// because then our scripts will mark the test as failed while in reality it
// just needed a bit more memory
std::cerr << "Error: insufficient memory" << std::endl;
retVal = 100;
}
return retVal;
}