1 // 2 // SuperTuxKart - a fun racing game with go-kart 3 // Copyright (C) 2006-2015 SuperTuxKart-Team 4 // 5 // This program is free software; you can redistribute it and/or 6 // modify it under the terms of the GNU General Public License 7 // as published by the Free Software Foundation; either version 3 8 // of the License, or (at your option) any later version. 9 // 10 // This program is distributed in the hope that it will be useful, 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 // GNU General Public License for more details. 14 // 15 // You should have received a copy of the GNU General Public License 16 // along with this program; if not, write to the Free Software 17 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 19 #ifndef HEADER_TRACK_MANAGER_HPP 20 #define HEADER_TRACK_MANAGER_HPP 21 22 #include <string> 23 #include <vector> 24 #include <map> 25 26 class Track; 27 28 /** 29 * \brief Simple class to load and manage track data, track names and such 30 * \ingroup tracks 31 */ 32 class TrackManager 33 { 34 private: 35 /** All directories in which tracks are searched. */ 36 static std::vector<std::string> m_track_search_path; 37 38 /** All directories in which tracks were found. */ 39 std::vector<std::string> m_all_track_dirs; 40 41 typedef std::vector<Track*> Tracks; 42 43 /** All track objects. */ 44 Tracks m_tracks; 45 46 typedef std::map<std::string, std::vector<int> > Group2Indices; 47 /** List of all racing track groups. */ 48 Group2Indices m_track_groups; 49 50 /** List of all arena groups. */ 51 Group2Indices m_arena_groups; 52 53 /** List of all soccer arena groups. */ 54 Group2Indices m_soccer_arena_groups; 55 56 /** List of the names of all groups containing tracks */ 57 std::vector<std::string> m_track_group_names; 58 59 /** List of the names of all groups containing arenas */ 60 std::vector<std::string> m_arena_group_names; 61 62 /** List of the names of all groups containing soccer arenas */ 63 std::vector<std::string> m_soccer_arena_group_names; 64 65 /** Flag if this track is available or not. Tracks are set unavailable 66 * if they are not available on all clients (applies only to network mode) 67 */ 68 std::vector<bool> m_track_avail; 69 70 void updateGroups(const Track* track); 71 72 public: 73 TrackManager(); 74 ~TrackManager(); 75 static void removeTrackSearchDirs(); 76 static void addTrackSearchDir(const std::string &dir); 77 /** Returns a list of all track identifiers. */ 78 std::vector<std::string> getAllTrackIdentifiers(); 79 80 /** Load all .track files from all directories */ 81 void loadTrackList(); 82 void removeTrack(const std::string &ident); 83 bool loadTrack(const std::string& dirname); 84 void removeAllCachedData(); 85 int getNumberOfRaceTracks() const; 86 Track* getTrack(const std::string& ident) const; 87 // ------------------------------------------------------------------------ 88 /** Sets a list of track as being unavailable (e.g. in network mode the 89 * track is not on all connected machines. 90 * \param tracks List of tracks to mark as unavilable. */ 91 void setUnavailableTracks(const std::vector<std::string> &tracks); 92 // ------------------------------------------------------------------------ 93 /** \brief Returns a list of all directories that contain a track. */ getAllTrackDirs() const94 const std::vector<std::string>* getAllTrackDirs() const 95 { 96 return &m_all_track_dirs; 97 } // getAllTrackDirs 98 // ------------------------------------------------------------------------ 99 /** \brief Returns a list of the names of all used track groups. */ getAllTrackGroups() const100 const std::vector<std::string>& getAllTrackGroups() const 101 { 102 return m_track_group_names; 103 } // getAllTrackGroups 104 // ------------------------------------------------------------------------ 105 /** \brief Returns a list of the names of all used arena groups. */ 106 const std::vector<std::string>& getAllArenaGroups(bool soccer_arena=false) const107 getAllArenaGroups(bool soccer_arena=false) const 108 { 109 return soccer_arena ? m_soccer_arena_group_names : m_arena_group_names; 110 } // getAllArenaGroups 111 // ------------------------------------------------------------------------ 112 /** Returns the number of tracks. */ getNumberOfTracks() const113 size_t getNumberOfTracks() const { return m_tracks.size(); } 114 // ------------------------------------------------------------------------ 115 /** Returns the track with a given index number. 116 * \param index The index number of the track. */ getTrack(unsigned int index) const117 Track* getTrack(unsigned int index) const { return m_tracks[index];} 118 // ------------------------------------------------------------------------ 119 int getTrackIndexByIdent(const std::string& ident) const; 120 // ------------------------------------------------------------------------ 121 /** Checks if a certain track is available. 122 * \param n Index of the track to check. */ isAvailable(unsigned int n) const123 bool isAvailable(unsigned int n) const {return m_track_avail[n];} 124 // ------------------------------------------------------------------------ 125 /** Returns a list of all tracks in a given group. 126 * \param g Name of the group. */ getTracksInGroup(const std::string & g)127 const std::vector<int>& getTracksInGroup(const std::string& g) 128 { 129 return m_track_groups[g]; 130 } // getTracksInGroup 131 // ------------------------------------------------------------------------ 132 /** Returns a list of all arenas in a given group. 133 * \param g Name of the group. */ 134 const std::vector<int>& getArenasInGroup(const std::string & g,bool soccer_arena=false)135 getArenasInGroup(const std::string& g, bool soccer_arena=false) 136 { 137 return soccer_arena ? m_soccer_arena_groups[g] : m_arena_groups[g]; 138 } // getArenasInGroup 139 140 }; // TrackManager 141 142 extern TrackManager* track_manager; 143 144 #endif // HEADER_TRACK_MANAGER_HPP 145