From caab8e9f9d87d4e4c22a74d0ac0eec490030a787 Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Sat, 14 May 2011 20:04:41 +0100 Subject: [PATCH] Add stub for track graph generator --- .gitignore | 1 + include/ITrackGraph.hpp | 34 +++++++++++++++++++++++++++++ include/IterateTrack.hpp | 2 +- src/Main.cpp | 21 ++++++++++++++---- src/TrackGraph.cpp | 47 ++++++++++++++++++++++++++++++++++++++++ src/Train.cpp | 2 +- 6 files changed, 101 insertions(+), 6 deletions(-) create mode 100644 include/ITrackGraph.hpp create mode 100644 src/TrackGraph.cpp diff --git a/.gitignore b/.gitignore index 9e8d6ca..ce5faad 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,4 @@ GG/ config.h core callgrind.out.* +*.dot diff --git a/include/ITrackGraph.hpp b/include/ITrackGraph.hpp new file mode 100644 index 0000000..6e595d7 --- /dev/null +++ b/include/ITrackGraph.hpp @@ -0,0 +1,34 @@ +// +// Copyright (C) 2011 Nick Gasson +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// + +#ifndef INC_ITRACK_GRAPH_HPP +#define INC_ITRACK_GRAPH_HPP + +#include "IMap.hpp" + +struct ITrackGraph { + virtual ~ITrackGraph() {} + + // Dump the track graph in DOT format for rendering with Graphviz + virtual void write_dot_file(const string& file) const = 0; +}; + +typedef shared_ptr ITrackGraphPtr; + +ITrackGraphPtr make_track_graph(IMapPtr map); + +#endif // INC_ITRACK_GRAPH_HPP diff --git a/include/IterateTrack.hpp b/include/IterateTrack.hpp index 07a3fd9..b882618 100644 --- a/include/IterateTrack.hpp +++ b/include/IterateTrack.hpp @@ -48,6 +48,6 @@ struct TrackIterator { // Kick off the iteration at an initial track segment TrackIterator iterate_track(IMapPtr a_map, track::Position a_position, - track::Direction a_direction); + track::Direction a_direction); #endif diff --git a/src/Main.cpp b/src/Main.cpp index a9fd695..c89e6d1 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -20,6 +20,7 @@ #include "GameScreens.hpp" #include "IResource.hpp" #include "IConfig.hpp" +#include "ITrackGraph.hpp" #include #include @@ -41,6 +42,11 @@ namespace { string action; } +static void dump_track_graph(IMapPtr map) +{ + make_track_graph(map)->write_dot_file(map_file + ".dot"); +} + static void parse_options(int argc, char** argv) { using namespace boost::program_options; @@ -103,8 +109,11 @@ int main(int argc, char** argv) init_resources(); IConfigPtr cfg = get_config(); - - ::window = make_sdl_window(); + + bool no_window = action == "graph"; + + if (!no_window) + ::window = make_sdl_window(); IScreenPtr screen; if (::action == "edit") { @@ -121,10 +130,14 @@ int main(int argc, char** argv) else if (::action == "uidemo") { screen = makeUIDemo(); } + else if (::action == "graph") { + dump_track_graph(load_map(::map_file)); + } else throw runtime_error("Unrecognised command: " + ::action); - - ::window->run(screen, run_cycles); + + if (::window) + ::window->run(screen, run_cycles); cfg->flush(); } diff --git a/src/TrackGraph.cpp b/src/TrackGraph.cpp new file mode 100644 index 0000000..95212ba --- /dev/null +++ b/src/TrackGraph.cpp @@ -0,0 +1,47 @@ +// +// Copyright (C) 2011 Nick Gasson +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// + +#include "ITrackGraph.hpp" +#include "ILogger.hpp" + +#include + +class TrackGraph : public ITrackGraph { +public: + TrackGraph(IMapPtr map); + + void write_dot_file(const string& file) const; +}; + +TrackGraph::TrackGraph(IMapPtr map) +{ + +} + +void TrackGraph::write_dot_file(const string& file) const +{ + ofstream of(file.c_str()); + if (!of.good()) + throw runtime_error("failed to open " + file); + + log() << "Wrote track graph to " << file; +} + +ITrackGraphPtr make_track_graph(IMapPtr map) +{ + return ITrackGraphPtr(new TrackGraph(map)); +} diff --git a/src/Train.cpp b/src/Train.cpp index a1ee43a..1d8d7f0 100644 --- a/src/Train.cpp +++ b/src/Train.cpp @@ -101,7 +101,7 @@ const double Train::SEPARATION(0.15); Train::Train(IMapPtr a_map) : map(a_map), velocity_vector(make_vector(0.0f, 0.0f, 0.0f)) { - parts.push_front(Part(load_engine("saddle"))); + parts.push_front(Part(load_engine("pclass"))); enter_segment(engine(), a_map->start()); -- 2.39.2