Веб-сайт самохостера Lotigara

summaryrefslogtreecommitdiff
path: root/source/utility/generation_benchmark.cpp
blob: c96095ee0d8c8f5457f70c89a6fee593bf0acb76 (plain)
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
#include "StarRootLoader.hpp"
#include "StarCelestialDatabase.hpp"
#include "StarWorldTemplate.hpp"
#include "StarWorldServer.hpp"

using namespace Star;

int main(int argc, char** argv) {
  try {
    RootLoader rootLoader({{}, {}, {}, LogLevel::Error, false, {}});
    rootLoader.addParameter("coordinate", "coordinate", OptionParser::Optional, "world coordinate to test");
    rootLoader.addParameter("regions", "regions", OptionParser::Optional, "number of regions to generate, default 1000");
    rootLoader.addParameter("regionsize", "size", OptionParser::Optional, "width / height of each generation region, default 10");
    rootLoader.addParameter("reportevery", "report regions", OptionParser::Optional, "number of generation regions before each progress report, default 20");

    RootUPtr root;
    OptionParser::Options options;
    tie(root, options) = rootLoader.commandInitOrDie(argc, argv);

    coutf("Fully loading root...");
    root->fullyLoad();
    coutf(" done\n");

    CelestialMasterDatabase celestialDatabase;

    CelestialCoordinate coordinate;
    if (auto coordinateOption = options.parameters.maybe("coordinate")) {
      coordinate = CelestialCoordinate(coordinateOption->first());
    } else {
      coordinate = celestialDatabase.findRandomWorld(100, 50, [&](CelestialCoordinate const& coord) {
          return celestialDatabase.parameters(coord)->isVisitable();
        }).take();
    }

    unsigned regionsToGenerate = 1000;
    if (auto regionsOption = options.parameters.maybe("regions"))
      regionsToGenerate = lexicalCast<unsigned>(regionsOption->first());

    unsigned regionSize = 10;
    if (auto regionSizeOption = options.parameters.maybe("regionsize"))
      regionSize = lexicalCast<unsigned>(regionSizeOption->first());

    unsigned reportEvery = 20;
    if (auto reportEveryOption = options.parameters.maybe("reportevery"))
      reportEvery = lexicalCast<unsigned>(reportEveryOption->first());

    coutf("testing generation on coordinate {}\n", coordinate);

    auto worldParameters = celestialDatabase.parameters(coordinate).take();
    auto worldTemplate = make_shared<WorldTemplate>(worldParameters.visitableParameters(), SkyParameters(), worldParameters.seed());

    auto rand = RandomSource(worldTemplate->worldSeed());

    WorldServer worldServer(std::move(worldTemplate), File::ephemeralFile());
    Vec2U worldSize = worldServer.geometry().size();

    double start = Time::monotonicTime();
    double lastReport = Time::monotonicTime();

    coutf("Starting world generation for {} regions\n", regionsToGenerate);

    for (unsigned i = 0; i < regionsToGenerate; ++i) {
      if (i != 0 && i % reportEvery == 0) {
        float gps = reportEvery / (Time::monotonicTime() - lastReport);
        lastReport = Time::monotonicTime();
        coutf("[{}] {}s | Generatons Per Second: {}\n", i, Time::monotonicTime() - start, gps);
      }

      RectI region = RectI::withCenter(Vec2I(rand.randInt(0, worldSize[0]), rand.randInt(0, worldSize[1])), Vec2I::filled(regionSize));
      worldServer.generateRegion(region);
    }

    coutf("Finished generating {} regions with size {}x{} in world '{}' in {} seconds", regionsToGenerate, regionSize, regionSize, coordinate, Time::monotonicTime() - start);

    return 0;

  } catch (std::exception const& e) {
    cerrf("Exception caught: {}\n", outputException(e, true));
    return 1;
  }
}