Used functions in stk_config to convert between ticks and times.

This commit is contained in:
hiker 2018-02-23 23:22:49 +11:00
parent cb712411e0
commit 95f0bf9e3b
17 changed files with 105 additions and 98 deletions

View File

@ -58,10 +58,12 @@ public:
* - SAME: give it one more item of the type it currently has.
* - ONLY_IF_SAME: only give it one more item if the randomly chosen item
* has the same type as the currently held item. */
enum {POWERUP_MODE_NEW,
POWERUP_MODE_SAME,
POWERUP_MODE_ONLY_IF_SAME}
m_same_powerup_mode;
enum {
POWERUP_MODE_NEW,
POWERUP_MODE_SAME,
POWERUP_MODE_ONLY_IF_SAME
}
m_same_powerup_mode;
static float UNDEFINED;
float m_bomb_time; /**<Time before a bomb explodes. */
@ -82,9 +84,9 @@ public:
int m_max_karts; /**<Maximum number of karts. */
bool m_smooth_normals; /**< If normals for raycasts for wheels
should be interpolated. */
/** If the angle between a normal on a vertex and the normal of the
* triangle are more than this value, the physics will use the normal
* of the triangle in smoothing normal. */
/** If the angle between a normal on a vertex and the normal of the
* 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. */
@ -93,9 +95,6 @@ public:
/** Default friction to be used for any moveable, e.g. karts, balls. */
float m_default_moveable_friction;
/** Default FPS rate for physics. */
int m_physics_fps;
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
@ -103,9 +102,9 @@ public:
* constraint is disabled to allow for
* more violent explosions. */
int m_min_kart_version, /**<The minimum and maximum .kart file */
m_max_kart_version; /**<version supported by this binary. */
m_max_kart_version; /**<version supported by this binary. */
int m_min_track_version, /**<The minimum and maximum .track file */
m_max_track_version; /**<version supported by this binary. */
m_max_track_version; /**<version supported by this binary. */
int m_max_display_news; /**<How often a news message is displayed
before it is ignored. */
bool m_enable_networking;
@ -124,8 +123,8 @@ public:
used to give a handicap to AIs */
std::vector<float>
m_leader_intervals; /**<Interval in follow the leader till
last kart is reomved. */
m_leader_intervals; /**<Interval in follow the leader till
last kart is reomved. */
float m_leader_time_per_kart; /**< Additional time to each leader
interval for each additional kart. */
std::vector<int> m_switch_items; /**< How to switch items. */
@ -171,12 +170,16 @@ private:
* loaded a user specified config file. */
bool m_has_been_loaded;
/** Default FPS rate for physics. */
int m_physics_fps;
public:
STKConfig();
~STKConfig();
void init_defaults ();
void getAllData (const XMLNode * root);
void load (const std::string &filename);
STKConfig();
~STKConfig();
void init_defaults();
void getAllData(const XMLNode * root);
void load(const std::string &filename);
const std::string &getMainMenuPicture(int n);
const std::string &getBackgroundPicture(int n);
@ -184,7 +187,7 @@ public:
// ------------------------------------------------------------------------
/** Returns the default kart properties for each kart. */
const KartProperties &
getDefaultKartProperties() const {return *m_default_kart_properties; }
getDefaultKartProperties() const { return *m_default_kart_properties; }
// ------------------------------------------------------------------------
/** Returns the kart properties for a certain type of kart.
@ -195,6 +198,15 @@ public:
{
return *m_kart_properties.at(type);
} // getKartProperties
// ------------------------------------------------------------------------
/** Converts a tick value (in physics time step size) into seconds. */
float ticks2Time(int ticks) { return float(ticks)/m_physics_fps; }
// ------------------------------------------------------------------------
/** Converts a time value into ticks (of physics time steps). */
int time2Ticks(float t) { return int(t * m_physics_fps); }
// ------------------------------------------------------------------------
/** Returns the physics frame per seconds rate. */
int getPhysicsFPS() const { return m_physics_fps; }
}
; // STKConfig

View File

@ -921,7 +921,7 @@ SColorf GetPlayerColor(int player_id)
SColorf color_rgb = { 0,0,0,1 };
col.Saturation = col.Saturation * (1.0f / (floorf(player_id / 4) + 1) );
col.Saturation = col.Saturation * (1.0f / (floorf(float(player_id / 4)) + 1) );
col.toRGB(color_rgb);
return color_rgb;
}

View File

@ -401,8 +401,7 @@ void Attachment::hitBanana(Item *item, int new_attachment)
if(m_initial_speed <= 1.5) m_initial_speed = 1.5;
break ;
case 1:
set(ATTACH_ANVIL,
int(kp->getAnvilDuration()*stk_config->m_physics_fps)
set(ATTACH_ANVIL, stk_config->time2Ticks(kp->getAnvilDuration())
+ leftover_ticks );
// if ( m_kart == m_kart[0] )
// sound -> playSfx ( SOUND_SHOOMF ) ;
@ -412,9 +411,8 @@ void Attachment::hitBanana(Item *item, int new_attachment)
m_kart->updateWeight();
break ;
case 2:
set( ATTACH_BOMB,
int(stk_config->m_bomb_time*stk_config->m_physics_fps)
+ leftover_ticks );
set( ATTACH_BOMB, stk_config->time2Ticks(stk_config->m_bomb_time)
+ leftover_ticks );
break ;
} // switch
@ -451,11 +449,11 @@ void Attachment::handleCollisionWithKart(AbstractKart *other)
if (getPreviousOwner() != other || World::getWorld()->getNumKarts() <= 2)
{
// Don't move if this bomb was from other kart originally
other->getAttachment()->set(ATTACH_BOMB,
getTicksLeft()+
int(stk_config->m_bomb_time_increase
*stk_config->m_physics_fps),
m_kart);
other->getAttachment()
->set(ATTACH_BOMB,
getTicksLeft()+stk_config->time2Ticks(
stk_config->m_bomb_time_increase),
m_kart);
other->playCustomSFX(SFXManager::CUSTOM_ATTACH);
clear();
}
@ -472,7 +470,7 @@ void Attachment::handleCollisionWithKart(AbstractKart *other)
}
set(ATTACH_BOMB,
other->getAttachment()->getTicksLeft()+
int(stk_config->m_bomb_time_increase*stk_config->m_physics_fps),
stk_config->time2Ticks(stk_config->m_bomb_time_increase),
other);
other->getAttachment()->clear();
m_kart->playCustomSFX(SFXManager::CUSTOM_ATTACH);
@ -503,17 +501,17 @@ void Attachment::update(float dt)
float m_wanted_node_scale = is_shield
? std::max(1.0f, m_kart->getHighestPoint()*1.1f)
: 1.0f;
int slow_flashes = 3*stk_config->m_physics_fps;
int slow_flashes = stk_config->time2Ticks(3.0f);
if (is_shield && m_ticks_left < slow_flashes)
{
int flashes_per_second = 4;
int ticks_per_flash = stk_config->m_physics_fps / 4;
int ticks_per_flash = stk_config->time2Ticks(0.25f);
int fast_flashes = stk_config->m_physics_fps/2;
int fast_flashes = stk_config->time2Ticks(0.5f);
if (m_ticks_left < fast_flashes)
{
flashes_per_second = 12;
ticks_per_flash = stk_config->m_physics_fps / 12;
ticks_per_flash = stk_config->time2Ticks(1.0f/12);
}
//int divisor = 2;
@ -584,7 +582,7 @@ void Attachment::update(float dt)
// Mesh animation frames are 1 to 61 frames (60 steps)
// The idea is change second by second, counterclockwise 60 to 0 secs
// If longer times needed, it should be a surprise "oh! bomb activated!"
float time_left = float(m_ticks_left) / stk_config->m_physics_fps;
float time_left = stk_config->ticks2Time(m_ticks_left);
if (time_left <= (m_node->getEndFrame() - m_node->getStartFrame() - 1))
{
m_node->setCurrentFrame(m_node->getEndFrame()

View File

@ -268,7 +268,7 @@ void Powerup::use()
case PowerupManager::POWERUP_SWATTER:
m_kart->getAttachment()
->set(Attachment::ATTACH_SWATTER,
int(kp->getSwatterDuration()*stk_config->m_physics_fps));
stk_config->time2Ticks(kp->getSwatterDuration()));
break;
case PowerupManager::POWERUP_BUBBLEGUM:
@ -304,16 +304,16 @@ void Powerup::use()
if (m_kart->getIdent() == "nolok")
{
m_kart->getAttachment()
->set(Attachment::ATTACH_NOLOK_BUBBLEGUM_SHIELD,
int(kp->getBubblegumShieldDuration()
*stk_config->m_physics_fps) );
->set(Attachment::ATTACH_NOLOK_BUBBLEGUM_SHIELD,
stk_config->
time2Ticks(kp->getBubblegumShieldDuration()));
}
else
{
m_kart->getAttachment()
->set(Attachment::ATTACH_BUBBLEGUM_SHIELD,
int(kp->getBubblegumShieldDuration()
*stk_config->m_physics_fps) );
stk_config->
time2Ticks(kp->getBubblegumShieldDuration()));
}
}
else // using a bubble gum while still having a shield
@ -322,17 +322,16 @@ void Powerup::use()
{
m_kart->getAttachment()
->set(Attachment::ATTACH_NOLOK_BUBBLEGUM_SHIELD,
int( (kp->getBubblegumShieldDuration()
+ m_kart->getShieldTime() )
*stk_config->m_physics_fps) );
stk_config->
time2Ticks(kp->getBubblegumShieldDuration()));
}
else
{
m_kart->getAttachment()
->set(Attachment::ATTACH_BUBBLEGUM_SHIELD,
int(kp->getBubblegumShieldDuration()
+ m_kart->getShieldTime() )
*stk_config->m_physics_fps );
stk_config->
time2Ticks(kp->getBubblegumShieldDuration()
+ m_kart->getShieldTime() ) );
}
}
@ -361,8 +360,8 @@ void Powerup::use()
if(kart->getPosition() == 1)
{
kart->getAttachment()->set(Attachment::ATTACH_ANVIL,
int(kp->getAnvilDuration()
*stk_config->m_physics_fps) );
stk_config->
time2Ticks(kp->getAnvilDuration()) );
kart->updateWeight();
kart->adjustSpeed(kp->getAnvilSpeedFactor() * 0.5f);

View File

@ -272,7 +272,7 @@ void RubberBall::init(const XMLNode &node, scene::IMesh *rubberball)
m_st_max_height_difference = 10.0f;
m_st_fast_ping_distance = 50.0f;
m_st_early_target_factor = 1.0f;
m_ticks_between_balls = 15 * stk_config->m_physics_fps;
m_ticks_between_balls = stk_config->time2Ticks(15.0f);
if(!node.get("interval", &m_st_interval))
Log::warn("powerup", "No interval specified for rubber ball.");
@ -309,7 +309,7 @@ void RubberBall::init(const XMLNode &node, scene::IMesh *rubberball)
if(!node.get("time-between-balls", &m_ticks_between_balls))
Log::warn("powerup",
"No time-between-balls specified for rubber ball.");
m_ticks_between_balls *= stk_config->m_physics_fps;
m_ticks_between_balls = stk_config->time2Ticks(float(m_ticks_between_balls));
Flyable::init(node, rubberball, PowerupManager::POWERUP_RUBBERBALL);
} // init

View File

@ -940,7 +940,7 @@ int AbstractCharacteristic::getParachuteDuration() const
if (!is_set)
Log::fatal("AbstractCharacteristic", "Can't get characteristic %s",
getName(PARACHUTE_DURATION).c_str());
return int(result*stk_config->m_physics_fps);
return stk_config->time2Ticks(result);
} // getParachuteDuration
// ----------------------------------------------------------------------------
@ -952,7 +952,7 @@ int AbstractCharacteristic::getParachuteDurationOther() const
if (!is_set)
Log::fatal("AbstractCharacteristic", "Can't get characteristic %s",
getName(PARACHUTE_DURATION_OTHER).c_str());
return int(result*stk_config->m_physics_fps);
return stk_config->time2Ticks(result);
} // getParachuteDurationOther
// ----------------------------------------------------------------------------

View File

@ -237,7 +237,7 @@ void AIBaseController::crashed(const Material *m)
// the track again if it is stuck (i.e. time for the push back plus
// time for the AI to accelerate and hit the terrain again).
const unsigned int NUM_COLLISION = 3;
const int COLLISION_TICKS = 3*stk_config->m_physics_fps/2;
const int COLLISION_TICKS = stk_config->time2Ticks(3.0f);
int ticks = World::getWorld()->getTicksSinceStart();
if(m_collision_ticks.size()==0)
@ -252,7 +252,7 @@ void AIBaseController::crashed(const Material *m)
// collisions to happen). The time of 0.2 seconds was experimentally
// found, typically it takes 0.5 seconds for a kart to be pushed back
// from the terrain and accelerate to hit the same terrain again.
if(5 * (ticks - m_collision_ticks.back()) < stk_config->m_physics_fps)
if(5 * (ticks - m_collision_ticks.back()) < stk_config->time2Ticks(1.0f))
return;
// Remove all outdated entries, i.e. entries that are older than the
@ -260,8 +260,8 @@ void AIBaseController::crashed(const Material *m)
// otherwise a collision that happened (say) 10 seconds ago could
// contribute to a stuck condition.
while(m_collision_ticks.size()>0 &&
ticks - m_collision_ticks[0] > stk_config->m_physics_fps
+COLLISION_TICKS )
ticks - m_collision_ticks[0] > stk_config->time2Ticks(1.0f)
+ COLLISION_TICKS )
m_collision_ticks.erase(m_collision_ticks.begin());
m_collision_ticks.push_back(ticks);

View File

@ -1052,8 +1052,7 @@ void Kart::collectedItem(Item *item, int add_info)
*/
float Kart::getStartupBoost() const
{
float t = float(World::getWorld()->getTicksSinceStart())
/ stk_config->m_physics_fps;
float t = stk_config->ticks2Time(World::getWorld()->getTicksSinceStart());
std::vector<float> startup_times = m_kart_properties->getStartupTime();
for (unsigned int i = 0; i < startup_times.size(); i++)
{
@ -1118,7 +1117,7 @@ void Kart::setShieldTime(float t)
{
if(isShielded())
{
getAttachment()->setTicksLeft(int(t*stk_config->m_physics_fps));
getAttachment()->setTicksLeft(stk_config->time2Ticks(t));
}
} // setShieldTime
@ -1146,9 +1145,8 @@ bool Kart::isShielded() const
*/
float Kart::getShieldTime() const
{
if(isShielded())
return float(getAttachment()->getTicksLeft())
/ stk_config->m_physics_fps;
if (isShielded())
return stk_config->ticks2Time(getAttachment()->getTicksLeft());
else
return 0.0f;
} // getShieldTime

View File

@ -237,8 +237,8 @@ void MainLoop::run()
PROFILER_PUSH_CPU_MARKER("Main loop", 0xFF, 0x00, 0xF7);
left_over_time += getLimitedDt();
int num_steps = int(left_over_time * stk_config->m_physics_fps);
float dt = 1.0f / stk_config->m_physics_fps;
int num_steps = stk_config->time2Ticks(left_over_time);
float dt = stk_config->ticks2Time(1);
left_over_time -= num_steps * dt ;
if (!m_abort && !ProfileWorld::isNoGraphics())

View File

@ -360,8 +360,7 @@ void LinearWorld::newLap(unsigned int kart_index)
{
m_fastest_lap_ticks = ticks_per_lap;
std::string s = StringUtils::timeToString( float(ticks_per_lap)
/ stk_config->m_physics_fps);
std::string s = StringUtils::ticksTimeToString(ticks_per_lap);
// Store the temporary string because clang would mess this up
// (remove the stringw before the wchar_t* is used).

View File

@ -160,7 +160,7 @@ public:
/** Returns time for the fastest laps */
float getFastestLap() const
{
return float(m_fastest_lap_ticks)/stk_config->m_physics_fps;
return stk_config->ticks2Time(m_fastest_lap_ticks);
}
}; // LinearWorld

View File

@ -640,7 +640,7 @@ void ThreeStrikesBattle::spawnSpareTireKarts()
}
// Spawn spare tire kart when necessary
m_next_sta_spawn_time = lifespan*stk_config->m_physics_fps
m_next_sta_spawn_time = stk_config->time2Ticks(lifespan)
+ getTicksSinceStart() * inc_factor
+ getTicksSinceStart();
int kart_has_few_lives = 0;

View File

@ -137,8 +137,8 @@ void WorldStatus::startEngines()
void WorldStatus::setClockMode(const ClockType mode, const float initial_time)
{
m_clock_mode = mode;
m_time_ticks = int(initial_time * stk_config->m_physics_fps);
m_time = float(m_time_ticks) / stk_config->m_physics_fps;
m_time_ticks = stk_config->time2Ticks(initial_time);
m_time = stk_config->ticks2Time(m_time_ticks);
} // setClockMode
//-----------------------------------------------------------------------------
@ -222,18 +222,18 @@ void WorldStatus::updateTime(const float dt)
// long, we use the aux timer to force the next phase
// after 3.5 seconds.
if (m_track_intro_sound->getStatus() == SFXBase::SFX_PLAYING &&
2*m_auxiliary_ticks < 7*stk_config->m_physics_fps)
m_auxiliary_ticks < stk_config->time2Ticks(3.5f) )
return; // Do not increase time
// Wait before ready phase if sounds are disabled
if (!UserConfigParams::m_sfx &&
m_auxiliary_ticks < 3*stk_config->m_physics_fps )
m_auxiliary_ticks < stk_config->time2Ticks(3.0f))
return;
if (!m_play_track_intro_sound)
{
startEngines();
if (m_auxiliary_ticks < 3*stk_config->m_physics_fps)
if (m_auxiliary_ticks < stk_config->time2Ticks(3.0f))
return; // Do not increase time
}
@ -270,8 +270,8 @@ void WorldStatus::updateTime(const float dt)
}
case READY_PHASE:
startEngines();
if (m_auxiliary_ticks > stk_config->m_physics_fps)
// One second
if (m_auxiliary_ticks > stk_config->getPhysicsFPS())
{
if (m_play_ready_set_go_sounds)
{
@ -295,7 +295,7 @@ void WorldStatus::updateTime(const float dt)
return; // Do not increase time
case SET_PHASE:
if (m_auxiliary_ticks > 2*stk_config->m_physics_fps)
if (m_auxiliary_ticks > 2*stk_config->getPhysicsFPS())
{
// set phase is over, go to the next one
m_phase = GO_PHASE;
@ -323,14 +323,14 @@ void WorldStatus::updateTime(const float dt)
return; // Do not increase time
case GO_PHASE :
// 2.5 seconds
if (2*m_auxiliary_ticks>5*stk_config->m_physics_fps &&
if (m_auxiliary_ticks>stk_config->time2Ticks(2.5f) &&
music_manager->getCurrentMusic() &&
!music_manager->getCurrentMusic()->isPlaying())
{
music_manager->startMusic();
}
// how long to display the 'go' message
if (m_auxiliary_ticks > 3 * stk_config->m_physics_fps)
if (m_auxiliary_ticks > 3 * stk_config->getPhysicsFPS())
{
m_phase = MUSIC_PHASE;
}
@ -356,8 +356,8 @@ void WorldStatus::updateTime(const float dt)
UserConfigParams::m_race_now = false;
}
// how long to display the 'music' message
if (m_auxiliary_ticks > stk_config->m_music_credit_time
* stk_config->m_physics_fps )
if (m_auxiliary_ticks >
stk_config->time2Ticks(stk_config->m_music_credit_time) )
{
m_phase = RACE_PHASE;
}
@ -373,8 +373,8 @@ void WorldStatus::updateTime(const float dt)
m_auxiliary_ticks++;
// Change to next phase if delay is over
if (m_auxiliary_ticks > stk_config->m_delay_finish_time
* stk_config->m_physics_fps )
if (m_auxiliary_ticks >
stk_config->time2Ticks(stk_config->m_delay_finish_time))
{
m_phase = RESULT_DISPLAY_PHASE;
terminateRace();
@ -403,7 +403,7 @@ void WorldStatus::updateTime(const float dt)
if (!device->getTimer()->isStopped())
{
m_time_ticks++;
m_time = float(m_time_ticks) / stk_config->m_physics_fps;
m_time = stk_config->ticks2Time(m_time_ticks);
m_count_up_ticks++;
}
break;
@ -420,7 +420,7 @@ void WorldStatus::updateTime(const float dt)
if (!device->getTimer()->isStopped())
{
m_time_ticks--;
m_time = float(m_time_ticks) / stk_config->m_physics_fps;
m_time = stk_config->ticks2Time(m_time_ticks);
m_count_up_ticks++;
}
@ -454,8 +454,8 @@ void WorldStatus::startReadySetGo()
*/
void WorldStatus::setTime(const float time)
{
m_time_ticks = int(time * stk_config->m_physics_fps);
m_time = float(time)/stk_config->m_physics_fps;
m_time_ticks = stk_config->time2Ticks(time);
m_time = stk_config->ticks2Time(m_time_ticks);
} // setTime
//-----------------------------------------------------------------------------

View File

@ -152,8 +152,8 @@ void Physics::update(float dt)
// Maximum of three substeps. This will work for framerate down to
// 20 FPS (bullet default frequency is 60 HZ).
m_dynamics_world->stepSimulation(dt, stk_config->m_physics_fps / 20,
1.0f / stk_config->m_physics_fps);
m_dynamics_world->stepSimulation(dt, stk_config->getPhysicsFPS() / 20,
1.0f / stk_config->getPhysicsFPS());
// Now handle the actual collision. Note: flyables can not be removed
// inside of this loop, since the same flyables might hit more than one

View File

@ -493,8 +493,8 @@ void RaceGUIBase::drawGlobalMusicDescription()
gui::IGUIFont* font = GUIEngine::getFont();
float race_time = float(World::getWorld()->getTicksSinceStart())
/ stk_config->m_physics_fps;
float race_time =
stk_config->ticks2Time(World::getWorld()->getTicksSinceStart());
// ---- Manage pulsing effect
// 3.0 is the duration of ready/set (TODO: don't hardcode)

View File

@ -168,8 +168,9 @@ void addAttachment(Attachment::AttachmentType type)
if (type == Attachment::ATTACH_ANVIL)
{
kart->getAttachment()
->set(type, int(kart->getKartProperties()->getAnvilDuration()
*stk_config->m_physics_fps) );
->set(type,
stk_config->time2Ticks(kart->getKartProperties()
->getAnvilDuration()) );
kart->adjustSpeed(kart->getKartProperties()->getAnvilSpeedFactor());
kart->updateWeight();
}
@ -181,8 +182,7 @@ void addAttachment(Attachment::AttachmentType type)
else if (type == Attachment::ATTACH_BOMB)
{
kart->getAttachment()
->set(type, int(stk_config->m_bomb_time
*stk_config->m_physics_fps) );
->set(type, stk_config->time2Ticks(stk_config->m_bomb_time) );
}
}

View File

@ -495,8 +495,9 @@ namespace StringUtils
/** Returns the time (in seconds) as string, based on ticks. */
std::string ticksTimeToString(int ticks)
{
return timeToString(float(ticks) / stk_config->m_physics_fps);
return timeToString(stk_config->ticks2Time(ticks));
} // ticksTimeToString(ticks)
// ------------------------------------------------------------------------
/** Converts a time in seconds into a string of the form mm:ss:hh (minutes,
* seconds, 1/100 seconds.