Made some solver parameters configurable in stk-config.

This commit is contained in:
hiker 2018-06-21 00:31:51 +10:00
parent 5a74ed92e6
commit 2c0d47e511
4 changed files with 86 additions and 10 deletions

View File

@ -101,12 +101,28 @@
any track/library pbject.
default-moveable-friction: Default friction to be used for any moveable,
e.g. karts, bowling balls, ...
solver-iteation: Number of solver iterations. A lower number reduces
the quality, but can reduce bouncing effect.
solver-split-impulse:: by default bullet solves for velocity and
position at the same time, which can introduce bounce. Setting
this to 1 can reduce bounce.
solver-split-impulse-threshold: Penetration threshold for using split
impulse (ignored if solver-split-impulse is false).
solver-mode: Bullet's solver mode is a bit mask. This field takes two
values: the first value is 'and'ed with bullet's default values
(i.e. it can be used to unset bullet defaults), the second value
is 'or'ed (i.e. is used to set a bit). A value of -1 for 'and'
means to keep all bits.
-->
<physics smooth-normals="true"
smooth-angle-limit="0.65"
fps="120"
default-track-friction="0.5"
default-moveable-friction="0.5" />
default-moveable-friction="0.5"
solver-iterations="10"
solver-split-impulse="false"
solver-split-impulse-threshold="-0.02"
solver-mode=""/>
<!-- The title music. -->
<music title="main_theme.music"/>
@ -503,7 +519,7 @@
Use a slow but high quality colour compressor.
kColourClusterFit = (32),
Use a fast but low quality colour compressor.
kColourRangeFit = (64),
kColourRangeFit = (64),
Use a very slow but very high quality colour compressor.
kColourIterativeClusterFit = (256),
STK default the low quality.

View File

@ -158,10 +158,13 @@ void STKConfig::load(const std::string &filename)
CHECK_NEG(m_minimap_ai_icon, "minimap ai_icon" );
CHECK_NEG(m_minimap_player_icon, "minimap player_icon" );
CHECK_NEG(m_smooth_angle_limit, "physics smooth-angle-limit" );
CHECK_NEG(m_default_track_friction, "physics default-track-friction");
CHECK_NEG(m_physics_fps, "physics fps" );
CHECK_NEG(m_network_state_frequeny, "network state-frequency" );
CHECK_NEG(m_default_track_friction, "physics default-track-friction" );
CHECK_NEG(m_physics_fps, "physics fps" );
CHECK_NEG(m_default_moveable_friction, "physics default-moveable-friction");
CHECK_NEG(m_solver_iterations, "physics: solver-iterations" );
CHECK_NEG(m_solver_split_impulse, "physics: solver-split-impulse" );
CHECK_NEG(m_network_state_frequeny, "network solver-state-frequency" );
CHECK_NEG(m_solver_split_impulse_thresh,"physics: solver-split-impulse-threshold");
// Square distance to make distance checks cheaper (no sqrt)
m_default_kart_properties->checkAllSet(filename);
@ -174,11 +177,11 @@ void STKConfig::load(const std::string &filename)
*/
void STKConfig::init_defaults()
{
m_bomb_time = m_bomb_time_increase =
m_explosion_impulse_objects = m_music_credit_time =
m_delay_finish_time = m_skid_fadeout_time =
m_near_ground =
m_smooth_angle_limit = m_default_track_friction =
m_bomb_time = m_bomb_time_increase =
m_explosion_impulse_objects = m_music_credit_time =
m_delay_finish_time = m_skid_fadeout_time =
m_near_ground = m_solver_split_impulse_thresh =
m_smooth_angle_limit = m_default_track_friction =
m_default_moveable_friction = UNDEFINED;
m_item_switch_ticks = -100;
m_penalty_ticks = -100;
@ -202,7 +205,9 @@ void STKConfig::init_defaults()
m_minimap_ai_icon = -100;
m_minimap_player_icon = -100;
m_network_state_frequeny = -100;
m_solver_iterations = -100;
m_title_music = NULL;
m_solver_split_impulse = false;
m_smooth_normals = false;
m_same_powerup_mode = POWERUP_MODE_ONLY_IF_SAME;
m_ai_acceleration = 1.0f;
@ -287,6 +292,11 @@ void STKConfig::getAllData(const XMLNode * root)
physics_node->get("default-moveable-friction",
&m_default_moveable_friction);
physics_node->get("fps", &m_physics_fps );
physics_node->get("solver-iterations", &m_solver_iterations );
physics_node->get("solver-split-impulse", &m_solver_split_impulse );
physics_node->get("solver-split-impulse-threshold",
&m_solver_split_impulse_thresh);
physics_node->get("solver-mode", &m_solver_mode );
}
if (const XMLNode *startup_node= root->getNode("startup"))

View File

@ -107,6 +107,18 @@ public:
/** Default friction to be used for any moveable, e.g. karts, balls. */
float m_default_moveable_friction;
/** Number of solver iterations. */
int m_solver_iterations;
/** If position and velocity constraints are solved separately. */
bool m_solver_split_impulse;
/** Threshold when to use the split impulse approach. */
float m_solver_split_impulse_thresh;
/** */
std::vector<std::string> m_solver_mode;
int m_max_skidmarks; /**<Maximum number of skid marks/kart. */
float m_skid_fadeout_time; /**<Time till skidmarks fade away. */
float m_near_ground; /**<Determines when a kart is not near

View File

@ -74,6 +74,44 @@ void Physics::init(const Vec3 &world_min, const Vec3 &world_max)
0.0f));
m_debug_drawer = new IrrDebugDrawer();
m_dynamics_world->setDebugDrawer(m_debug_drawer);
// Get the solver settings from the config file
btContactSolverInfo& info = m_dynamics_world->getSolverInfo();
info.m_numIterations = stk_config->m_solver_iterations;
info.m_splitImpulse = stk_config->m_solver_split_impulse;
info.m_splitImpulsePenetrationThreshold =
stk_config->m_solver_split_impulse_thresh;
int set_flags=0, reset_flags = 0;
int *p;
for(auto mode : stk_config->m_solver_mode)
{
std::string s = mode;
p = &set_flags;
if (s[0] == '-')
{
s.erase(s.begin());
p = &reset_flags;
}
s = StringUtils::toLowerCase(s);
if (s=="randmize_order" ) *p |= 1;
else if (s=="friction_separate" ) *p |= 2;
else if (s=="use_warmstarting" ) *p |= 4;
else if (s=="use_friction_warmstarting" ) *p |= 8;
else if (s=="use_2_friction_directions" ) *p |= 16;
else if (s=="enable_friction_direction_caching" ) *p |= 32;
else if (s=="disable_velocity_dependent_friction_direction") *p |= 64;
else if (s=="cache_friendly" ) *p |= 128;
else if (s=="simd" ) *p |= 256;
else if (s=="cuda" ) *p |= 512;
else
{
Log::error("STK-Config",
"Unknown option '%s' for solver-mode - ignored.",
s.c_str());
}
}
info.m_solverMode = (info.m_solverMode & (~reset_flags)) | set_flags;
} // init
//-----------------------------------------------------------------------------