Some refactoring of xmas code. Command line options:

--xmas=1 enables xmas hats anytime, --xmas=2 disables
it completely, and (default) --xmas=0 (default) switches
Xmas mode on between 17. of December and 9th of January.


git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@14396 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
hikerstk
2013-11-07 11:34:13 +00:00
parent bc0724935e
commit 376d60b8c6
8 changed files with 87 additions and 47 deletions

View File

@@ -483,9 +483,6 @@ namespace UserConfigParams
/** True if hardware skinning should be enabled */
PARAM_PREFIX bool m_hw_skinning_enabled PARAM_DEFAULT( false );
/** True if Christmas Mode should be enabled */
PARAM_PREFIX bool m_xmas_enabled PARAM_DEFAULT( false );
// not saved to file
// ---- Networking
@@ -521,6 +518,11 @@ namespace UserConfigParams
PARAM_DEFAULT( BoolUserConfigParam(true, "anim_gfx",
&m_graphics_quality, "Scenery animations") );
// This saves the actual user preference.
PARAM_PREFIX IntUserConfigParam m_xmas_mode
PARAM_DEFAULT( IntUserConfigParam(0, "christmas-mode",
&m_graphics_quality, "Christmas hats: 0 use calendar, 1 always on, 2 always off") );
PARAM_PREFIX BoolUserConfigParam m_weather_effects
PARAM_DEFAULT( BoolUserConfigParam(true, "weather_gfx",
&m_graphics_quality, "Weather effects") );

View File

@@ -192,15 +192,8 @@ void KartModel::loadInfo(const XMLNode &node)
if(const XMLNode *hat_node=node.getNode("hat"))
{
if(hat_node->get("offset", &m_hat_offset))
{
// Xmas mode handling :)
if(UserConfigParams::m_xmas_enabled)
setHatMeshName("christmas_hat.b3d");
}
hat_node->get("offset", &m_hat_offset);
}
else
m_hat_offset = core::vector3df(0,0,0);
} // loadInfo
// ----------------------------------------------------------------------------
@@ -357,7 +350,7 @@ scene::ISceneNode* KartModel::attachModel(bool animated_models)
std::string debug_name = m_model_filename+" (animated-kart-model)";
node->setName(debug_name.c_str());
#if SKELETON_DEBUG
irr_driber->addDebugMesh(m_animated_node);
irr_driver->addDebugMesh(m_animated_node);
#endif
#endif
m_animated_node->setLoopMode(false);

View File

@@ -419,6 +419,14 @@ public:
* should not be modified, not attachModel be called on it. */
const KartModel& getMasterKartModel() const {return *m_kart_model; }
// ------------------------------------------------------------------------
/** Sets the name of a mesh to be used for this kart.
* \param hat_name Name of the mesh.
*/
void setHatMeshName(const std::string &hat_name)
{
m_kart_model->setHatMeshName(hat_name);
} // setHatMeshName
// ------------------------------------------------------------------------
/** Returns the name of this kart.
\note Pass it through fridibi as needed, this is the LTR name

View File

@@ -232,6 +232,18 @@ bool KartPropertiesManager::loadKart(const std::string &dir)
return true;
} // loadKartData
//-----------------------------------------------------------------------------
/** Sets the name of a mesh to use as a hat for all karts.
* \param hat_name Name of the hat mash.
*/
void KartPropertiesManager::setHatMeshName(const std::string &hat_name)
{
for (int i=0; i<m_karts_properties.size(); i++)
{
m_karts_properties[i].setHatMeshName(hat_name);
}
} // setHatMeshName
//-----------------------------------------------------------------------------
/** Returns index of the kart properties with the given ident.
* \return Index of kart (between 0 and number of karts - 1).

View File

@@ -87,6 +87,7 @@ public:
void getRandomKartList(int count,
RemoteKartInfoList& existing_karts,
std::vector<std::string> *ai_list);
void setHatMeshName(const std::string &hat_name);
// ------------------------------------------------------------------------
/** Returns a list of all groups. */
const std::vector<std::string>& getAllGroups() const {return m_all_groups;}

View File

@@ -128,7 +128,6 @@
#else
# include <unistd.h>
#endif
#include <time.h>
#include <stdexcept>
#include <cstdio>
#include <string>
@@ -339,11 +338,38 @@ void gamepadVisualisation()
driver->endScene();
}
}
} // gamepadVisualisation
// ============================================================================
/** Sets the Christmas flag (m_xmas_enabled), depending on currently set
* Christ mode (m_xmas_mode)
*/
void handleXmasMode()
{
bool xmas = false;
switch(UserConfigParams::m_xmas_mode)
{
case 0:
{
int day, month;
StkTime::getDate(&day, &month);
// Christmat hats are shown between 17. of December
// and 9th of January
xmas = (month == 12 && day>=17) || (month == 1 && day <10);
break;
}
case 1: xmas = true; break;
default: xmas = false; break;
} // switch m_xmas_mode
if(xmas)
kart_properties_manager->setHatMeshName("christmas_hat.b3d");
} // handleXmasMode
void cmdLineHelp (char* invocation)
// ----------------------------------------------------------------------------
/** Prints help for command line options to stdout.
*/
void cmdLineHelp(char* invocation)
{
Log::info("main",
"Usage: %s [OPTIONS]\n\n"
@@ -466,14 +492,7 @@ int handleCmdLinePreliminary(int argc, char **argv)
}
else if ( sscanf(argv[i], "--xmas=%d", &n) )
{
if (n)
{
UserConfigParams::m_xmas_enabled = true;
}
else
{
UserConfigParams::m_xmas_enabled = false;
}
UserConfigParams::m_xmas_mode = n;
}
else if( !strcmp(argv[i], "--no-console"))
{
@@ -592,7 +611,7 @@ int handleCmdLinePreliminary(int argc, char **argv)
} // --verbose or -v
}
return 0;
}
} // handleCmdLinePreliminary
// ============================================================================
/** Handles command line options.
@@ -1113,8 +1132,7 @@ void initUserConfig(char *argv[])
irr_driver = new IrrDriver();
file_manager = new FileManager(argv);
user_config = new UserConfig(); // needs file_manager
const bool config_ok = user_config->loadConfig();
const bool config_ok = user_config->loadConfig();
if (UserConfigParams::m_language.toString() != "system")
{
#ifdef WIN32
@@ -1283,15 +1301,6 @@ bool ShowDumpResults(const wchar_t* dump_path,
}
#endif
static bool checkXmasTime()
{
time_t rawtime;
struct tm* timeinfo;
time(&rawtime);
timeinfo = localtime(&rawtime);
return (timeinfo->tm_mon == 12-1); // Xmas mode happens in December
}
#if defined(DEBUG) && defined(WIN32) && !defined(__CYGWIN__)
#pragma comment(linker, "/SUBSYSTEM:console")
#endif
@@ -1311,8 +1320,6 @@ int main(int argc, char *argv[] )
initUserConfig(argv); // argv passed so config file can be
// found more reliably
UserConfigParams::m_xmas_enabled = checkXmasTime();
handleCmdLinePreliminary(argc, argv);
initRest();
@@ -1335,6 +1342,7 @@ int main(int argc, char *argv[] )
GUIEngine::addLoadingIcon( irr_driver->getTexture(
file_manager->getGUIDir() + "options_video.png") );
kart_properties_manager -> loadAllKarts ();
handleXmasMode();
unlock_manager = new UnlockManager();
//m_tutorial_manager = new TutorialManager();
GUIEngine::addLoadingIcon( irr_driver->getTexture(

View File

@@ -17,8 +17,11 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "utils/time.hpp"
#include "graphics/irr_driver.hpp"
#include <ctime>
/** Returns a time based on an arbitrary 'epoch' (e.g. could be start
* time of the application, 1.1.1970, ...).
* The value is a double precision floating point value in seconds.
@@ -27,3 +30,19 @@ double StkTime::getRealTime(long startAt)
{
return irr_driver->getRealTime()/1000.0;
} // getTimeSinceEpoch
// ----------------------------------------------------------------------------
/** Returns the current date.
* \param day Day (1 - 31).
* \param month (1-12).
* \param year (4 digits).
*/
void StkTime::getDate(int *day, int *month, int *year)
{
std::time_t t = std::time(0); // get time now
std::tm * now = std::localtime(&t);
if(day) *day = now->tm_mday;
if(month) *month = now->tm_mon + 1;
if(year) *year = now->tm_year + 1900;
} // getDate

View File

@@ -37,7 +37,10 @@ class StkTime
public:
typedef time_t TimeType;
/** Converts the time in this object to a human readable string. */
static double getRealTime(long startAt=0);
static void getDate(int *day=NULL, int *month=NULL, int *year=NULL);
/** Converts the time in this object to a human readable string. */
static std::string toString(const TimeType &tt)
{
const struct tm *t = gmtime(&tt);
@@ -77,13 +80,6 @@ public:
#endif
}; // getTimeSinceEpoch
// ------------------------------------------------------------------------
/** Returns a time based on an arbitrary 'epoch' (e.g. could be start
* time of the application, 1.1.1970, ...).
* The value is a double precision floating point value in seconds.
*/
static double getRealTime(long startAt=0);
// ------------------------------------------------------------------------
/**
* \brief Compare two different times.
@@ -111,8 +107,9 @@ public:
t.tm_mon += month;
t.tm_mday += day;
return mktime(&t);
}
} // addInterval
// ------------------------------------------------------------------------
class ScopeProfiler
{
float m_time;
@@ -128,7 +125,7 @@ public:
float f2 = (float)getRealTime();
printf("} // took %f s\n", (f2 - m_time));
}
};
}; // class ScopeProfiler
}; // namespace time
#endif