Added support for setting zipper properties per material.

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@6502 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
hikerstk 2010-11-11 10:35:55 +00:00
parent 81be97dd56
commit 0d8f157ecc
4 changed files with 103 additions and 31 deletions

View File

@ -59,7 +59,6 @@ Material::Material(const XMLNode *node, int index)
node->get("sphere", &m_sphere_map );
node->get("friction", &m_friction );
node->get("ignore", &m_ignore );
node->get("zipper", &m_zipper );
node->get("reset", &m_resetter );
node->get("max-speed", &m_max_speed_fraction);
node->get("slowdown-time", &m_slowdown_time );
@ -78,6 +77,12 @@ Material::Material(const XMLNode *node, int index)
else
m_graphical_effect = GE_NONE;
node->get("zipper", &m_zipper );
node->get("zipper-duration", &m_zipper_duration );
node->get("zipper-fade-out-time", &m_zipper_fade_out_time );
node->get("zipper-max-speed-increase", &m_zipper_max_speed_increase);
node->get("zipper-speed-gain", &m_zipper_speed_gain );
// Terrain-specifc sound effect
for(unsigned int i=0; i<node->getNumNodes(); i++)
{
@ -118,27 +123,31 @@ Material::Material(const std::string& fname, int index, bool is_full_path)
*/
void Material::init(unsigned int index)
{
m_index = index;
m_clamp_tex = 0;
m_alpha_testing = false;
m_lightmap = false;
m_alpha_blending = false;
m_lighting = true;
m_anisotropic = false;
m_backface_culling = true;
m_sphere_map = false;
m_friction = 1.0f;
m_ignore = false;
m_zipper = false;
m_resetter = false;
m_max_speed_fraction = 1.0f;
m_slowdown_time = 1.0f;
m_sfx_name = "";
m_sfx_min_speed = 0.0f;
m_sfx_max_speed = 30;
m_sfx_min_pitch = 1.0f;
m_sfx_max_pitch = 1.0f;
m_graphical_effect = GE_NONE;
m_index = index;
m_clamp_tex = 0;
m_alpha_testing = false;
m_lightmap = false;
m_alpha_blending = false;
m_lighting = true;
m_anisotropic = false;
m_backface_culling = true;
m_sphere_map = false;
m_friction = 1.0f;
m_ignore = false;
m_resetter = false;
m_max_speed_fraction = 1.0f;
m_slowdown_time = 1.0f;
m_sfx_name = "";
m_sfx_min_speed = 0.0f;
m_sfx_max_speed = 30;
m_sfx_min_pitch = 1.0f;
m_sfx_max_pitch = 1.0f;
m_graphical_effect = GE_NONE;
m_zipper = false;
m_zipper_duration = -1.0f;
m_zipper_fade_out_time = -1.0f;
m_zipper_max_speed_increase = -1.0f;
m_zipper_speed_gain = -1.0f;
} // init
//-----------------------------------------------------------------------------

View File

@ -81,6 +81,20 @@ private:
* the pitch of a sfx depending on speed of the kart.
*/
float m_sfx_pitch_per_speed;
/** Additional speed allowed on top of the kart-specific maximum kart speed
* if a zipper is used. If this value is <0 the kart specific value will
* be used. */
float m_zipper_max_speed_increase;
/** Time a zipper stays activated. If this value is <0 the kart specific
* value will be used. */
float m_zipper_duration;
/** A one time additional speed gain - the kart will instantly add this
* amount of speed to its current speed. If this value is <0 the kart
* specific value will be used. */
float m_zipper_speed_gain;
/** Time it takes for the zipper advantage to fade out. If this value
* is <0 the kart specific value will be used. */
float m_zipper_fade_out_time;
void init (unsigned int index);
void install (bool is_full_path=false);
@ -96,6 +110,7 @@ public:
/** Returns the ITexture associated with this material. */
video::ITexture *getTexture() const { return m_texture; }
bool isIgnore () const { return m_ignore; }
/** Returns true if this material is a zipper. */
bool isZipper () const { return m_zipper; }
bool isSphereMap () const { return m_sphere_map; }
bool isReset () const { return m_resetter; }
@ -122,6 +137,18 @@ public:
* terrain. The string will be "" if no special sfx exists. */
const std::string &
getSFXName () const { return m_sfx_name; }
// ------------------------------------------------------------------------
/** Returns the zipper parametersfor the current material. */
void getZipperParameter(float *zipper_max_speed_increase,
float *zipper_duration,
float *zipper_speed_gain,
float *zipper_fade_out_time) const
{
*zipper_max_speed_increase = m_zipper_max_speed_increase;
*zipper_duration = m_zipper_duration;
*zipper_speed_gain = m_zipper_speed_gain;
} // getZipperParameter
} ;

View File

@ -848,7 +848,7 @@ void Kart::update(float dt)
m_last_material = material;
if (material->isReset() && isOnGround()) forceRescue();
else if(material->isZipper() && isOnGround()) handleZipper();
else if(material->isZipper() && isOnGround()) handleZipper(material);
else
{
MaxSpeed::setSlowdown(MaxSpeed::MS_DECREASE_TERRAIN,
@ -888,22 +888,58 @@ void Kart::update(float dt)
} // update
//-----------------------------------------------------------------------------
/** Sets zipper time, and apply one time additional speed boost.
/** Sets zipper time, and apply one time additional speed boost. It can be
* used with a specific material, in which case the zipper parmaters are
* taken from this material (parameters that are <0 will be using the
* kart-specific values from kart-properties.
* \param material If not NULL, will be used to determine the zipper
* parameters, otherwise the defaults from kart properties
* will be used.
*/
void Kart::handleZipper()
void Kart::handleZipper(const Material *material)
{
/** The additional speed allowed on top of the kart-specific maximum kart
* speed. */
float max_speed_increase;
/**Time the zipper stays activated. */
float duration;
/** A one time additional speed gain - the kart will instantly add this
* amount of speed to its current speed. */
float speed_gain;
/** Time it takes for the zipper advantage to fade out. */
float fade_out_time;
if(material)
{
material->getZipperParameter(&max_speed_increase, &duration,
&speed_gain, &fade_out_time);
if(max_speed_increase<0)
max_speed_increase = m_kart_properties->getZipperMaxSpeedIncrease();
if(duration<0)
duration = m_kart_properties->getZipperTime();
if(speed_gain<0)
speed_gain = m_kart_properties->getZipperSpeedGain();
if(fade_out_time<0)
fade_out_time = m_kart_properties->getZipperFadeOutTime();
}
else
{
max_speed_increase = m_kart_properties->getZipperMaxSpeedIncrease();
duration = m_kart_properties->getZipperTime();
speed_gain = m_kart_properties->getZipperSpeedGain();
fade_out_time = m_kart_properties->getZipperFadeOutTime();
}
// Ignore a zipper that's activated while braking
if(m_controls.m_brake) return;
MaxSpeed::increaseMaxSpeed(MaxSpeed::MS_INCREASE_ZIPPER,
m_kart_properties->getZipperMaxSpeedIncrease(),
m_kart_properties->getZipperTime(),
/*fade_out_time*/ 3.0f);
max_speed_increase, duration, fade_out_time);
// This will result in all max speed settings updated, but no
// changes to any slow downs since dt=0
MaxSpeed::update(0);
float speed = std::min(m_speed+m_kart_properties->getZipperSpeedGain(),
MaxSpeed::getCurrentMaxSpeed() );
float speed = std::min(m_speed + speed_gain,
MaxSpeed::getCurrentMaxSpeed() );
m_vehicle->activateZipper(speed);
// Play custom character sound (weee!)

View File

@ -235,7 +235,7 @@ public:
void updatedWeight ();
virtual void collectedItem (Item *item, int random_attachment);
virtual void reset ();
virtual void handleZipper ();
virtual void handleZipper (const Material *m=NULL);
virtual void crashed (Kart *k);
virtual void update (float dt);