From 2c0a135d9442c26cdfb9498606dff35b4f77cd98 Mon Sep 17 00:00:00 2001 From: hikerstk Date: Tue, 13 Jan 2009 00:16:09 +0000 Subject: [PATCH] Improved shortcut handling: 1) on road/off road is now detected with a certain tolerance to the drivelines (currently 15%), i.e. the drivelines are made 15% wider. 2) Skipped segments distance was shortened to 50m (since it should be used less with the above higher tolerance, and it caused problems with shortcut not being detected. 3) The new drivelines with tolerance can be seen with --track-debug=4 (--track-debug=2 shows the original drivelines) git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@2890 178a84e3-b1eb-0310-8ba1-8eac791a3b58 --- data/stk_config.data | 3 +- src/main.cpp | 5 +-- src/modes/linear_world.cpp | 5 +-- src/stk_config.cpp | 6 ++-- src/stk_config.hpp | 3 ++ src/track.cpp | 73 +++++++++++++++++++++++++++++--------- src/track.hpp | 9 +++-- 7 files changed, 79 insertions(+), 25 deletions(-) diff --git a/data/stk_config.data b/data/stk_config.data index 11686167c..bc6ccc585 100644 --- a/data/stk_config.data +++ b/data/stk_config.data @@ -39,8 +39,9 @@ (zipper-force 250.0 ) ;; additional zipper force (zipper-speed-gain 4.5 ) ;; one time additional speed - (shortcut-length 120 ) ;; leaving the road and coming back on it more than + (shortcut-length 50 ) ;; leaving the road and coming back on it more than ;; x 'meters" later is considered to be a shortcut + (offroad-tolerance 0.15) ;; Widen the road 15% for shortcut detection. (enable_networking #f ) ;; For now disable networking (explosion-impulse 10000.0 ) ;; explosion impulse on not directly hit karts (explosion-impulse-objects 500.0) ;; explosion impulse for physics objects (smaller diff --git a/src/main.cpp b/src/main.cpp index 9b998b40e..effcb68ae 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -451,12 +451,13 @@ void InitTuxkart() highscore_manager = new HighscoreManager (); grand_prix_manager = new GrandPrixManager (); network_manager = new NetworkManager (); + + stk_config->load(file_manager->getConfigFile("stk_config.data")); track_manager->loadTrackList(); - // Check needs GP and track manager. + // unlock_manager->check needs GP and track manager. unlock_manager->check(); sound_manager->addMusicToTracks(); - stk_config->load(file_manager->getConfigFile("stk_config.data")); race_manager = new RaceManager (); // default settings for Quickstart race_manager->setNumPlayers(1); diff --git a/src/modes/linear_world.cpp b/src/modes/linear_world.cpp index 84423cd5c..4d1bc9caa 100644 --- a/src/modes/linear_world.cpp +++ b/src/modes/linear_world.cpp @@ -149,8 +149,9 @@ void LinearWorld::update(float delta) // update sector variables int prev_sector = kart_info.m_track_sector; - m_track->findRoadSector( kart->getXYZ(), &kart_info.m_track_sector); - + m_track->findRoadSector( kart->getXYZ(), &kart_info.m_track_sector, + /*tolerance*/ true); + // Check if the kart is taking a shortcut (if it's not already doing one): // ----------------------------------------------------------------------- kart_info.m_on_road = kart_info.m_track_sector != Track::UNKNOWN_SECTOR; diff --git a/src/stk_config.cpp b/src/stk_config.cpp index 83ba74427..ff1a9a958 100644 --- a/src/stk_config.cpp +++ b/src/stk_config.cpp @@ -108,6 +108,7 @@ void STKConfig::load(const std::string &filename) CHECK_NEG(m_zipper_force, "zipper-force" ); CHECK_NEG(m_zipper_speed_gain, "zipper-speed-gain" ); CHECK_NEG(m_shortcut_length, "shortcut-length" ); + CHECK_NEG(m_offroad_tolerance, "offroad-tolerance" ); CHECK_NEG(m_explosion_impulse, "explosion-impulse" ); CHECK_NEG(m_explosion_impulse_objects, "explosion-impulse-objects" ); CHECK_NEG(m_max_history, "max-history" ); @@ -135,7 +136,7 @@ void STKConfig::init_defaults() m_explosion_impulse = m_explosion_impulse_objects = m_shortcut_length = m_music_credit_time = m_delay_finish_time = m_skid_fadeout_time = - m_slowdown_factor = + m_slowdown_factor = m_offroad_tolerance = UNDEFINED; m_max_karts = -100; m_grid_order = -100; @@ -175,7 +176,8 @@ void STKConfig::getAllData(const lisp::Lisp* lisp) // Get the values which are not part of the default KartProperties // --------------------------------------------------------------- lisp->get("anvil-weight", m_anvil_weight ); - lisp->get("shortcut-length", m_shortcut_length ); + lisp->get("shortcut-length", m_shortcut_length ); + lisp->get("offroad-tolerance", m_offroad_tolerance ); lisp->get("anvil-speed-factor", m_anvil_speed_factor ); lisp->get("parachute-friction", m_parachute_friction ); lisp->get("parachute-time", m_parachute_time ); diff --git a/src/stk_config.hpp b/src/stk_config.hpp index f3c0b6d18..d3923e5cb 100644 --- a/src/stk_config.hpp +++ b/src/stk_config.hpp @@ -55,6 +55,9 @@ public: float m_zipper_speed_gain; /**add(sphere); } // for i } /// type ==1 - if(type&2) + // 2: drivelines, 4: driveline with tolerance + if(type&6) { ssgVertexArray* v_array = new ssgVertexArray(); ssgColourArray* c_array = new ssgColourArray(); + const std::vector &left = type&2 ? m_left_driveline + : m_dl_with_tolerance_left; + const std::vector &right = type&2 ? m_right_driveline + : m_dl_with_tolerance_right; for(unsigned int i = 0; i < m_driveline.size(); i++) { int ip1 = i==m_driveline.size()-1 ? 0 : i+1; // The segment display must be slightly higher than the // track, otherwise it's not clearly visible. sgVec3 v; - sgCopyVec3(v,m_left_driveline [i ].toFloat()); v[2]+=0.1f; v_array->add(v); - sgCopyVec3(v,m_right_driveline[i ].toFloat()); v[2]+=0.1f; v_array->add(v); - sgCopyVec3(v,m_right_driveline[ip1].toFloat()); v[2]+=0.1f; v_array->add(v); - sgCopyVec3(v,m_left_driveline [ip1].toFloat()); v[2]+=0.1f; v_array->add(v); + sgCopyVec3(v,left [i ].toFloat()); v[2]+=0.1f; v_array->add(v); + sgCopyVec3(v,right[i ].toFloat()); v[2]+=0.1f; v_array->add(v); + sgCopyVec3(v,right[ip1].toFloat()); v[2]+=0.1f; v_array->add(v); + sgCopyVec3(v,left [ip1].toFloat()); v[2]+=0.1f; v_array->add(v); sgVec4 vc; vc[0] = i%2==0 ? 1.0f : 0.0f; vc[1] = 1.0f-v[0]; @@ -902,8 +935,7 @@ void Track::startMusic() const { } // startMusic //----------------------------------------------------------------------------- -void -Track::loadDriveline() +void Track::loadDriveline() { readDrivelineFromFile(m_left_driveline, ".drvl"); @@ -917,6 +949,8 @@ Track::loadDriveline() "and the left driveline is " << m_left_driveline.size() << " vertex long. Track is " << m_name << " ." << std::endl; + m_dl_with_tolerance_left.reserve(DRIVELINE_SIZE); + m_dl_with_tolerance_right.reserve(DRIVELINE_SIZE); m_driveline.reserve(DRIVELINE_SIZE); m_path_width.reserve(DRIVELINE_SIZE); m_angle.reserve(DRIVELINE_SIZE); @@ -927,6 +961,13 @@ Track::loadDriveline() float width = ( m_right_driveline[i] - center_point ).length(); m_path_width.push_back(width); + + // Compute the drivelines with tolerance + Vec3 diff = (m_left_driveline[i] - m_right_driveline[i]) + * stk_config->m_offroad_tolerance; + m_dl_with_tolerance_left.push_back(m_left_driveline[i]+diff); + m_dl_with_tolerance_right.push_back(m_right_driveline[i]-diff); + } for(unsigned int i = 0; i < DRIVELINE_SIZE; ++i) diff --git a/src/track.hpp b/src/track.hpp index 834a9363a..ce5f23a7f 100644 --- a/src/track.hpp +++ b/src/track.hpp @@ -97,7 +97,11 @@ public: //FIXME: Maybe the next 4 vectors should be inside an struct and be used //from a vector of structs? //FIXME: should the driveline be set as a sgVec2? - std::vector m_driveline; + std::vector m_driveline; + /** Same as drivelines, but with stk_config->m_offroad_tolerance applied + * to widen the road (to make shortcut detection less severe). */ + std::vector m_dl_with_tolerance_left; + std::vector m_dl_with_tolerance_right; std::vector m_distance_from_start; std::vector m_path_width; std::vector m_angle; @@ -134,7 +138,8 @@ public: void drawScaled2D (float x, float y, float w, float h ) const; - void findRoadSector (const Vec3& XYZ, int *sector) const; + void findRoadSector (const Vec3& XYZ, int *sector, + bool with_tolerance=false) const; int findOutOfRoadSector(const Vec3& XYZ, const RoadSide SIDE, const int CURR_SECTOR