SuperTuxKart
Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
TrackManager Class Reference

Simple class to load and manage track data, track names and such. More...

#include <track_manager.hpp>

Public Member Functions

 TrackManager ()
 Constructor (currently empty). More...
 
 ~TrackManager ()
 Delete all tracks.
 
void setFavoriteTrackStatus (FavoriteStatus *status)
 Adds a track to the special group of favorite tracks. More...
 
void clearFavoriteTrackStatus ()
 Clears the list of active favorite tracks, used e.g. More...
 
std::vector< std::string > getAllTrackIdentifiers ()
 Returns a list of all track identifiers. More...
 
void loadTrackList ()
 Load all .track files from all directories. More...
 
void removeTrack (const std::string &ident)
 Removes a track. More...
 
bool loadTrack (const std::string &dirname)
 Tries to load a track from a single directory. More...
 
void removeAllCachedData ()
 Removes all cached data from all tracks. More...
 
int getNumberOfRaceTracks () const
 Returns the number of racing tracks. More...
 
TrackgetTrack (const std::string &ident) const
 Get TrackData by the track identifier. More...
 
void setUnavailableTracks (const std::vector< std::string > &tracks)
 Sets a list of track as being unavailable (e.g. More...
 
const std::vector< std::string > * getAllTrackDirs () const
 Returns a list of all directories that contain a track.
 
const std::vector< std::string > & getAllTrackGroups () const
 Returns a list of the names of all used track groups.
 
const std::vector< std::string > & getAllArenaGroups (bool soccer_arena=false) const
 Returns a list of the names of all used arena groups.
 
size_t getNumberOfTracks () const
 Returns the number of tracks.
 
TrackgetTrack (unsigned int index) const
 Returns the track with a given index number. More...
 
int getTrackIndexByIdent (const std::string &ident) const
 
bool isAvailable (unsigned int n) const
 Checks if a certain track is available. More...
 
const std::vector< int > & getTracksInGroup (const std::string &g)
 Returns a list of all tracks in a given group. More...
 
const std::vector< int > & getArenasInGroup (const std::string &g, bool soccer_arena=false)
 Returns a list of all arenas in a given group. More...
 
void onDemandLoadTrackScreenshots ()
 
void updateScreenshotCache ()
 

Static Public Member Functions

static void removeTrackSearchDirs ()
 
static void addTrackSearchDir (const std::string &dir)
 Adds a directory from which tracks are loaded. More...
 

Private Types

enum  TrackGroupType { RACING_TRACK = 0 , BATTLE_ARENA , SOCCER_ARENA }
 
typedef std::vector< Track * > Tracks
 
typedef std::map< std::string, std::vector< int > > Group2Indices
 

Private Member Functions

void updateAllGroups (const Track *track)
 Updates the groups after a track was read in. More...
 
void updateGroups (TrackGroupType type, const Track *track)
 
void removeTrackFromGroups (TrackGroupType type, const Track *track)
 Remove the track from all groups it belongs to in a group type. More...
 

Private Attributes

std::vector< std::string > m_all_track_dirs
 All directories in which tracks were found.
 
Tracks m_tracks
 All track objects.
 
Group2Indices m_track_groups
 List of all track indexes for each racing track group.
 
Group2Indices m_arena_groups
 List of all arena indexes for each arena group.
 
Group2Indices m_soccer_arena_groups
 List of all soccer arena indexes for each soccer arena group.
 
std::vector< std::string > m_track_group_names
 List of the names of all groups containing tracks.
 
std::vector< std::string > m_arena_group_names
 List of the names of all groups containing arenas.
 
std::vector< std::string > m_soccer_arena_group_names
 List of the names of all groups containing soccer arenas.
 
Group2Indices m_track_groups_no_custom
 Same as above but without user-defined groups.
 
Group2Indices m_arena_groups_no_custom
 
Group2Indices m_soccer_arena_groups_no_custom
 
std::vector< bool > m_track_avail
 Flag if this track is available or not. More...
 
FavoriteStatusm_current_favorite_status
 

Static Private Attributes

static std::vector< std::string > m_track_search_path
 All directories in which tracks are searched.
 

Detailed Description

Simple class to load and manage track data, track names and such.

Constructor & Destructor Documentation

◆ TrackManager()

TrackManager::TrackManager ( )

Constructor (currently empty).

The real work happens in loadTrackList.

Member Function Documentation

◆ addTrackSearchDir()

void TrackManager::addTrackSearchDir ( const std::string &  dir)
static

Adds a directory from which tracks are loaded.

The track manager checks if either this directory itself contains a track, and if any subdirectory contains a track.

Parameters
dirThe directory to add.

◆ clearFavoriteTrackStatus()

void TrackManager::clearFavoriteTrackStatus ( )

Clears the list of active favorite tracks, used e.g.

when switching between player profiles.

◆ getAllTrackIdentifiers()

std::vector< std::string > TrackManager::getAllTrackIdentifiers ( )

Returns a list of all track identifiers.

Returns a list with all track identifiert.

◆ getArenasInGroup()

const std::vector<int>& TrackManager::getArenasInGroup ( const std::string &  g,
bool  soccer_arena = false 
)
inline

Returns a list of all arenas in a given group.

Parameters
gName of the group.

◆ getNumberOfRaceTracks()

int TrackManager::getNumberOfRaceTracks ( ) const

Returns the number of racing tracks.

Those are tracks that are not internal (like cut scenes), arenas, or soccer fields.

◆ getTrack() [1/2]

Track * TrackManager::getTrack ( const std::string &  ident) const

Get TrackData by the track identifier.

Parameters
identIdentifier = basename of the directory the track is in.
Returns
The corresponding track object, or NULL if not found

◆ getTrack() [2/2]

Track* TrackManager::getTrack ( unsigned int  index) const
inline

Returns the track with a given index number.

Parameters
indexThe index number of the track.

◆ getTracksInGroup()

const std::vector<int>& TrackManager::getTracksInGroup ( const std::string &  g)
inline

Returns a list of all tracks in a given group.

Parameters
gName of the group.

◆ isAvailable()

bool TrackManager::isAvailable ( unsigned int  n) const
inline

Checks if a certain track is available.

Parameters
nIndex of the track to check.

◆ loadTrack()

bool TrackManager::loadTrack ( const std::string &  dirname)

Tries to load a track from a single directory.

Returns true if a track was successfully loaded.

Parameters
dirnameName of the directory to load the track from.

◆ loadTrackList()

void TrackManager::loadTrackList ( )

Load all .track files from all directories.

Loads all tracks from the track directory (data/track).

◆ removeAllCachedData()

void TrackManager::removeAllCachedData ( )

Removes all cached data from all tracks.

This is called when the screen resolution is changed and all textures need to be bound again.

◆ removeTrack()

void TrackManager::removeTrack ( const std::string &  ident)

Removes a track.

Parameters
identIdentifier of the track (i.e. the name of the directory).

◆ removeTrackFromGroups()

void TrackManager::removeTrackFromGroups ( TrackGroupType  type,
const Track track 
)
private

Remove the track from all groups it belongs to in a group type.

Parameters
typeThe type of track groups (battle arena, soccer arena, racing track)
trackThe track to be removed

◆ setFavoriteTrackStatus()

void TrackManager::setFavoriteTrackStatus ( FavoriteStatus status)

Adds a track to the special group of favorite tracks.

Adds a player's favorite track status to define the custom group.

We need to treat it specially, because the list of tracks in this group depends on the player-profile, not on the track data.

◆ setUnavailableTracks()

void TrackManager::setUnavailableTracks ( const std::vector< std::string > &  tracks)

Sets a list of track as being unavailable (e.g.

Sets all tracks that are not in the list a to be unavailable.

in network mode the track is not on all connected machines.

Parameters
tracksList of tracks to mark as unavilable.

This is used by the network manager upon receiving the list of available tracks from a client.

Parameters
tracksList of all track identifiere (available on a client).

◆ updateAllGroups()

void TrackManager::updateAllGroups ( const Track track)
private

Updates the groups after a track was read in.

Parameters
trackPointer to the new track, whose groups are now analysed.

Member Data Documentation

◆ m_track_avail

std::vector<bool> TrackManager::m_track_avail
private

Flag if this track is available or not.

Tracks are set unavailable if they are not available on all clients (applies only to network mode)


The documentation for this class was generated from the following files: