1) Refactored KartProperties and STKConfig, so that kart defaults
and checks if all values are actually defined are done in one file now (and not in two different classes as before). Added doxygen comments as well. 2) More physics improvements. git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@2345 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
35c1c3eb32
commit
b1de626e3e
@ -98,7 +98,7 @@
|
||||
(gear-power-increase 2.2 1.7 1.3)
|
||||
(upright-tolerance 0.2)
|
||||
(upright-max-force 30)
|
||||
(track-connection-force 2)
|
||||
(track-connection-accel 2)
|
||||
(camera-max-accel 10)
|
||||
(camera-max-brake 10)
|
||||
(camera-distance 3.5)
|
||||
|
@ -29,9 +29,11 @@ btScalar calcRollingFriction(btWheelContactPoint& contactPoint);
|
||||
|
||||
static btRigidBody s_fixedObject( 0,0,0);
|
||||
|
||||
btKart::btKart(const btVehicleTuning& tuning,btRigidBody* chassis, btVehicleRaycaster* raycaster )
|
||||
btKart::btKart(const btVehicleTuning& tuning,btRigidBody* chassis,
|
||||
btVehicleRaycaster* raycaster, float track_connect_accel )
|
||||
: btRaycastVehicle(tuning, chassis, raycaster)
|
||||
{
|
||||
m_track_connect_accel = track_connect_accel;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@ -47,7 +49,8 @@ btScalar btKart::rayCast(btWheelInfo& wheel)
|
||||
|
||||
btScalar depth = -1;
|
||||
|
||||
btScalar raylen = wheel.getSuspensionRestLength()+wheel.m_wheelsRadius;
|
||||
btScalar raylen = wheel.getSuspensionRestLength()+wheel.m_wheelsRadius+
|
||||
wheel.m_maxSuspensionTravelCm*0.01f;
|
||||
|
||||
btVector3 rayvector = wheel.m_raycastInfo.m_wheelDirectionWS * (raylen);
|
||||
const btVector3& source = wheel.m_raycastInfo.m_hardPointWS;
|
||||
@ -120,6 +123,7 @@ btScalar btKart::rayCast(btWheelInfo& wheel)
|
||||
wheel.m_suspensionRelativeVelocity = btScalar(0.0);
|
||||
wheel.m_raycastInfo.m_contactNormalWS = - wheel.m_raycastInfo.m_wheelDirectionWS;
|
||||
wheel.m_clippedInvContactDotSuspension = btScalar(1.0);
|
||||
|
||||
}
|
||||
|
||||
return depth;
|
||||
@ -161,22 +165,25 @@ void btKart::updateVehicle( btScalar step )
|
||||
depth = rayCast( m_wheelInfo[i]);
|
||||
}
|
||||
|
||||
updateSuspension(step);
|
||||
// Work around: make sure that either both wheels on one axis
|
||||
// are on ground, or none of them. This avoids the problem of
|
||||
// the kart suddenly getting additional angular velocity because
|
||||
// e.g. only one rear wheel is on the ground.
|
||||
for(i=0; i<4; i+=2)
|
||||
{
|
||||
if(m_wheelInfo[i].m_raycastInfo.m_isInContact &&
|
||||
!(m_wheelInfo[i+1].m_raycastInfo.m_isInContact))
|
||||
{
|
||||
m_wheelInfo[i+1].m_raycastInfo = m_wheelInfo[i].m_raycastInfo;
|
||||
}
|
||||
if(!(m_wheelInfo[i].m_raycastInfo.m_isInContact) &&
|
||||
m_wheelInfo[i+1].m_raycastInfo.m_isInContact)
|
||||
{
|
||||
m_wheelInfo[i].m_raycastInfo = m_wheelInfo[i+1].m_raycastInfo;
|
||||
}
|
||||
} // for i=0; i<4; i+=2
|
||||
|
||||
// A very unphysical thing to handle slopes that are a bit too steep
|
||||
// or uneven (resulting in only one wheel on the ground)
|
||||
// If only the front or only the rear wheels are on the ground, add
|
||||
// a force pulling the axis down (towards the ground). Note that it
|
||||
// is already guaranteed that either both or no wheels on one axis
|
||||
// are on the ground, so we have to test only one of the wheels
|
||||
for(int i=0; i<m_wheelInfo.size(); i++)
|
||||
{
|
||||
if(!(m_wheelInfo[i].m_raycastInfo.m_isInContact) )
|
||||
{
|
||||
btScalar mass=1.0f/m_chassisBody->getInvMass();
|
||||
m_wheelInfo[i].m_wheelsSuspensionForce = -2.0f*mass;
|
||||
}
|
||||
}
|
||||
updateSuspension(step);
|
||||
|
||||
for (i=0;i<m_wheelInfo.size();i++)
|
||||
{
|
||||
@ -287,7 +294,13 @@ void btKart::updateSuspension(btScalar deltaTime)
|
||||
}
|
||||
else
|
||||
{
|
||||
wheel_info.m_wheelsSuspensionForce = btScalar(0.0);
|
||||
// A very unphysical thing to handle slopes that are a bit too steep
|
||||
// or uneven (resulting in only one wheel on the ground)
|
||||
// If only the front or only the rear wheels are on the ground, add
|
||||
// a force pulling the axis down (towards the ground). Note that it
|
||||
// is already guaranteed that either both or no wheels on one axis
|
||||
// are on the ground, so we have to test only one of the wheels
|
||||
wheel_info.m_wheelsSuspensionForce = -m_track_connect_accel*chassisMass ;
|
||||
}
|
||||
} // for w_it<number of wheels
|
||||
|
||||
|
@ -25,9 +25,10 @@ struct btWheelInfo;
|
||||
class btKart : public btRaycastVehicle
|
||||
{
|
||||
void defaultInit(const btVehicleTuning& tuning);
|
||||
btScalar m_track_connect_accel;
|
||||
public:
|
||||
btKart(const btVehicleTuning& tuning,btRigidBody* chassis,
|
||||
btVehicleRaycaster* raycaster );
|
||||
btVehicleRaycaster* raycaster, float track_connect_accel );
|
||||
virtual ~btKart() ;
|
||||
btScalar rayCast(btWheelInfo& wheel);
|
||||
virtual void updateVehicle(btScalar step);
|
||||
|
@ -185,7 +185,8 @@ void Kart::createPhysics(ssgEntity *obj)
|
||||
new btDefaultVehicleRaycaster(RaceManager::getWorld()->getPhysics()->getPhysicsWorld());
|
||||
m_tuning = new btKart::btVehicleTuning();
|
||||
m_tuning->m_maxSuspensionTravelCm = m_kart_properties->getSuspensionTravelCM();
|
||||
m_vehicle = new btKart(*m_tuning, m_body, m_vehicle_raycaster);
|
||||
m_vehicle = new btKart(*m_tuning, m_body, m_vehicle_raycaster,
|
||||
m_kart_properties->getTrackConnectionAccel());
|
||||
|
||||
// never deactivate the vehicle
|
||||
m_body->setActivationState(DISABLE_DEACTIVATION);
|
||||
@ -616,8 +617,8 @@ void Kart::update(float dt)
|
||||
herring_manager->hitHerring(this);
|
||||
|
||||
processSkidMarks();
|
||||
}
|
||||
|
||||
}
|
||||
//-----------------------------------------------------------------------------
|
||||
// Set zipper time, and apply one time additional speed boost
|
||||
void Kart::handleZipper()
|
||||
|
@ -37,23 +37,67 @@
|
||||
# define snprintf _snprintf
|
||||
#endif
|
||||
|
||||
// This constructor would be a bit more useful, nicer, if we could call
|
||||
// init_defaults() and load from here. Unfortunately, this object is used
|
||||
// as a base class for STKConfig, which has to overwrite
|
||||
// init_defaults() and getAllData(). But during the call of this constructor,
|
||||
// the STKConfig object does not (yet) exist, so the overwriting
|
||||
// functions do NOT get called, only the virtual functions here would be
|
||||
// called. Therefore, a two step initialisation is necessary: the constructor
|
||||
// doing not much, but then in load the overwriting functions can be used.
|
||||
float KartProperties::UNDEFINED = -99.9f;
|
||||
|
||||
/** The constructor initialises all values with invalid values. It can later
|
||||
* then be checked (for STKConfig) that all values are indeed defined.
|
||||
* Otherwise the defaults are taken from STKConfig (and since they are all
|
||||
* defined, it is guaranteed that each kart has well defined physics values.
|
||||
*/
|
||||
KartProperties::KartProperties() : m_icon_material(0), m_model(0)
|
||||
{} // KartProperties
|
||||
{
|
||||
m_name = "Tux";
|
||||
m_ident = "tux";
|
||||
m_model_file = "tuxkart.ac";
|
||||
m_icon_file = "tuxicon.png";
|
||||
m_shadow_file = "tuxkartshadow.png";
|
||||
m_groups.clear();
|
||||
|
||||
// Set all other values to undefined, so that it can later be tested
|
||||
// if everything is defined properly.
|
||||
m_wheel_base = m_mass = m_min_speed_turn = m_angle_at_min =
|
||||
m_max_speed_turn = m_angle_at_max = m_engine_power = m_brake_factor =
|
||||
m_time_full_steer = m_wheelie_max_pitch = m_wheelie_max_speed_ratio =
|
||||
m_wheelie_pitch_rate = m_wheelie_restore_rate = m_wheelie_speed_boost =
|
||||
m_suspension_stiffness = m_wheel_damping_relaxation =
|
||||
m_wheel_damping_compression = m_friction_slip = m_roll_influence =
|
||||
m_wheel_radius = m_wheelie_power_boost = m_chassis_linear_damping =
|
||||
m_chassis_angular_damping = m_maximum_speed = m_suspension_rest =
|
||||
m_max_speed_reverse_ratio = m_jump_velocity = m_upright_tolerance =
|
||||
m_upright_max_force = m_suspension_travel_cm = m_mass =
|
||||
m_track_connection_accel = m_wheel_base = m_min_speed_turn =
|
||||
m_angle_at_min = m_max_speed_turn = m_angle_at_max = m_engine_power =
|
||||
m_brake_factor = m_time_full_steer = m_wheelie_max_pitch =
|
||||
m_wheelie_max_speed_ratio = m_wheelie_pitch_rate = m_wheel_radius =
|
||||
m_wheelie_restore_rate = m_wheelie_speed_boost = m_maximum_speed =
|
||||
m_suspension_stiffness = m_wheel_damping_relaxation = m_jump_velocity =
|
||||
m_wheel_damping_compression = m_friction_slip = m_roll_influence =
|
||||
m_wheelie_power_boost = m_chassis_linear_damping = m_suspension_rest =
|
||||
m_chassis_angular_damping = m_max_speed_reverse_ratio =
|
||||
m_upright_tolerance = m_upright_max_force = m_suspension_travel_cm =
|
||||
m_track_connection_accel = m_camera_max_accel = m_camera_max_brake =
|
||||
m_camera_distance = UNDEFINED;
|
||||
m_gravity_center_shift = Vec3(UNDEFINED);
|
||||
m_front_wheel_connection = Vec3(UNDEFINED);
|
||||
m_rear_wheel_connection = Vec3(UNDEFINED);
|
||||
m_color.setValue(1.0f, 0.0f, 0.0f);
|
||||
|
||||
} // KartProperties
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void KartProperties::load(const std::string filename, const std::string node,
|
||||
bool dont_load_models, bool dont_load_materials)
|
||||
/** Loads the kart properties from a file.
|
||||
* \param filename Filename to load.
|
||||
* \param node Name of the lisp node to load the data from
|
||||
* (default: tuxkart-kart)
|
||||
* \param dont_load_models If set does not load the actual kart models, used
|
||||
* when only printing kart information to stdout.
|
||||
*/
|
||||
void KartProperties::load(const std::string &filename, const std::string &node,
|
||||
bool dont_load_models)
|
||||
{
|
||||
|
||||
init_defaults();
|
||||
// Get the default values from STKConfig:
|
||||
*this = stk_config->getDefaultKartProperties();
|
||||
|
||||
const lisp::Lisp* root = 0;
|
||||
m_ident = StringUtils::basename(StringUtils::without_extension(filename));
|
||||
@ -81,8 +125,11 @@ void KartProperties::load(const std::string filename, const std::string node,
|
||||
}
|
||||
delete root;
|
||||
|
||||
if(!dont_load_materials)
|
||||
{
|
||||
// Set a default group (that has to happen after init_default and load)
|
||||
if(m_groups.size()==0)
|
||||
m_groups.push_back("standard");
|
||||
|
||||
|
||||
// Load material
|
||||
std::string materials_file = file_manager->getKartFile("materials.dat",getIdent());
|
||||
file_manager->pushModelSearchPath(file_manager->getKartFile("", getIdent()));
|
||||
@ -91,7 +138,7 @@ void KartProperties::load(const std::string filename, const std::string node,
|
||||
// addShared makes sure that these textures/material infos stay in memory
|
||||
material_manager->addSharedMaterial(materials_file);
|
||||
m_icon_material = material_manager->getMaterial(m_icon_file);
|
||||
}
|
||||
|
||||
// Load model, except when called as part of --list-karts
|
||||
if(m_model_file.length()>0 && !dont_load_models)
|
||||
{
|
||||
@ -116,20 +163,89 @@ void KartProperties::load(const std::string filename, const std::string node,
|
||||
m_kart_width, m_kart_length, m_kart_height);
|
||||
m_model->ref();
|
||||
} // if
|
||||
if(!dont_load_materials)
|
||||
{
|
||||
|
||||
file_manager->popTextureSearchPath();
|
||||
file_manager->popModelSearchPath();
|
||||
}
|
||||
|
||||
} // load
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/** Destructor, dereferences the kart model. */
|
||||
KartProperties::~KartProperties()
|
||||
{
|
||||
ssgDeRefDelete(m_model);
|
||||
} // ~KartProperties
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/** Checks if all necessary physics values are indeed defines. This helps
|
||||
* finding bugs early, e.g. missing default in stk_config.dat file.
|
||||
*/
|
||||
void KartProperties::checkAllSet(const std::string &filename)
|
||||
{
|
||||
if(m_gear_switch_ratio.size()==0)
|
||||
{
|
||||
fprintf(stderr,"Missing default value for 'gear-switch-ratio' in '%s'.\n",
|
||||
filename.c_str());
|
||||
exit(-1);
|
||||
}
|
||||
if(m_gear_power_increase.size()==0)
|
||||
{
|
||||
fprintf(stderr,"Missing default value for 'gear-power-increase' in '%s'.\n",
|
||||
filename.c_str());
|
||||
exit(-1);
|
||||
}
|
||||
if(m_gear_switch_ratio.size()!=m_gear_power_increase.size()) {
|
||||
fprintf(stderr,"Number of entries for 'gear-switch-ratio' and 'gear-power-increase");
|
||||
fprintf(stderr,"in '%s' must be equal.\n", filename.c_str());
|
||||
exit(-1);
|
||||
}
|
||||
#define CHECK_NEG( a,strA) if(a<=UNDEFINED) { \
|
||||
fprintf(stderr,"Missing default value for '%s' in '%s'.\n", \
|
||||
strA,filename.c_str());exit(-1); \
|
||||
}
|
||||
|
||||
CHECK_NEG(m_mass, "mass" );
|
||||
CHECK_NEG(m_wheel_base, "wheel-base" );
|
||||
CHECK_NEG(m_engine_power, "engine-power" );
|
||||
CHECK_NEG(m_min_speed_turn, "min-speed-angle" );
|
||||
CHECK_NEG(m_angle_at_min, "min-speed-angle" );
|
||||
CHECK_NEG(m_max_speed_turn, "max-speed-angle" );
|
||||
CHECK_NEG(m_angle_at_max, "max-speed-angle" );
|
||||
CHECK_NEG(m_brake_factor, "brake-factor" );
|
||||
CHECK_NEG(m_time_full_steer, "time-full-steer" );
|
||||
|
||||
CHECK_NEG(m_wheelie_max_speed_ratio, "wheelie-max-speed-ratio" );
|
||||
CHECK_NEG(m_wheelie_max_pitch, "wheelie-max-pitch" );
|
||||
CHECK_NEG(m_wheelie_pitch_rate, "wheelie-pitch-rate" );
|
||||
CHECK_NEG(m_wheelie_restore_rate, "wheelie-restore-rate" );
|
||||
CHECK_NEG(m_wheelie_speed_boost, "wheelie-speed-boost" );
|
||||
CHECK_NEG(m_wheelie_power_boost, "wheelie-power-boost" );
|
||||
//bullet physics data
|
||||
CHECK_NEG(m_suspension_stiffness, "suspension-stiffness" );
|
||||
CHECK_NEG(m_wheel_damping_relaxation, "wheel-damping-relaxation" );
|
||||
CHECK_NEG(m_wheel_damping_compression, "wheel-damping-compression" );
|
||||
CHECK_NEG(m_friction_slip, "friction-slip" );
|
||||
CHECK_NEG(m_roll_influence, "roll-influence" );
|
||||
CHECK_NEG(m_wheel_radius, "wheel-radius" );
|
||||
CHECK_NEG(m_chassis_linear_damping, "chassis-linear-damping" );
|
||||
CHECK_NEG(m_chassis_angular_damping, "chassis-angular-damping" );
|
||||
CHECK_NEG(m_maximum_speed, "maximum-speed" );
|
||||
CHECK_NEG(m_max_speed_reverse_ratio, "max-speed-reverse-ratio" );
|
||||
CHECK_NEG(m_gravity_center_shift[0], "gravity-center-shift" );
|
||||
CHECK_NEG(m_gravity_center_shift[1], "gravity-center-shift" );
|
||||
CHECK_NEG(m_gravity_center_shift[2], "gravity-center-shift" );
|
||||
CHECK_NEG(m_suspension_rest, "suspension-rest" );
|
||||
CHECK_NEG(m_suspension_travel_cm, "suspension-travel-cm" );
|
||||
CHECK_NEG(m_jump_velocity, "jump-velocity" );
|
||||
CHECK_NEG(m_upright_tolerance, "upright-tolerance" );
|
||||
CHECK_NEG(m_upright_max_force, "upright-max-force" );
|
||||
CHECK_NEG(m_track_connection_accel, "track-connection-accel" );
|
||||
CHECK_NEG(m_camera_max_accel, "camera-max-accel" );
|
||||
CHECK_NEG(m_camera_max_brake, "camera-max-brake" );
|
||||
CHECK_NEG(m_camera_distance, "camera-distance" );
|
||||
|
||||
} // checkAllSet
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void KartProperties::getAllData(const lisp::Lisp* lisp)
|
||||
{
|
||||
@ -201,10 +317,8 @@ void KartProperties::getAllData(const lisp::Lisp* lisp)
|
||||
lisp->get("jump-velocity", m_jump_velocity );
|
||||
lisp->get("upright-tolerance", m_upright_tolerance );
|
||||
lisp->get("upright-max-force", m_upright_max_force );
|
||||
lisp->get("track-connection-force", m_track_connection_accel );
|
||||
lisp->get("track-connection-accel", m_track_connection_accel );
|
||||
lisp->getVector("groups", m_groups );
|
||||
if(m_groups.size()==0)
|
||||
m_groups.push_back("standard");
|
||||
|
||||
// getVector appends to existing vectors, so a new one must be used to load
|
||||
std::vector<float> temp;
|
||||
@ -221,64 +335,6 @@ void KartProperties::getAllData(const lisp::Lisp* lisp)
|
||||
|
||||
} // getAllData
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void KartProperties::init_defaults()
|
||||
{
|
||||
|
||||
m_name = "Tux";
|
||||
m_ident = "tux";
|
||||
m_model_file = "tuxkart.ac";
|
||||
m_icon_file = "tuxicon.png";
|
||||
m_shadow_file = "tuxkartshadow.png";
|
||||
m_groups.clear();
|
||||
|
||||
m_color.setValue(1.0f, 0.0f, 0.0f);
|
||||
|
||||
m_kart_width = 1.0f;
|
||||
m_kart_length = 1.5f;
|
||||
m_wheel_base = stk_config->m_wheel_base;
|
||||
m_engine_power = stk_config->m_engine_power;
|
||||
m_time_full_steer = stk_config->m_time_full_steer;
|
||||
m_brake_factor = stk_config->m_brake_factor;
|
||||
m_mass = stk_config->m_mass;
|
||||
m_wheelie_max_speed_ratio = stk_config->m_wheelie_max_speed_ratio;
|
||||
m_wheelie_max_pitch = stk_config->m_wheelie_max_pitch;
|
||||
m_wheelie_pitch_rate = stk_config->m_wheelie_pitch_rate;
|
||||
m_wheelie_restore_rate = stk_config->m_wheelie_restore_rate;
|
||||
m_wheelie_speed_boost = stk_config->m_wheelie_speed_boost;
|
||||
m_wheelie_power_boost = stk_config->m_wheelie_power_boost;
|
||||
|
||||
//bullet physics data
|
||||
m_suspension_stiffness = stk_config->m_suspension_stiffness;
|
||||
m_wheel_damping_relaxation = stk_config->m_wheel_damping_relaxation;
|
||||
m_wheel_damping_compression = stk_config->m_wheel_damping_compression;
|
||||
m_friction_slip = stk_config->m_friction_slip;
|
||||
m_roll_influence = stk_config->m_roll_influence;
|
||||
m_wheel_radius = stk_config->m_wheel_radius;
|
||||
m_chassis_linear_damping = stk_config->m_chassis_linear_damping;
|
||||
m_chassis_angular_damping = stk_config->m_chassis_angular_damping;
|
||||
m_maximum_speed = stk_config->m_maximum_speed;
|
||||
m_max_speed_reverse_ratio = stk_config->m_max_speed_reverse_ratio;
|
||||
m_gravity_center_shift = stk_config->m_gravity_center_shift;
|
||||
m_front_wheel_connection = stk_config->m_front_wheel_connection;
|
||||
m_rear_wheel_connection = stk_config->m_rear_wheel_connection;
|
||||
m_suspension_rest = stk_config->m_suspension_rest;
|
||||
m_suspension_travel_cm = stk_config->m_suspension_travel_cm;
|
||||
m_jump_velocity = stk_config->m_jump_velocity;
|
||||
m_gear_switch_ratio = stk_config->m_gear_switch_ratio;
|
||||
m_gear_power_increase = stk_config->m_gear_power_increase;
|
||||
m_upright_tolerance = stk_config->getUprightTolerance();
|
||||
m_upright_max_force = stk_config->getUprightMaxForce();
|
||||
m_track_connection_accel = 0.0f; //FIXME
|
||||
m_camera_max_accel = stk_config->getCameraMaxAccel();
|
||||
m_camera_max_brake = stk_config->getCameraMaxBrake();
|
||||
m_camera_distance = stk_config->getCameraDistance();
|
||||
m_min_speed_turn = stk_config->m_min_speed_turn;
|
||||
m_angle_at_min = stk_config->m_angle_at_min;
|
||||
m_max_speed_turn = stk_config->m_max_speed_turn;
|
||||
m_angle_at_max = stk_config->m_angle_at_max;
|
||||
} // init_defaults
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
float KartProperties::getMaxSteerAngle(float speed) const
|
||||
{
|
||||
|
@ -33,7 +33,7 @@ class ssgEntity;
|
||||
* identifier, physical properties etc. It is atm also the base class for
|
||||
* STKConfig, which stores the default values for all physics constants.
|
||||
*/
|
||||
class KartProperties : public NoCopy
|
||||
class KartProperties
|
||||
{
|
||||
private:
|
||||
|
||||
@ -41,6 +41,7 @@ private:
|
||||
ssgEntity *m_model; /**< The 3d model of the kart.*/
|
||||
std::vector<std::string> m_groups; /**< List of all groups the kart
|
||||
belongs to. */
|
||||
static float UNDEFINED;
|
||||
|
||||
protected:
|
||||
// Display and gui
|
||||
@ -128,16 +129,14 @@ protected:
|
||||
|
||||
public:
|
||||
KartProperties ();
|
||||
virtual ~KartProperties ();
|
||||
~KartProperties ();
|
||||
void getAllData (const lisp::Lisp* lisp);
|
||||
void load (const std::string &filename,
|
||||
const std::string &node="tuxkart-kart",
|
||||
bool dont_load_models=false);
|
||||
void checkAllSet(const std::string &filename);
|
||||
|
||||
virtual void init_defaults ();
|
||||
virtual void getAllData (const lisp::Lisp* lisp);
|
||||
virtual void load (const std::string filename,
|
||||
const std::string node="tuxkart-kart",
|
||||
bool dont_load_models=false,
|
||||
bool dont_load_materials=false);
|
||||
float getMaxSteerAngle (float speed) const;
|
||||
|
||||
Material* getIconMaterial () const {return m_icon_material; }
|
||||
ssgEntity* getModel () const {return m_model; }
|
||||
const std::string& getName () const {return m_name; }
|
||||
@ -181,7 +180,7 @@ public:
|
||||
float getJumpVelocity () const {return m_jump_velocity; }
|
||||
float getUprightTolerance () const {return m_upright_tolerance; }
|
||||
float getUprightMaxForce () const {return m_upright_max_force; }
|
||||
float getTrackConnectionForce () const {return m_track_connection_accel; }
|
||||
float getTrackConnectionAccel () const {return m_track_connection_accel; }
|
||||
const std::vector<float>&
|
||||
getGearSwitchRatio () const {return m_gear_switch_ratio; }
|
||||
const std::vector<float>&
|
||||
|
@ -18,21 +18,50 @@
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
#include "stk_config.hpp"
|
||||
#if defined(WIN32) && !defined(__CYGWIN__)
|
||||
# define snprintf _snprintf
|
||||
#endif
|
||||
|
||||
#include "file_manager.hpp"
|
||||
#include "lisp/parser.hpp"
|
||||
#include "translation.hpp"
|
||||
#include "audio/music_information.hpp"
|
||||
|
||||
STKConfig* stk_config=0;
|
||||
float STKConfig::UNDEFINED = -99.9f;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void STKConfig::load(const std::string filename)
|
||||
/** Loads the stk configuration file. After loading it checks if all necessary
|
||||
* values are actually defined, otherwise an error message is printed and STK
|
||||
* is aborted.
|
||||
* /param filename Name of the configuration file to load.
|
||||
*/
|
||||
void STKConfig::load(const std::string &filename)
|
||||
{
|
||||
const lisp::Lisp* root = 0;
|
||||
|
||||
// Use the kart properties loader to read in the default kart
|
||||
// values, but don't try to load any models or materials */
|
||||
KartProperties::load(filename, "config",
|
||||
/*dont_load_models */ true,
|
||||
/*dont_load_materials*/ true );
|
||||
try
|
||||
{
|
||||
lisp::Parser parser;
|
||||
root = parser.parse(filename);
|
||||
|
||||
const lisp::Lisp* const LISP = root->getLisp("config");
|
||||
if(!LISP)
|
||||
{
|
||||
char msg[MAX_ERROR_MESSAGE_LENGTH];
|
||||
snprintf(msg, sizeof(msg), "No 'config' node found.");
|
||||
throw std::runtime_error(msg);
|
||||
}
|
||||
getAllData(LISP);
|
||||
}
|
||||
catch(std::exception& err)
|
||||
{
|
||||
fprintf(stderr, "Error while parsing KartProperties '%s':\n",
|
||||
filename.c_str());
|
||||
fprintf(stderr, err.what());
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
delete root;
|
||||
|
||||
// Check that all necessary values are indeed set
|
||||
// -----------------------------------------------
|
||||
@ -41,23 +70,6 @@ void STKConfig::load(const std::string filename)
|
||||
fprintf(stderr,"Missing default value for '%s' in '%s'.\n", \
|
||||
strA,filename.c_str());exit(-1); \
|
||||
}
|
||||
if(m_gear_switch_ratio.size()==0)
|
||||
{
|
||||
fprintf(stderr,"Missing default value for 'gear-switch-ratio' in '%s'.\n",
|
||||
filename.c_str());
|
||||
exit(-1);
|
||||
}
|
||||
if(m_gear_power_increase.size()==0)
|
||||
{
|
||||
fprintf(stderr,"Missing default value for 'gear-power-increase' in '%s'.\n",
|
||||
filename.c_str());
|
||||
exit(-1);
|
||||
}
|
||||
if(m_gear_switch_ratio.size()!=m_gear_power_increase.size()) {
|
||||
fprintf(stderr,"Number of entries for 'gear-switch-ratio' and 'gear-power-increase");
|
||||
fprintf(stderr,"in '%s' must be equal.\n", filename.c_str());
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
if(m_scores.size()==0 || (int)m_scores.size()!=m_max_karts)
|
||||
{
|
||||
@ -76,44 +88,10 @@ void STKConfig::load(const std::string filename)
|
||||
}
|
||||
CHECK_NEG(m_max_karts, "max-karts" );
|
||||
CHECK_NEG(m_grid_order, "grid-order" );
|
||||
|
||||
CHECK_NEG(m_mass, "mass" );
|
||||
CHECK_NEG(m_wheel_base, "wheel-base" );
|
||||
CHECK_NEG(m_engine_power, "engine-power" );
|
||||
CHECK_NEG(m_min_speed_turn, "min-speed-angle" );
|
||||
CHECK_NEG(m_angle_at_min, "min-speed-angle" );
|
||||
CHECK_NEG(m_max_speed_turn, "max-speed-angle" );
|
||||
CHECK_NEG(m_angle_at_max, "max-speed-angle" );
|
||||
CHECK_NEG(m_brake_factor, "brake-factor" );
|
||||
|
||||
CHECK_NEG(m_wheelie_max_speed_ratio, "wheelie-max-speed-ratio" );
|
||||
CHECK_NEG(m_wheelie_max_pitch, "wheelie-max-pitch" );
|
||||
CHECK_NEG(m_wheelie_pitch_rate, "wheelie-pitch-rate" );
|
||||
CHECK_NEG(m_wheelie_restore_rate, "wheelie-restore-rate" );
|
||||
CHECK_NEG(m_wheelie_speed_boost, "wheelie-speed-boost" );
|
||||
CHECK_NEG(m_wheelie_power_boost, "wheelie-power-boost" );
|
||||
|
||||
CHECK_NEG(m_parachute_friction, "parachute-friction" );
|
||||
CHECK_NEG(m_parachute_done_fraction, "parachute-done-fraction" );
|
||||
CHECK_NEG(m_parachute_time, "parachute-time" );
|
||||
CHECK_NEG(m_parachute_time_other, "parachute-time-other" );
|
||||
|
||||
CHECK_NEG(m_time_full_steer, "time-full-steer" );
|
||||
|
||||
//bullet physics data
|
||||
CHECK_NEG(m_suspension_stiffness, "suspension-stiffness" );
|
||||
CHECK_NEG(m_wheel_damping_relaxation, "wheel-damping-relaxation" );
|
||||
CHECK_NEG(m_wheel_damping_compression, "wheel-damping-compression" );
|
||||
CHECK_NEG(m_friction_slip, "friction-slip" );
|
||||
CHECK_NEG(m_roll_influence, "roll-influence" );
|
||||
CHECK_NEG(m_wheel_radius, "wheel-radius" );
|
||||
CHECK_NEG(m_chassis_linear_damping, "chassis-linear-damping" );
|
||||
CHECK_NEG(m_chassis_angular_damping, "chassis-angular-damping" );
|
||||
CHECK_NEG(m_maximum_speed, "maximum-speed" );
|
||||
CHECK_NEG(m_max_speed_reverse_ratio, "max-speed-reverse-ratio" );
|
||||
CHECK_NEG(m_gravity_center_shift[0], "gravity-center-shift" );
|
||||
CHECK_NEG(m_gravity_center_shift[1], "gravity-center-shift" );
|
||||
CHECK_NEG(m_gravity_center_shift[2], "gravity-center-shift" );
|
||||
CHECK_NEG(m_bomb_time, "bomb-time" );
|
||||
CHECK_NEG(m_bomb_time_increase, "bomb-time-increase" );
|
||||
CHECK_NEG(m_anvil_time, "anvil-time" );
|
||||
@ -122,21 +100,12 @@ 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_suspension_rest, "suspension-rest" );
|
||||
CHECK_NEG(m_suspension_travel_cm, "suspension-travel-cm" );
|
||||
CHECK_NEG(m_jump_velocity, "jump-velocity" );
|
||||
CHECK_NEG(m_explosion_impulse, "explosion-impulse" );
|
||||
CHECK_NEG(m_explosion_impulse_objects, "explosion-impulse-objects" );
|
||||
CHECK_NEG(m_upright_tolerance, "upright-tolerance" );
|
||||
CHECK_NEG(m_upright_max_force, "upright-max-force" );
|
||||
CHECK_NEG(m_track_connection_accel, "track-connection-force" );
|
||||
CHECK_NEG(m_camera_max_accel, "camera-max-accel" );
|
||||
CHECK_NEG(m_camera_max_brake, "camera-max-brake" );
|
||||
CHECK_NEG(m_camera_distance, "camera-distance" );
|
||||
CHECK_NEG(m_max_history, "max-history" );
|
||||
CHECK_NEG(m_delay_finish_time, "delay-finish-time" );
|
||||
CHECK_NEG(m_music_credit_time, "music-credit-time" );
|
||||
|
||||
m_kart_properties.checkAllSet(filename);
|
||||
} // load
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
@ -146,31 +115,16 @@ void STKConfig::load(const std::string filename)
|
||||
*/
|
||||
void STKConfig::init_defaults()
|
||||
{
|
||||
m_wheel_base = m_mass =
|
||||
m_min_speed_turn = m_angle_at_min = m_max_speed_turn = m_angle_at_max =
|
||||
m_anvil_weight = m_parachute_friction =
|
||||
m_parachute_time = m_parachute_done_fraction = m_parachute_time_other =
|
||||
m_engine_power = m_brake_factor =
|
||||
m_anvil_speed_factor = m_time_full_steer = m_wheelie_max_pitch =
|
||||
m_wheelie_max_speed_ratio = m_wheelie_pitch_rate =
|
||||
m_wheelie_restore_rate = m_wheelie_speed_boost =
|
||||
m_bomb_time = m_bomb_time_increase= m_anvil_time =
|
||||
m_zipper_time = m_zipper_force = m_zipper_speed_gain =
|
||||
m_shortcut_length = m_music_credit_time = m_delay_finish_time =
|
||||
//bullet physics data
|
||||
m_suspension_stiffness = m_wheel_damping_relaxation =
|
||||
m_wheel_damping_compression = m_friction_slip = m_roll_influence =
|
||||
m_wheel_radius = m_wheelie_power_boost =
|
||||
m_chassis_linear_damping = m_chassis_angular_damping =
|
||||
m_maximum_speed = m_suspension_rest =
|
||||
m_max_speed_reverse_ratio = m_explosion_impulse = m_jump_velocity =
|
||||
m_explosion_impulse_objects = m_upright_tolerance = m_upright_max_force =
|
||||
m_suspension_travel_cm = m_track_connection_accel =
|
||||
// Camera
|
||||
m_camera_max_accel = m_camera_max_brake = m_camera_distance = UNDEFINED;
|
||||
m_gravity_center_shift = Vec3(UNDEFINED);
|
||||
m_front_wheel_connection = Vec3(UNDEFINED);
|
||||
m_rear_wheel_connection = Vec3(UNDEFINED);
|
||||
m_parachute_time = m_parachute_done_fraction =
|
||||
m_parachute_time_other = m_anvil_speed_factor =
|
||||
m_bomb_time = m_bomb_time_increase =
|
||||
m_anvil_time = m_zipper_time =
|
||||
m_zipper_force = m_zipper_speed_gain =
|
||||
m_explosion_impulse = m_explosion_impulse_objects =
|
||||
m_shortcut_length = m_music_credit_time =
|
||||
m_delay_finish_time =
|
||||
UNDEFINED;
|
||||
m_max_karts = -100;
|
||||
m_grid_order = -100;
|
||||
m_max_history = -100;
|
||||
@ -180,6 +134,9 @@ void STKConfig::init_defaults()
|
||||
} // init_defaults
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/** Extracts the actual information from a lisp file.
|
||||
* \param lisp Pointer to the lisp data structure.
|
||||
*/
|
||||
void STKConfig::getAllData(const lisp::Lisp* lisp)
|
||||
{
|
||||
|
||||
@ -214,5 +171,6 @@ void STKConfig::getAllData(const lisp::Lisp* lisp)
|
||||
|
||||
// Get the default KartProperties
|
||||
// ------------------------------
|
||||
KartProperties::getAllData(lisp->getLisp("kart-defaults"));
|
||||
m_kart_properties.getAllData(lisp->getLisp("kart-defaults"));
|
||||
|
||||
} // getAllData
|
||||
|
@ -30,8 +30,10 @@ class MusicInformation;
|
||||
* includes the list of default kart physics parameters which are used for
|
||||
* each kart (but which can be overwritten for each kart, too).
|
||||
*/
|
||||
class STKConfig : public KartProperties
|
||||
class STKConfig
|
||||
{
|
||||
protected:
|
||||
KartProperties m_kart_properties; /**< Default kart properties. */
|
||||
public:
|
||||
static float UNDEFINED;
|
||||
float m_anvil_weight; /**<Additional kart weight if anvil is
|
||||
@ -69,16 +71,22 @@ public:
|
||||
std::vector<float>
|
||||
m_leader_intervals; /**<Interval in follow the leader till
|
||||
last kart is reomved. */
|
||||
std::vector<int> m_scores; /**<Scores depending on position. */
|
||||
std::vector<int>
|
||||
m_scores; /**<Scores depending on position. */
|
||||
|
||||
MusicInformation* m_title_music; /**<Filename of the title music to play.*/
|
||||
std::string m_menu_background; /**<Picture used as menu background. */
|
||||
MusicInformation
|
||||
*m_title_music; /**<Filename of the title music to play.*/
|
||||
std::string
|
||||
m_menu_background; /**<Picture used as menu background. */
|
||||
|
||||
/** Empty constructor. The actual work is done in load. */
|
||||
STKConfig() : KartProperties() {};
|
||||
STKConfig() {};
|
||||
void init_defaults ();
|
||||
void getAllData (const lisp::Lisp* lisp);
|
||||
void load (const std::string filename);
|
||||
void load (const std::string &filename);
|
||||
/** Returns the default kart properties for each kart. */
|
||||
const KartProperties &
|
||||
getDefaultKartProperties() const {return m_kart_properties; }
|
||||
}
|
||||
; // STKConfig
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user