nanoMMO 0.97.8
Building an MMO: The Engineering Series
Loading...
Searching...
No Matches
graph_main.cc
Go to the documentation of this file.
1// Writes the game's content as a graph in smollerGraph, into a folder that
2// smollerGraph's sg can serve, with its explorer, and says what a new player
3// can't reach:
4//
5// nanommo_graph content content.sg
6// sg serve content.sg 8474
7#include <iostream>
8#include <string>
9#include <vector>
10
11#include "absl/status/status.h"
12#include "absl/status/statusor.h"
13#include "content/content.h"
14#include "content/graph.h"
15#include "smollergraph/graph.h"
16
17int main(int argc, char** argv) {
18 if (argc != 3) {
19 std::cerr << "usage: nanommo_graph <content folder> <graph folder>\n";
20 return 1;
21 }
22 const absl::StatusOr<nanommo::Content> content =
23 nanommo::ReadContent(argv[1]);
24 if (!content.ok()) {
25 std::cerr << "nanommo_graph: " << content.status().message() << '\n';
26 return 1;
27 }
28 smollergraph::Graph graph;
29 absl::Status status = graph.Open(argv[2]);
30 if (status.ok()) status = nanommo::AddContentGraph(*content, graph);
31 if (!status.ok()) {
32 std::cerr << "nanommo_graph: " << status.message() << '\n';
33 return 1;
34 }
35 std::cout << graph.node_count() << " nodes, " << graph.relationship_count()
36 << " relationships\n";
37 absl::StatusOr<std::vector<std::string>> lines = nanommo::Unreachable(graph);
38 const absl::StatusOr<std::vector<std::string>> cycles =
39 nanommo::Cycles(graph);
40 if (!lines.ok() || !cycles.ok()) {
41 std::cerr << "nanommo_graph: "
42 << (lines.ok() ? cycles.status() : lines.status()).message()
43 << '\n';
44 return 1;
45 }
46 lines->insert(lines->end(), cycles->begin(), cycles->end());
47 for (const std::string& line : *lines) std::cout << line << '\n';
48 graph.Flush();
49 // Something out of reach, or that goes round, is an error, so a script can
50 // tell.
51 return lines->empty() ? 0 : 1;
52}
int main()
Definition login_main.cc:28
absl::StatusOr< std::vector< std::string > > Cycles(const smollergraph::Graph &graph)
Definition graph.cc:293
absl::Status AddContentGraph(const Content &content, smollergraph::Graph &graph)
Definition graph.cc:142
absl::StatusOr< std::vector< std::string > > Unreachable(const smollergraph::Graph &graph)
Definition graph.cc:257
absl::StatusOr< Content > ReadContent(const std::string &folder)
Reads each file in the folder, or says which file is wrong, and where.
Definition content.cc:64