]> git.localhorst.tv Git - blank.git/blob - src/generate.cpp
new gcc version
[blank.git] / src / generate.cpp
1 #include "app/Assets.hpp"
2 #include "shared/WorldResources.hpp"
3 #include "world/Chunk.hpp"
4 #include "world/Generator.hpp"
5
6 #include <chrono>
7 #include <iostream>
8 #include <glm/gtx/io.hpp>
9
10 using namespace blank;
11 using namespace std;
12 using namespace chrono;
13
14
15 int main() {
16         AssetLoader loader("assets/");
17         WorldResources res;
18         res.Load(loader, "default");
19         Generator::Config conf;
20         Generator gen(conf);
21         gen.LoadTypes(res.block_types);
22         Chunk chunk(res.block_types);
23
24         const ExactLocation::Coarse begin(-6);
25         const ExactLocation::Coarse end(6);
26         size_t total_chunks = ((end.x - begin.x) * (end.y - begin.y) * (end.z - begin.z));
27
28         size_t candidates = 0;
29         for (const BlockType &type : res.block_types) {
30                 if (type.generate) {
31                         ++candidates;
32                 }
33         }
34
35         cout << "generating " << total_chunks << " chunks from " << begin << " to " << (end - 1) << endl;
36         cout << candidates << " of " << res.block_types.size() << " block types applicable for generation" << endl;
37         auto enter = high_resolution_clock::now();
38
39         for (int z = begin.z; z < end.z; ++z) {
40                 for (int y = begin.y; y < end.y; ++y) {
41                         for (int x = begin.x; x < end.x; ++x) {
42                                 chunk.Position({ x, y, z });
43                                 gen(chunk);
44                         }
45                 }
46         }
47
48         auto exit = high_resolution_clock::now();
49         cout << duration_cast<milliseconds>(exit - enter).count() << "ms ("
50                 << (duration_cast<nanoseconds>(exit - enter).count() / total_chunks / 1.0e6f) << "ms chunk avg)" << endl;
51         return 0;
52 }