From b903baf226aee731b0b44a42d2fdc11c4ce60e19 Mon Sep 17 00:00:00 2001 From: Benau Date: Fri, 8 Jul 2016 23:43:12 +0800 Subject: [PATCH 1/4] Fix crash sound only working once if the timer counts backwards --- src/karts/kart.cpp | 4 ++-- src/modes/follow_the_leader.cpp | 9 --------- src/modes/follow_the_leader.hpp | 1 - src/modes/world.cpp | 1 + src/modes/world_status.cpp | 6 +++++- src/modes/world_status.hpp | 6 ++++++ src/states_screens/race_gui_base.cpp | 12 ++---------- 7 files changed, 16 insertions(+), 23 deletions(-) diff --git a/src/karts/kart.cpp b/src/karts/kart.cpp index e79f26911..e3ef86d53 100644 --- a/src/karts/kart.cpp +++ b/src/karts/kart.cpp @@ -1990,9 +1990,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). diff --git a/src/modes/follow_the_leader.cpp b/src/modes/follow_the_leader.cpp index 7b29a8653..626d1260a 100644 --- a/src/modes/follow_the_leader.cpp +++ b/src/modes/follow_the_leader.cpp @@ -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. */ diff --git a/src/modes/follow_the_leader.hpp b/src/modes/follow_the_leader.hpp index 37e395b8f..dcfaa62be 100644 --- a/src/modes/follow_the_leader.hpp +++ b/src/modes/follow_the_leader.hpp @@ -49,7 +49,6 @@ public: 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 *info) OVERRIDE; virtual void init() OVERRIDE; diff --git a/src/modes/world.cpp b/src/modes/world.cpp index 2cbd03982..413c8d3c5 100644 --- a/src/modes/world.cpp +++ b/src/modes/world.cpp @@ -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(); diff --git a/src/modes/world_status.cpp b/src/modes/world_status.cpp index 880a18175..81e066a0e 100644 --- a/src/modes/world_status.cpp +++ b/src/modes/world_status.cpp @@ -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 @@ -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) { diff --git a/src/modes/world_status.hpp b/src/modes/world_status.hpp index 736dcfb6b..0a329d8f9 100644 --- a/src/modes/world_status.hpp +++ b/src/modes/world_status.hpp @@ -114,6 +114,8 @@ private: */ float m_auxiliary_timer; + float m_count_up_timer; + bool m_engines_started; void startEngines(); public: @@ -172,6 +174,10 @@ public: /** 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 diff --git a/src/states_screens/race_gui_base.cpp b/src/states_screens/race_gui_base.cpp index 5d69851e8..03606a355 100644 --- a/src/states_screens/race_gui_base.cpp +++ b/src/states_screens/race_gui_base.cpp @@ -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" @@ -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) From 3d3b7a7de7a9a74b9118a832bd20de77cfd87da0 Mon Sep 17 00:00:00 2001 From: qwertychouskie Date: Sat, 23 Jul 2016 16:12:59 -0700 Subject: [PATCH 2/4] Update deps from INSTALL.md (and put them in alphabetical order.) --- .travis.yml | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5cdbe2ecc..ae4e22d25 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,17 +21,21 @@ addons: apt: packages: - build-essential - - libogg-dev - - libvorbis-dev - - libopenal-dev - - libxxf86vm-dev - - libcurl4-openssl-dev - - libfribidi-dev - - libbluetooth-dev - - libgl1-mesa-dev - - libglu1-mesa-dev - - libglew-dev - cmake + - libbluetooth-dev + - libcurl4-gnutls-dev + - libfreetype6-dev + - libfribidi-dev + - libgl1-mesa-dev + - libjpeg-dev + - libogg-dev + - libopenal-dev + - libpng-dev + - libvorbis-dev + - libxrandr-dev + - mesa-common-dev + - pkg-config + - zlib1g-dev before_script: - export THREADS=$((`nproc` + 1)) From 5a7f3caefd4d2c70ebe83e87401afd832a6a79ab Mon Sep 17 00:00:00 2001 From: Benau Date: Mon, 25 Jul 2016 13:48:41 +0800 Subject: [PATCH 3/4] Fix the rest non-working timer-related function --- src/items/powerup.cpp | 2 +- src/karts/controller/ai_base_controller.cpp | 2 +- src/karts/kart.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/items/powerup.cpp b/src/items/powerup.cpp index 93ef5e802..930c8c1bb 100644 --- a/src/items/powerup.cpp +++ b/src/items/powerup.cpp @@ -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; } diff --git a/src/karts/controller/ai_base_controller.cpp b/src/karts/controller/ai_base_controller.cpp index 085addbaa..ce8307808 100644 --- a/src/karts/controller/ai_base_controller.cpp +++ b/src/karts/controller/ai_base_controller.cpp @@ -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); diff --git a/src/karts/kart.cpp b/src/karts/kart.cpp index e3ef86d53..e19373cdb 100644 --- a/src/karts/kart.cpp +++ b/src/karts/kart.cpp @@ -1000,7 +1000,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 startup_times = m_kart_properties->getStartupTime(); for (unsigned int i = 0; i < startup_times.size(); i++) { From cefead119adcdc3b52d47d2edd225b4b0af14ad3 Mon Sep 17 00:00:00 2001 From: Benau Date: Tue, 26 Jul 2016 08:04:12 +0800 Subject: [PATCH 4/4] Try to use c++11 typeid for getFont --- src/font/font_manager.cpp | 4 ++++ src/font/font_manager.hpp | 20 ++++++++++++-------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/font/font_manager.cpp b/src/font/font_manager.cpp index 772c7de22..df237fb0b 100644 --- a/src/font/font_manager.cpp +++ b/src/font/font_manager.cpp @@ -52,17 +52,21 @@ void FontManager::loadFonts() m_digit_ttf = new FaceTTF(stk_config->m_digit_ttf); // Now load fonts with settings of ttf file + unsigned int font_loaded = 0; RegularFace* regular = new RegularFace(m_normal_ttf); regular->init(); m_fonts.push_back(regular); + m_font_type_map[std::type_index(typeid(RegularFace))] = font_loaded++; BoldFace* bold = new BoldFace(m_normal_ttf); bold->init(); m_fonts.push_back(bold); + m_font_type_map[std::type_index(typeid(BoldFace))] = font_loaded++; DigitFace* digit = new DigitFace(m_digit_ttf); digit->init(); m_fonts.push_back(digit); + m_font_type_map[std::type_index(typeid(DigitFace))] = font_loaded++; } // loadFonts // ---------------------------------------------------------------------------- diff --git a/src/font/font_manager.hpp b/src/font/font_manager.hpp index 68f2118cc..aae90c0f3 100644 --- a/src/font/font_manager.hpp +++ b/src/font/font_manager.hpp @@ -25,6 +25,8 @@ #include "utils/ptr_vector.hpp" #include +#include +#include #include #include FT_FREETYPE_H @@ -35,13 +37,15 @@ class FontWithFace; class FontManager : public NoCopy { private: - PtrVector m_fonts; + PtrVector m_fonts; - FT_Library m_ft_library; + FT_Library m_ft_library; - FaceTTF* m_normal_ttf; + FaceTTF* m_normal_ttf; - FaceTTF* m_digit_ttf; + FaceTTF* m_digit_ttf; + + std::unordered_map m_font_type_map; public: LEAK_CHECK() @@ -53,11 +57,11 @@ public: template T* getFont() { T* out = NULL; - for (unsigned int i = 0; i < m_fonts.size(); i++) + const unsigned int n = m_font_type_map[std::type_index(typeid(T))]; + out = dynamic_cast(m_fonts.get(n)); + if (out != NULL) { - out = dynamic_cast(m_fonts.get(i)); - if (out != NULL) - return out; + return out; } Log::fatal("FontManager", "Can't get a font!"); return out;