From e76c1dc87cc465e68201c46882a310ce0c822b91 Mon Sep 17 00:00:00 2001 From: hikerstk Date: Mon, 8 Dec 2008 01:07:16 +0000 Subject: [PATCH] 1) The number of drivelines per kart is now limited (stk_config.data setting) 2) Reduced smoke effect somewhat (and made it dependent on actually turning the wheel) 3) Removed skid marks when restarting a race. git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@2576 178a84e3-b1eb-0310-8ba1-8eac791a3b58 --- data/stk_config.data | 1 + src/graphics/skid_marks.cpp | 77 +++++++++++++++++++++++-------------- src/graphics/skid_marks.hpp | 15 ++++---- src/graphics/smoke.cpp | 2 +- src/karts/kart.cpp | 8 +++- src/stk_config.cpp | 3 ++ src/stk_config.hpp | 1 + 7 files changed, 67 insertions(+), 40 deletions(-) diff --git a/data/stk_config.data b/data/stk_config.data index 6eea6bb19..7bc9f773f 100644 --- a/data/stk_config.data +++ b/data/stk_config.data @@ -13,6 +13,7 @@ (menu-background "st_title_screen.rgb") (game-style "nitro") ;; "wheelie" or "nitro" (max-history 10000) ;; maximum number of history frames. + (max-skidmarks 100) ;; max. number of skidmarks per kart. (delay-finish-time 10) ;; delay till race results are displayed. (music-credit-time 10) ;; time for which the music credits are displayed. diff --git a/src/graphics/skid_marks.cpp b/src/graphics/skid_marks.cpp index 6fa5f743e..7c3fd14ff 100644 --- a/src/graphics/skid_marks.cpp +++ b/src/graphics/skid_marks.cpp @@ -27,33 +27,42 @@ /** Initialises empty skid marks. */ SkidMarks::SkidMarks(const Kart& kart, float width) : m_kart(kart) { - m_width = width; - m_skid_state = new ssgSimpleState(); + m_width = width; + m_skid_state = new ssgSimpleState(); m_skid_state->ref(); m_skid_state->enable(GL_BLEND); - //This is just for the skidmarks, so the ones drawn when the kart is in - //reverse get drawn -// m_skid_state -> disable (GL_CULL_FACE); m_skid_marking = false; + m_current = -1; } // SkidMark //----------------------------------------------------------------------------- +/** Removes all skid marks from the scene graph and frees the state. */ SkidMarks::~SkidMarks() { -#ifdef NOTYET - if(!m_skid_marks.empty()) - { - const unsigned int SIZE = (unsigned int)m_skid_marks.size() -1; - for(unsigned int i = 0; i < SIZE; ++i) - { - ssgDeRefDelete(m_skid_marks[i]); - } // for - } // if !empty + reset(); // remove all skid marks ssgDeRefDelete(m_skid_state); -#endif } // ~SkidMarks //----------------------------------------------------------------------------- +/** Removes all skid marks, called when a race is restarted. + */ +void SkidMarks::reset() +{ + for(unsigned int i=0; iremove(m_left[i]); + scene->remove(m_right[i]); + } + m_left.clear(); + m_right.clear(); + m_skid_marking = false; +} // reset + +//----------------------------------------------------------------------------- +/** Either adds to an existing skid mark quad, or (if the kart is skidding) + * starts a new skid mark quad. + * \param dt Time step. + */ void SkidMarks::update(float dt) { if(m_skid_marking) @@ -66,8 +75,6 @@ void SkidMarks::update(float dt) m_kart.getVehicle()->getWheelInfo(3).m_raycastInfo; Vec3 delta = raycast_right.m_contactPointWS - raycast_left.m_contactPointWS; - int current=m_left.size()-1; - // We were skid marking, but not anymore (either because the // wheels don't touch the ground, or the kart has stopped // skidding). One special case: the physics force both wheels @@ -80,8 +87,8 @@ void SkidMarks::update(float dt) delta.length2()<0.0001) { m_skid_marking = false; - m_left[current]->makeDList(); - m_right[current]->makeDList(); + m_left[m_current]->makeDList(); + m_right[m_current]->makeDList(); return; } @@ -91,10 +98,10 @@ void SkidMarks::update(float dt) delta.normalize(); delta *= m_width; - m_left [current]->add(raycast_left.m_contactPointWS, - raycast_left.m_contactPointWS + delta); - m_right[current]->add(raycast_right.m_contactPointWS-delta, - raycast_right.m_contactPointWS); + m_left [m_current]->add(raycast_left.m_contactPointWS, + raycast_left.m_contactPointWS + delta); + m_right[m_current]->add(raycast_right.m_contactPointWS-delta, + raycast_right.m_contactPointWS); return; } @@ -108,6 +115,7 @@ void SkidMarks::update(float dt) m_kart.getVehicle()->getWheelInfo(2).m_raycastInfo; // No skidmarking if wheels don't have contact if(!raycast_right.m_isInContact) return; + const btWheelInfo::RaycastInfo raycast_left = m_kart.getVehicle()->getWheelInfo(3).m_raycastInfo; @@ -123,13 +131,28 @@ void SkidMarks::update(float dt) raycast_left.m_contactPointWS + delta, m_skid_state); scene->add(smq_left); - m_left.push_back(smq_left); SkidMarkQuads *smq_right = new SkidMarkQuads(raycast_right.m_contactPointWS - delta, raycast_right.m_contactPointWS, m_skid_state); scene->add(smq_right); - m_right.push_back(smq_right); + m_current++; + if(m_current>=stk_config->m_max_skidmarks) + m_current = 0; + if(m_current>=(int)m_left.size()) + { + m_left. push_back(smq_left ); + m_right.push_back(smq_right); + } + else + { + scene->remove(m_left [m_current]); + scene->remove(m_right[m_current]); + m_left [m_current] = smq_left; + m_right[m_current] = smq_right; + } + + m_skid_marking = true; } // update @@ -148,10 +171,6 @@ SkidMarks::SkidMarkQuads::SkidMarkQuads(const Vec3 &left, const Vec3 &right, } // SkidMarkQuads -//----------------------------------------------------------------------------- -SkidMarks::SkidMarkQuads::~SkidMarkQuads() -{} // ~SkidMarkPos - //----------------------------------------------------------------------------- void SkidMarks::SkidMarkQuads::recalcBSphere() { diff --git a/src/graphics/skid_marks.hpp b/src/graphics/skid_marks.hpp index 67c98fda2..8e81943e4 100644 --- a/src/graphics/skid_marks.hpp +++ b/src/graphics/skid_marks.hpp @@ -39,30 +39,29 @@ private: bool m_skid_marking; /** Reduce effect of Z-fighting. */ float m_width; + /** Index of current (last added) skid mark quad. */ + int m_current; class SkidMarkQuads : public ssgVtxTable { public: - SkidMarkQuads (const Vec3 &left, const Vec3 &right, - ssgSimpleState *state); - ~SkidMarkQuads(); + SkidMarkQuads (const Vec3 &left, const Vec3 &right, + ssgSimpleState *state); void recalcBSphere(); void add (const Vec3 &left, const Vec3 &right); - private: - float m_track_offset; // Amount of which the skidmark is lifted - // above the track to avoid z-buffer errors }; // SkidMarkQuads /** Two skidmark objects for the left and right wheel. */ std::vector m_left, m_right; - ssgSimpleState *m_skid_state; + /** The state for colour etc. */ + ssgSimpleState *m_skid_state; public: SkidMarks(const Kart& kart, float width=0.2f); ~SkidMarks(); void update (float dt); - + void reset(); }; // SkidMarks #endif diff --git a/src/graphics/smoke.cpp b/src/graphics/smoke.cpp index 709d80538..db76d5d51 100755 --- a/src/graphics/smoke.cpp +++ b/src/graphics/smoke.cpp @@ -71,7 +71,7 @@ void Smoke::particle_create(int, Particle *p) sgSetVec3(p->m_vel, 0, 0, 0 ); sgSetVec3(p->m_acc, 0, 0, 2.0f ); /* Gravity */ p->m_size = 0.5f; - p->m_time_to_live = 0.8f; + p->m_time_to_live = 0.4f; // Change from left to right wheel and back for each new particle static int wheel_number = 2; diff --git a/src/karts/kart.cpp b/src/karts/kart.cpp index 532939003..32d1c9ce0 100644 --- a/src/karts/kart.cpp +++ b/src/karts/kart.cpp @@ -342,6 +342,7 @@ void Kart::reset() m_vehicle->applyEngineForce (0.0f, 3); Moveable::reset(); + m_skidmarks->reset(); for(int j=0; jgetNumWheels(); j++) { m_vehicle->updateWheelTransform(j, true); @@ -887,7 +888,7 @@ void Kart::endRescue() } // endRescue //----------------------------------------------------------------------------- -#include + void Kart::loadData() { float r [ 2 ] = { -10.0f, 100.0f } ; @@ -959,7 +960,10 @@ void Kart::updateGraphics(const Vec3& off_xyz, const Vec3& off_hpr) const float offset_pitch = DEGREE_TO_RAD(m_wheelie_angle); if(m_smoke_system) - m_smoke_system->setCreationRate((m_skidding-1)*100.0f); + { + float f = fabsf(m_controls.lr) > 0.8 ? 50.0f : 0.0f; + m_smoke_system->setCreationRate((m_skidding-1)*f); + } if(m_nitro) m_nitro->setCreationRate(m_controls.wheelie && m_collected_energy>0 ? getSpeed()*5.0f : 0); diff --git a/src/stk_config.cpp b/src/stk_config.cpp index 7b853f3c0..3e44a89ee 100644 --- a/src/stk_config.cpp +++ b/src/stk_config.cpp @@ -106,6 +106,7 @@ void STKConfig::load(const std::string &filename) CHECK_NEG(m_explosion_impulse, "explosion-impulse" ); CHECK_NEG(m_explosion_impulse_objects, "explosion-impulse-objects" ); CHECK_NEG(m_max_history, "max-history" ); + CHECK_NEG(m_max_skidmarks, "max-skidmarks" ); CHECK_NEG(m_delay_finish_time, "delay-finish-time" ); CHECK_NEG(m_music_credit_time, "music-credit-time" ); m_kart_properties.checkAllSet(filename); @@ -131,6 +132,7 @@ void STKConfig::init_defaults() m_max_karts = -100; m_grid_order = -100; m_max_history = -100; + m_max_skidmarks = -100; m_title_music = NULL; m_game_style = GS_WHEELIE; m_scores.clear(); @@ -166,6 +168,7 @@ void STKConfig::getAllData(const lisp::Lisp* lisp) lisp->get("grid-order", m_grid_order ); lisp->getVector("scores", m_scores ); lisp->get("max-history", m_max_history ); + lisp->get("max-skidmarks", m_max_skidmarks ); lisp->get("delay-finish-time", m_delay_finish_time ); lisp->get("music-credit-time", m_music_credit_time ); lisp->get("menu-background", m_menu_background ); diff --git a/src/stk_config.hpp b/src/stk_config.hpp index 9a029b39a..a6e0d3f83 100644 --- a/src/stk_config.hpp +++ b/src/stk_config.hpp @@ -67,6 +67,7 @@ public: or reverse point order. */ int m_max_history; /**