1180 Loading Grand Prix's from locale directory

This commit is contained in:
konstin 2014-03-06 11:30:51 +01:00
parent c09a3172f1
commit b561f440ba
6 changed files with 138 additions and 93 deletions

View File

@ -144,6 +144,48 @@ void PlayerManager::deletePlayer(PlayerProfile *player)
m_all_players.erase(player);
} // deletePlayer
// ----------------------------------------------------------------------------
/** This function makes sure that a current player is defined. This is called
* when a screen skipping command line option is given (-N, -R, ...), in
* which case there might not be a current player (if no default player is
* set in players.xml, i.e. the 'remember be' option was not picked ). Since
* a lot of code depends on having a local player, just set the most
* frequently used non-guest to be the current player.
*/
void PlayerManager::enforceCurrentPlayer()
{
if (m_current_player) return;
PlayerProfile *player;
for_in(player, m_all_players)
{
if (!player->isGuestAccount())
{
Log::info("PlayerManager", "Enfocring current player '%ls'.",
player->getName().c_str() );
m_current_player = player;
return;
}
} // for player in m_all_players
// This shouldn't happen - but just in case: add the default players
// again, and search again for a non-guest player.
addDefaultPlayer();
for_in(player, m_all_players)
{
if (!player->isGuestAccount())
{
Log::info("PlayerManager", "Enfocring current player '%s'.",
player->getName().c_str());
m_current_player = player;
return;
}
} // for player in m_all_players
// Now this really really should not happen.
Log::fatal("PlayerManager", "Failed to find a non-guest player.");
} // enforceCurrentPlayer
// ----------------------------------------------------------------------------
/** Called when no player profiles exists. It creates two players: one
* guest player, and one non-guest player for whic hit tries to guess a

View File

@ -78,6 +78,7 @@ public:
void deletePlayer(PlayerProfile *player);
void setCurrentPlayer(PlayerProfile *player, bool remember_me);
const PlayerProfile *getPlayerById(unsigned int id);
void enforceCurrentPlayer();
// ------------------------------------------------------------------------
/** Returns the current player. */
PlayerProfile* getCurrentPlayer() { return m_current_player; }

View File

@ -398,46 +398,46 @@ namespace UserConfigParams
"Always put the player at the back or not (Bully mode).") );
PARAM_PREFIX StringUserConfigParam m_additional_gp_directory
PARAM_DEFAULT( StringUserConfigParam("", "additional_gp_directory",
"Directory with additional GP's."));
"Directory with additional GP's."));
// ---- Video
PARAM_PREFIX GroupUserConfigParam m_video_group
PARAM_DEFAULT( GroupUserConfigParam("Video", "Video Settings") );
PARAM_PREFIX IntUserConfigParam m_width
PARAM_PREFIX IntUserConfigParam m_width
PARAM_DEFAULT( IntUserConfigParam(1024, "width", &m_video_group,
"Screen/window width in pixels") );
PARAM_PREFIX IntUserConfigParam m_height
PARAM_PREFIX IntUserConfigParam m_height
PARAM_DEFAULT( IntUserConfigParam(768, "height", &m_video_group,
"Screen/window height in pixels") );
PARAM_PREFIX BoolUserConfigParam m_fullscreen
PARAM_PREFIX BoolUserConfigParam m_fullscreen
PARAM_DEFAULT( BoolUserConfigParam(false, "fullscreen",
&m_video_group) );
PARAM_PREFIX IntUserConfigParam m_prev_width
PARAM_PREFIX IntUserConfigParam m_prev_width
PARAM_DEFAULT( IntUserConfigParam(1024, "prev_width",
&m_video_group, "Previous screen/window width") );
PARAM_PREFIX IntUserConfigParam m_prev_height
PARAM_PREFIX IntUserConfigParam m_prev_height
PARAM_DEFAULT( IntUserConfigParam(768, "prev_height",
&m_video_group,"Previous screen/window height") );
PARAM_PREFIX BoolUserConfigParam m_prev_fullscreen
PARAM_PREFIX BoolUserConfigParam m_prev_fullscreen
PARAM_DEFAULT( BoolUserConfigParam(false, "prev_fullscreen",
&m_video_group) );
PARAM_PREFIX BoolUserConfigParam m_remember_window_location
PARAM_PREFIX BoolUserConfigParam m_remember_window_location
PARAM_DEFAULT( BoolUserConfigParam(false, "remember_window_location",
&m_video_group) );
PARAM_PREFIX IntUserConfigParam m_window_x
PARAM_PREFIX IntUserConfigParam m_window_x
PARAM_DEFAULT( IntUserConfigParam(-1, "window_x",
&m_video_group,"If remember_window_location is true") );
PARAM_PREFIX IntUserConfigParam m_window_y
PARAM_PREFIX IntUserConfigParam m_window_y
PARAM_DEFAULT( IntUserConfigParam(-1, "window_y",
&m_video_group,"If remember_window_location is true") );
PARAM_PREFIX BoolUserConfigParam m_display_fps
PARAM_PREFIX BoolUserConfigParam m_display_fps
PARAM_DEFAULT( BoolUserConfigParam(false, "show_fps",
&m_video_group, "Display frame per seconds") );
PARAM_PREFIX IntUserConfigParam m_max_fps
PARAM_PREFIX IntUserConfigParam m_max_fps
PARAM_DEFAULT( IntUserConfigParam(120, "max_fps",
&m_video_group, "Maximum fps, should be at least 60") );

View File

@ -392,21 +392,19 @@ void cmdLineHelp()
{
Log::info("main",
"Usage: %s [OPTIONS]\n\n"
"Run SuperTuxKart, a racing game with go-kart that features"
" the Tux and friends.\n\n"
"Options:\n"
" -N, --no-start-screen Immediately start race without showing a "
"menu.\n"
" -R, --race-now Same as -N but also skip the ready-set-go phase "
"and the music.\n"
" -R, --race-now Same as -N but also skip the ready-set-go phase"
" and the music.\n"
" -t, --track=NAME Start at track NAME.\n"
" --gp=NAME Start the specified Grand Prix.\n"
" --stk-config=FILE use ./data/FILE instead of "
"./data/stk_config.xml\n"
" --add-gp-dir=DIR Load Grand Prixs in DIR. Setting will be saved "
"in config.xml\n"
" --stk-config=FILE use ./data/FILE instead of "
"./data/stk_config.xml\n"
" -k, --numkarts=NUM Number of karts on the racetrack.\n"
" --kart=NAME Use kart number NAME.\n"
" --ai=a,b,... Use the karts a, b, ... for the AI.\n"
@ -471,7 +469,8 @@ int handleCmdLinePreliminary()
cmdLineHelp();
exit(0);
}
if( CommandLine::has("--gamepad-visualisation") )
if( CommandLine::has("--gamepad-visualisation") ||
CommandLine::has("--gamepad-visualization") )
UserConfigParams::m_gamepad_visualisation=true;
if( CommandLine::has("--debug=memory"))
UserConfigParams::m_verbosity |= UserConfigParams::LOG_MEMORY;
@ -501,15 +500,15 @@ int handleCmdLinePreliminary()
if( CommandLine::has( "--stk-config", &s))
{
stk_config->load(file_manager->getAsset(s));
Log::info("main", "STK config will be read from %s.", s.c_str());
Log::info("main", "STK config will be read from %s.",s.c_str());
}
if( CommandLine::has( "--trackdir", &s))
TrackManager::addTrackSearchDir(s);
if( CommandLine::has( "--kartdir", &s))
KartPropertiesManager::addKartSearchDir(s);
if( CommandLine::has("--no-graphics") ||
CommandLine::has("-l" ) )
if( CommandLine::has( "--no-graphics") ||
CommandLine::has("-l" ) )
{
ProfileWorld::disableGraphics();
UserConfigParams::m_log_errors_to_console=true;
@ -542,14 +541,13 @@ int handleCmdLinePreliminary()
}
else
Log::warn("main", "Resolution %s has been blacklisted, so "
"it is not available!", res.c_str());
"it is not available!", res.c_str());
}
else
{
Log::fatal("main", "Error: --screensize argument must be given as "
"WIDTHxHEIGHT");
Log::fatal("main", "Error: --screensize argument must be "
"given as WIDTHxHEIGHT");
}
}
@ -586,13 +584,7 @@ int handleCmdLinePreliminary()
IRRLICHT_VERSION_REVISION, IRRLICHT_SDK_VERSION );
Log::info("main", "==============================");
} // --verbose or -v
int n;
if(CommandLine::has("--xmas", &n))
UserConfigParams::m_xmas_mode = n;
if(CommandLine::has("--log", &n))
Log::setLogLevel(n);
// Enable loading GP's from local directory
if(CommandLine::has("--add-gp-dir", &s))
{
@ -602,10 +594,16 @@ int handleCmdLinePreliminary()
else
UserConfigParams::m_additional_gp_directory = s + "/";
Log::info("main", "Additional Grand Prix will be loaded from %s",
UserConfigParams::m_additional_gp_directory.c_str());
Log::info("main", "Additional Grand Prix's will be loaded from %s",
UserConfigParams::m_additional_gp_directory.c_str());
}
int n;
if(CommandLine::has("--xmas", &n))
UserConfigParams::m_xmas_mode = n;
if(CommandLine::has("--log", &n))
Log::setLogLevel(n);
return 0;
} // handleCmdLinePreliminary
@ -1078,18 +1076,43 @@ void initRest()
} // initRest
//=============================================================================
#ifdef BREAKPAD
bool ShowDumpResults(const wchar_t* dump_path,
const wchar_t* minidump_id,
void* context,
EXCEPTION_POINTERS* exinfo,
MDRawAssertionInfo* assertion,
bool succeeded)
void askForInternetPermission()
{
wprintf(L"Path: %s id %s.\n", dump_path, minidump_id);
return succeeded;
}
#endif
if (UserConfigParams::m_internet_status ==
Online::RequestManager::IPERM_NOT_ASKED)
{
class ConfirmServer :
public MessageDialog::IConfirmDialogListener
{
public:
virtual void onConfirm()
{
UserConfigParams::m_internet_status =
Online::RequestManager::IPERM_ALLOWED;
GUIEngine::ModalDialog::dismiss();
} // onConfirm
// --------------------------------------------------------
virtual void onCancel()
{
UserConfigParams::m_internet_status =
Online::RequestManager::IPERM_NOT_ALLOWED;
GUIEngine::ModalDialog::dismiss();
} // onCancel
}; // ConfirmServer
new MessageDialog(_("SuperTuxKart may connect to a server "
"to download add-ons and notify you of updates. Would you "
"like this feature to be enabled? (To change this setting "
"at a later time, go to options, select tab "
"'User Interface', and edit \"Allow STK to connect to the "
"Internet\")."),
MessageDialog::MESSAGE_DIALOG_CONFIRM,
new ConfirmServer(), true);
}
} // askForInternetPermission
//=============================================================================
#if defined(DEBUG) && defined(WIN32) && !defined(__CYGWIN__)
#pragma comment(linker, "/SUBSYSTEM:console")
@ -1098,10 +1121,6 @@ bool ShowDumpResults(const wchar_t* dump_path,
// ----------------------------------------------------------------------------
int main(int argc, char *argv[] )
{
#ifdef BREAKPAD
google_breakpad::ExceptionHandler eh(L"C:\\Temp", NULL, ShowDumpResults,
NULL, google_breakpad::ExceptionHandler::HANDLER_ALL);
#endif
CommandLine::init(argc, argv);
CrashReporting::installHandlers();
@ -1161,8 +1180,7 @@ int main(int argc, char *argv[] )
// Both item_manager and powerup_manager load models and therefore
// textures from the model directory. To avoid reading the
// materials.xml twice, we do this here once for both:
file_manager->pushTextureSearchPath(file_manager->getAsset(
FileManager::MODEL,""));
file_manager->pushTextureSearchPath(file_manager->getAsset(FileManager::MODEL,""));
const std::string materials_file =
file_manager->getAsset(FileManager::MODEL,"materials.xml");
if(materials_file!="")
@ -1227,40 +1245,15 @@ int main(int argc, char *argv[] )
wiimote_manager->askUserToConnectWiimotes();
}
#endif
if(UserConfigParams::m_internet_status ==
Online::RequestManager::IPERM_NOT_ASKED)
{
class ConfirmServer :
public MessageDialog::IConfirmDialogListener
{
public:
virtual void onConfirm()
{
UserConfigParams::m_internet_status =
Online::RequestManager::IPERM_ALLOWED;
GUIEngine::ModalDialog::dismiss();
} // onConfirm
// --------------------------------------------------------
virtual void onCancel()
{
UserConfigParams::m_internet_status =
Online::RequestManager::IPERM_NOT_ALLOWED;
GUIEngine::ModalDialog::dismiss();
} // onCancel
}; // ConfirmServer
new MessageDialog(_("SuperTuxKart may connect to a server "
"to download add-ons and notify you of updates. Would you "
"like this feature to be enabled? (To change this setting "
"at a later time, go to options, select tab "
"'User Interface', and edit \"Allow STK to connect to the "
"Internet\")."),
MessageDialog::MESSAGE_DIALOG_CONFIRM,
new ConfirmServer(), true);
}
askForInternetPermission();
}
else
{
// Skip the start screen. This esp. means that no login screen is
// displayed (if necessary), so we have to make sure there is
// a current player
PlayerManager::get()->enforceCurrentPlayer();
InputDevice *device;
// Use keyboard 0 by default in --no-start-screen

View File

@ -37,10 +37,14 @@ GrandPrixManager::GrandPrixManager()
if (StringUtils::hasSuffix(*i, ".grandprix"))
{
try
{ m_gp_data.push_back(new GrandPrixData(*i)); }
catch (std::logic_error& er)
{ Log::error("GrandPrixManager", "Ignoring GP %s ( %s ) \n",
i->c_str(), er.what()); }
{
m_gp_data.push_back(new GrandPrixData(*i));
}
catch (std::logic_error& e)
{
Log::error("GrandPrixManager", "Ignoring GP %s ( %s ) \n",
i->c_str(), e.what());
}
}
}
@ -54,10 +58,14 @@ GrandPrixManager::GrandPrixManager()
if (StringUtils::hasSuffix(*i, ".grandprix"))
{
try
{ m_gp_data.push_back(new GrandPrixData(dir, *i)); }
catch (std::logic_error& er)
{ Log::error("GrandPrixManager", "Ignoring GP %s ( %s ) \n",
i->c_str(), er.what()); }
{
m_gp_data.push_back(new GrandPrixData(dir, *i));
}
catch (std::logic_error& e)
{
Log::error("GrandPrixManager", "Ignoring GP %s ( %s ) \n",
i->c_str(), e.what());
}
}
}
}

View File

@ -34,9 +34,10 @@ private:
public:
GrandPrixManager();
~GrandPrixManager();
const GrandPrixData* getGrandPrix(int i) const {return m_gp_data[i]; }
void load(const std::string &filename);
const GrandPrixData* getGrandPrix(int i) const { return m_gp_data[i]; }
const GrandPrixData* getGrandPrix(const std::string& s) const;
unsigned int getNumberOfGrandPrix() const {return m_gp_data.size();}
unsigned int getNumberOfGrandPrix() const { return m_gp_data.size(); }
void checkConsistency();
}; // GrandPrixManager