SuperTuxKart
Loading...
Searching...
No Matches
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 <string>
23#include <vector>
24#include <map>
25
26class Track;
27
33{
34private:
36 static std::vector<std::string> m_track_search_path;
37
39 std::vector<std::string> m_all_track_dirs;
40
41 typedef std::vector<Track*> Tracks;
42
44 Tracks m_tracks;
45
46 typedef std::map<std::string, std::vector<int> > Group2Indices;
48 Group2Indices m_track_groups;
49
51 Group2Indices m_arena_groups;
52
54 Group2Indices m_soccer_arena_groups;
55
57 std::vector<std::string> m_track_group_names;
58
60 std::vector<std::string> m_arena_group_names;
61
63 std::vector<std::string> m_soccer_arena_group_names;
64
68 std::vector<bool> m_track_avail;
69
70 void updateGroups(const Track* track);
71
72public:
75 static void removeTrackSearchDirs();
76 static void addTrackSearchDir(const std::string &dir);
78 std::vector<std::string> getAllTrackIdentifiers();
79
81 void loadTrackList();
82 void removeTrack(const std::string &ident);
83 bool loadTrack(const std::string& dirname);
85 int getNumberOfRaceTracks() const;
86 Track* getTrack(const std::string& ident) const;
87 // ------------------------------------------------------------------------
91 void setUnavailableTracks(const std::vector<std::string> &tracks);
92 // ------------------------------------------------------------------------
94 const std::vector<std::string>* getAllTrackDirs() const
95 {
96 return &m_all_track_dirs;
97 } // getAllTrackDirs
98 // ------------------------------------------------------------------------
100 const std::vector<std::string>& getAllTrackGroups() const
101 {
102 return m_track_group_names;
103 } // getAllTrackGroups
104 // ------------------------------------------------------------------------
106 const std::vector<std::string>&
107 getAllArenaGroups(bool soccer_arena=false) const
108 {
109 return soccer_arena ? m_soccer_arena_group_names : m_arena_group_names;
110 } // getAllArenaGroups
111 // ------------------------------------------------------------------------
113 size_t getNumberOfTracks() const { return m_tracks.size(); }
114 // ------------------------------------------------------------------------
117 Track* getTrack(unsigned int index) const { return m_tracks[index];}
118 // ------------------------------------------------------------------------
119 int getTrackIndexByIdent(const std::string& ident) const;
120 // ------------------------------------------------------------------------
123 bool isAvailable(unsigned int n) const {return m_track_avail[n];}
124 // ------------------------------------------------------------------------
127 const std::vector<int>& getTracksInGroup(const std::string& g)
128 {
129 return m_track_groups[g];
130 } // getTracksInGroup
131 // ------------------------------------------------------------------------
134 const std::vector<int>&
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 void onDemandLoadTrackScreenshots();
141 // ------------------------------------------------------------------------
142 void updateScreenshotCache();
143}; // TrackManager
144
145extern TrackManager* track_manager;
146
147#endif // HEADER_TRACK_MANAGER_HPP
Simple class to load and manage track data, track names and such.
Definition: track_manager.hpp:33
std::vector< std::string > m_all_track_dirs
All directories in which tracks were found.
Definition: track_manager.hpp:39
~TrackManager()
Delete all tracks.
Definition: track_manager.cpp:51
std::vector< std::string > m_soccer_arena_group_names
List of the names of all groups containing soccer arenas.
Definition: track_manager.hpp:63
std::vector< std::string > getAllTrackIdentifiers()
Returns a list of all track identifiers.
Definition: track_manager.cpp:138
Track * getTrack(const std::string &ident) const
Get TrackData by the track identifier.
Definition: track_manager.cpp:92
const std::vector< std::string > * getAllTrackDirs() const
Returns a list of all directories that contain a track.
Definition: track_manager.hpp:94
std::vector< bool > m_track_avail
Flag if this track is available or not.
Definition: track_manager.hpp:68
TrackManager()
Constructor (currently empty).
Definition: track_manager.cpp:45
std::vector< std::string > m_track_group_names
List of the names of all groups containing tracks.
Definition: track_manager.hpp:57
void setUnavailableTracks(const std::vector< std::string > &tracks)
Sets a list of track as being unavailable (e.g.
Definition: track_manager.cpp:119
Tracks m_tracks
All track objects.
Definition: track_manager.hpp:44
void updateGroups(const Track *track)
Updates the groups after a track was read in.
Definition: track_manager.cpp:311
Group2Indices m_track_groups
List of all racing track groups.
Definition: track_manager.hpp:48
Group2Indices m_arena_groups
List of all arena groups.
Definition: track_manager.hpp:51
void removeTrack(const std::string &ident)
Removes a track.
Definition: track_manager.cpp:237
void removeAllCachedData()
Removes all cached data from all tracks.
Definition: track_manager.cpp:108
const std::vector< std::string > & getAllTrackGroups() const
Returns a list of the names of all used track groups.
Definition: track_manager.hpp:100
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:107
std::vector< std::string > m_arena_group_names
List of the names of all groups containing arenas.
Definition: track_manager.hpp:60
size_t getNumberOfTracks() const
Returns the number of tracks.
Definition: track_manager.hpp:113
const std::vector< int > & getTracksInGroup(const std::string &g)
Returns a list of all tracks in a given group.
Definition: track_manager.hpp:127
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:135
bool loadTrack(const std::string &dirname)
Tries to load a track from a single directory.
Definition: track_manager.cpp:195
Group2Indices m_soccer_arena_groups
List of all soccer arena groups.
Definition: track_manager.hpp:54
bool isAvailable(unsigned int n) const
Checks if a certain track is available.
Definition: track_manager.hpp:123
Track * getTrack(unsigned int index) const
Returns the track with a given index number.
Definition: track_manager.hpp:117
int getNumberOfRaceTracks() const
Returns the number of racing tracks.
Definition: track_manager.cpp:78
void loadTrackList()
Load all .track files from all directories.
Definition: track_manager.cpp:151
static std::vector< std::string > m_track_search_path
All directories in which tracks are searched.
Definition: track_manager.hpp:36
static void addTrackSearchDir(const std::string &dir)
Adds a directory from which tracks are loaded.
Definition: track_manager.cpp:69
Definition: track.hpp:114