Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/fix_timer'
Browse files Browse the repository at this point in the history
  • Loading branch information
Benau committed Jul 25, 2016
2 parents c64733e + 5a7f3ca commit 8c38e9e
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/items/powerup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ void Powerup::hitBonusBox(const Item &item, int add_info)
{
new_powerup = powerup_manager->getRandomPowerup(position, &n);
if(new_powerup != PowerupManager::POWERUP_RUBBERBALL ||
( World::getWorld()->getTime() - powerup_manager->getBallCollectTime()) >
( World::getWorld()->getTimeSinceStart() - powerup_manager->getBallCollectTime()) >
RubberBall::getTimeBetweenRubberBalls() )
break;
}
Expand Down
2 changes: 1 addition & 1 deletion src/karts/controller/ai_base_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ void AIBaseController::crashed(const Material *m)
const unsigned int NUM_COLLISION = 3;
const float COLLISION_TIME = 1.5f;

float time = World::getWorld()->getTime();
float time = World::getWorld()->getTimeSinceStart();
if(m_collision_times.size()==0)
{
m_collision_times.push_back(time);
Expand Down
6 changes: 3 additions & 3 deletions src/karts/kart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1001,7 +1001,7 @@ void Kart::collectedItem(Item *item, int add_info)
*/
float Kart::getStartupBoost() const
{
float t = World::getWorld()->getTime();
float t = World::getWorld()->getTimeSinceStart();
std::vector<float> startup_times = m_kart_properties->getStartupTime();
for (unsigned int i = 0; i < startup_times.size(); i++)
{
Expand Down Expand Up @@ -1991,9 +1991,9 @@ void Kart::crashed(const Material *m, const Vec3 &normal)
*/
void Kart::playCrashSFX(const Material* m, AbstractKart *k)
{
if(World::getWorld()->getTime()-m_time_last_crash < 0.5f) return;
if(World::getWorld()->getTimeSinceStart()-m_time_last_crash < 0.5f) return;

m_time_last_crash = World::getWorld()->getTime();
m_time_last_crash = World::getWorld()->getTimeSinceStart();
// After a collision disable the engine for a short time so that karts
// can 'bounce back' a bit (without this the engine force will prevent
// karts from bouncing back, they will instead stuck towards the obstable).
Expand Down
9 changes: 0 additions & 9 deletions src/modes/follow_the_leader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,6 @@ const btTransform &FollowTheLeaderRace::getStartTransform(int index)
return m_track->getStartTransform(start_index);
} // getStartTransform

//-----------------------------------------------------------------------------
/** Returns the original time at which the countdown timer started. This is
* used by the race_gui to display the music credits in FTL mode correctly.
*/
float FollowTheLeaderRace::getClockStartTime() const
{
return m_leader_intervals[0];
} // getClockStartTime

//-----------------------------------------------------------------------------
/** Called when a kart must be eliminated.
*/
Expand Down
1 change: 0 additions & 1 deletion src/modes/follow_the_leader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ class FollowTheLeaderRace : public LinearWorld
virtual void reset() OVERRIDE;
virtual const std::string& getIdent() const OVERRIDE;
virtual const btTransform &getStartTransform(int index) OVERRIDE;
virtual float getClockStartTime() const;
virtual void getKartsDisplayInfo(
std::vector<RaceGUIBase::KartIconDisplayInfo> *info) OVERRIDE;
virtual void init() OVERRIDE;
Expand Down
1 change: 1 addition & 0 deletions src/modes/world.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,7 @@ World::~World()
race_manager->setRaceGhostKarts(false);
race_manager->setRecordRace(false);
race_manager->setWatchingReplay(false);
race_manager->setTimeTarget(0.0f);

Camera::removeAllCameras();

Expand Down
6 changes: 5 additions & 1 deletion src/modes/world_status.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ void WorldStatus::reset()
{
m_time = 0.0f;
m_auxiliary_timer = 0.0f;

m_count_up_timer = 0.0f;

m_engines_started = false;

// Using SETUP_PHASE will play the track into sfx first, and has no
Expand Down Expand Up @@ -340,16 +341,19 @@ void WorldStatus::update(const float dt)
{
case CLOCK_CHRONO:
m_time += dt;
m_count_up_timer += dt;
break;
case CLOCK_COUNTDOWN:
// stop countdown when race is over
if (m_phase == RESULT_DISPLAY_PHASE || m_phase == FINISH_PHASE)
{
m_time = 0.0f;
m_count_up_timer = 0.0f;
break;
}

m_time -= dt;
m_count_up_timer += dt;

if(m_time <= 0.0)
{
Expand Down
6 changes: 6 additions & 0 deletions src/modes/world_status.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ class WorldStatus
*/
float m_auxiliary_timer;

float m_count_up_timer;

bool m_engines_started;
void startEngines();
public:
Expand Down Expand Up @@ -172,6 +174,10 @@ class WorldStatus
/** Called when the race actually starts. */
virtual void onGo() {};

// ------------------------------------------------------------------------
/** Get the time since start regardless of which way the clock counts */
float getTimeSinceStart() const { return m_count_up_timer; }

}; // WorldStatus


Expand Down
12 changes: 2 additions & 10 deletions src/states_screens/race_gui_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
#include "karts/kart_properties.hpp"
#include "karts/kart_properties_manager.hpp"
#include "karts/rescue_animation.hpp"
#include "modes/follow_the_leader.hpp"
#include "modes/linear_world.hpp"
#include "modes/world.hpp"
#include "tracks/track.hpp"
#include "utils/constants.hpp"
Expand Down Expand Up @@ -457,15 +457,7 @@ void RaceGUIBase::drawGlobalMusicDescription()

gui::IGUIFont* font = GUIEngine::getFont();

float race_time = World::getWorld()->getTime();
// In the modes that the clock counts backwards, convert the
// countdown time to time since start:
if(race_manager->getMinorMode()==RaceManager::MINOR_MODE_FOLLOW_LEADER)
race_time = ((FollowTheLeaderRace*)World::getWorld())->getClockStartTime()
- race_time;
else if (race_manager->getMinorMode()==RaceManager::MINOR_MODE_SOCCER &&
race_manager->hasTimeTarget())
race_time = race_manager->getTimeTarget() - World::getWorld()->getTime();
float race_time = World::getWorld()->getTimeSinceStart();

// ---- Manage pulsing effect
// 3.0 is the duration of ready/set (TODO: don't hardcode)
Expand Down

0 comments on commit 8c38e9e

Please sign in to comment.