From 1c8f2afd28d40134bf6f576f34b3c2bdee4bb690 Mon Sep 17 00:00:00 2001 From: Benau Date: Sat, 3 Nov 2018 16:31:51 +0800 Subject: [PATCH] Don't show thunderbird when waiting for others --- src/modes/world_status.cpp | 6 +++++- src/modes/world_status.hpp | 6 +++++- src/network/protocols/client_lobby.cpp | 1 + src/network/protocols/server_lobby.cpp | 5 +++-- src/states_screens/race_gui_base.cpp | 11 ++++++++++- 5 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/modes/world_status.cpp b/src/modes/world_status.cpp index f1bd80e34..28d270d82 100644 --- a/src/modes/world_status.cpp +++ b/src/modes/world_status.cpp @@ -184,7 +184,7 @@ void WorldStatus::update(int ticks) */ void WorldStatus::updateTime(int ticks) { - switch (m_phase) + switch (m_phase.load()) { // Note: setup phase must be a separate phase, since the race_manager // checks the phase when updating the camera: in the very first time @@ -265,6 +265,10 @@ void WorldStatus::updateTime(int ticks) } return; // Don't increase time case WAIT_FOR_SERVER_PHASE: + { + return; // Don't increase time + } + case SERVER_READY_PHASE: { auto lobby = LobbyProtocol::get(); if (lobby && lobby->isRacing()) diff --git a/src/modes/world_status.hpp b/src/modes/world_status.hpp index d6d99f14b..bccb6b716 100644 --- a/src/modes/world_status.hpp +++ b/src/modes/world_status.hpp @@ -19,6 +19,7 @@ #define HEADER_WORLD_STATUS_HPP #include "utils/cpp2011.hpp" +#include class SFXBase; @@ -49,6 +50,9 @@ public: // 'start'. This happens on a network client only WAIT_FOR_SERVER_PHASE, + // Used in network games only: server is ready + SERVER_READY_PHASE, + // 'Ready' is displayed READY_PHASE, @@ -111,7 +115,7 @@ private: protected: bool m_play_track_intro_sound; bool m_play_ready_set_go_sounds; - Phase m_phase; + std::atomic m_phase; private: diff --git a/src/network/protocols/client_lobby.cpp b/src/network/protocols/client_lobby.cpp index 10e78315d..4a125d010 100644 --- a/src/network/protocols/client_lobby.cpp +++ b/src/network/protocols/client_lobby.cpp @@ -808,6 +808,7 @@ void ClientLobby::connectionRefused(Event* event) */ void ClientLobby::startGame(Event* event) { + World::getWorld()->setPhase(WorldStatus::SERVER_READY_PHASE); uint64_t start_time = event->data().getUInt64(); joinStartGameThread(); m_start_game_thread = std::thread([start_time, this]() diff --git a/src/network/protocols/server_lobby.cpp b/src/network/protocols/server_lobby.cpp index ec5f49fe3..a45765d38 100644 --- a/src/network/protocols/server_lobby.cpp +++ b/src/network/protocols/server_lobby.cpp @@ -2330,9 +2330,9 @@ void ServerLobby::configPeersStartTime() } max_ping = std::max(peer->getAveragePing(), max_ping); } - // Start up time will be after 2000ms, so even if this packet is sent late + // Start up time will be after 2500ms, so even if this packet is sent late // (due to packet loss), the start time will still ahead of current time - uint64_t start_time = STKHost::get()->getNetworkTimer() + (uint64_t)2000; + uint64_t start_time = STKHost::get()->getNetworkTimer() + (uint64_t)2500; NetworkString* ns = getNetworkString(10); ns->addUInt8(LE_START_RACE).addUInt64(start_time); sendMessageToPeers(ns, /*reliable*/true); @@ -2347,6 +2347,7 @@ void ServerLobby::configPeersStartTime() delete ns; m_state = WAIT_FOR_RACE_STARTED; + World::getWorld()->setPhase(WorldStatus::SERVER_READY_PHASE); joinStartGameThread(); m_start_game_thread = std::thread([start_time, this]() { diff --git a/src/states_screens/race_gui_base.cpp b/src/states_screens/race_gui_base.cpp index c5aa9d09f..28491e620 100644 --- a/src/states_screens/race_gui_base.cpp +++ b/src/states_screens/race_gui_base.cpp @@ -43,6 +43,7 @@ #include "modes/capture_the_flag.hpp" #include "modes/linear_world.hpp" #include "modes/world.hpp" +#include "network/network_config.hpp" #include "states_screens/race_gui_multitouch.hpp" #include "tracks/track.hpp" #include "utils/constants.hpp" @@ -434,7 +435,15 @@ void RaceGUIBase::update(float dt) m_referee_height += dt*5.0f; m_referee->selectReadySetGo(2); } - else if(world->getPhase()==World::TRACK_INTRO_PHASE) + else if (world->getPhase()==World::WAIT_FOR_SERVER_PHASE || + (NetworkConfig::get()->isNetworking() && + world->getPhase()==World::TRACK_INTRO_PHASE)) + { + } + else if ((!NetworkConfig::get()->isNetworking() && + world->getPhase()==World::TRACK_INTRO_PHASE) || + (NetworkConfig::get()->isNetworking() && + world->getPhase()==World::SERVER_READY_PHASE)) { m_referee->selectReadySetGo(0); // set red color m_referee_height -= dt*5.0f;