SuperTuxKart
track_manager.hpp
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 "config/favorite_status.hpp"
23 
24 #include <string>
25 #include <vector>
26 #include <map>
27 
28 class Track;
29 
35 {
36 private:
37  enum TrackGroupType
38  {
39  RACING_TRACK = 0,
40  BATTLE_ARENA,
41  SOCCER_ARENA
42  };
43 
45  static std::vector<std::string> m_track_search_path;
46 
48  std::vector<std::string> m_all_track_dirs;
49 
50  typedef std::vector<Track*> Tracks;
51 
53  Tracks m_tracks;
54 
55  typedef std::map<std::string, std::vector<int> > Group2Indices;
57  Group2Indices m_track_groups;
58 
60  Group2Indices m_arena_groups;
61 
63  Group2Indices m_soccer_arena_groups;
64 
66  std::vector<std::string> m_track_group_names;
67 
69  std::vector<std::string> m_arena_group_names;
70 
72  std::vector<std::string> m_soccer_arena_group_names;
73 
75  Group2Indices m_track_groups_no_custom;
76  Group2Indices m_arena_groups_no_custom;
77  Group2Indices m_soccer_arena_groups_no_custom;
78 
82  std::vector<bool> m_track_avail;
83 
84  FavoriteStatus *m_current_favorite_status;
85 
86  void updateAllGroups(const Track* track);
87  void updateGroups(TrackGroupType type, const Track* track);
88  void removeTrackFromGroups(TrackGroupType type, const Track* track);
89 
90 public:
91  TrackManager();
92  ~TrackManager();
93  static void removeTrackSearchDirs();
94  static void addTrackSearchDir(const std::string &dir);
95 
100 
102 
104  std::vector<std::string> getAllTrackIdentifiers();
105 
107  void loadTrackList();
108  void removeTrack(const std::string &ident);
109  bool loadTrack(const std::string& dirname);
110  void removeAllCachedData();
111  int getNumberOfRaceTracks() const;
112  Track* getTrack(const std::string& ident) const;
113  // ------------------------------------------------------------------------
117  void setUnavailableTracks(const std::vector<std::string> &tracks);
118  // ------------------------------------------------------------------------
120  const std::vector<std::string>* getAllTrackDirs() const
121  {
122  return &m_all_track_dirs;
123  } // getAllTrackDirs
124  // ------------------------------------------------------------------------
126  const std::vector<std::string>& getAllTrackGroups() const
127  {
128  return m_track_group_names;
129  } // getAllTrackGroups
130  // ------------------------------------------------------------------------
132  const std::vector<std::string>&
133  getAllArenaGroups(bool soccer_arena=false) const
134  {
135  return soccer_arena ? m_soccer_arena_group_names : m_arena_group_names;
136  } // getAllArenaGroups
137  // ------------------------------------------------------------------------
139  size_t getNumberOfTracks() const { return m_tracks.size(); }
140  // ------------------------------------------------------------------------
143  Track* getTrack(unsigned int index) const { return m_tracks[index];}
144  // ------------------------------------------------------------------------
145  int getTrackIndexByIdent(const std::string& ident) const;
146  // ------------------------------------------------------------------------
149  bool isAvailable(unsigned int n) const {return m_track_avail[n];}
150  // ------------------------------------------------------------------------
153  const std::vector<int>& getTracksInGroup(const std::string& g)
154  {
155  return m_track_groups[g];
156  } // getTracksInGroup
157  // ------------------------------------------------------------------------
160  const std::vector<int>&
161  getArenasInGroup(const std::string& g, bool soccer_arena=false)
162  {
163  return soccer_arena ? m_soccer_arena_groups[g] : m_arena_groups[g];
164  } // getArenasInGroup
165  // ------------------------------------------------------------------------
166  void onDemandLoadTrackScreenshots();
167  // ------------------------------------------------------------------------
168  void updateScreenshotCache();
169 }; // TrackManager
170 
171 extern TrackManager* track_manager;
172 
173 #endif // HEADER_TRACK_MANAGER_HPP
Class for storing the current favorites/custom groups of karts and tracks.
Definition: favorite_status.hpp:43
Simple class to load and manage track data, track names and such.
Definition: track_manager.hpp:35
Track * getTrack(unsigned int index) const
Returns the track with a given index number.
Definition: track_manager.hpp:143
void updateAllGroups(const Track *track)
Updates the groups after a track was read in.
Definition: track_manager.cpp:372
std::vector< std::string > m_all_track_dirs
All directories in which tracks were found.
Definition: track_manager.hpp:48
~TrackManager()
Delete all tracks.
Definition: track_manager.cpp:53
std::vector< std::string > m_soccer_arena_group_names
List of the names of all groups containing soccer arenas.
Definition: track_manager.hpp:72
void setFavoriteTrackStatus(FavoriteStatus *status)
Adds a track to the special group of favorite tracks.
Definition: track_manager.cpp:436
std::vector< std::string > getAllTrackIdentifiers()
Returns a list of all track identifiers.
Definition: track_manager.cpp:140
Track * getTrack(const std::string &ident) const
Get TrackData by the track identifier.
Definition: track_manager.cpp:94
void clearFavoriteTrackStatus()
Clears the list of active favorite tracks, used e.g.
Definition: track_manager.cpp:495
std::vector< bool > m_track_avail
Flag if this track is available or not.
Definition: track_manager.hpp:82
TrackManager()
Constructor (currently empty).
Definition: track_manager.cpp:45
Group2Indices m_track_groups_no_custom
Same as above but without user-defined groups.
Definition: track_manager.hpp:75
std::vector< std::string > m_track_group_names
List of the names of all groups containing tracks.
Definition: track_manager.hpp:66
void setUnavailableTracks(const std::vector< std::string > &tracks)
Sets a list of track as being unavailable (e.g.
Definition: track_manager.cpp:121
Tracks m_tracks
All track objects.
Definition: track_manager.hpp:53
Group2Indices m_track_groups
List of all track indexes for each racing track group.
Definition: track_manager.hpp:57
const std::vector< std::string > * getAllTrackDirs() const
Returns a list of all directories that contain a track.
Definition: track_manager.hpp:120
Group2Indices m_arena_groups
List of all arena indexes for each arena group.
Definition: track_manager.hpp:60
void removeTrack(const std::string &ident)
Removes a track.
Definition: track_manager.cpp:245
void removeAllCachedData()
Removes all cached data from all tracks.
Definition: track_manager.cpp:110
const std::vector< int > & getTracksInGroup(const std::string &g)
Returns a list of all tracks in a given group.
Definition: track_manager.hpp:153
const std::vector< int > & getArenasInGroup(const std::string &g, bool soccer_arena=false)
Returns a list of all arenas in a given group.
Definition: track_manager.hpp:161
std::vector< std::string > m_arena_group_names
List of the names of all groups containing arenas.
Definition: track_manager.hpp:69
size_t getNumberOfTracks() const
Returns the number of tracks.
Definition: track_manager.hpp:139
void removeTrackFromGroups(TrackGroupType type, const Track *track)
Remove the track from all groups it belongs to in a group type.
Definition: track_manager.cpp:304
bool loadTrack(const std::string &dirname)
Tries to load a track from a single directory.
Definition: track_manager.cpp:203
Group2Indices m_soccer_arena_groups
List of all soccer arena indexes for each soccer arena group.
Definition: track_manager.hpp:63
bool isAvailable(unsigned int n) const
Checks if a certain track is available.
Definition: track_manager.hpp:149
const std::vector< std::string > & getAllArenaGroups(bool soccer_arena=false) const
Returns a list of the names of all used arena groups.
Definition: track_manager.hpp:133
int getNumberOfRaceTracks() const
Returns the number of racing tracks.
Definition: track_manager.cpp:80
const std::vector< std::string > & getAllTrackGroups() const
Returns a list of the names of all used track groups.
Definition: track_manager.hpp:126
void loadTrackList()
Load all .track files from all directories.
Definition: track_manager.cpp:153
static std::vector< std::string > m_track_search_path
All directories in which tracks are searched.
Definition: track_manager.hpp:45
static void addTrackSearchDir(const std::string &dir)
Adds a directory from which tracks are loaded.
Definition: track_manager.cpp:71
Definition: track.hpp:115