Draw music description properly in network

This commit is contained in:
Benau 2019-01-04 14:54:00 +08:00
parent 62ce61d980
commit 7a112ee6ef
4 changed files with 55 additions and 36 deletions

View File

@ -173,7 +173,7 @@
<delay-finish time="1.0"/>
<!-- How long the music credits are shown. -->
<credits music="10"/>
<credits music="8"/>
<!-- time is the time till a bomb explodes. time-increase is the time added
to timer when bomb is passed on. -->

View File

@ -26,7 +26,7 @@
#include "graphics/irr_driver.hpp"
#include "guiengine/modaldialog.hpp"
#include "karts/abstract_kart.hpp"
#include "modes/world.hpp"
#include "modes/profile_world.hpp"
#include "network/network_config.hpp"
#include "network/protocols/client_lobby.hpp"
#include "network/rewind_manager.hpp"
@ -65,7 +65,9 @@ void WorldStatus::reset(bool restart)
m_time_ticks = 0;
m_auxiliary_ticks = 0;
m_count_up_ticks = 0;
m_start_music_ticks = -1;
m_race_ticks = -1;
m_live_join_ticks = -1;
m_engines_started = false;
// Using SETUP_PHASE will play the track into sfx first, and has no
@ -335,6 +337,21 @@ void WorldStatus::updateTime(int ticks)
// event
onGo();
// In artist debug mode, when without opponents,
// skip the ready/set/go counter faster
m_start_music_ticks =
UserConfigParams::m_artist_debug_mode &&
!NetworkConfig::get()->isNetworking() &&
race_manager->getNumberOfKarts() -
race_manager->getNumSpareTireKarts() == 1 &&
race_manager->getTrackName() != "tutorial" ?
stk_config->time2Ticks(0.2f) :
stk_config->time2Ticks(1.0f);
// how long to display the 'music' message
// no graphics mode goes race phase at 3 seconds;
m_race_ticks = ProfileWorld::isNoGraphics() ?
stk_config->time2Ticks(3.0f) :
stk_config->time2Ticks(stk_config->m_music_credit_time);
}
m_auxiliary_ticks++;
@ -352,48 +369,35 @@ void WorldStatus::updateTime(int ticks)
return; // Do not increase time
case GO_PHASE:
// 2.5 seconds
if (m_auxiliary_ticks>stk_config->time2Ticks(2.5f) &&
music_manager->getCurrentMusic() &&
{
if (m_start_music_ticks != -1 &&
m_count_up_ticks >= m_start_music_ticks)
{
m_start_music_ticks = -1;
if (music_manager->getCurrentMusic() &&
!music_manager->getCurrentMusic()->isPlaying())
{
music_manager->startMusic();
}
// how long to display the 'go' message
if (m_auxiliary_ticks > 3 * stk_config->getPhysicsFPS())
{
m_phase = MUSIC_PHASE;
}
m_auxiliary_ticks++;
// In artist debug mode, when without opponents,
// skip the ready/set/go counter faster
if (UserConfigParams::m_artist_debug_mode &&
race_manager->getNumberOfKarts() -
race_manager->getNumSpareTireKarts() == 1 &&
race_manager->getTrackName() != "tutorial")
{
m_auxiliary_ticks += 6;
}
break; // Now the world time starts
}
case MUSIC_PHASE:
{
// Start the music here when starting fast
if (UserConfigParams::m_race_now)
{
music_manager->startMusic();
UserConfigParams::m_race_now = false;
}
// how long to display the 'music' message
if (m_auxiliary_ticks >
stk_config->time2Ticks(stk_config->m_music_credit_time) )
if (m_race_ticks != -1 && m_count_up_ticks >= m_race_ticks)
{
m_race_ticks = -1;
m_phase = RACE_PHASE;
}
m_auxiliary_ticks++;
break;
}
case RACE_PHASE:
// Nothing to do for race phase, switch to delay finish phase
// happens when
@ -465,6 +469,7 @@ void WorldStatus::updateTime(int ticks)
break;
default: break;
} // switch m_phase
} // update
//-----------------------------------------------------------------------------
@ -545,11 +550,14 @@ void WorldStatus::unpause()
*/
void WorldStatus::endLiveJoinWorld(int ticks_now)
{
m_live_join_ticks = ticks_now;
m_live_join_world = false;
m_auxiliary_ticks = 0;
m_phase = RACE_PHASE;
m_phase = MUSIC_PHASE;
m_race_ticks = m_live_join_ticks + stk_config->time2Ticks(
stk_config->m_music_credit_time);
onGo();
startEngines();
music_manager->startMusic();
setTicksForRewind(ticks_now);
setTicksForRewind(m_live_join_ticks);
} // endLiveJoinWorld

View File

@ -130,6 +130,12 @@ private:
*/
int m_auxiliary_ticks;
int m_start_music_ticks;
int m_race_ticks;
int m_live_join_ticks;
/** Special counter to count ticks since start (in terms of physics
* timestep size). */
int m_count_up_ticks;
@ -219,6 +225,12 @@ public:
// ------------------------------------------------------------------------
void setLiveJoinWorld(bool val) { m_live_join_world = val; }
// ------------------------------------------------------------------------
int getMusicDescriptionTicks() const
{
return m_live_join_ticks == -1 ?
m_count_up_ticks : m_count_up_ticks - m_live_join_ticks;
}
// ------------------------------------------------------------------------
void endLiveJoinWorld(int ticks_now);
}; // WorldStatus

View File

@ -527,12 +527,11 @@ void RaceGUIBase::drawGlobalMusicDescription()
gui::IGUIFont* font = GUIEngine::getFont();
float race_time =
stk_config->ticks2Time(World::getWorld()->getTicksSinceStart());
stk_config->ticks2Time(World::getWorld()->getMusicDescriptionTicks());
// ---- Manage pulsing effect
// 3.0 is the duration of ready/set (TODO: don't hardcode)
float timeProgression = (float)(race_time) /
(float)(stk_config->m_music_credit_time - 2.0f);
(float)(stk_config->m_music_credit_time);
const int x_pulse = (int)(sin(race_time*9.0f)*10.0f);
const int y_pulse = (int)(cos(race_time*9.0f)*10.0f);