From d32cb733a57000792ff0043a36b3b2a1d826e9a4 Mon Sep 17 00:00:00 2001 From: hiker Date: Wed, 15 Mar 2017 22:30:32 +1100 Subject: [PATCH 01/19] Bugfix, if path was given the filename was not used at all. --- src/audio/sfx_manager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/audio/sfx_manager.cpp b/src/audio/sfx_manager.cpp index e5c1013da..a370d45f6 100644 --- a/src/audio/sfx_manager.cpp +++ b/src/audio/sfx_manager.cpp @@ -593,7 +593,7 @@ SFXBuffer* SFXManager::loadSingleSfx(const XMLNode* node, // to load terrain specific sfx. const std::string full_path = (path == "") ? file_manager->getAsset(FileManager::SFX,filename) - : path; + : path+"/"+filename; SFXBuffer tmpbuffer(full_path, node); From 9a5eec3761f1647f81b5879d993c0ba8ae0584a4 Mon Sep 17 00:00:00 2001 From: hiker Date: Thu, 16 Mar 2017 16:14:48 +1100 Subject: [PATCH 02/19] Try tp reduce sudden rotation after a collision, and reduce frequencies of kart being pushed into the air. --- src/karts/kart.cpp | 5 ++++- src/physics/btKart.cpp | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/karts/kart.cpp b/src/karts/kart.cpp index f8e4972d4..52bcfc89c 100644 --- a/src/karts/kart.cpp +++ b/src/karts/kart.cpp @@ -2043,7 +2043,10 @@ void Kart::crashed(const Material *m, const Vec3 &normal) impulse *= ( abs_speed<10 ? 10.0f : sqrt(abs_speed) ) * m_kart_properties->getCollisionTerrainImpulse(); m_bounce_back_time = 0.2f; - m_vehicle->setTimedCentralImpulse(0.1f, impulse); + m_bounce_back_time = 0.0f;; + impulse = Vec3(0, 0, 0); + //m_vehicle->setTimedCentralImpulse(0.1f, impulse); + m_vehicle->setTimedCentralImpulse(0.0, impulse); } // If there is a quad graph, push the kart towards the previous // graph node center (we have to use the previous point since the diff --git a/src/physics/btKart.cpp b/src/physics/btKart.cpp index d9b3d68b1..1aff3b8be 100644 --- a/src/physics/btKart.cpp +++ b/src/physics/btKart.cpp @@ -675,7 +675,7 @@ void btKart::updateSuspension(btScalar deltaTime) // force is used, which makes it much less likely for the kart to hit // the terrain, while when driving on flat terrain (length small), // there is hardly any difference - length_diff *= f*f; + //length_diff *= f*f; force = wheel_info.m_suspensionStiffness * length_diff * wheel_info.m_clippedInvContactDotSuspension; From 6ac6d9ebfe843f64c34f75986c1853ab33baa755 Mon Sep 17 00:00:00 2001 From: hiker Date: Fri, 17 Mar 2017 15:56:47 +1100 Subject: [PATCH 03/19] Fixed compiler warnings. --- src/karts/kart.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/karts/kart.cpp b/src/karts/kart.cpp index 52bcfc89c..2c42f9020 100644 --- a/src/karts/kart.cpp +++ b/src/karts/kart.cpp @@ -2348,13 +2348,13 @@ void Kart::updateEngineSFX(float dt) if (fc>1.0f) fc = 1.0f; float gears = 3.0f * fmod(fc, 0.333334f); assert(!std::isnan(f)); - m_last_factor_engine_sound = (0.9*f + gears) * 0.35f; + m_last_factor_engine_sound = (0.9f*f + gears) * 0.35f; m_engine_sound->setSpeedPosition(0.6f + m_last_factor_engine_sound, getXYZ()); } else { // When flying, reduce progressively the sound engine (since we can't accelerate) - m_last_factor_engine_sound *= (1.0f-0.1*dt); + m_last_factor_engine_sound *= (1.0f-0.1f*dt); m_engine_sound->setSpeedPosition(0.6f + m_last_factor_engine_sound, getXYZ()); if (m_speed < 0.1f) m_last_factor_engine_sound = 0.0f; } From 5bbacfc72dc89aa6f40d1226497b356e33009562 Mon Sep 17 00:00:00 2001 From: hiker Date: Tue, 21 Mar 2017 16:24:29 +1100 Subject: [PATCH 04/19] Allow tracks to set their friction (defaults to the bullet default 0f 0.5). --- src/physics/triangle_mesh.cpp | 9 +++++++-- src/physics/triangle_mesh.hpp | 3 ++- src/tracks/track.cpp | 4 +++- src/tracks/track.hpp | 5 +++++ 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/physics/triangle_mesh.cpp b/src/physics/triangle_mesh.cpp index 7533c31fa..72ec1456a 100644 --- a/src/physics/triangle_mesh.cpp +++ b/src/physics/triangle_mesh.cpp @@ -174,10 +174,13 @@ void TriangleMesh::createCollisionShape(bool create_collision_object, const char * removed and all objects together with the track is converted again into * a single rigid body. This avoids using irrlicht (or the graphics engine) * for height of terrain detection). - * @param serializedBhv if non-NULL, the bhv is deserialized instead of + * \param friction Friction to be used for this TriangleMesh. + * \param flags Additional collision flags (default 0). + * \param serializedBhv if non-NULL, the bhv is deserialized instead of * being calculated on the fly */ -void TriangleMesh::createPhysicalBody(btCollisionObject::CollisionFlags flags, +void TriangleMesh::createPhysicalBody(float friction, + btCollisionObject::CollisionFlags flags, const char* serializedBhv) { // We need the collision shape, but not the collision object (since @@ -189,6 +192,8 @@ void TriangleMesh::createPhysicalBody(btCollisionObject::CollisionFlags flags, btRigidBody::btRigidBodyConstructionInfo info(0.0f, m_motion_state, m_collision_shape); info.m_restitution = 0.8f; + info.m_friction = friction; + m_body=new btRigidBody(info); Physics::getInstance()->addBody(m_body); diff --git a/src/physics/triangle_mesh.hpp b/src/physics/triangle_mesh.hpp index bd297755c..7480cf859 100644 --- a/src/physics/triangle_mesh.hpp +++ b/src/physics/triangle_mesh.hpp @@ -57,7 +57,8 @@ public: const btVector3 &n2, const btVector3 &n3, const Material* m); void createCollisionShape(bool create_collision_object=true, const char* serialized_bhv=NULL); - void createPhysicalBody(btCollisionObject::CollisionFlags flags= + void createPhysicalBody(float friction, + btCollisionObject::CollisionFlags flags= (btCollisionObject::CollisionFlags)0, const char* serializedBhv = NULL); void removeAll(); diff --git a/src/tracks/track.cpp b/src/tracks/track.cpp index 99c454b7e..84dd6b134 100644 --- a/src/tracks/track.cpp +++ b/src/tracks/track.cpp @@ -480,6 +480,7 @@ void Track::loadTrackInfo() m_fog_height_start = 0.0f; m_fog_height_end = 100.0f; m_gravity = 9.80665f; + m_friction = 0.5f; m_smooth_normals = false; m_godrays = false; m_godrays_opacity = 1.0f; @@ -514,6 +515,7 @@ void Track::loadTrackInfo() getMusicInformation(filenames, m_music); root->get("screenshot", &m_screenshot); root->get("gravity", &m_gravity); + root->get("friction", &m_friction); root->get("soccer", &m_is_soccer); root->get("arena", &m_is_arena); root->get("max-arena-players", &m_max_arena_players); @@ -836,7 +838,7 @@ void Track::createPhysicsModel(unsigned int main_track_count) { convertTrackToBullet(m_all_nodes[i]); } - m_track_mesh->createPhysicalBody(); + m_track_mesh->createPhysicalBody(m_friction); m_gfx_effect_mesh->createCollisionShape(); } // createPhysicsModel diff --git a/src/tracks/track.hpp b/src/tracks/track.hpp index 05658f5d0..a0d5a5adb 100644 --- a/src/tracks/track.hpp +++ b/src/tracks/track.hpp @@ -104,7 +104,12 @@ private: unsigned int m_magic_number; #endif + /* Gravity to be used for this track. */ float m_gravity; + + /** Friction to be used for the track. */ + float m_friction; + std::string m_ident; std::string m_screenshot; bool m_is_day; From f55c39b3b11e3922bf954449bc0bf5592dd7d620 Mon Sep 17 00:00:00 2001 From: hiker Date: Wed, 22 Mar 2017 19:52:03 +1100 Subject: [PATCH 05/19] Support setting of friction for karts, moveable and track in stk_config.xml and kart_characteristics.xml (for now no changed settings, all are at tbe default of 0.5). --- data/kart_characteristics.xml | 2 ++ data/stk_config.xml | 8 +++++++- src/config/stk_config.cpp | 10 ++++++++-- src/config/stk_config.hpp | 7 +++++++ src/karts/abstract_characteristic.cpp | 16 ++++++++++++++++ src/karts/abstract_characteristic.hpp | 5 +++++ src/karts/kart.cpp | 1 + src/karts/kart_properties.cpp | 6 ++++++ src/karts/kart_properties.hpp | 2 ++ src/karts/moveable.cpp | 2 ++ src/karts/xml_characteristic.cpp | 6 ++++++ src/tracks/track.cpp | 2 +- tools/create_kart_properties.py | 3 ++- 13 files changed, 65 insertions(+), 5 deletions(-) diff --git a/data/kart_characteristics.xml b/data/kart_characteristics.xml index 3fbd556d5..f0a56a9ba 100644 --- a/data/kart_characteristics.xml +++ b/data/kart_characteristics.xml @@ -120,6 +120,8 @@ + + diff --git a/data/stk_config.xml b/data/stk_config.xml index b782a1a69..4556f524a 100644 --- a/data/stk_config.xml +++ b/data/stk_config.xml @@ -92,9 +92,15 @@ case (all three normals discarded, the interpolation will just return the normal of the triangle (i.e. de facto no interpolation), but it helps making smoothing much more useful without fixing tracks. + default-track-friction: Default friction to be used for the track and + any track/library pbject. + default-moveable-friction: Default friction to be used for any moveable, + e.g. karts, bowling balls, ... --> + smooth-angle-limit="0.65" + default-track-friction="0.5" + default-moveable-friction="0.5" /> diff --git a/src/config/stk_config.cpp b/src/config/stk_config.cpp index 0f52a462a..add75014f 100644 --- a/src/config/stk_config.cpp +++ b/src/config/stk_config.cpp @@ -138,6 +138,8 @@ void STKConfig::load(const std::string &filename) CHECK_NEG(m_replay_delta_pos2, "replay delta-position" ); CHECK_NEG(m_replay_dt, "replay delta-t" ); CHECK_NEG(m_smooth_angle_limit, "physics smooth-angle-limit" ); + CHECK_NEG(m_default_track_friction, "physics default-track-friction"); + CHECK_NEG(m_default_moveable_friction, "physics default-moveable-friction"); // Square distance to make distance checks cheaper (no sqrt) m_replay_delta_pos2 *= m_replay_delta_pos2; @@ -156,6 +158,7 @@ void STKConfig::init_defaults() m_delay_finish_time = m_skid_fadeout_time = m_near_ground = m_item_switch_time = m_smooth_angle_limit = m_penalty_time = + m_default_track_friction = m_default_moveable_friction = UNDEFINED; m_bubblegum_counter = -100; m_shield_restrict_weapos = false; @@ -239,8 +242,11 @@ void STKConfig::getAllData(const XMLNode * root) if (const XMLNode *physics_node= root->getNode("physics")) { - physics_node->get("smooth-normals", &m_smooth_normals ); - physics_node->get("smooth-angle-limit", &m_smooth_angle_limit); + physics_node->get("smooth-normals", &m_smooth_normals ); + physics_node->get("smooth-angle-limit", &m_smooth_angle_limit ); + physics_node->get("default-track-friction", &m_default_track_friction); + physics_node->get("default-moveable-friction", + &m_default_moveable_friction); } if (const XMLNode *startup_node= root->getNode("startup")) diff --git a/src/config/stk_config.hpp b/src/config/stk_config.hpp index 314144c55..b29d91891 100644 --- a/src/config/stk_config.hpp +++ b/src/config/stk_config.hpp @@ -85,6 +85,13 @@ public: * triangle are more than this value, the physics will use the normal * of the triangle in smoothing normal. */ float m_smooth_angle_limit; + + /** Default friction for the track and any track/library object. */ + float m_default_track_friction; + + /** Default friction to be used for any moveable, e.g. karts, balls. */ + float m_default_moveable_friction; + int m_max_skidmarks; /**getRestitution()); + m_body->setFriction(m_kart_properties->getFrictionKartFriction()); m_user_pointer.set(this); m_body->setDamping(m_kart_properties->getStabilityChassisLinearDamping(), m_kart_properties->getStabilityChassisAngularDamping() ); diff --git a/src/karts/kart_properties.cpp b/src/karts/kart_properties.cpp index 969456079..0bf8e97ed 100644 --- a/src/karts/kart_properties.cpp +++ b/src/karts/kart_properties.cpp @@ -783,6 +783,12 @@ float KartProperties::getParachuteMaxSpeed() const return m_cached_characteristic->getParachuteMaxSpeed(); } // getParachuteMaxSpeed +// ---------------------------------------------------------------------------- +float KartProperties::getFrictionKartFriction() const +{ + return m_cached_characteristic->getFrictionKartFriction(); +} // getFrictionKartFriction + // ---------------------------------------------------------------------------- float KartProperties::getBubblegumDuration() const { diff --git a/src/karts/kart_properties.hpp b/src/karts/kart_properties.hpp index 85624acb9..868c95c07 100644 --- a/src/karts/kart_properties.hpp +++ b/src/karts/kart_properties.hpp @@ -473,6 +473,8 @@ public: float getParachuteUboundFraction() const; float getParachuteMaxSpeed() const; + float getFrictionKartFriction() const; + float getBubblegumDuration() const; float getBubblegumSpeedFraction() const; float getBubblegumTorque() const; diff --git a/src/karts/moveable.cpp b/src/karts/moveable.cpp index c5b918ffa..6af29a679 100644 --- a/src/karts/moveable.cpp +++ b/src/karts/moveable.cpp @@ -20,6 +20,7 @@ #include #include "karts/moveable.hpp" +#include "config/stk_config.hpp" #include "graphics/irr_driver.hpp" #include "graphics/material.hpp" #include "graphics/material_manager.hpp" @@ -170,6 +171,7 @@ void Moveable::createBody(float mass, btTransform& trans, btRigidBody::btRigidBodyConstructionInfo info(mass, m_motion_state, shape, inertia); info.m_restitution = restitution; + info.m_friction = stk_config->m_default_moveable_friction; // Then create a rigid body // ------------------------ diff --git a/src/karts/xml_characteristic.cpp b/src/karts/xml_characteristic.cpp index c548fe791..cda76893c 100644 --- a/src/karts/xml_characteristic.cpp +++ b/src/karts/xml_characteristic.cpp @@ -447,6 +447,12 @@ void XmlCharacteristic::load(const XMLNode *node) &m_values[PARACHUTE_MAX_SPEED]); } + if (const XMLNode *sub_node = node->getNode("friction")) + { + sub_node->get("kart-friction", + &m_values[FRICTION_KART_FRICTION]); + } + if (const XMLNode *sub_node = node->getNode("bubblegum")) { sub_node->get("duration", diff --git a/src/tracks/track.cpp b/src/tracks/track.cpp index 84dd6b134..c03e5d9a8 100644 --- a/src/tracks/track.cpp +++ b/src/tracks/track.cpp @@ -480,7 +480,7 @@ void Track::loadTrackInfo() m_fog_height_start = 0.0f; m_fog_height_end = 100.0f; m_gravity = 9.80665f; - m_friction = 0.5f; + m_friction = stk_config->m_default_track_friction; m_smooth_normals = false; m_godrays = false; m_godrays_opacity = 1.0f; diff --git a/tools/create_kart_properties.py b/tools/create_kart_properties.py index e0ab990bd..15cb253b5 100755 --- a/tools/create_kart_properties.py +++ b/tools/create_kart_properties.py @@ -39,6 +39,7 @@ Jump: animationTime Lean: max, speed Anvil: duration, weight, speedFactor Parachute: friction, duration, durationOther, durationRankMult, durationSpeedMult, lboundFraction, uboundFraction, maxSpeed +Friction: kartFriction Bubblegum: duration, speedFraction, torque, fadeInTime, shieldDuration Zipper: duration, force, speedGain, maxSpeedIncrease, fadeOutTime Swatter: duration, distance, squashDuration, squashSlowdown @@ -245,7 +246,7 @@ functions = { "getName": (createGetName, "Implement the getName function", "karts/abstract_characteristic.cpp"), "kpdefs": (createKpDefs, "Create the header function definitions for the getters", "karts/kart_properties.hpp"), "kpgetter": (createKpGetter, "Implement the getters", "karts/kart_properties.cpp"), - "loadXml": (createLoadXml, "Code to load the characteristics from an xml file", "karts/xml_characteristic.hpp"), + "loadXml": (createLoadXml, "Code to load the characteristics from an xml file", "karts/xml_characteristic.cpp"), } def main(): From b8655e53cce41e891fd546d40da3cfbf09106195 Mon Sep 17 00:00:00 2001 From: hiker Date: Thu, 23 Mar 2017 19:07:34 +1100 Subject: [PATCH 06/19] Added support to modify the angular factor of a kart. The angular factor can be used to reduce the effect of an impulse for roll and pitch - keeping karts more parallel to the ground. --- data/kart_characteristics.xml | 4 ++++ src/karts/abstract_characteristic.cpp | 18 +++++++++++++++++- src/karts/abstract_characteristic.hpp | 2 ++ src/karts/kart.cpp | 4 ++++ src/karts/kart_properties.cpp | 6 ++++++ src/karts/kart_properties.hpp | 1 + src/karts/xml_characteristic.cpp | 2 ++ tools/create_kart_properties.py | 2 +- 8 files changed, 37 insertions(+), 2 deletions(-) diff --git a/data/kart_characteristics.xml b/data/kart_characteristics.xml index f0a56a9ba..320fce54b 100644 --- a/data/kart_characteristics.xml +++ b/data/kart_characteristics.xml @@ -45,6 +45,9 @@ the ground if its off ground. Reduces the affect if a kart loses contact with the ground (i.e. it then can't steer or accelerate anymore). + angular-factor: Factor to change angular impulses. X and Z rotations + are damped to avoid that karts in a collision are too easily pushed + into a roll or pitch, which makes them topple over smooth-flying-impulse: apply a torque impulse to flying kart to keep them parallel to the ground. --> - + From b26d833e8419263051067a7f7bb59cd6a803c3ce Mon Sep 17 00:00:00 2001 From: hiker Date: Fri, 24 Mar 2017 08:41:17 +1100 Subject: [PATCH 08/19] Fixed compiler warnings. --- src/graphics/shader_based_renderer.cpp | 4 ++-- src/input/input_manager.cpp | 4 ++-- src/karts/kart.cpp | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/graphics/shader_based_renderer.cpp b/src/graphics/shader_based_renderer.cpp index b0cd78b38..c1bcba02a 100644 --- a/src/graphics/shader_based_renderer.cpp +++ b/src/graphics/shader_based_renderer.cpp @@ -865,8 +865,8 @@ void ShaderBasedRenderer::render(float dt) irr_driver->getActualScreenSize().Height)); m_current_screen_size = core::vector2df( - irr_driver->getActualScreenSize().Width, - irr_driver->getActualScreenSize().Height); + (float)irr_driver->getActualScreenSize().Width, + (float)irr_driver->getActualScreenSize().Height); for(unsigned int i=0; iaxis_x = -event.AccelerometerEvent.X / 5.0f; + button->axis_x = (float)-event.AccelerometerEvent.X / 5.0f; device->handleControls(button); } else if (UserConfigParams::m_multitouch_accelerometer == 2) { - button->axis_x = event.AccelerometerEvent.Y / 5.0f; + button->axis_x = (float)event.AccelerometerEvent.Y / 5.0f; device->handleControls(button); } } diff --git a/src/karts/kart.cpp b/src/karts/kart.cpp index f8e4972d4..1d17d89e8 100644 --- a/src/karts/kart.cpp +++ b/src/karts/kart.cpp @@ -2345,13 +2345,13 @@ void Kart::updateEngineSFX(float dt) if (fc>1.0f) fc = 1.0f; float gears = 3.0f * fmod(fc, 0.333334f); assert(!std::isnan(f)); - m_last_factor_engine_sound = (0.9*f + gears) * 0.35f; + m_last_factor_engine_sound = (0.9f*f + gears) * 0.35f; m_engine_sound->setSpeedPosition(0.6f + m_last_factor_engine_sound, getXYZ()); } else { // When flying, reduce progressively the sound engine (since we can't accelerate) - m_last_factor_engine_sound *= (1.0f-0.1*dt); + m_last_factor_engine_sound *= (1.0f-0.1f*dt); m_engine_sound->setSpeedPosition(0.6f + m_last_factor_engine_sound, getXYZ()); if (m_speed < 0.1f) m_last_factor_engine_sound = 0.0f; } From 6c35c0847461e2f0049a08a5592855257aad7ee7 Mon Sep 17 00:00:00 2001 From: hiker Date: Fri, 24 Mar 2017 09:58:26 +1100 Subject: [PATCH 09/19] Increased suspensoin stiffness to offset the reduced impulse casued by removing the '*f' factor (seee 9a5eec3761f1647f81b5879d993c0ba8ae0584a4). Otherwise the AI triggers rescue in sandtrack because of very frequent chassis-track collisions. --- data/kart_characteristics.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/kart_characteristics.xml b/data/kart_characteristics.xml index bcca79261..b4542ba97 100644 --- a/data/kart_characteristics.xml +++ b/data/kart_characteristics.xml @@ -34,7 +34,7 @@ http://bulletphysics.org/Bullet/phpBB3/viewtopic.php?f=9&t=7369\&p=25236&hilit=vehicle#p25236 for details. max-force: Maximum suspension force --> -