-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathengine.cc
91 lines (87 loc) · 3.99 KB
/
engine.cc
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
#include "Include/easy_image.h"
#include "Include/ini_configuration.h"
#include <fstream>
#include <iostream>
#include <string>
#include <algorithm>
#include "Objects/IniLoader.h"
#include "Objects/ZBuffer.h"
img::EasyImage generate_image(const ini::Configuration &configuration)
{
return IniLoader::createImage(configuration);
}
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);
if (fin.peek() == std::istream::traits_type::eof()) {
std::cout << "Ini file appears empty. Does '" <<
fileName << "' exist?" << std::endl;
continue;
}
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;
}