From 370fa809941192336e9413c7f367fe837a4e49ca Mon Sep 17 00:00:00 2001 From: hikerstk Date: Tue, 24 Jun 2008 06:29:35 +0000 Subject: [PATCH] 1) Made some attributes private. 2) Fixed the AI calling rescue when crashing repeatedly (which hasn't d been working since bullet physics was used). git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@2138 178a84e3-b1eb-0310-8ba1-8eac791a3b58 --- src/kart.cpp | 2 +- src/kart.hpp | 8 +++++--- src/moveable.cpp | 2 -- src/moveable.hpp | 9 +++------ src/physics.cpp | 9 +-------- src/player_kart.cpp | 6 +++++- src/robots/default_robot.cpp | 14 ++++++++------ src/robots/default_robot.hpp | 2 ++ 8 files changed, 25 insertions(+), 27 deletions(-) diff --git a/src/kart.cpp b/src/kart.cpp index 2cfe2e3a5..3913b7cb6 100644 --- a/src/kart.cpp +++ b/src/kart.cpp @@ -318,7 +318,7 @@ void Kart::reset() // Set the brakes so that karts don't slide downhill for(int i=0; i<4; i++) m_vehicle->setBrake(5.0f, i); - m_transform = m_reset_transform; + setTrans(m_reset_transform); world->m_track->findRoadSector(getXYZ(), &m_track_sector); diff --git a/src/kart.hpp b/src/kart.hpp index 1a35142c4..6f7839e09 100644 --- a/src/kart.hpp +++ b/src/kart.hpp @@ -50,6 +50,11 @@ class Smoke; class Kart : public TerrainInfo, public Moveable { +private: + btTransform m_reset_transform; // reset position + Vec3 m_curr_track_coords; + Vec3 m_last_track_coords; + protected: bool m_on_road; // true if the kart is on top of the // road path drawn by the drivelines @@ -62,9 +67,6 @@ protected: KartControl m_controls; // The position of the karts controls int m_track_sector; // index in driveline, special values // e.g. UNKNOWN_SECTOR can be negative! - btTransform m_reset_transform; // reset position - Vec3 m_curr_track_coords; - Vec3 m_last_track_coords; float m_max_speed; // maximum speed of the kart, computed from float m_max_speed_reverse_ratio; float m_wheelie_angle; diff --git a/src/moveable.cpp b/src/moveable.cpp index 813628870..5ba05598d 100644 --- a/src/moveable.cpp +++ b/src/moveable.cpp @@ -65,8 +65,6 @@ Moveable::~Moveable() // The reset position must be set before calling reset void Moveable::reset () { - m_collided = false; - m_crashed = false; m_material_hot = NULL; m_normal_hot = NULL; if(m_body) diff --git a/src/moveable.hpp b/src/moveable.hpp index 60e98b940..7f894a576 100644 --- a/src/moveable.hpp +++ b/src/moveable.hpp @@ -37,22 +37,19 @@ class Moveable { private: btVector3 m_velocityLC; /* velocity in kart coordinates */ + btTransform m_transform; + Vec3 m_hpr; protected: UserPointer m_user_pointer; sgVec4* m_normal_hot; /* plane on which HOT was computed */ Material* m_material_hot; /* Material at HOT */ ssgTransform* m_model_transform; // The transform where the model is under ssgTransform* m_shadow; - int m_collided; - int m_crashed; - sgVec3 m_surface_avoidance_vector ; int m_first_time ; sgCoord* m_history_velocity; sgCoord* m_history_position; btRigidBody* m_body; btDefaultMotionState* m_motion_state; - btTransform m_transform; - Vec3 m_hpr; public: Moveable (bool bHasHistory=false); @@ -84,7 +81,7 @@ public: void createBody(float mass, btTransform& trans, btCollisionShape *shape); const btTransform& getTrans() const {return m_transform;} - void setTrans (btTransform& t){m_transform=t;m_motion_state->setWorldTransform(t);} + void setTrans (const btTransform& t){m_transform=t;m_motion_state->setWorldTransform(t);} } ; // class Moveable diff --git a/src/physics.cpp b/src/physics.cpp index e5e3da578..43da749a7 100644 --- a/src/physics.cpp +++ b/src/physics.cpp @@ -213,14 +213,7 @@ btScalar Physics::solveGroup(btCollisionObject** bodies, int numBodies, if(upB->is(UserPointer::UP_FLYABLE)) // 1.1 projectile hits track m_all_collisions.push_back(upB, upA); else if(upB->is(UserPointer::UP_KART)) - // FIXME: sound disabled for now, since the chassis of the karts hits - // the track when accelerating, causing a constant crash sfx - // to be played. Might be fixed with better physics parameters - //upB->getPointerKart()->crashed(); -#if defined(WIN32) && !defined(__CYGWIN__) - 0 // avoid VS compiler warning while the above statement is commented out -#endif - ; + upB->getPointerKart()->crashed(); } // 2) object a is a kart // ===================== diff --git a/src/player_kart.cpp b/src/player_kart.cpp index e67382d54..901ad695d 100644 --- a/src/player_kart.cpp +++ b/src/player_kart.cpp @@ -208,9 +208,13 @@ void PlayerKart::crashed() // noise by playing the crash sound over and over again. To prevent // this, the crash sound is only played if there was at least 0.5 // seconds since the last time it was played (for this kart) + if(world->getTime() - m_time_last_crash_sound > 0.5f) { - sound_manager->playSfx( SOUND_CRASH ); + // FIXME: sound disabled for now, since the chassis of the karts hits + // the track when accelerating, causing a constant crash sfx + // to be played. Might be fixed with better physics parameters + //sound_manager->playSfx( SOUND_CRASH ); m_time_last_crash_sound = world->getTime(); } } // crashed diff --git a/src/robots/default_robot.cpp b/src/robots/default_robot.cpp index 6cb5a211f..5bcf8479b 100755 --- a/src/robots/default_robot.cpp +++ b/src/robots/default_robot.cpp @@ -130,6 +130,7 @@ void DefaultRobot::update( float delta ) /*And obviously general kart stuff*/ AutoKart::update( delta ); + m_collided = false; } // update //----------------------------------------------------------------------------- @@ -175,7 +176,7 @@ void DefaultRobot::handle_braking() //if the curve angle is bigger than what the kart can steer, brake //even if we are in the inside, because the kart would be 'thrown' //out of the curve. - if(!(m_curr_track_coords[0] > world->m_track-> + if(!(getDistanceToCenter() > world->m_track-> getWidth()[m_track_sector] * -CURVE_INSIDE_PERC || m_curve_angle > getMaxSteerAngle())) { @@ -185,7 +186,7 @@ void DefaultRobot::handle_braking() } else if( m_curve_angle < -MIN_TRACK_ANGLE ) //Next curve is right { - if(!(m_curr_track_coords[0] < world->m_track-> + if(!(getDistanceToCenter() < world->m_track-> getWidth()[m_track_sector] * CURVE_INSIDE_PERC || m_curve_angle < -getMaxSteerAngle())) { @@ -226,7 +227,7 @@ void DefaultRobot::handle_steering() *finite state machine. */ //Reaction to being outside of the road - if( fabsf(m_curr_track_coords[0]) + 0.5 > + if( fabsf(getDistanceToCenter()) + 0.5 > world->m_track->getWidth()[m_track_sector] ) { steer_angle = steer_to_point( world->m_track-> @@ -254,7 +255,7 @@ void DefaultRobot::handle_steering() } else { - if(m_curr_track_coords[0] > world->getKart(m_crashes.m_kart)-> + if(getDistanceToCenter() > world->getKart(m_crashes.m_kart)-> getDistanceToCenter()) { steer_angle = steer_to_angle( NEXT_SECTOR, -90.0f ); @@ -496,8 +497,8 @@ void DefaultRobot::handle_rescue(const float DELTA) //TODO: check if we collided against a dynamic object (ej.:kart) or //against the track's static object. //The m_crash_time measures if a kart has been crashing for too long - m_crash_time += (m_collided && isOnGround()) ? 3.0f * DELTA : -0.25f * DELTA; + m_crash_time += (m_collided && isOnGround()) ? 3.0f * DELTA : -0.25f * DELTA; if( m_crash_time < 0.0f ) m_crash_time = 0.0f; //Reaction to being stuck @@ -780,8 +781,9 @@ void DefaultRobot::reset() m_future_sector = 0; m_time_till_start = -1.0f; - m_crash_time = 0.0f; + m_collided = false; + m_time_since_stuck = 0.0f; diff --git a/src/robots/default_robot.hpp b/src/robots/default_robot.hpp index ab8f19211..8ee2604ab 100755 --- a/src/robots/default_robot.hpp +++ b/src/robots/default_robot.hpp @@ -79,6 +79,7 @@ private: //The crash percentage is how much of the time the AI has been crashing, //if the AI has been crashing for some time, use the rescue. float m_crash_time; + int m_collided; // true if the kart collided with the track float m_time_since_last_shot; int m_future_sector; @@ -132,6 +133,7 @@ public: void update (float delta) ; void reset (); + virtual void crashed() {m_collided = true;}; }; #endif