From 8edf1b6f9e882b6801248ae0561fa06cf1423703 Mon Sep 17 00:00:00 2001 From: hilnius Date: Thu, 18 Jul 2013 13:55:42 +0000 Subject: [PATCH] trying to fix a bug concerning the state modification during asynchronous messages git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/hilnius@13266 178a84e3-b1eb-0310-8ba1-8eac791a3b58 --- doc/protocols.xls | Bin 12288 -> 12288 bytes src/network/protocol_manager.cpp | 6 +++--- src/network/protocols/start_game_protocol.cpp | 9 ++++++++- src/network/protocols/start_game_protocol.hpp | 1 + 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/doc/protocols.xls b/doc/protocols.xls index b7b170c4cfa3fb327c1933281bf2e1663a814315..70ffa359fff8b0afd7d130bf2f0843cc96eaa76a 100644 GIT binary patch delta 341 zcmZojXh_&#&BNF;*@mZ?eF1wV0|P_g=3_jm?AAgI4Bm-FC7}f=i6yB4MfoN9$@w|_ z42%H`ISh#ml?3uu6WNG=nj-R5~>pt8-GMf)*S}-$y-uzRCof!ZHMK*5$ delta 132 zcmZojXh_&#&BGWr*@mZ?J&V1Bfq}t)^D&-OcGmw4TtH@;NG=nj>EPd*rZm-%xE&XNK=cW!FcD| ZzYXUYCo8hZY(AiA!OSSU`KJy$GXQF6AjJRx diff --git a/src/network/protocol_manager.cpp b/src/network/protocol_manager.cpp index 4b8abf4b9..88e64caff 100644 --- a/src/network/protocol_manager.cpp +++ b/src/network/protocol_manager.cpp @@ -62,11 +62,11 @@ ProtocolManager::ProtocolManager() pthread_mutex_lock(&m_exit_mutex); // will let the update function run /// FIXME used on server because mainloop never running - if (NetworkManager::getInstance()->isServer()) + /*if (NetworkManager::getInstance()->isServer()) { m_update_thread = (pthread_t*)(malloc(sizeof(pthread_t))); pthread_create(m_update_thread, NULL, protocolManagerUpdate, this); - } + }*/ // always run this one m_asynchronous_update_thread = (pthread_t*)(malloc(sizeof(pthread_t))); pthread_create(m_asynchronous_update_thread, NULL, protocolManagerAsynchronousUpdate, this); @@ -208,10 +208,10 @@ void ProtocolManager::requestTerminate(Protocol* protocol) void ProtocolManager::startProtocol(ProtocolInfo protocol) { - Log::info("ProtocolManager", "A %s protocol with id=%u has been started. There are %ld protocols running.", typeid(*protocol.protocol).name(), protocol.id, m_protocols.size()+1); // add the protocol to the protocol vector so that it's updated pthread_mutex_lock(&m_protocols_mutex); pthread_mutex_lock(&m_asynchronous_protocols_mutex); + Log::info("ProtocolManager", "A %s protocol with id=%u has been started. There are %ld protocols running.", typeid(*protocol.protocol).name(), protocol.id, m_protocols.size()+1); m_protocols.push_back(protocol); pthread_mutex_unlock(&m_protocols_mutex); pthread_mutex_unlock(&m_asynchronous_protocols_mutex); diff --git a/src/network/protocols/start_game_protocol.cpp b/src/network/protocols/start_game_protocol.cpp index dfebeee3e..7de51d3c8 100644 --- a/src/network/protocols/start_game_protocol.cpp +++ b/src/network/protocols/start_game_protocol.cpp @@ -60,7 +60,8 @@ void StartGameProtocol::notifyEvent(Event* event) { protocol->startCountdown(5000); // 5 seconds countdown Log::info("StartGameProtocol", "All players ready, starting countdown."); - m_state = READY; + m_ready = true; + return; } else Log::error("StartGameProtocol", "The Synchronization protocol hasn't been started."); @@ -77,6 +78,7 @@ void StartGameProtocol::setup() { m_state = NONE; m_ready_count = 0; + m_ready = false; Log::info("SynchronizationProtocol", "Ready !"); } @@ -165,6 +167,10 @@ void StartGameProtocol::update() } else if (m_state == LOADING) { + if (m_ready) + { + m_state = READY; + } } else if (m_state == READY) { @@ -182,6 +188,7 @@ void StartGameProtocol::ready() // on clients, means the loading is finished Log::info("StartGameProtocol", "Player ready, notifying server."); m_listener->sendMessage(this, ns, true); m_state = READY; + return; } else // on the server { diff --git a/src/network/protocols/start_game_protocol.hpp b/src/network/protocols/start_game_protocol.hpp index cbb9c800f..86e066efa 100644 --- a/src/network/protocols/start_game_protocol.hpp +++ b/src/network/protocols/start_game_protocol.hpp @@ -18,6 +18,7 @@ class StartGameProtocol : public Protocol double m_sending_time; STATE m_state; + bool m_ready; public: StartGameProtocol(GameSetup* game_setup);